From 3b0d4e032e9b5c5a0158fd38fc5e7ca58309b59d Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Tue, 16 Jun 2026 19:34:13 +0200 Subject: [PATCH] fix: cache results.length before explosion loop to prevent double-count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pushing explosion dice to DieTerm.results made the for loop condition (j < results.length) grow mid-iteration, re-processing the explosion result as a normal die. This produced spurious entries like `1D6 → 4` alongside the correct `1D6-1 → 3`. Fixes prompt() (for loop) and rollSpellDamageToMessage() (for...of) by caching result count / snapshotting the array before iterating. --- module/documents/roll.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/module/documents/roll.mjs b/module/documents/roll.mjs index b8ea83a..6ec817a 100644 --- a/module/documents/roll.mjs +++ b/module/documents/roll.mjs @@ -616,8 +616,10 @@ export default class LethalFantasyRoll extends Roll { let singleDice = `1D${maxValue}` for (let i = 0; i < rollBase.dice.length; i++) { - for (let j = 0; j < rollBase.dice[i].results.length; j++) { - let diceResult = rollBase.dice[i].results[j].result + const dieResults = rollBase.dice[i].results + const resultCount = dieResults.length + for (let j = 0; j < resultCount; j++) { + let diceResult = dieResults[j].result diceResults.push({ dice: `${singleDice.toUpperCase()}`, value: diceResult }) diceSum += diceResult if (hasMaxValue) { @@ -627,7 +629,7 @@ export default class LethalFantasyRoll extends Roll { diceResults.push({ dice: `${singleDice.toUpperCase()}-1`, value: diceResult - 1 }) diceSum += (diceResult - 1) // Add to DieTerm results so DSN/Foundry display shows explosion dice - rollBase.dice[i].results.push({ result: diceResult, active: true }) + dieResults.push({ result: diceResult, active: true }) } } } @@ -1592,7 +1594,8 @@ export default class LethalFantasyRoll extends Roll { let diceSum = 0 for (const term of roll.dice) { const singleDice = `1D${term.faces}` - for (const r of term.results) { + const termResults = Array.from(term.results) + for (const r of termResults) { let diceResult = r.result diceResults.push({ dice: singleDice.toUpperCase(), value: diceResult }) diceSum += diceResult