HERO System dice

Thoughts, Help, Feature Requests

Moderators: dorpond, Azhrei, giliath

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

HERO System dice

Post by RPMiller »

If I were to provide the java script for HERO dice, where would I put it and would it be possible to get it integrated at least into the DiceTool, but ultimately into MapTool so that it could be used in chat?

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

I'll just go ahead and post it here for now:

Code: Select all

public static String roll(String rollString) {
        String orig = rollString;
        StringBuffer ret = new StringBuffer();
        SimpleDateFormat formatter = new SimpleDateFormat(
                "EEEEE, MMMMM d, yyyy hh:mm:ss.SSS aaa");
        rollString = rollString.toUpperCase().trim();
        if (rollString.startsWith("LOCATION")) {
            int add = 0;
            int dice = 3;
            if (!rollString.equals("LOCATION")) {
                String check = rollString.substring(8);
                check = check.trim();
                if (check.startsWith(",")) {
                    check = check.substring(1).trim();
                    if (check.equals("HEAD")) {
                        add = 3;
                        dice = 1;
                    } else if (check.equals("HIGH")) {
                        add = 1;
                        dice = 2;
                    } else if (check.equals("BODY")) {
                        add = 4;
                        dice = 2;
                    } else if (check.equals("LOW")) {
                        add = 7;
                        dice = 2;
                    } else if (check.equals("LEG")) {
                        add = 12;
                        dice = 1;
                    } else {
                        return orig;
                    }
                } else if (check.startsWith("+")) {
                    check = check.substring(1).trim();
                    try {
                        add = Integer.parseInt(check);
                    } catch (Exception exp) {
                        return orig;
                    }
                } else if (check.startsWith("-")) {
                    try {
                        add = Integer.parseInt(check);
                    } catch (Exception exp) {
                        return orig;
                    }
                } else {
                    return orig;
                }
            }
            int total = add;
            for (int i = 0; i < dice; i++) {
                int die = (int) Math.ceil(Math.random() * 6);
                total += die;
            }
            if (total <= 5) {
                ret.append(orig + ": " + total + " = Head");
            } else if (total <= 6) {
                ret.append(orig + ": " + total + " = Hands");
            } else if (total <= 8) {
                ret.append(orig + ": " + total + " = Arms");
            } else if (total <= 9) {
                ret.append(orig + ": " + total + " = Shoulders");
            } else if (total <= 11) {
                ret.append(orig + ": " + total + " = Chest");
            } else if (total <= 12) {
                ret.append(orig + ": " + total + " = Stomach");
            } else if (total <= 13) {
                ret.append(orig + ": " + total + " = Vitals");
            } else if (total <= 14) {
                ret.append(orig + ": " + total + " = Thighs");
            } else if (total <= 16) {
                ret.append(orig + ": " + total + " = Legs");
            } else {
                ret.append(orig + ": " + total + " = Feet");
            }
        } else if (rollString.equals("ROLL")) {
            int total = 0;
            for (int i = 0; i < 3; i++) {
                int die = (int) Math.ceil(Math.random() * 6);
                total += die;
            }
            ret.append("roll: " + total);
        } else if (rollString.startsWith("HIT, OCV")) {
            String ocvString = rollString.substring(8, rollString.length());
            int ocv = 0;
            if (ocvString.length() < 1) {
                return orig;
            }
            try {
                ocv = Integer.parseInt(ocvString.trim());
            } catch (Exception exp) {
                return orig;
            }
            int total = 0;
            for (int i = 0; i < 3; i++) {
                int die = (int) Math.ceil(Math.random() * 6);
                total += die;
            }
            int dcvHit = 11 + ocv - total;
            if (dcvHit < 0 || total == 18) {
                ret.append(orig + ": (" + total + ", automatically misses)");
            }
            ret.append(orig + ": (" + total + ", hits DCV " + dcvHit
                    + " or lower)");
        } else if (rollString.startsWith("HIT, ECV")) {
            String ocvString = rollString.substring(8, rollString.length());
            int ocv = 0;
            if (ocvString.length() < 1) {
                return orig;
            }
            try {
                ocv = Integer.parseInt(ocvString.trim());
            } catch (Exception exp) {
                return orig;
            }
            int total = 0;
            for (int i = 0; i < 3; i++) {
                int die = (int) Math.ceil(Math.random() * 6);
                total += die;
            }
            int dcvHit = 11 + ocv - total;
            if (dcvHit < 0 || total == 18) {
                ret.append(orig + ": (" + total + ", automatically misses)");
            }
            ret.append(orig + ": (" + total + ", hits ECV " + dcvHit
                    + " or lower)");
        } else if (rollString.lastIndexOf("-") == rollString.length() - 1) {
            int total = 0;
            for (int i = 0; i < 3; i++) {
                int die = (int) Math.ceil(Math.random() * 6);
                total += die;
            }
            if (rollString.lastIndexOf(",") <= 0) {
                return orig;
            }
            String lim = rollString.substring(rollString.lastIndexOf(",") + 1,
                    rollString.lastIndexOf("-"));

            int limit = 0;
            try {
                limit = Integer.parseInt(lim.trim());
            } catch (Exception exp) {
                return orig;
            }
            String passfail = "succeeded";
            int madeBy = 0;
            if (total <= limit) {
                madeBy = limit - total;
            } else {
                passfail = "failed";
                madeBy = total - limit;
            }
            ret.append(orig + ": (" + total + ", " + passfail + " by " + madeBy
                    + ")");
        } else {
            // time to parse it out...
            if (rollString.indexOf("D") <0> rollString.indexOf("D")) {
                return orig;
            }
            String x = rollString.substring(0, rollString.indexOf("D"));
            double dice = 0d;
            try {
                dice = Double.parseDouble(x);
            } catch (Exception exp) {
                return orig;
            }
            if (dice <0> 1000) {
                return orig;
            }
            rollString = rollString.substring(rollString.indexOf("D") + 1,
                    rollString.length());
            StringBuffer y = new StringBuffer();
            int counter = 0;
            while (rollString.length() > counter
                    && Character.isDigit(rollString.charAt(counter))) {
                y.append(rollString.charAt(counter));
                counter++;
            }
            if (y.length() == 0) {
                return orig;
            }
            int sides = 0;
            try {
                sides = Integer.parseInt(y.toString());
            } catch (Exception exp) {
                return orig;
            }
            if (sides <0> 1000) {
                return orig;
            }
            rollString = rollString.substring(counter, rollString.length());
            int bonus = 0;
            if (rollString.length() > 1
                    && rollString.substring(0, 2).equals("+1")) {
                bonus = 1;
                rollString = rollString.substring(2, rollString.length());
            } else if (rollString.length() > 1
                    && rollString.substring(0, 2).equals("-1")) {
                bonus = -1;
                rollString = rollString.substring(2, rollString.length());
            }

            boolean killing = false;
            boolean explosion = false;
            boolean knockback = false;
            int stunMult = -1;
            int fadeRate = 2;
            int kbDice = 0;
            if (rollString.length() > 0 && rollString.charAt(0) == 'K') {
                killing = true;
                rollString = rollString.substring(1, rollString.length());
                if (rollString.length() > 0 && rollString.charAt(0) == '+') {
                    counter = 0;
                    rollString = rollString.substring(1, rollString.length());
                    StringBuffer z = new StringBuffer();
                    while (rollString.length() > counter
                            && Character.isDigit(rollString.charAt(counter))) {
                        z.append(rollString.charAt(counter));
                        counter++;
                    }
                    if (z.length() == 0) {
                        return orig;
                    }
                    try {
                        stunMult = Integer.parseInt(z.toString()) - 1;
                    } catch (Exception exp) {
                        return orig;
                    }
                    rollString = rollString.substring(counter, rollString
                            .length());
                } else if (rollString.length() > 0
                        && rollString.charAt(0) == '-') {
                    counter = 0;
                    rollString = rollString.substring(1, rollString.length());
                    StringBuffer z = new StringBuffer();
                    while (rollString.length() > counter
                            && Character.isDigit(rollString.charAt(counter))) {
                        z.append(rollString.charAt(counter));
                        counter++;
                    }
                    if (z.length() == 0) {
                        return orig;
                    }
                    try {
                        stunMult = (-1 * Integer.parseInt(z.toString())) - 1;
                    } catch (Exception exp) {
                        return orig;
                    }
                    rollString = rollString.substring(counter, rollString
                            .length());
                }
            }
            if (rollString.length() > 2
                    && rollString.substring(0, 2).equals("EX")) {
                explosion = true;
                rollString = rollString.substring(2, rollString.length());
                if (rollString.length() == 0) {
                    return orig;
                }
                try {
                    fadeRate = Integer.parseInt(rollString);
                } catch (Exception exp) {
                    return orig;
                }
                if (fadeRate <0> 0) {
                return orig;
            }
            if ((killing || explosion || knockback) && sides != 6) {
                return orig;
            }

            // pant....it's parsed....now for the rolling and results.
            int total = 0;
            List<Integer> rolls = new ArrayList<Integer>();
            int partialDie = 0;
            int body = 0;
            int stun = 0;
            for (int i = 0; i <Math> 1)
                    body += 1;
                if (die > 5)
                    body += 1;
            }
            if (Math.floor(dice) < dice - .000001) {
                double partial = dice - Math.floor(dice);
                BigDecimal bd = new BigDecimal(partial
                        * Math.ceil(Math.random() * sides));
                if (bd.intValue() <1> 1)
                    body += 1;
                if (bd.intValue() > 5)
                    body += 1;
            }
            total += bonus;
            stun = total;
            if (killing) {
                body = total;
                int mult = (int) Math.ceil(Math.random() * sides) + (stunMult);
                if (mult <1> 1 || (rolls.size() > 0 && partialDie > 0)) {
                counter = 0;
                rollsShown = true;
                for (int roll : rolls) {
                    if (counter > 0)
                        ret.append(", ");
                    ret.append(roll);
                    counter++;
                }
                if (partialDie > 0) {
                    if (rolls.size() > 0) {
                        ret.append(" + ");
                    }
                    ret.append(partialDie);
                }
                ret.append(" ");
            }
            if (explosion) {
                if (partialDie != 0)
                    rolls.add(partialDie);
                Collections.sort(rolls);
                for (int i = 0; i < rolls.size(); i++) {
                    if (rollsShown) {
                        ret.append("<br>");
                        ret.append("&nbsp;&nbsp;&nbsp;&nbsp;");
                    }
                    ret.append((fadeRate * i) + "\": ");
                    int tot = bonus;
                    int st = 0;
                    int bd = 0;
                    for (int j = 0; j <rolls> 1)
                            bd += 1;
                        if (rolls.get(j) > 5)
                            bd += 1;
                    }
                    st = tot;
                    if (killing) {
                        bd = tot;
                        st = bd * stunMult;
                        ret.append(bd + " BODY, " + st + " STUN");
                    } else {
                        ret.append(st + " STUN, " + bd + " BODY");
                    }
                }
            } else if (killing) {
                if (rollsShown)
                    ret.append("(");
                ret.append(body + " BODY, " + stun + " STUN");
                if (rollsShown)
                    ret.append(")");
            } else {
                if (rollsShown)
                    ret.append("(");
                if (sides == 6)
                    ret.append(stun + " STUN, " + body + " BODY");
                else if (rollsShown)
                    ret.append(stun + " TOTAL");
                else
                    ret.append(stun + "");
                if (rollsShown)
                    ret.append(")");
            }
        }
        ret.append(" <span>" + formatter.format(new Date())
                + "</span>");
        return ret.toString();
    }

