Options
All
  • Public
  • Public/Protected
  • All
Menu

A type of DiceTerm used to represent flipping a two-sided coin.

implements

{DiceTerm}

Hierarchy

Index

Constructors

  • new Coin(termData: any): Coin

Properties

faces: number

The number of faces on the die

number: number

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

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

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

MODIFIERS: { c: string } = ...

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

Type declaration

  • c: 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

Methods

  • roll(__namedParameters?: { minimize: boolean; maximize: boolean }): { result: any; active: boolean }
  • 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 { result: any; active: boolean }

    The produced result

    • result: any
    • active: boolean
  • getResultLabel(result: any): any
  • Return a string used as the label for each rolled result

    Parameters

    • result: any

      The rolled result

    Returns any

    The result label

  • getResultCSS(result: any): string[]
  • Get the CSS classes that should be used to display each rolled result

    Parameters

    • result: any

      The rolled result

    Returns string[]

    The desired classes

  • call(modifier: string): boolean
  • Call the result of the coin flip, marking any coins that matched the called target as a success 3dcc1 Flip 3 coins and treat "heads" as successes 2dcc0 Flip 2 coins and treat "tails" as successes

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

  • 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

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