A type of RollTerm used to apply a function.

Hierarchy (view full)

Properties

fn: string

The name of the configured function, or one in the Math environment, which should be applied to the term

terms: string[]

An array of string argument terms for the function

rolls: Roll[]

The cached Roll instances for each function argument

result: string | number

The cached result of evaluating the method arguments

isIntermediate: boolean = true

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

options: object

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

_root: Roll

A reference to the Roll at the root of the evaluation tree.

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

REGEXP: RegExp = undefined

A regular expression used to match a term of this type

Accessors

  • get dice(): DiceTerm[]
  • An array of evaluated DiceTerm instances that should be bubbled up to the parent Roll

    Returns DiceTerm[]

  • get total(): string | number
  • A string or numeric representation of the final output for this term, after evaluation.

    Returns string | number

  • get expression(): string
  • A string representation of the formula expression for this RollTerm, prior to evaluation.

    Returns string

  • get function(): RollFunction
  • The function this term represents.

    Returns RollFunction

  • get isDeterministic(): boolean
  • Whether this term is entirely deterministic or contains some randomness.

    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

  • get resolver(): RollResolver
  • A reference to the RollResolver app being used to externally resolve this term.

    Returns RollResolver

Methods

  • Evaluate the term.

    Parameters

    • options: {} = {}

      Options which modify how the RollTerm is evaluated, see RollTerm#evaluate

      Returns RollTerm | Promise<RollTerm>

      Returns a Promise if the term is non-deterministic.

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

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

      Parameters

      • Optional options: {
            minimize: boolean;
            maximize: boolean;
            allowStrings: boolean;
        } = {}

        Options which modify how the RollTerm is evaluated

        • minimize: boolean

          Minimize the result, obtaining the smallest possible value.

        • maximize: boolean

          Maximize the result, obtaining the largest possible value.

        • allowStrings: boolean

          If true, string terms will not throw an error when evaluated.

      Returns RollTerm | Promise<RollTerm>

      Returns a Promise if the term is non-deterministic.

    • Protected

      Evaluate this function when it contains any non-deterministic sub-terms.

      Parameters

      • Optional options: object = {}

      Returns Promise<RollTerm>

    • Protected

      Evaluate this function when it contains only deterministic sub-terms.

      Parameters

      • Optional options: object = {}

      Returns RollTerm

    • Parse a function argument from its evaluated Roll instance.

      Parameters

      • roll: Roll

        The evaluated Roll instance that wraps the argument.

      Returns string | number

    • 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

    • Determine if evaluating a given RollTerm with certain evaluation options can be done so deterministically.

      Parameters

      • term: RollTerm

        The term.

      • Optional options: {
            maximize: boolean;
            minimize: boolean;
        } = {}

        Options for evaluating the term.

        • maximize: boolean

          Force the result to be maximized.

        • minimize: boolean

          Force the result to be minimized.

      Returns boolean

    • Construct a RollTerm from a provided data object

      Parameters

      • data: object

        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