DicePool

DicePool

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.

Constructor

new DicePool()

Source:
Examples
// Consider 3 rolls
let r1 = new Roll("4d6");
let r2 = new Roll("3d8");
let r3 = new Roll("2d10");

// Keep the highest of the 3 roll expressions
let pool = new DicePool({
  rolls: [r1,r2,r3],
  modifiers: ["kh"]
});
pool.evaluate();
// Construct a DicePool from a string formula
let pool = DicePool.fromExpression("{4d6,3d8,2d10}kh");

Members

dice

Source:

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

formula

Source:

Return a standardized representation for the displayed formula associated with this DicePool.

MODIFIER_REGEX :RegExp

Source:

A regular expression pattern which identifies a potential DicePool modifier

Type:
  • RegExp

modifiers :Array.<string>

Source:

The string modifiers applied to resolve the pool

Type:

MODIFIERS :Object.<string, function()>

Source:

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

Type:
  • Object.<string, function()>

options :object

Source:

An object of additional options which modify the pool

Type:
  • object

POOL_REGEX :RegExp

Source:

A regular expression used to identify a valid Dice Pool

Type:
  • RegExp

results :Array.<{result: number, active: boolean}>

Source:

The array of dice pool results which have been rolled

Type:
  • Array.<{result: number, active: boolean}>

rolls :Array.<(Roll|number)>

Source:

The elements of a Dice Pool must be Roll objects or numbers

Type:

total :number|null

Source:

Return the total result of the DicePool if it has been evaluated

Type:
  • number | null

values :Array.<number>

Source:

Return an array of rolled values which are still active within the DicePool

Type:

Methods

(static) fromData(data) → {DicePool}

Source:

Reconstruct a DicePool instance from a provided data Object

Parameters:
Name Type Description
data Object

The provided data

Returns:

The constructed Dice Pool

Type
DicePool

(static) fromExpression(formula, optionsopt, dataopt) → {DicePool|null}

Source:

Given a string formula, create and return an evaluated DicePool object

Parameters:
Name Type Attributes Description
formula string

The string formula to parse

options object <optional>

Additional options applied to the DicePool

data object <optional>

A data object which defines data substitutions for Rolls in the DicePool

Returns:

The evaluated DicePool object or null if the formula is invalid

Type
DicePool | null

(static) fromJSON(json) → {DicePool}

Source:

Reconstruct a DicePool instance from a provided data Object

Parameters:
Name Type Description
json string

The serialized JSON string

Returns:

The constructed Dice Pool

Type
DicePool

alter(…args) → {DicePool}

Source:

Alter the DiceTerm by adding or multiplying the number of dice which are rolled

Parameters:
Name Type Attributes Description
args Array.<any> <repeatable>

Arguments passed to each contained Roll#alter method.

Returns:

The altered pool

Type
DicePool

countFailures(modifier)

Source:

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:
Name Type Description
modifier string

The matched modifier query

countSuccess(modifier)

Source:

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:
Name Type Description
modifier string

The matched modifier query

drop(modifier)

Source:

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:
Name Type Description
modifier string

The matched modifier query

evaluate(minimizeopt, maximizeopt) → {DiceTerm}

Source:

Evaluate the DicePool, populating the results Array.

Parameters:
Name Type Attributes Description
minimize boolean <optional>

Apply the minimum possible result for each roll.

maximize boolean <optional>

Apply the maximum possible result for each roll.

Returns:

The evaluated dice term

Type
DiceTerm

keep(modifier)

Source:

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:
Name Type Description
modifier string

The matched modifier query

toJSON() → {Object}

Source:

Convert the DicePool instance into an Object which can be serialized to JSON

Returns:

The converted data

Type
Object