RPTools.net

Discussion and Support

Skip to content

It is currently Fri Jul 28, 2017 11:51 am 






Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject: HERO System dice
PostPosted: Wed Jul 04, 2007 2:03 am 
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?


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Wed Jul 04, 2007 2:11 am 
I'll just go ahead and post it here for now:
Code:
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.


Top
 Profile  
 
User avatar  Offline
RPTools Founder
 
Joined: Tue Jan 31, 2006 11:10 am
Posts: 277
Location: Austin, TX
 Post subject:
PostPosted: Thu Jul 05, 2007 9:29 am 
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


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Thu Jul 05, 2007 11:35 am 
Thanks! I'll check those out and see if I can figure out how to get the above script into DiceTool.


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Sun Jul 08, 2007 3:31 am 
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


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Mon Jul 09, 2007 10:45 pm 
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


Top
 Profile  
 
User avatar  Offline
Codeum Arcanum (RPTools Founder)
 
Joined: Mon Jan 09, 2006 4:16 pm
Posts: 11390
Location: Austin, Tx
 Post subject:
PostPosted: Mon Jul 09, 2007 11:31 pm 
I'll bug giliath about responding ;)

_________________
Dreaming of a 1.3 release


Top
 Profile  
 
User avatar  Offline
RPTools Founder
 
Joined: Tue Jan 31, 2006 11:10 am
Posts: 277
Location: Austin, TX
 Post subject:
PostPosted: Tue Jul 10, 2007 10:06 am 
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:
function registerFunctions() {
    var map = new java.util.HashMap();
    map.put("fnord", fnord);

    return map;
}

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

_________________
~Giliath


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Tue Jul 10, 2007 11:46 am 
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


Top
 Profile  
 
User avatar  Offline
Codeum Arcanum (RPTools Founder)
 
Joined: Mon Jan 09, 2006 4:16 pm
Posts: 11390
Location: Austin, Tx
 Post subject:
PostPosted: Tue Jul 10, 2007 1:11 pm 
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


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Tue Jul 10, 2007 1:19 pm 
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


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Fri Sep 07, 2007 10:13 pm 
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


Top
 Profile  
 
User avatar  Offline
Giant
 
Joined: Fri Mar 02, 2007 3:18 am
Posts: 129
 Post subject:
PostPosted: Tue Sep 18, 2007 12:02 am 
I'll second a request for Hero Dice.


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Jul 01, 2007 12:23 am
Posts: 2821
 Post subject:
PostPosted: Tue Sep 18, 2007 1:00 am 
Hehe, Keith! When did you sneak in here? :)

_________________
You're just jealous 'cause the voices only talk to me.

ImageImage


Top
 Profile  
 
 Offline
Cave Troll
 
Joined: Wed Aug 15, 2007 7:11 am
Posts: 83
 Post subject:
PostPosted: Tue Sep 18, 2007 8:32 am 
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...


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman