DiceTerm

DiceTerm

An abstract base class for any term which appears in a dice roll formula

Constructor

(abstract) new DiceTerm(termData)

Source:
Parameters:
Name Type Description
termData object

Data used to create the Dice Term, including the following:

Properties
Name Type Description
number number

The number of dice of this term to roll, before modifiers are applied

faces number

The number of faces on each die of this type

modifiers Array.<string>

An array of modifiers applied to the results

options object

Additional options that modify the term

Members

(static) DENOMINATION

Source:

Define the denomination string used to register this Dice type in CONFIG.Dice.terms

(static) FLAVOR_TEXT_REGEX :string

Source:

A regular expression pattern which identifies part-specific flavor text

Type:
  • string

(static) MODIFIER_REGEX :RegExp

Source:

A regular expression pattern which identifies a potential DiceTerm modifier

Type:
  • RegExp

(static) MODIFIERS :Object

Source:

Define the modifiers that can be used for this particular DiceTerm type.

Type:
  • Object

(static) MODIFIERS_REGEX :string

Source:

A regular expression pattern which indicates the end of a DiceTerm

Type:
  • string

faces :number

Source:

The number of faces on the die

Type:
  • number

formula

Source:

Return a standardized representation for the displayed formula associated with this DiceTerm

modifiers :Array.<string>

Source:

An Array of dice term modifiers which are applied

Type:

number :number

Source:

The number of dice of this term to roll, before modifiers are applied

Type:
  • number

options :object

Source:

An object of additional options which modify the dice term

Type:
  • object

results :Array.<object>

Source:

The array of dice term results which have been rolled

Type:

total :number|null

Source:

Return the total result of the DiceTerm if it has been evaluated

Type:
  • number | null

values :Array.<number>

Source:

Return an array of rolled values which are still active within this term

Type:

Methods

(static) _applyCount()

Source:

A reusable helper function to handle the identification and deduction of failures

(static) _applyDeduct()

Source:

A reusable helper function to handle the identification and deduction of failures

(static) _keepOrDrop(results, number, keepopt, highestopt) → {Array.<object>}

Source:

A helper method to modify the results array of a dice term by flagging certain results are kept or dropped.

Parameters:
Name Type Attributes Description
results Array.<object>

The results array

number number

The number to keep or drop

keep boolean <optional>

Keep results?

highest boolean <optional>

Keep the highest?

Returns:

The modified results array

Type
Array.<object>

(static) compareResult(result, comparison, target) → {boolean}

Source:

A helper comparison function. Returns a boolean depending on whether the result compares favorably against the target.

Parameters:
Name Type Description
result number

The result being compared

comparison string

The comparison operator in [=,<,<=,>,>=]

target number

The target value

Returns:

Is the comparison true?

Type
boolean

(static) fromData(data) → {DiceTerm}

Source:

Construct a DiceTerm from a provided data object

Parameters:
Name Type Description
data object

Provided data from an un-serialized term

Returns:

The constructed DiceTerm

Type
DiceTerm

(static) fromExpression(expression, options) → {DiceTerm|null}

Source:

Parse a provided roll term expression, identifying whether it matches this type of term.

Parameters:
Name Type Description
expression string
options object

Additional term options

Returns:

The constructed DiceTerm instance

Type
DiceTerm | null

(static) fromJSON(json) → {DiceTerm}

Source:

Reconstruct a DiceTerm instance from a provided JSON string

Parameters:
Name Type Description
json string

A serialized JSON representation of a DiceTerm

Returns:

A reconstructed DiceTerm from the provided JSON

Type
DiceTerm

(static) fromResults(options, results) → {DiceTerm}

Source:

Create a "fake" dice term from a pre-defined array of results

Example
let d = new Die({faces: 6, number: 4, modifiers: ["r<3"]});
d.evaluate();
let d2 = Die.fromResults({faces: 6, number: 4, modifiers: ["r<3"]}, d.results);
Parameters:
Name Type Description
options object

Arguments used to initialize the term

results Array.<object>

An array of pre-defined results

Returns:
Type
DiceTerm

(static) getResultLabel(result) → {string}

Source:

Return a string used as the label for each rolled result

Parameters:
Name Type Description
result string

The numeric result

Returns:

The result label

Type
string

(static) matchTerm(expression) → {RegExpMatchArray|null}

Source:

Check if the expression matches this type of term

Parameters:
Name Type Description
expression string
Returns:
Type
RegExpMatchArray | null

alter(multiply, add) → {DiceTerm}

Source:

Alter the DiceTerm by adding or multiplying the number of dice which are rolled

Parameters:
Name Type Description
multiply number

A factor to multiply. Dice are multiplied before any additions.

add number

A number of dice to add. Dice are added after multiplication.

Returns:

The altered term

Type
DiceTerm

evaluate(minimizeopt, maximizeopt) → {DiceTerm}

Source:

Evaluate the roll term, populating the results Array.

Parameters:
Name Type Attributes Description
minimize boolean <optional>

Apply the minimum possible result for each roll.

maximize boolean <optional>

Apply the maximum possible result for each roll.

Returns:

The evaluated dice term

Type
DiceTerm

roll(minimizeopt, maximizeopt) → {object}

Source:

Roll the DiceTerm by mapping a random uniform draw against the faces of the dice term.

Parameters:
Name Type Attributes Description
minimize boolean <optional>

Apply the minimum possible result instead of a random result.

maximize boolean <optional>

Apply the maximum possible result instead of a random result.

Returns:
Type
object

toJSON() → {object}

Source:

Serialize the DiceTerm 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.

Returns:
Type
object