A type of DiceTerm used to represent a three-sided Fate/Fudge die. Mathematically behaves like 1d3-2

Hierarchy (view full)

Properties

modifiers: string[]

An Array of dice term modifiers which are applied

results: DiceTermResult[]

The array of dice term results which have been rolled

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.

isIntermediate: boolean = false

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

_number: any

The number of dice of this term to roll, before modifiers are applied, or a Roll instance that will be evaluated to a number.

_faces: any

The number of faces on the die, or a Roll instance that will be evaluated to a number.

DENOMINATION: string = "f"

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

MODIFIERS: {
    r: ((modifier, recursive?) => Promise<false | void>);
    rr: ((modifier) => Promise<false | void>);
    k: ((modifier) => boolean);
    kh: ((modifier) => boolean);
    kl: ((modifier) => boolean);
    d: ((modifier) => boolean);
    dh: ((modifier) => boolean);
    dl: ((modifier) => boolean);
} = ...

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

Type declaration

  • r: ((modifier, recursive?) => Promise<false | void>)
      • (modifier, recursive?): Promise<false | void>
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        • recursive: boolean = {}

          Reroll recursively, continuing to reroll until the condition is no longer met

        Returns Promise<false | void>

        False if the modifier was unmatched

  • rr: ((modifier) => Promise<false | void>)
      • (modifier): Promise<false | void>
      • Parameters

        • modifier: any

        Returns Promise<false | void>

  • k: ((modifier) => boolean)
      • (modifier): boolean
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        Returns boolean

  • kh: ((modifier) => boolean)
      • (modifier): boolean
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        Returns boolean

  • kl: ((modifier) => boolean)
      • (modifier): boolean
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        Returns boolean

  • d: ((modifier) => boolean)
      • (modifier): boolean
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        Returns boolean

  • dh: ((modifier) => boolean)
      • (modifier): boolean
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        Returns boolean

  • dl: ((modifier) => boolean)
      • (modifier): boolean
      • 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

        Parameters

        • modifier: string

          The matched modifier query

        Returns boolean

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 method(): string
  • The resolution method used to resolve this DiceTerm.

    Returns string

  • get number(): number | void
  • The number of dice of this term to roll. Returns undefined if the number is a complex term that has not yet been evaluated.

    Returns number | void

  • get faces(): number | void
  • The number of faces on the die. Returns undefined if the faces are represented as a complex term that has not yet been evaluated.

    Returns number | void

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

    Returns string

  • get denomination(): string
  • The denomination of this DiceTerm instance.

    Returns string

  • get dice(): DiceTerm[]
  • An array of additional DiceTerm instances involved in resolving this DiceTerm.

    Returns DiceTerm[]

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

    Returns number

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

    Returns number[]

  • 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

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

    Parameters

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

      Options which modify how a random result is produced

      • minimize: boolean
      • maximize: boolean

    Returns Promise<{
        result: any;
        active: boolean;
    }>

    The produced result

  • Parameters

    • randomUniform: any

    Returns number

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

    Parameters

    • result: any

      The rolled result

    Returns any

    The result label

  • 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

  • Evaluate the term.

    Parameters

    • options: {} = {}

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

      Returns DiceTerm | Promise<DiceTerm>

      Returns a Promise if the term is non-deterministic.

    • Generate a random face value for this die using the configured PRNG.

      Returns number

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

      Parameters

      Returns string[]

      The desired classes

    • Render the tooltip HTML for a Roll instance

      Returns object

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

    • Internal

      Sequentially evaluate each dice roll modifier by passing the term to its evaluation function Augment or modify the results array.

      Returns Promise<void>

    • Internal

      Asynchronously 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 Promise<void>

    • 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 dice term asynchronously.

      Parameters

      • Optional options: object = {}

        Options forwarded to inner Roll evaluation.

      Returns Promise<DiceTerm>

    • Protected

      Evaluate deterministic values of this term synchronously.

      Parameters

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

          Force the result to be maximized.

        • minimize: boolean

          Force the result to be minimized.

        • strict: boolean

          Throw an error if attempting to evaluate a die term in a way that cannot be done synchronously.

      Returns DiceTerm

    • Protected

      Generate a roll result value for this DiceTerm based on its fulfillment method.

      Parameters

      • Optional options: object = {}

        Options forwarded to the fulfillment method handler.

      Returns Promise<number | void>

      Returns a Promise that resolves to the fulfilled number, or undefined if it could not be fulfilled.

    • Invoke the configured fulfillment handler for this term to produce a result value.

      Parameters

      • Optional options: object = {}

        Options forwarded to the fulfillment method handler.

      Returns Promise<number | void>

      Returns a Promise that resolves to the fulfilled number, or undefined if it could not be fulfilled.

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

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

      Parameters

      • results: object[]

        The results array

      • number: number

        The number to keep or drop

      • Optional __namedParameters: boolean = {}

      Returns object[]

      The modified results array

    • 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

    • 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

    • Determine whether a string expression matches this type of term

      Parameters

      • expression: string

        The expression to parse

      • Optional options: {
            imputeNumber: boolean;
        } = {}

        Additional options which customize the match

        • imputeNumber: boolean

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

      Returns RegExpMatchArray

    • 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

    • 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