From 0e43bf197d4e4a323406a82e887cb5094f8c2bfb Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Sat, 16 Aug 2025 01:35:04 +0200 Subject: [PATCH] [Fix] 948 - Damage Reroll Parts (#965) * Fixed so rerolling damage doesn't make damageParts an object * Improved to properly handle theoretical additional damage parts --- module/dice/damageRoll.mjs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 0d64329e..427b6273 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -137,7 +137,7 @@ export default class DamageRoll extends DHRoll { } if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { - const total = part.roll.dice.reduce((acc, term) => acc + term._faces*term._number, 0); + const total = part.roll.dice.reduce((acc, term) => acc + term._faces * term._number, 0); if (total > 0) { part.roll.terms.push(...this.formatModifier(total)); } @@ -161,11 +161,11 @@ export default class DamageRoll extends DHRoll { if (config.data.parent.appliedEffects) { // Bardic Rally const rallyChoices = config.data?.parent?.appliedEffects.reduce((a, c) => { - const change = c.changes.find(ch => ch.key === 'system.bonuses.rally'); - if (change) a.push({ value: c.id, label: change.value }); - return a; - }, []) - if(rallyChoices.length) { + const change = c.changes.find(ch => ch.key === 'system.bonuses.rally'); + if (change) a.push({ value: c.id, label: change.value }); + return a; + }, []); + if (rallyChoices.length) { mods.rally = { label: 'DAGGERHEART.CLASS.Feature.rallyDice', values: rallyChoices, @@ -318,15 +318,19 @@ export default class DamageRoll extends DHRoll { }); const updateMessage = game.messages.get(message._id); + const damageParts = updateMessage.system.damage[damageType].parts.map((damagePart, index) => { + if (index !== Number(part)) return damagePart; + return { + ...rollPart, + total: parsedRoll.total, + dice: rerolledDice + }; + }); await updateMessage.update({ [`system.damage.${damageType}`]: { ...updateMessage, total: parsedRoll.total, - [`parts.${part}`]: { - ...rollPart, - total: parsedRoll.total, - dice: rerolledDice - } + parts: damageParts } }); }