World of Darkness Roller

Thoughts, Help, Feature Requests

Moderators: Azhrei, dorpond, giliath

Post Reply
hellfur
Kobold
Posts: 2
Joined: Wed May 08, 2013 11:35 pm

World of Darkness Roller

Post by hellfur »

First post, but if you're using the DiceTool and playing New World of Darkness, then I figured I should share this function.

To use, paste the code at end of this post into a "functions.js" file in the same directory as your dicetool-1.0*.jar file. This will give you a new function called wodRoll. The first argument is the number of dice, then the number to re-roll (in case you're playing 8/9/10 again), and finally a 'chance roll' boolean (where 0 is false, and anything else is true).

The total number of successes is given at the top, followed by each die roll. Blue rows are successes, green rows accrue an extra die (/reroll), and black rows show a Dramatic Failure (only in chance rolls).

This means you can put the following rolls in your tabs:

Code: Select all

wodRoll(4)
This will roll 4d10, and reroll any 10s.

Code: Select all

wodRoll(4, 8)
This will roll 4d10s, and reroll any 8s, 9s, or 10s.

Code: Select all

wodRoll(1, 10, 1)
This will roll a chance roll, rerolling 10s (only a 10 is a success, 1s come out as black)

Code: Select all

wodRoll(1, 8, 1)
This will roll a chance roll, but reroll 8s, 9s, or 10s (Still only 10 is success)

Code: Select all

wodRoll(10, 8, 1)
As above. The number of dice are ignored on a chance roll.

You can also combine that function and some constants, if you'd like, by using:

Code: Select all

wodRoll(4) + 4
Roll 4d10, reroll any 10s, add 4 to the total number of successes

The code to paste in your functions.js file follows. Enjoy!

Code: Select all


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

function wodRoll(numDice, rerollAt, isChanceRoll) {
   row.setLabel("Successes:");
   
   if (!rerollAt) {
      rerollAt = 10;
   }
   
   // Can only roll one, regardless of what they way.
   if (isChanceRoll) {
      numDice = 1;
   }
   
   var originalDice = numDice;
   var successes = 0;
   for (var i = 0; i < numDice; i++) {
      var value = rand.nextInt(10) + 1;
      
      resultSet.addExpression("Die " + (i + 1) + (i >= originalDice ? ' (Extra die!)' : ''), value + '', null, value);
      var innerRow = resultSet.getCurrentRow();
      
      if (isChanceRoll) {
         if (value == 10) {
            // If chance roll, only 10s are successes.
            //  10s give another chance.
            successes++;
            numDice++;
            innerRow.setBackgroundColor(0, 0, 255);
            innerRow.setForegroundColor(255, 255, 255);
         }
         if (value == 1) {
            innerRow.setBackgroundColor(0, 0, 0);
            innerRow.setForegroundColor(255, 255, 255);
         }
      } else {
         if (value >= 8) {
            successes++;
            innerRow.setBackgroundColor(0, 0, 255);
            innerRow.setForegroundColor(255, 255, 255);
         }
         if (value >= rerollAt) {
            numDice++;
            innerRow.setBackgroundColor(0, 255, 0);
            innerRow.setForegroundColor(0, 0, 0);
         }
      }
      innerRow.setTotal(successes);
   }
   
   return successes;
}


hellfur
Kobold
Posts: 2
Joined: Wed May 08, 2013 11:35 pm

Re: World of Darkness Roller

Post by hellfur »

Oops. I pasted an older version of that file. It will work for most cases, but doesn't reroll on anything lower than 10 in chance rolls. The following fixes that.

Code: Select all

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

function wodRoll(numDice, rerollAt, isChanceRoll) {
   row.setLabel("Successes:");
   
   if (!rerollAt) {
      rerollAt = 10;
   }
   
   // Can only roll one, regardless of what they want.
   if (isChanceRoll) {
      numDice = 1;
   }
   
   var originalDice = numDice;
   var successes = 0;
   for (var i = 0; i < numDice; i++) {
      var value = rand.nextInt(10) + 1;
      
      resultSet.addExpression("Die " + (i + 1) + (i >= originalDice ? ' (Extra die!)' : ''), value + '', null, value);
      var innerRow = resultSet.getCurrentRow();
      
      if (isChanceRoll) {
         // Anything at or above rerollAt gives another die, but is not a success.
         if (value >= rerollAt) {
            numDice++;
         }
         if (value == 10) {
            // If chance roll, only 10s are successes.
            successes++;
            innerRow.setBackgroundColor(0, 0, 255);
            innerRow.setForegroundColor(255, 255, 255);
         }
         if (value == 1) {
            innerRow.setBackgroundColor(0, 0, 0);
            innerRow.setForegroundColor(255, 255, 255);
         }
      } else {
         if (value >= 8) {
            successes++;
            innerRow.setBackgroundColor(0, 0, 255);
            innerRow.setForegroundColor(255, 255, 255);
         }
         if (value >= rerollAt) {
            numDice++;
            innerRow.setBackgroundColor(0, 255, 0);
            innerRow.setForegroundColor(0, 0, 0);
         }
      }
      innerRow.setTotal(successes);
   }
   
   return successes;
}

User avatar
wolph42
Deity
Posts: 9709
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: World of Darkness Roller

Post by wolph42 »

Hi, thanks for sharing. Note that you can always update the original post (op). Which is good practice to do here!

Post Reply

Return to “DiceTool”