From 20febb82d5441405315b537ae622af5dbaf5bc17 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 15 Jul 2026 02:35:27 +0200 Subject: [PATCH] Semi-corrected reroll of one of multiple results on a die --- module/applications/ui/chatLog.mjs | 4 ++-- module/data/chat-message/actorRoll.mjs | 15 ++++++++------- templates/ui/chat/parts/damage-part.hbs | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index d17ddbb5..210727d7 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -254,8 +254,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo const target = event.target.closest('[data-die-index]'); if (target.dataset.type === 'damage') { - const { damageType, dice } = target.dataset; - await message.system.damage.rerollDamageDice(damageType, dice); + const { damageType, dice, result } = target.dataset; + await message.system.damage.rerollDamageDice(damageType, dice, result); await message.update({ 'system.damage.types': { [damageType]: { diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index 834d2dab..002715fe 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -59,20 +59,21 @@ class ChatMessageRollDamage extends foundry.abstract.DataModel { } } - async rerollDamageDice(damageType, dice) { + async rerollDamageDice(damageType, dice, resultIndex) { const reroll = this.types[damageType].roll; const rerollDice = reroll.dice[dice]; - await rerollDice.reroll(`/r1=${rerollDice.total}`); + const diceResult = rerollDice.results[resultIndex]; + await rerollDice.reroll(`/r1=${diceResult.result}`); await reroll._evaluate(); - - const result = rerollDice.results.find(x => x.active); - if (result) { + + const rerolledResult = rerollDice.results[rerollDice.results.length - 1]; + if (rerolledResult) { const fakeRoll = { _evaluated: true, dice: [new foundry.dice.terms.Die({ ...rerollDice, - results: [result], - total: result.value, + results: [rerolledResult], + total: rerolledResult.value, faces: rerollDice.faces })], options: { appearance: {} } diff --git a/templates/ui/chat/parts/damage-part.hbs b/templates/ui/chat/parts/damage-part.hbs index cd4085e0..e1d35b97 100644 --- a/templates/ui/chat/parts/damage-part.hbs +++ b/templates/ui/chat/parts/damage-part.hbs @@ -40,7 +40,7 @@
{{#if hasRerolls}}{{/if}} {{result}}