Options
All
  • Public
  • Public/Protected
  • All
Menu

A type of DiceTerm used to represent rolling a fair n-sided die.

implements

{DiceTerm}

example

Roll four six-sided dice

let die = new Die({faces: 6, number: 4}).evaluate();

Hierarchy

Index

Constructors

  • new Die(termData?: {}): Die

Accessors

  • get total(): number
  • inheritdoc

    Returns number

  • get expression(): string
  • inheritdoc

    Returns string

  • 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

  • reroll(modifier: string, recursive?: boolean): boolean | 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 boolean | void

    False if the modifier was unmatched

  • rerollRecursive(modifier: any): boolean | void
  • see

    {@link Die#reroll}

    Parameters

    • modifier: any

    Returns boolean | void

  • explode(modifier: string, recursive?: boolean): boolean
  • Explode the Die, rolling additional results for any values which match the target set. If no target number is specified, explode the highest possible result. Explosion can be a "small explode" using a lower-case x or a "big explode" using an upper-case "X"

    Parameters

    • modifier: string

      The matched modifier query

    • recursive: boolean = {}

      Explode recursively, such that new rolls can also explode?

    Returns boolean

  • explodeOnce(modifier: any): boolean
  • see

    {@link Die#explode}

    Parameters

    • modifier: any

    Returns boolean

  • keep(modifier: string): 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

  • drop(modifier: string): 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

  • countSuccess(modifier: string): boolean
  • Count the number of successful results which occurred in a given result set. 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 boolean

  • countFailures(modifier: string): boolean
  • 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 boolean

  • countEven(modifier: string): void
  • Count the number of even results which occurred in a given result set. Even numbers are marked as a success and counted as 1 Odd numbers are marked as a non-success and counted as 0.

    6d6even Count the number of even numbers rolled

    Parameters

    • modifier: string

      The matched modifier query

    Returns void

  • countOdd(modifier: string): void
  • Count the number of odd results which occurred in a given result set. Odd numbers are marked as a success and counted as 1 Even numbers are marked as a non-success and counted as 0.

    6d6odd Count the number of odd numbers rolled

    Parameters

    • modifier: string

      The matched modifier query

    Returns void

  • deductFailures(modifier: string): boolean
  • Deduct the number of failures from the dice result, counting each failure as -1 Failures are identified relative to some target, or relative to the lowest possible value if no target is given. Applying a deduct-failures modifier to the results counts all failed results as -1.

    6d6df Subtract the number of dice which rolled a 1 from the non-failed total. 6d6cs>3df Subtract the number of dice which rolled a 3 or less from the non-failed count. 6d6cf<3df Subtract the number of dice which rolled less than 3 from the non-failed count.

    Parameters

    • modifier: string

      The matched modifier query

    Returns boolean

  • subtractFailures(modifier: string): boolean
  • Subtract the value of failed dice from the non-failed total, where each failure counts as its negative value. Failures are identified relative to some target, or relative to the lowest possible value if no target is given. Applying a deduct-failures modifier to the results counts all failed results as -1.

    6d6df<3 Subtract the value of results which rolled less than 3 from the non-failed total.

    Parameters

    • modifier: string

      The matched modifier query

    Returns boolean

  • marginSuccess(modifier: string): boolean
  • Subtract the total value of the DiceTerm from a target value, treating the difference as the final total. Example: 6d6ms>12 Roll 6d6 and subtract 12 from the resulting total.

    Parameters

    • modifier: string

      The matched modifier query

    Returns boolean

  • minimum(modifier: string): boolean
  • Constrain each rolled result to be at least some minimum value. Example: 6d6min2 Roll 6d6, each result must be at least 2

    Parameters

    • modifier: string

      The matched modifier query

    Returns boolean

  • maximum(modifier: string): boolean
  • Constrain each rolled result to be at most some maximum value. Example: 6d6max5 Roll 6d6, each result must be at most 5

    Parameters

    • modifier: string

      The matched modifier query

    Returns boolean

  • 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 }): Die
  • 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 Die

  • 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

  • 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

  • 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

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 = "d"

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

MODIFIERS: { r: string; rr: string; x: string; xo: string; k: string; kh: string; kl: string; d: string; dh: string; dl: string; min: string; max: string; even: string; odd: string; cs: string; cf: string; df: string; sf: string; ms: string } = ...

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

Type declaration

  • r: string
  • rr: string
  • x: string
  • xo: string
  • k: string
  • kh: string
  • kl: string
  • d: string
  • dh: string
  • dl: string
  • min: string
  • max: string
  • even: string
  • odd: string
  • cs: string
  • cf: string
  • df: string
  • sf: string
  • ms: string
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