RollGroup
RollGroup
A RollGroup
is a group of one or more "sub-rolls".
A sub-roll is just simple roll notation (e.g. 4d6
, 2d10*3
, 5/10d20
)
Kind: global class
Since: 4.5.0
- RollGroup
- new RollGroup([expressions], [modifiers], [description])
- .expressions ⇒
Array.<Array.<(StandardDice|string|number)>>
- .expressions
- .modifiers ⇒
Map.<string, Modifier>
|null
- .modifiers
- .notation ⇒
string
- .roll() ⇒
ResultGroup
- .toJSON() ⇒
Object
- .toString() ⇒
string
new RollGroup([expressions], [modifiers], [description])
Create a RollGroup
instance.
Param | Type | Default | Description |
---|---|---|---|
[expressions] | Array.<Array.<(StandardDice|string|number)>> | [] | List of sub-rolls |
[modifiers] | Map.<string, Modifier> | Array.<Modifier> | Object | null | [] | The modifiers that affect the group |
[description] | Description | string | null |
| The roll description. |
Example (`{4d6+4, 2d%/5}k1`)
const expressions = [
[
new StandardDice(6, 4),
'+',
4,
],
[
new PercentileDice(2),
'/',
5,
],
];
const modifiers = [
new KeepModifier(),
];
const group = new RollGroup(expressions, modifiers);
Array.<Array.<(StandardDice|string|number)>>
rollGroup.expressions ⇒ The sub-roll expressions in the group.
Kind: instance property of RollGroup
rollGroup.expressions
Set the sub-roll expressions in the group.
Kind: instance property of RollGroup
Throws:
TypeError
Expressions must be an array of arraysTypeError
Sub expressions cannot be emptyTypeError
Sub expression items must be Dice, numbers, or strings
Param | Type |
---|---|
expressions | Array.<Array.<(StandardDice|string|number)>> |
Map.<string, Modifier>
| null
rollGroup.modifiers ⇒ The modifiers that affect the object.
Kind: instance property of RollGroup
rollGroup.modifiers
Set the modifiers that affect this group.
Kind: instance property of RollGroup
Throws:
TypeError
Modifiers should be a Map, array of Modifiers, or an Object
Param | Type |
---|---|
value | Map.<string, Modifier> | Array.<Modifier> | Object | null |
string
rollGroup.notation ⇒ The group notation. e.g. {4d6, 2d10+3}k1
.
Kind: instance property of RollGroup
ResultGroup
rollGroup.roll() ⇒ Run the sub-roll expressions for the group.
Kind: instance method of RollGroup
Returns: ResultGroup
- The results of the sub-rolls
Example (`{4d6+4/1d6, 2d10/3}k1`)
ResultGroup {
results: [
// sub-roll 1 - 4d6+4/1d6
ResultGroup {
results: [
RollResults {
rolls: [
RollResult {
value: 2
},
RollResult {
value: 5
},
RollResult {
value: 4
},
RollResult {
value: 1
}
]
},
'+',
4,
'/',
RollResults {
rolls: [
RollResult {
value: 4
}
]
}
]
},
// sub-roll 2 - 2d10/3
ResultGroup {
results: [
RollResults {
rolls: [
RollResults {
4
},
RollResults {
9
}
]
},
'/',
3
]
}
]
}
Object
rollGroup.toJSON() ⇒ Return an object for JSON serialising.
This is called automatically when JSON encoding the object.
Kind: instance method of RollGroup
string
rollGroup.toString() ⇒ Return the String representation of the object.
This is called automatically when casting the object to a string.