Skip to content

Commit

Permalink
Add simplify method to BasicRoll (#4104)
Browse files Browse the repository at this point in the history
Co-authored-by: Kim Mantas <kim.mantas@gmail.com>
  • Loading branch information
krbz999 and Fyorl authored Sep 3, 2024
1 parent 2911253 commit 4332fc4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions module/dice/basic-roll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,25 @@ export default class BasicRoll extends Roll {

return matchedModifier ? face * number : null;
}

/* -------------------------------------------- */
/* Simplification Methods */
/* -------------------------------------------- */

/**
* Replace number and faces of dice terms with numeric values where possible.
*/
simplify() {
for ( const die of this.dice ) {
const n = die._number;
if ( (n instanceof BasicRoll) && n.isDeterministic ) die._number = n.evaluateSync().total;
const f = die._faces;
if ( (f instanceof BasicRoll) && f.isDeterministic ) die._faces = f.evaluateSync().total;

// Preserve flavor.
if ( f.terms?.[0]?.flavor ) die.options.flavor = f.terms[0].flavor;
}

this.resetFormula();
}
}

0 comments on commit 4332fc4

Please sign in to comment.