Fix inititiative rolls
All checks were successful
Release Creation / build (release) Successful in 52s
All checks were successful
Release Creation / build (release) Successful in 52s
This commit is contained in:
@@ -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 }])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,16 @@ export default class LethalFantasyUtils {
|
||||
console.log(`handleSocketEvent !`, msg)
|
||||
let actor
|
||||
switch (msg.type) {
|
||||
case "applyDamage":
|
||||
if (game.user.isGM) {
|
||||
// Prefer the specific token actor (correct for unlinked monsters); fall back to world actor.
|
||||
actor = msg.tokenId
|
||||
? canvas.tokens?.placeables?.find(t => t.id === msg.tokenId)?.actor
|
||||
: (game.combat?.combatants?.find(c => c.actorId === msg.actorId)?.actor
|
||||
?? game.actors.get(msg.actorId))
|
||||
if (actor) actor.applyDamage(msg.damage)
|
||||
}
|
||||
break
|
||||
case "rollInitiative":
|
||||
actor = game.actors.get(msg.actorId)
|
||||
actor.system.rollInitiative(msg.combatId, msg.combatantId)
|
||||
|
||||
Reference in New Issue
Block a user