Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Dice

Representation of a dice roll.

Hierarchy

  • Dice

Index

Constructors

constructor

  • Create a new dice from the given atomic expression.

    throws

    If the value of n is not between 0 and Dice.maxN inclusive.

    throws

    If the value of d is not between 0 and Dice.maxD inclusive.

    Parameters

    • Optional diceExpr: string

      The atomic dice expression to create the dice from. If not given, the dice is initialized as "1d20".

    • Optional binding: object

      An object to bind to if the expression includes bindings.

    • Default value device: RandomDevice = RD

      The random number generator that this Dice should use.

    Returns Dice

Accessors

d

  • get d(): number
  • set d(value: number): void
  • The value of d is the number of faces on this dice. In the case of fate dice, returns 3 (d3).

    Returns number

  • Set the value of d. If the dice is a fate dice, the fate attribute is cleared.

    throws

    If the value of d is not between 0 and Dice.maxD inclusive.

    Parameters

    • value: number

    Returns void

fate

  • get fate(): boolean
  • set fate(value: boolean): void
  • True if this dice is a fate dice.

    Returns boolean

  • Set if this dice is a fate dice. If the value changes to true, the previous value for d is cleared. If the value changes to false, the value of d is set to 3 (the dice becomes a d3 and keeps its value of n). If the new value is the same as the dice's current value, there is no effect.

    Parameters

    • value: boolean

    Returns void

minRoll

  • get minRoll(): number
  • The lowest numeric value that this dice can roll. This is usually 1, except in the case of fate dice, where it is -1.

    Returns number

mod

n

  • get n(): number
  • set n(value: number): void
  • Get the value of n, which is the number of times the d-sided dice is rolled when roll() is called.

    Returns number

  • Set the value of n.

    throws

    If the value of n is not between 0 and Dice.maxN inclusive.

    Parameters

    • value: number

    Returns void

rawRolls

  • get rawRolls(): number[]
  • An array of the individual dice values for the most recent roll before modifiers were applied.

    Returns number[]

result

  • get result(): number
  • The most recently rolled result, or null if the dice has never been rolled.

    Returns number

rolls

  • get rolls(): number[]
  • An array of the individual dice values for the most recent roll.

    Returns number[]

Static Protected diceRegExp

  • get diceRegExp(): RegExp
  • The RegExp used to parse the core dice expression.

    Returns RegExp

Static maxD

  • get maxD(): number
  • set maxD(d: number): void
  • The maximum allowed value of d, which is equal to the largest representable integer in JavaScript (9007199254740991, or Number.MAX_SAFE_INTEGER).

    Returns number

  • The maximum allowed value of d, which is equal to the largest representable integer in JavaScript (9007199254740991, or Number.MAX_SAFE_INTEGER).

    Parameters

    • d: number

    Returns void

Static maxN

  • get maxN(): number
  • set maxN(n: number): void
  • The maximum allowed value of n, which is equal to the largest representable integer in JavaScript (9007199254740991, or Number.MAX_SAFE_INTEGER in ES6).

    Returns number

  • The maximum allowed value of n, which is equal to the largest representable integer in JavaScript (9007199254740991, or Number.MAX_SAFE_INTEGER in ES6).

    Parameters

    • n: number

    Returns void

Methods

roll

  • roll(n?: number): number
  • Roll the dice. Returns the combined result of the dice roll. Individual rolls are stored in the rolls property.

    throws

    If the value of n is not between 0 and Dice.maxN inclusive.

    throws

    It is possible for certain types of roll modifiers to continue rolling infinitely. Instead of crashing we throw an error describing where we stopped prematurely. The value of the rolls that we did execute can still be accessed via the rolls property, and the result can still be accessed via the result property.

    Parameters

    • Default value n: number = this.n

      The number of dice to roll. If not given, defaults to the value of n given when the dice was constructed.

    Returns number

    The combined result of the dice roll.

toString

  • toString(): string
  • Returns string

    The string representation of the Dice, using Roll20 notation.

toStringPlaintext

  • toStringPlaintext(): string
  • Returns string

    The string representation of the Dice, in English text.

Static roll

  • roll(d: number, n?: number, device?: RandomDevice): number[]
  • Perform a simple dice roll.

    throws

    If the value of n is not between 0 and Dice.maxN inclusive.

    throws

    If the value of d is not between 0 and Dice.maxD inclusive.

    Parameters

    • d: number

      The number of faces the dice should have.

    • Optional n: number
    • Default value device: RandomDevice = RD

      The random number generator to use in this roll.

    Returns number[]

Generated using TypeDoc