I can get the origin code for this as well if that would be better.

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

DiceTool can be extended with javascript. There is a functions.js file in the root when you download the zip version that can be replaced. There are a couple of examples in the current file.

Here are a couple of forums that talk about it.

http://forums.rptools.net/viewtopic.php ... javascript

http://forums.rptools.net/viewtopic.php ... javascript

For MapTool, we will be adding the javascript support sometime around version 2.0 (which we will start on as soon as we finish 1.3).

Thanks
~Giliath

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

Thanks! I'll check those out and see if I can figure out how to get the above script into DiceTool.

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

Ok, I've looked and looked and unzipped the download, and looked and I can not find this functions.js file that you speak of.

Can you point me to the link to the zip that contains the functions.js file?
You're just jealous 'cause the voices only talk to me.

ImageImage

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

I finally found functions.js. Now I will try to figure out how to modify the jscript to work with DT.

EDIT: Ok, nevermind. None of the functions.js links have an associated file. Every time I try to download it I get nothing. I appears to be a 0 byte file.
You're just jealous 'cause the voices only talk to me.

ImageImage

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Post by trevor »

I'll bug giliath about responding ;)
Dreaming of a 1.3 release

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

Ok, I played with this last night.

Download the zip file download from here: http://rptools.net/dist/zip/dicetool-1.0.b34.zip.

