Options
All
  • Public
  • Public/Protected
  • All
Menu

A type of RollTerm which encloses a pool of multiple inner Rolls which are evaluated jointly.

A dice pool represents a set of Roll expressions which are collectively modified to compute an effective total across all Rolls in the pool. The final total for the pool is defined as the sum over kept rolls, relative to any success count or margin.

example

Keep the highest of the 3 roll expressions

let pool = new PoolTerm({
rolls: ["4d6", "3d8 - 1", "2d10 + 3"],
modifiers: ["kh"]
});
pool.evaluate();

Hierarchy

Index

Constructors

  • new PoolTerm(__namedParameters?: { terms: any[]; modifiers: any[]; rolls: any[]; results: any[]; options: {} }): PoolTerm
  • Parameters

    • __namedParameters: { terms: any[]; modifiers: any[]; rolls: any[]; results: any[]; options: {} } = {}
      • terms: any[]
      • modifiers: any[]
      • rolls: any[]
      • results: any[]
      • options: {}

      Returns PoolTerm

    Properties

    terms: string[]

    The original provided terms to the Dice Pool

    modifiers: string[]

    The string modifiers applied to resolve the pool

    rolls: Roll[]

    Each component term of a dice pool is evaluated as a Roll instance

    results: DiceTermResult[]

    The array of dice pool 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?

    MODIFIERS: Object = ...

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

    OPEN_REGEXP: RegExp = ...

    The regular expression pattern used to identify the opening of a dice pool expression.

    CLOSE_REGEXP: RegExp = ...

    A regular expression pattern used to identify the closing of a dice pool expression.

    REGEXP: RegExp = ...

    A regular expression pattern used to match the entirety of a DicePool expression.

    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

    • Return an Array of each individual DiceTerm instances contained within the PoolTerm.

      Returns DiceTerm[]

    • 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 the PoolTerm

      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 the DiceTerm by adding or multiplying the number of dice which are rolled

      Parameters

      • Rest ...args: any[]

        Arguments passed to each contained Roll#alter method.

      Returns PoolTerm

      The altered pool

    • _evaluateSync(__namedParameters?: { minimize: boolean; maximize: boolean }): PoolTerm
    • 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 PoolTerm

    • _evaluate(__namedParameters?: { minimize: boolean; maximize: boolean }): Promise<PoolTerm>
    • Evaluate the term.

      Parameters

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

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

        • minimize: boolean
        • maximize: boolean

      Returns Promise<PoolTerm>

    • _evaluateModifiers(): any
    • Use the same logic as for the DiceTerm to avoid duplication

      see

      DiceTerm#_evaluateModifiers

      Returns any

    • _evaluateModifier(command: any, modifier: any): any
    • Use the same logic as for the DiceTerm to avoid duplication

      see

      DiceTerm#_evaluateModifier

      Parameters

      • command: any
      • modifier: any

      Returns any

    • 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

    • keep(modifier: string): any
    • Keep a certain number of highest or lowest dice rolls from the result set.

      {1d6,1d8,1d10,1d12}kh2 Keep the 2 best rolls from the pool {1d12,6}kl Keep the lowest result in the pool

      Parameters

      • modifier: string

        The matched modifier query

      Returns any

    • drop(modifier: string): any
    • Keep a certain number of highest or lowest dice rolls from the result set.

      {1d6,1d8,1d10,1d12}dl3 Drop the 3 worst results in the pool {1d12,6}dh Drop the highest result in the pool

      Parameters

      • modifier: string

        The matched modifier query

      Returns any

    • countSuccess(modifier: string): any
    • Count the number of successful results which occurred in the pool. Successes are counted relative to some target, or relative to the maximum possible value if no target is given. Applying a count-success modifier to the results re-casts all results to 1 (success) or 0 (failure)

      20d20cs Count the number of dice which rolled a 20 20d20cs>10 Count the number of dice which rolled higher than 10 20d20cs<10 Count the number of dice which rolled less than 10

      Parameters

      • modifier: string

        The matched modifier query

      Returns any

    • countFailures(modifier: string): any
    • Count the number of failed results which occurred in a given result set. Failures are counted relative to some target, or relative to the lowest possible value if no target is given. Applying a count-failures modifier to the results re-casts all results to 1 (failure) or 0 (non-failure)

      6d6cf Count the number of dice which rolled a 1 as failures 6d6cf<=3 Count the number of dice which rolled less than 3 as failures 6d6cf>4 Count the number of dice which rolled greater than 4 as failures

      Parameters

      • modifier: string

        The matched modifier query

      Returns any

    • 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

    • 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

    • fromExpression(formula: string, options?: any): PoolTerm
    • Given a string formula, create and return an evaluated PoolTerm object

      Parameters

      • formula: string

        The string formula to parse

      • options: any = {}

      Returns PoolTerm

      The evaluated PoolTerm object or null if the formula is invalid

    • Create a PoolTerm by providing an array of existing Roll objects

      Parameters

      • rolls: Roll[] = []

        An array of Roll objects from which to create the pool

      Returns RollTerm

      The constructed PoolTerm comprised of the provided rolls

    • 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