Methods
parse(roll) → {Roll|WodRoll|null}
- Source:
- Since:
- v2.0.0
- See:
Parses simplified, classic or WoD roll notation.
Example
parse('2 10 -1'); //=> { dice: 10, count: 2, modifier: -1 }
parse('2d10+1'); //=> { dice: 10, count: 2, modifier: 1 }
parse('4d10!>8f1'); //=> { dice: 10, count: 4, again: true, success: 8, fail: 1 }
parse('xyz'); //=> null
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
parseAndRoll(roll) → {Result|null}
- Source:
- Since:
- v2.0.0
- See:
Parses simplified, classic or WoD roll notation and then rolls the dice.
Example
parseAndRoll('2 10 -1'); //=> { notation: '2d10-1', value: 14, rolls: [ 7, 8 ] }
parseAndRoll('2d10+1'); //=> { notation: '2d10+1', value: 9, rolls: [ 2, 6 ] }
parseAndRoll('4d10!>8f1'); //=> { notation: '4d10!>8f1', value: 2, rolls: [ 3, 10, 7, 9, 5 ] }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
Returns Result for defined parameters, otherwise returns null.
- Type
- Result | null
parseAndRollClassic(roll) → {Result}
- Source:
- Since:
- v2.0.0
- See:
Parses classic notation and then rolls the dice.
Example
parseAndRollClassic('2d10+1'); //=> { notation: '2d10+1', value: 9, rolls: [ 2, 6 ] }
parseAndRollClassic('d6'); //=> { notation: 'd6', value: 3, rolls: [ 3 ] }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
- Type
- Result
parseAndRollSimple(roll) → {Result}
- Source:
- Since:
- v2.0.0
- See:
Parses simple notation and then rolls the dice.
Example
parseAndRollSimple('2 10 -1'); //=> { notation: '2d10-1', value: 14, rolls: [ 7, 8 ] }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
- Type
- Result
parseAndRollWod(roll) → {Result}
- Source:
- Since:
- v2.0.0
- See:
Parses WoD roll notation and then rolls the dice.
Example
parseAndRollWod('2d10>6'); //=> { notation: '2d10>6', value: 1, rolls: [ 5, 10 ] }
parseAndRollWod('4d10!>8f1'); //=> { notation: '4d10!>8f1', value: 2, rolls: [ 3, 10, 7, 9, 5 ] }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
- Type
- Result
parseClassicRoll(roll) → {Roll}
- Source:
- Since:
- v2.0.0
- See:
Parses classic DnD roll notation.
Example
parseClassicRoll('d10'); //=> { dice: 10, count: 1, modifier: 0 }
parseClassicRoll('2d10'); //=> { dice: 10, count: 2, modifier: 0 }
parseClassicRoll('d10+1'); //=> { dice: 10, count: 1, modifier: 1 }
parseClassicRoll('2d10-1'); //=> { dice: 10, count: 2, modifier: -1 }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
- Type
- Roll
parseSimpleRoll(roll) → {Roll}
- Source:
- Since:
- v2.0.0
- See:
Parses simple roll notation (space separated values).
Example
parseSimpleRoll('10'); //=> { dice: 10, count: 1, modifier: 0 }
parseSimpleRoll('2 10'); //=> { dice: 10, count: 2, modifier: 0 }
parseSimpleRoll('2 10 -1'); //=> { dice: 10, count: 2, modifier: -1 }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
- Type
- Roll
parseWodRoll(roll) → {WodRoll}
- Source:
- Since:
- v2.0.0
- See:
Parses World of Darkness (WoD) roll notation.
Example
parseWodRoll('d10>6'); //=> { dice: 10, count: 1, again: false, success: 6, fail: 0 }
parseWodRoll('2d10!>6'); //=> { dice: 10, count: 2, again: true, success: 6, fail: 0 }
parseWodRoll('4d10!>8f1'); //=> { dice: 10, count: 4, again: true, success: 8, fail: 1 }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
String |
Returns:
- Type
- WodRoll
convert(object) → {Roll|WodRoll}
- Source:
- Since:
- v2.1.0
Converts any arguments to Roll or WodRoll object.
If passed argument has again, success or fail property, the function will return WodRoll.
Otherwise, Roll will be returned.
Example
convert({ dice: 6 }); //=> new Roll( 6 )
convert({ modifier: 6 }); //=> new Roll( undefined, undefined, 6 )
convert({ dice: 10, count: 5, success: 5 }); //=> new WodRoll( 10, 5, undefined, 5 )
Parameters:
| Name | Type | Description |
|---|---|---|
object |
Object |
|
Returns:
Result of converion.
random(max) → {Number}
Generates random positive integer from 1 to max.
Example
random(100); //=> 77 - random number from 1 to 100
random(1); //=> 1 - always rolls 1
Parameters:
| Name | Type | Description |
|---|---|---|
max |
Number | maximum possible generated value |
Returns:
Positive integer, from 1 to max
- Type
- Number
rollClassic(roll) → {Result}
Rolls the dice from Roll object.
Example
rollClassic(new Roll(10, 2, -1)); //=> { notation: '2d10-1', value: 14, rolls: [ 7, 8 ] }
rollClassic({ dice: 6 }); //=> { notation: 'd6', value: 4, rolls: [ 4 ] }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
Roll |
|
Returns:
- Type
- Result
rollWod(roll) → {Result}
- Source:
- Since:
- v2.0.0
- See:
Rolls the dice from WodRoll object.
Example
rollWod(new WodRoll(10, 4, true, 8)); //=> { notation: '4d10!>8', value: 2, rolls: [3,10,7,9,5] }
rollWod({ dice: 8, count: 3 }); //=> { notation: '3d8>6', value: 2, rolls: [ 7, 3, 9 ] }
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
WodRoll |
|
Returns:
- Type
- Result
roll(roll) → {Result}
- Source:
- Since:
- v2.0.0
- See:
Rolls the dice from Roll or WodRoll objects.
Example
roll(new Roll(10, 2, -1)); //=> { notation: '2d10-1', value: 14, rolls: [ 7, 8 ] }
roll({ dice: 6 }); //=> { notation: 'd6', value: 4, rolls: [ 4 ] }
roll(new WodRoll(10, 4, true, 8)); //=> { notation: '4d10!>8', value: 2, rolls: [3,10,7,9,5] }
roll({ dice: 8, count: 3, again: true }); //=> { notation: '3d8!>6', value: 2, rolls: [7,3,9 ] }
roll( null ); //=> null
Parameters:
| Name | Type | Description |
|---|---|---|
roll |
Roll | WodRoll | Object |
|
Returns:
Returns Result for defined parameters, otherwise returns null.
- Type
- Result