Options
All
  • Public
  • Public/Protected
  • All
Menu

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

param termData

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

param [termData.number=1]

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

param termData.faces

The number of faces on each die of this type

param [termData.modifiers]

An array of modifiers applied to the results

param [termData.results]

An optional array of pre-cast results for the term

param [termData.options]

Additional options that modify the term

Hierarchy

Index

Constructors

  • new DiceTerm(__namedParameters: Object): DiceTerm

Properties

number: number

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

faces: number

The number of faces on the die

modifiers: string[]

An Array of dice term modifiers which are applied

results: DiceTermResult[]

The array of dice term results which have been rolled

_evaluated: boolean

An internal flag for whether the term has been evaluated

options: any

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

isIntermediate: boolean = false

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

DENOMINATION: string = ""

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

MODIFIERS: { string: string | Function } = {}

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

Type declaration

  • string: string | Function
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

MODIFIER_REGEXP: RegExp = ...

A regular expression used to separate individual modifiers

REGEXP: RegExp = ...

A regular expression used to match a term of this type

SERIALIZE_ATTRIBUTES: string[] = ...

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

FLAVOR_REGEXP_STRING: string = "(?:\\[([^\\]]+)\\])"

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

FLAVOR_REGEXP: RegExp = ...

A regular expression which identifies term-level flavor text

Accessors

  • get expression(): string
  • inheritdoc

    Returns string

  • get total(): number
  • inheritdoc

    Returns number

  • get values(): number[]
  • Return an array of rolled values which are still active within this term

    Returns number[]

  • get isDeterministic(): boolean
  • inheritdoc

    Returns boolean

  • get formula(): string
  • A string representation of the formula, including optional flavor text.

    Returns string

  • get flavor(): string
  • Optional flavor text which modifies and describes this term.

    Returns string

Methods

  • alter(multiply: number, add: number): DiceTerm
  • Alter the DiceTerm by adding or multiplying the number of dice which are rolled

    Parameters

    • 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 DiceTerm

    The altered term

  • _evaluateSync(__namedParameters?: { minimize: boolean; maximize: boolean }): DiceTerm
  • This method is temporarily factored out in order to provide different behaviors synchronous evaluation. This will be removed in 0.10.x

    Parameters

    • __namedParameters: { minimize: boolean; maximize: boolean } = {}
      • minimize: boolean
      • maximize: boolean

    Returns DiceTerm

  • roll([options={}]?: { minimize: boolean; maximize: boolean }): DiceTermResult
  • Roll the DiceTerm by mapping a random uniform draw against the faces of the dice term.

    Parameters

    • [options={}]: { minimize: boolean; maximize: boolean } = {}

      Options which modify how a random result is produced

      • minimize: boolean
      • maximize: boolean

    Returns DiceTermResult

    The produced result

  • Return a string used as the label for each rolled result

    Parameters

    Returns string

    The result label

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

    Parameters

    Returns string[]

    The desired classes

  • getTooltipData(): any
  • Render the tooltip HTML for a Roll instance

    Returns any

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

  • evaluate([options={}]?: { minimize: boolean; maximize: boolean; async: boolean }): RollTerm
  • Evaluate the term, processing its inputs and finalizing its total.

    Parameters

    • [options={}]: { minimize: boolean; maximize: boolean; async: boolean } = {}

      Options which modify how the RollTerm is evaluated

      • minimize: boolean
      • maximize: boolean
      • async: boolean

    Returns RollTerm

    The evaluated RollTerm

  • toJSON(): any
  • 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 any

  • _evaluateModifiers(): void
  • Sequentially evaluate each dice roll modifier by passing the term to its evaluation function Augment or modify the results array.

    Returns void

  • _evaluateModifier(command: string, modifier: string): void
  • Evaluate a single modifier command, recording it in the array of evaluated modifiers

    Parameters

    • command: string

      The parsed modifier command

    • modifier: string

      The full modifier request

    Returns void

  • compareResult(result: number, comparison: string, target: number): boolean
  • A helper comparison function. Returns a boolean depending on whether the result compares favorably against the target.

    Parameters

    • result: number

      The result being compared

    • comparison: string

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

    • target: number

      The target value

    Returns boolean

    Is the comparison true?

  • _keepOrDrop(results: any[], number: number, __namedParameters?: boolean): any[]
  • A helper method to modify the results array of a dice term by flagging certain results are kept or dropped.

    Parameters

    • results: any[]

      The results array

    • number: number

      The number to keep or drop

    • __namedParameters: boolean = {}

    Returns any[]

    The modified results array

  • _applyCount(results: any, comparison: any, target: any, __namedParameters?: { flagSuccess: boolean; flagFailure: boolean }): void
  • A reusable helper function to handle the identification and deduction of failures

    Parameters

    • results: any
    • comparison: any
    • target: any
    • __namedParameters: { flagSuccess: boolean; flagFailure: boolean } = {}
      • flagSuccess: boolean
      • flagFailure: boolean

    Returns void

  • _applyDeduct(results: any, comparison: any, target: any, __namedParameters?: { deductFailure: boolean; invertFailure: boolean }): void
  • A reusable helper function to handle the identification and deduction of failures

    Parameters

    • results: any
    • comparison: any
    • target: any
    • __namedParameters: { deductFailure: boolean; invertFailure: boolean } = {}
      • deductFailure: boolean
      • invertFailure: boolean

    Returns void

  • matchTerm(expression: string, [options={}]?: { imputeNumber: boolean }): RegExpMatchArray
  • Determine whether a string expression matches this type of term

    Parameters

    • expression: string

      The expression to parse

    • [options={}]: { imputeNumber: boolean } = {}

      Additional options which customize the match

      • imputeNumber: boolean

    Returns RegExpMatchArray

  • fromMatch(match: RegExpMatchArray): DiceTerm
  • Construct a term of this type given a matched regular expression array.

    Parameters

    • match: RegExpMatchArray

      The matched regular expression array

    Returns DiceTerm

    The constructed term

  • Construct a RollTerm from a provided data object

    Parameters

    • data: any

      Provided data from an un-serialized term

    Returns RollTerm

    The constructed RollTerm

  • Reconstruct a RollTerm instance from a provided JSON string

    Parameters

    • json: string

      A serialized JSON representation of a DiceTerm

    Returns RollTerm

    A reconstructed RollTerm from the provided JSON

  • Define term-specific logic for how a de-serialized data object is restored as a functional RollTerm

    Parameters

    • data: any

      The de-serialized term data

    Returns RollTerm

    The re-constructed RollTerm object