UNPKG

2.18 kBMarkdownView Raw
1DiceRoll
2====================================
3A simple dice rolling lib for Node, written in Coffee.
4
5Usage
6-----------------
7Clone this repo or install hrough npm:
8 npm install diceroll
9
10Require the class and construct a new dice roll:
11 var DiceRoll = require("diceroll");
12 var roll = new DiceRoll({ dice: 2, sides: 20 });
13 console.log(roll.result());
14
15The dice roll results in a json object with the following:
16 {
17 rolls: [ 17, 5 ],
18 conclusion: 22
19 }
20
21'rolls' contains the result of each die roll, conclusion contains the total result. By default the conclusion is the sum of the roll results, but this can be configured.
22
23Note that the roll is fully initialized upon creation, result merely feeding you the results. Result can as such be called multiple times with the result staying the same. If you want to reroll, make a new DiceRoll.
24
25The following parameters are currently supported:
26 - dice [number] (mandatory): the amount of dice to roll
27 - sides [number] (mandatory): how many sides the dice should have
28 - sum [bool]: Whether the conclusion should summarize the roll results or not
29 - target [number]: If sum is false, the conclusion will instead contain the amount of rolls that reach or exceed this target number.
30
31Example using a target number (6, as is the case in the Vampire: the Masquerade RPG for instance):
32 var roll = new DiceRoll({ dice: 5, sides: 10, sum: false, target: 6 });
33 console.log(roll.result());
34The result yielded could look like this:
35 {
36 rolls: [3, 10, 4, 2, 8],
37 conclusion: 2
38 }
39
40If you wish to run the unit tests for DiceRoll, do so with
41 npm test
42
43Future plans
44----------------------
45These are features that may or may not make it into the code in the foreseeable future:
46 - Exploding dice (dice that reach a certain threshold are re-rolled for additional value)
47 - Ones subtract (in certain RPG systems any 1s rolled reduce the conclusion number)
48 - Multiple types of dice in the same roll (support for rolling "1d10 + 1d8")
49 - Static modifiers (support for rolling "1d6 +2")
50
51Contribution
52-----------------------
53The licence for this software is found in LICENCE.txt. Pull requests and issues are always welcome.