ATtempt to fix init rolls

This commit is contained in:
2026-04-07 20:43:15 +02:00
parent 3ad5681539
commit 1bf88bac06
33 changed files with 134 additions and 124 deletions

View File

@@ -216,6 +216,18 @@ export default class LethalFantasyUtils {
return
}
// Resolve the specific token ID now while we still have combatant/token context.
// This is passed through to the damage roll so the GM-side socket handler can find the
// correct synthetic actor for unlinked tokens (avoids wrong-instance damage with multiple
// unlinked copies of the same monster).
const defenderTokenId = (() => {
if (game.combat && combatantId) {
const cbt = game.combat.combatants.get(combatantId)
if (cbt?.token?.id) return cbt.token.id
}
return tokenId ?? canvas.tokens?.placeables?.find(t => t.actor?.id === defender.id)?.id ?? null
})()
const isMonster = defender.type === "monster"
// Pour les monstres, récupérer les attaques activées
@@ -277,11 +289,10 @@ export default class LethalFantasyUtils {
attackWeaponId,
attackRollType,
attackRollKey,
defenderId: defender.id
defenderId: defender.id,
defenderTokenId
}
console.log("Storing defense data for monster:", defender.id)
defender.system.prepareMonsterRoll("monster-defense", result)
}
return
@@ -347,7 +358,8 @@ export default class LethalFantasyUtils {
attackWeaponId,
attackRollType,
attackRollKey,
defenderId: defender.id
defenderId: defender.id,
defenderTokenId
}
console.log("Storing defense data for character:", defender.id)
@@ -536,10 +548,10 @@ export default class LethalFantasyUtils {
if (data.attackRollType === "weapon-attack") {
damageButton = `
<div class="attack-result-damage">
<button class="roll-damage-btn" data-attacker-id="${data.attackerId}" data-defender-id="${data.defenderId}" data-weapon-id="${data.attackWeaponId}" data-damage-type="small">
<button class="roll-damage-btn" data-attacker-id="${data.attackerId}" data-defender-id="${data.defenderId}" data-defender-token-id="${data.defenderTokenId || ""}" data-weapon-id="${data.attackWeaponId}" data-damage-type="small">
<i class="fa-solid fa-dice-d6"></i> Damage (Small)
</button>
<button class="roll-damage-btn" data-attacker-id="${data.attackerId}" data-defender-id="${data.defenderId}" data-weapon-id="${data.attackWeaponId}" data-damage-type="medium">
<button class="roll-damage-btn" data-attacker-id="${data.attackerId}" data-defender-id="${data.defenderId}" data-defender-token-id="${data.defenderTokenId || ""}" data-weapon-id="${data.attackWeaponId}" data-damage-type="medium">
<i class="fa-solid fa-dice-d20"></i> Damage (Medium)
</button>
</div>
@@ -547,7 +559,7 @@ export default class LethalFantasyUtils {
} else if (data.attackRollType === "monster-attack") {
damageButton = `
<div class="attack-result-damage">
<button class="roll-damage-btn" data-attacker-id="${data.attackerId}" data-defender-id="${data.defenderId}" data-attack-key="${data.attackRollKey}" data-damage-type="monster">
<button class="roll-damage-btn" data-attacker-id="${data.attackerId}" data-defender-id="${data.defenderId}" data-defender-token-id="${data.defenderTokenId || ""}" data-attack-key="${data.attackRollKey}" data-damage-type="monster">
<i class="fa-solid fa-burst"></i> Damage
</button>
</div>