Data used to create the Dice Term, including the following:
Optional
faces?: number | RollThe number of faces on each die of this type, or a Roll instance that will be evaluated to a number.
The resolution method used to resolve DiceTerm.
Optional
modifiers?: string[]An array of modifiers applied to the results
Optional
number?: number | RollThe number of dice of this term to roll, before modifiers are applied, or a Roll instance that will be evaluated to a number.
Optional
options?: objectAdditional options that modify the term
Optional
results?: DiceTermResult[]An optional array of pre-cast results for the term
Internal
_rootA reference to the Roll at the root of the evaluation tree.
Is this term intermediate, and should be evaluated first as part of the simplification process?
An Array of dice term modifiers which are applied
An object of additional options which describes and modifies the term.
The array of dice term results which have been rolled
Protected
_facesThe number of faces on the die, or a Roll instance that will be evaluated to a number.
Protected
_numberThe number of dice of this term to roll, before modifiers are applied, or a Roll instance that will be evaluated to a number.
Static
DENOMINATIONDefine the denomination string used to register this DiceTerm type in CONFIG.Dice.terms
Static
FLAVOR_A regular expression which identifies term-level flavor text
Static
FLAVOR_A regular expression pattern which identifies optional term-level flavor text
Static
MODIFIER_A regular expression used to separate individual modifiers
Static
MODIFIERSDefine the named modifiers that can be applied for this particular DiceTerm type.
Static
MODIFIERS_A regular expression pattern which captures the full set of term modifiers Anything until a space, group symbol, or arithmetic operator
Static
REGEXPA regular expression used to match a term of this type
Static
SERIALIZE_An array of additional attributes which should be retained when the term is serialized
The denomination of this DiceTerm instance.
An array of additional DiceTerm instances involved in resolving this DiceTerm.
A string representation of the formula expression for this RollTerm, prior to evaluation.
The number of faces on the die. Returns undefined if the faces are represented as a complex term that has not yet been evaluated.
Optional flavor text which modifies and describes this term.
A string representation of the formula, including optional flavor text.
Whether this term is entirely deterministic or contains some randomness.
The resolution method used to resolve this DiceTerm.
The number of dice of this term to roll. Returns undefined if the number is a complex term that has not yet been evaluated.
A reference to the RollResolver app being used to externally resolve this term.
A string or numeric representation of the final output for this term, after evaluation.
Return an array of rolled values which are still active within this term
Internal
Asynchronously evaluate a single modifier command, recording it in the array of evaluated modifiers
The parsed modifier command
The full modifier request
Internal
Sequentially evaluate each dice roll modifier by passing the term to its evaluation function Augment or modify the results array.
Alter the DiceTerm by adding or multiplying the number of dice which are rolled
A factor to multiply. Dice are multiplied before any additions.
A number of dice to add. Dice are added after multiplication.
The altered term
Count the number of even results which occurred in a given result set. Even numbers are marked as a success and counted as 1 Odd numbers are marked as a non-success and counted as 0.
6d6even Count the number of even numbers rolled
The matched modifier query (unused here, but passed to overrides anyway)
Count the number of failed results which occurred in a given result set. Failures are counted relative to some target, or relative to the lowest possible value if no target is given. Applying a count-failures modifier to the results re-casts all results to 1 (failure) or 0 (non-failure)
6d6cf Count the number of dice which rolled a 1 as failures 6d6cf<=3 Count the number of dice which rolled less than 3 as failures 6d6cf>4 Count the number of dice which rolled greater than 4 as failures
The matched modifier query
Count the number of odd results which occurred in a given result set. Odd numbers are marked as a success and counted as 1 Even numbers are marked as a non-success and counted as 0.
6d6odd Count the number of odd numbers rolled
The matched modifier query (unused here, but passed to overrides anyway)
Count the number of successful results which occurred in a given result set. Successes are counted relative to some target, or relative to the maximum possible value if no target is given. Applying a count-success modifier to the results re-casts all results to 1 (success) or 0 (failure)
20d20cs Count the number of dice which rolled a 20 20d20cs>10 Count the number of dice which rolled higher than 10 20d20cs<10 Count the number of dice which rolled less than 10
The matched modifier query
Deduct the number of failures from the dice result, counting each failure as -1 Failures are identified relative to some target, or relative to the lowest possible value if no target is given. Applying a deduct-failures modifier to the results counts all failed results as -1.
6d6df Subtract the number of dice which rolled a 1 from the non-failed total. 6d6cs>3df Subtract the number of dice which rolled a 3 or less from the non-failed count. 6d6cf<3df Subtract the number of dice which rolled less than 3 from the non-failed count.
The matched modifier query
Drop a certain number of highest or lowest dice rolls from the result set.
20d20d Drop the 1 lowest die 20d20dh Drop the 1 highest die 20d20dl Drop the 1 lowest die 20d20dh10 Drop the 10 highest die 20d20dl10 Drop the 10 lowest die
The matched modifier query
Evaluate the term, processing its inputs and finalizing its total.
Optional
options: { allowStrings?: boolean; maximize?: boolean; minimize?: boolean } = {}Options which modify how the RollTerm is evaluated
Optional
allowStrings?: booleanIf true, string terms will not throw an error when evaluated.
Optional
maximize?: booleanMaximize the result, obtaining the largest possible value.
Optional
minimize?: booleanMinimize the result, obtaining the smallest possible value.
Returns a Promise if the term is non-deterministic.
Explode the Die, rolling additional results for any values which match the target set. If no target number is specified, explode the highest possible result. Explosion can be a "small explode" using a lower-case x or a "big explode" using an upper-case "X"
The matched modifier query
Explode recursively, such that new rolls can also explode?
False if the modifier was unmatched.
Get the CSS classes that should be used to display each rolled result
The rolled result
The desired classes
Return a string used as the label for each rolled result
The rolled result
The result label
Render the tooltip HTML for a Roll instance
The data object used to render the default tooltip template for this DiceTerm
Keep a certain number of highest or lowest dice rolls from the result set.
20d20k Keep the 1 highest die 20d20kh Keep the 1 highest die 20d20kh10 Keep the 10 highest die 20d20kl Keep the 1 lowest die 20d20kl10 Keep the 10 lowest die
The matched modifier query
Maps a randomly-generated value in the interval [0, 1) to a face value on the die.
A value to map. Must be in the interval [0, 1).
The face value.
Subtract the total value of the DiceTerm from a target value, treating the difference as the final total. Example: 6d6ms>12 Roll 6d6 and subtract 12 from the resulting total.
The matched modifier query
Constrain each rolled result to be at most some maximum value. Example: 6d6max5 Roll 6d6, each result must be at most 5
The matched modifier query
Constrain each rolled result to be at least some minimum value. Example: 6d6min2 Roll 6d6, each result must be at least 2
The matched modifier query
Generate a random face value for this die using the configured PRNG.
Re-roll the Die, rolling additional results for any values which fall within a target set. If no target number is specified, re-roll the lowest possible result.
20d20r reroll all 1s 20d20r1 reroll all 1s 20d20r=1 reroll all 1s 20d20r1=1 reroll a single 1
The matched modifier query
Reroll recursively, continuing to reroll until the condition is no longer met
False if the modifier was unmatched
Roll the DiceTerm by mapping a random uniform draw against the faces of the dice term.
Optional
options: { maximize?: boolean; minimize?: boolean } = {}Options which modify how a random result is produced
Optional
maximize?: booleanMaximize the result, obtaining the largest possible value.
Optional
minimize?: booleanMinimize the result, obtaining the smallest possible value.
The produced result
Subtract the value of failed dice from the non-failed total, where each failure counts as its negative value. Failures are identified relative to some target, or relative to the lowest possible value if no target is given. Applying a deduct-failures modifier to the results counts all failed results as -1.
6d6df<3 Subtract the value of results which rolled less than 3 from the non-failed total.
The matched modifier query
Serialize the RollTerm to a JSON string which allows it to be saved in the database or embedded in text. This method should return an object suitable for passing to the JSON.stringify function.
Protected
_evaluateProtected
Evaluate this dice term asynchronously.
Optional
options: object = {}Options forwarded to inner Roll evaluation.
Protected
_evaluateProtected
Evaluate deterministic values of this term synchronously.
Optional
options: { maximize?: boolean; minimize?: boolean; strict?: boolean } = {}Optional
maximize?: booleanForce the result to be maximized.
Optional
minimize?: booleanForce the result to be minimized.
Optional
strict?: booleanThrow an error if attempting to evaluate a die term in a way that cannot be done synchronously.
Protected
_rollProtected
Generate a roll result value for this DiceTerm based on its fulfillment method.
Optional
options: object = {}Options forwarded to the fulfillment method handler.
Returns a Promise that resolves to the fulfilled number, or undefined if it could not be fulfilled.
Static
_applyA reusable helper function to handle the identification and deduction of failures
Static
_applyA reusable helper function to handle the identification and deduction of failures
Static
_fromDefine term-specific logic for how a de-serialized data object is restored as a functional RollTerm
The de-serialized term data
The re-constructed RollTerm object
Static
_keepA helper method to modify the results array of a dice term by flagging certain results are kept or dropped.
The results array
The number to keep or drop
Optional
options: { highest?: boolean; keep?: boolean } = {}Optional
highest?: booleanKeep the highest?
Optional
keep?: booleanKeep results?
The modified results array
Static
compareA helper comparison function. Returns a boolean depending on whether the result compares favorably against the target.
The result being compared
The comparison operator in [=,<,<=,>,>=]
The target value
Is the comparison true?
Static
fromConstruct a RollTerm from a provided data object
Provided data from an un-serialized term
The constructed RollTerm
Static
fromJSONReconstruct a RollTerm instance from a provided JSON string
A serialized JSON representation of a DiceTerm
A reconstructed RollTerm from the provided JSON
Static
fromConstruct a term of this type given a matched regular expression array.
The matched regular expression array
The constructed term
Static
fromStatic
isDetermine if evaluating a given RollTerm with certain evaluation options can be done so deterministically.
The term.
Optional
options: { maximize?: boolean; minimize?: boolean } = {}Options for evaluating the term.
Optional
maximize?: booleanForce the result to be maximized.
Optional
minimize?: booleanForce the result to be minimized.
Static
matchDetermine whether a string expression matches this type of term
The expression to parse
Optional
options: { imputeNumber?: boolean } = {}Additional options which customize the match
Optional
imputeNumber?: booleanAllow the number of dice to be optional, i.e. "d6"
A type of DiceTerm used to represent rolling a fair n-sided die.
Example: Roll four six-sided dice