DiceTerm

DiceTerm

An abstract base class for any type of RollTerm which involves randomized input from dice, coins, or other devices.

Constructor

new DiceTerm(termData)

Parameters:
Name Type Description
termData object

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

Properties
Name Type Attributes Default Description
number number <optional>
1

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> <optional>

An array of modifiers applied to the results

results Array.<object> <optional>

An optional array of pre-cast results for the term

options object <optional>

Additional options that modify the term

Extends

Members

_evaluated :boolean

Overrides:

An internal flag for whether the term has been evaluated

Type:
  • boolean

DENOMINATION :string

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

Type:
  • string

expression :string

Overrides:

A string representation of the formula expression for this RollTerm, prior to evaluation.

Type:
  • string

faces :number

The number of faces on the die

Type:
  • number

flavor :string

Overrides:

Optional flavor text which modifies and describes this term.

Type:
  • string

FLAVOR_REGEXP :RegExp

Overrides:

A regular expression which identifies term-level flavor text

Type:

FLAVOR_REGEXP_STRING :string

Overrides:

A regular expression pattern which identifies optional term-level flavor text

Type:
  • string

formula :string

Overrides:

A string representation of the formula, including optional flavor text.

Type:
  • string

isIntermediate :boolean

Overrides:

Is this term intermediate, and should be evaluated first as part of the simplification process?

Type:
  • boolean

MODIFIER_REGEXP :RegExp

A regular expression used to separate individual modifiers

Type:

modifiers :Array.<string>

An Array of dice term modifiers which are applied

Type:

MODIFIERS :Object

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

Type:
  • Object

MODIFIERS_REGEXP_STRING :string

A regular expression pattern which captures the full set of term modifiers Anything until a space, group symbol, or arithmetic operator

Type:
  • string

number :number

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

Type:
  • number

options :object

Overrides:

An object of additional options which describes and modifies the term.

Type:
  • object

REGEXP :RegExp

Overrides:

A regular expression used to match a term of this type

Type:

results :Array.<DiceTermResult>

The array of dice term results which have been rolled

Type:

SERIALIZE_ATTRIBUTES :Array.<string>

Overrides:

An array of additional attributes which should be retained when the term is serialized

Type:

total :number|string

Overrides:

A string or numeric representation of the final output for this term, after evaluation.

Type:
  • number | string

values :Array.<number>

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

Type:

Methods

(static) _applyCount()

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

(static) _applyDeduct()

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

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

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}

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) fromMatch(match) → {DiceTerm}

Construct a term of this type given a matched regular expression array.

Parameters:
Name Type Description
match RegExpMatchArray

The matched regular expression array

Returns:

The constructed term

Type
DiceTerm

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

Determine whether a string expression matches this type of term

Parameters:
Name Type Attributes Default Description
expression string

The expression to parse

options object <optional>
{}

Additional options which customize the match

Properties
Name Type Attributes Default Description
imputeNumber boolean <optional>
true

Allow the number of dice to be optional, i.e. "d6"

Returns:
Type
RegExpMatchArray | null

alter(multiply, add) → {DiceTerm}

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(optionsopt) → {RollTerm}

Overrides:

Evaluate the term, processing its inputs and finalizing its total.

Parameters:
Name Type Attributes Default Description
options object <optional>
{}

Options which modify how the RollTerm is evaluated

Properties
Name Type Attributes Default Description
minimize boolean <optional>
false

Minimize the result, obtaining the smallest possible value.

maximize boolean <optional>
false

Maximize the result, obtaining the largest possible value.

async boolean <optional>
false

Evaluate the term asynchronously, receiving a Promise as the returned value. This will become the default behavior in version 10.x

Returns:

The evaluated RollTerm

Type
RollTerm

getResultCSS(result) → {Array.<string>}

Get the CSS classes that should be used to display each rolled result

Parameters:
Name Type Description
result DiceTermResult

The rolled result

Returns:

The desired classes

Type
Array.<string>

getResultLabel(result) → {string}

Return a string used as the label for each rolled result

Parameters:
Name Type Description
result DiceTermResult

The rolled result

Returns:

The result label

Type
string

getTooltipData() → {object}

Render the tooltip HTML for a Roll instance

Returns:

The data object used to render the default tooltip template for this DiceTerm

Type
object

roll(optionsopt) → {DiceTermResult}

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

Parameters:
Name Type Attributes Default Description
options object <optional>
{}

Options which modify how a random result is produced

Properties
Name Type Attributes Default Description
minimize boolean <optional>
false

Minimize the result, obtaining the smallest possible value.

maximize boolean <optional>
false

Maximize the result, obtaining the largest possible value.

Returns:

The produced result

Type
DiceTermResult

toJSON() → {object}

Overrides:

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.

Returns:
Type
object