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/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 3c99f489..14b88c15 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -19,11 +19,15 @@ export default class DamageRoll extends DHRoll { for (const roll of config.roll) { await roll.roll.evaluate(); + + if (!config.damage?.types) config.damage = { types: {} }; config.damage.types[roll.applyTo] = { roll: roll.roll, damageTypes: roll.damageTypes ?? [] }; } + + roll._evaluated = true; } static async buildPost(roll, config, message) { 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}}