From 05c93f9475e1facd54769c5edd7610fcef9f9923 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Sun, 28 Jun 2026 08:39:55 +0200 Subject: [PATCH] Full reroll management --- lethal-fantasy.mjs | 29 +++++++++++++++-------------- module/documents/roll.mjs | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lethal-fantasy.mjs b/lethal-fantasy.mjs index 97b1fb1..7b38360 100644 --- a/lethal-fantasy.mjs +++ b/lethal-fantasy.mjs @@ -553,6 +553,17 @@ Hooks.on("preCreateChatMessage", (message) => { } }) +// Build dice breakdown HTML from a reroll result +function formatRerollBreakdown(reroll) { + const breakdown = (reroll.options?.diceResults || []) + .map(r => `${r.dice}${r.value}`) + .join("") + const d30 = reroll.options?.D30message + ? `
D30 → ${reroll.options.D30result || "?"} — ${reroll.options.D30message.description}
` + : "" + return { breakdown, d30 } +} + // Hook global pour gérer l'offre de Grit à l'attaquant après une défense Hooks.on("createChatMessage", async (message) => { const rollType = message.rolls[0]?.options?.rollType @@ -572,7 +583,7 @@ Hooks.on("createChatMessage", async (message) => { return } - let { + const { attackerId, attackRoll, attackerName, @@ -580,13 +591,13 @@ Hooks.on("createChatMessage", async (message) => { attackWeaponId, attackRollType, attackRollKey, - attackD30message, attackRerollContext, attackNaturalRoll, damageTier, defenderId, defenderTokenId } = attackData + let { attackD30message } = attackData let defenseRoll = message.rolls[0]?.options?.rollTotal || message.rolls[0]?.total || 0 let defenseD30message = message.rolls[0]?.options?.D30message || null @@ -807,12 +818,7 @@ Hooks.on("createChatMessage", async (message) => { if (!reroll) continue defenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll // Build dice breakdown HTML from the reroll - const rerollBreakdown = (reroll.options?.diceResults || []) - .map(r => `${r.dice}${r.value}`) - .join("") - const rerollD30 = reroll.options?.D30message - ? `
D30 → ${reroll.options.D30result || "?"} — ${reroll.options.D30message.description}
` - : "" + const { breakdown: rerollBreakdown, d30: rerollD30 } = formatRerollBreakdown(reroll) await createReactionMessage(defender, `

${defenderName} uses Mulligan and re-rolls defense: ${oldDefenseRoll}${defenseRoll}.

${rerollBreakdown}
${rerollD30} @@ -1020,12 +1026,7 @@ Hooks.on("createChatMessage", async (message) => { if (!reroll) continue attackRollFinal = reroll.options?.rollTotal || reroll.total || oldAttackRoll // Build dice breakdown HTML from the reroll - const rerollBreakdown = (reroll.options?.diceResults || []) - .map(r => `${r.dice}${r.value}`) - .join("") - const rerollD30 = reroll.options?.D30message - ? `
D30 → ${reroll.options.D30result || "?"} — ${reroll.options.D30message.description}
` - : "" + const { breakdown: rerollBreakdown, d30: rerollD30 } = formatRerollBreakdown(reroll) await createReactionMessage(attacker, `

${attackerName} uses Mulligan and re-rolls attack: ${oldAttackRoll}${attackRollFinal}.

${rerollBreakdown}
${rerollD30} diff --git a/module/documents/roll.mjs b/module/documents/roll.mjs index a81cc89..25da966 100644 --- a/module/documents/roll.mjs +++ b/module/documents/roll.mjs @@ -1505,7 +1505,7 @@ export default class LethalFantasyRoll extends Roll { if (this.type === "weapon-attack" && this.rollTarget?.weapon) { const weapon = this.rollTarget.weapon weaponDamageOptions = { - weaponId: weapon.id, + weaponId: weapon._id || weapon.id, weaponName: weapon.name, damageM: weapon.system?.damage?.damageM }