fix: cache results.length before explosion loop to prevent double-count
Release Creation / build (release) Successful in 50s

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.
This commit is contained in:
2026-06-16 19:34:13 +02:00
parent 539841c4ff
commit 3b0d4e032e
+7 -4
View File
@@ -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