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:
@@ -267,9 +267,13 @@ Hooks.on(hookName, (message, html, data) => {
|
||||
}
|
||||
|
||||
// Envoyer le message socket à l'utilisateur contrôlant le combatant
|
||||
const owners = game.users.filter(u =>
|
||||
combatant.actor.testUserPermission(u, "OWNER")
|
||||
// Only consider active (online) users; fall back to any active GM for unowned/GM monsters.
|
||||
let owners = game.users.filter(u =>
|
||||
u.active && combatant.actor.testUserPermission(u, "OWNER")
|
||||
)
|
||||
if (owners.length === 0) {
|
||||
owners = game.users.filter(u => u.active && u.isGM)
|
||||
}
|
||||
|
||||
// Récupérer l'acteur attaquant pour vérifier qui l'a lancé
|
||||
const attacker = game.actors.get(attackerId)
|
||||
@@ -546,12 +550,27 @@ Hooks.on("createChatMessage", async (message) => {
|
||||
|
||||
// Calculer les DR
|
||||
const armorDR = defender.computeDamageReduction() || 0
|
||||
|
||||
// Appliquer les dégâts avec armure DR par défaut
|
||||
const finalDamage = Math.max(0, damageTotal - armorDR)
|
||||
await defender.applyDamage(-finalDamage)
|
||||
|
||||
// Créer un message de confirmation
|
||||
// For unlinked tokens (default for monsters), we need the specific token actor, not the base
|
||||
// world actor — otherwise applyDamage would modify the base actor and affect every unlinked
|
||||
// copy of that monster. Prefer the combatant actor, fall back to canvas scan.
|
||||
const defenderCombatant = game.combat?.combatants?.find(c => c.actorId === defender.id)
|
||||
const defenderTokenId = defenderCombatant?.token?.id
|
||||
?? canvas.tokens?.placeables?.find(t => t.actor?.id === defender.id)?.id
|
||||
?? null
|
||||
|
||||
// Apply damage. If the current user does not own the defender (e.g. player hitting a GM monster),
|
||||
// route the HP update to the GM via socket. The confirmation message is still created here
|
||||
// since all users can create chat messages.
|
||||
if (defender.isOwner) {
|
||||
const tokenActor = defenderCombatant?.actor ?? defender
|
||||
await tokenActor.applyDamage(-finalDamage)
|
||||
} else {
|
||||
game.socket.emit(`system.${SYSTEM.id}`, { type: "applyDamage", actorId: defender.id, tokenId: defenderTokenId, damage: -finalDamage })
|
||||
}
|
||||
|
||||
// Créer un message de confirmation (visible to GM only)
|
||||
const messageContent = await foundry.applications.handlebars.renderTemplate(
|
||||
"systems/fvtt-lethal-fantasy/templates/damage-applied-message.hbs",
|
||||
{
|
||||
@@ -566,7 +585,8 @@ Hooks.on("createChatMessage", async (message) => {
|
||||
|
||||
await ChatMessage.create({
|
||||
content: messageContent,
|
||||
speaker: ChatMessage.getSpeaker({ actor: defender })
|
||||
speaker: ChatMessage.getSpeaker({ actor: defender }),
|
||||
whisper: ChatMessage.getWhisperRecipients("GM")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user