Fix inititiative rolls
All checks were successful
Release Creation / build (release) Successful in 52s

This commit is contained in:
2026-04-06 00:02:14 +02:00
parent df6f8e5710
commit 3ad5681539
4 changed files with 48 additions and 9 deletions

View File

@@ -681,7 +681,15 @@ export default class LethalFantasyRoll extends Roll {
rejectClose: false // Click on Close button will not launch an error
})
let initRoll = new Roll(`min(${rollContext.initiativeDice}, ${options.maxInit})`, options.data, rollContext)
if (!rollContext) return
// When the value is a plain number (e.g. "1" for Declared Ready on Alert), wrapping it in
// min(1, maxInit) produces a dice-less formula that FoundryVTT cannot evaluate to a valid
// total. Use the constant directly; min() is only needed for actual dice expressions.
const isDiceFormula = /[dD]/.test(rollContext.initiativeDice)
const formula = isDiceFormula ? `min(${rollContext.initiativeDice}, ${options.maxInit})` : rollContext.initiativeDice
let initRoll = new Roll(formula, options.data)
await initRoll.evaluate()
let msg = await initRoll.toMessage({ flavor: `Initiative for ${options.actorName}` }, { rollMode: rollContext.visibility })
if (game?.dice3d) {
@@ -690,7 +698,7 @@ export default class LethalFantasyRoll extends Roll {
if (options.combatId && options.combatantId) {
let combat = game.combats.get(options.combatId)
combat.updateEmbeddedDocuments("Combatant", [{ _id: options.combatantId, initiative: initRoll.total, 'system.progressionCount': 0 }]);
await combat.updateEmbeddedDocuments("Combatant", [{ _id: options.combatantId, initiative: initRoll.total, 'system.progressionCount': 0 }])
}
}