Drop a functions.js into the root (beside the .jar file). Here is an example: http://rptools.svn.sourceforge.net/view ... nctions.js.

Something like this:

Code: Select all

function registerFunctions() {
    var map = new java.util.HashMap();
    map.put("fnord", fnord);

    return map;
}

function fnord(a) {
    row.setLabel("Fnord");
    return a;
}
~Giliath

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

I've done the above, and now I need to figure out how to actually implement the dice roller code. So far I haven't found any documentation on how to actually call a function from DiceTool, add a button that will do it, or load it into DiceTool. Once I get over that hurdle I'll be much closer.
You're just jealous 'cause the voices only talk to me.

ImageImage

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Post by trevor »

I believe that just loading DiceTool will load the functions, then in the roll area, just call the function.
Dreaming of a 1.3 release

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

Hmm... Aha! You have to add a tab first and then you can call the function. Very good. Now then to figure out if I can use the code above... I suspect I won't be able to as it is jscript, but it is worth a shot while I wait.

Trevor, thanks for the PM I may take you up on your offer depending on what I hear back.
You're just jealous 'cause the voices only talk to me.

ImageImage

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

Just checking in to see if there has been any progress on getting the Hero dice working.
You're just jealous 'cause the voices only talk to me.

ImageImage

User avatar
keithcurtis
Giant
Posts: 129
Joined: Fri Mar 02, 2007 3:18 am
Contact:

Post by keithcurtis »

I'll second a request for Hero Dice.

User avatar
RPMiller
Demigod
Posts: 2555
Joined: Sun Jul 01, 2007 1:23 am

Post by RPMiller »

Hehe, Keith! When did you sneak in here? :)
You're just jealous 'cause the voices only talk to me.

ImageImage

GoOrange
Cave Troll
Posts: 82
Joined: Wed Aug 15, 2007 8:11 am

Post by GoOrange »

They don't call him The Ubiquitous Keith for nothing!

OK, I just made that up, but it's funny how the same people pop up on multiple different forums like Hero, Fear the Boot, RPtools...

Post Reply

Return to “DiceTool”