Skip to content

Commit

Permalink
Fix parsing of damage formulas with MathTerms (foundryvtt#5931)
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam authored Jan 26, 2023
1 parent d6ced4e commit ea9745d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/module/system/damage/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AbstractDamageRoll extends Roll {
options: { missing?: string; warn?: boolean } = {}
): string {
const replaced = super.replaceFormulaData(formula, data, options);
return replaced.replace(/\((\d+)\)/g, "$1");
return replaced.replace(/(?<![a-z])\((\d+)\)/gi, "$1");
}

/** The theoretically lowest total of this roll */
Expand Down Expand Up @@ -98,7 +98,7 @@ class DamageRoll extends AbstractDamageRoll {

/** Ensure the roll is parsable as `PoolTermData` */
static override validate(formula: string): boolean {
const wrapped = formula.startsWith("{") ? formula : `{${formula}}`;
const wrapped = this.replaceFormulaData(formula.startsWith("{") ? formula : `{${formula}}`, {});
try {
const result = this.parser.parse(wrapped);
return isObject(result) && "class" in result && ["PoolTerm", "InstancePool"].includes(String(result.class));
Expand Down

0 comments on commit ea9745d

Please sign in to comment.