From 4d81509e79fd7fcf084731d017656e68eefdeb4c Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sun, 21 Jun 2026 16:08:46 +0200 Subject: [PATCH] Fixed so that automated countdowns reverse progress from Fear when rerolling dice if the duality result changes --- module/applications/ui/combatTracker.mjs | 6 ++--- module/applications/ui/countdowns.mjs | 13 ++++----- module/data/action/attackAction.mjs | 2 +- module/dice/dualityRoll.mjs | 6 ++--- module/dice/helpers.mjs | 34 +++++++++++++++++------- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/module/applications/ui/combatTracker.mjs b/module/applications/ui/combatTracker.mjs index 25f3e06b..b3b011f9 100644 --- a/module/applications/ui/combatTracker.mjs +++ b/module/applications/ui/combatTracker.mjs @@ -202,11 +202,11 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; if (combatant.actor?.type === 'character') { await updateCountdowns( - CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id, - CONFIG.DH.GENERAL.countdownProgressionTypes.characterSpotlight.id + { type: CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id }, + { type: CONFIG.DH.GENERAL.countdownProgressionTypes.characterSpotlight.id } ); } else { - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id); + await updateCountdowns({ type: CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id }); } const autoPoints = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).actionPoints; diff --git a/module/applications/ui/countdowns.mjs b/module/applications/ui/countdowns.mjs index d559582f..2e669d4f 100644 --- a/module/applications/ui/countdowns.mjs +++ b/module/applications/ui/countdowns.mjs @@ -342,7 +342,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application * Sends updates of the countdowns to the GM player. Since this is asynchronous, be sure to * update all the countdowns at the same time. * - * @param {...any} progressTypes Countdowns to be updated + * @param {...{ type: , reverseDirection: boolean }} progressTypes Countdowns to be updated */ static async updateCountdowns(...progressTypes) { const { countdownAutomation } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation); @@ -351,20 +351,21 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns); const updatedCountdowns = Object.keys(countdownSetting.countdowns).reduce((acc, key) => { const countdown = countdownSetting.countdowns[key]; - if (progressTypes.indexOf(countdown.progress.type) !== -1 && countdown.progress.current > 0) { - acc.push(key); + const progressData = progressTypes.find(x => x.type === countdown.progress.type); + if (progressData && countdown.progress.current > 0) { + acc[key] = { value: progressData.reverseDirection ? 1 : -1 }; } return acc; - }, []); + }, {}); const countdownData = countdownSetting.toObject(); const settings = { ...countdownData, countdowns: Object.keys(countdownData.countdowns).reduce((acc, key) => { const countdown = foundry.utils.deepClone(countdownData.countdowns[key]); - if (updatedCountdowns.includes(key)) { - countdown.progress.current -= 1; + if (updatedCountdowns[key]) { + countdown.progress.current += updatedCountdowns[key].value; } acc[key] = countdown; diff --git a/module/data/action/attackAction.mjs b/module/data/action/attackAction.mjs index 1988b1d8..f3537d93 100644 --- a/module/data/action/attackAction.mjs +++ b/module/data/action/attackAction.mjs @@ -55,7 +55,7 @@ export default class DHAttackAction extends DHDamageAction { if (result?.message?.system.action?.roll?.type === 'attack') { const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.characterAttack.id); + await updateCountdowns({ type: CONFIG.DH.GENERAL.countdownProgressionTypes.characterAttack.id }); } return result; diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index e2d967a3..884c6a18 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -362,11 +362,11 @@ export default class DualityRoll extends D20Roll { if (config.roll.result.duality === -1) { await updateCountdowns( - CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id, - CONFIG.DH.GENERAL.countdownProgressionTypes.fear.id + { type: CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id }, + { type: CONFIG.DH.GENERAL.countdownProgressionTypes.fear.id } ); } else { - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id); + await updateCountdowns({ type: CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id }); } } diff --git a/module/dice/helpers.mjs b/module/dice/helpers.mjs index 5f8a7bbb..327e7a45 100644 --- a/module/dice/helpers.mjs +++ b/module/dice/helpers.mjs @@ -1,19 +1,33 @@ import { ResourceUpdateMap } from '../data/action/baseAction.mjs'; export function updateResourcesForDualityReroll(oldDuality, newDuality, actor) { - const { hopeFear } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation); - if (game.user.isGM ? !hopeFear.gm : !hopeFear.players) return; - - const updates = []; const hope = (newDuality >= 0 ? 1 : 0) - (oldDuality >= 0 ? 1 : 0); const stress = (newDuality === 0 ? 1 : 0) - (oldDuality === 0 ? 1 : 0); const fear = (newDuality === -1 ? 1 : 0) - (oldDuality === -1 ? 1 : 0); - if (hope !== 0) updates.push({ key: 'hope', value: hope, enabled: true }); - if (stress !== 0) updates.push({ key: 'stress', value: -1 * stress, enabled: true }); - if (fear !== 0) updates.push({ key: 'fear', value: fear, enabled: true }); + const { hopeFear, countdownAutomation } = + game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation); - const resourceUpdates = new ResourceUpdateMap(actor); - resourceUpdates.addResources(updates); - resourceUpdates.updateResources(); + if (game.user.isGM ? hopeFear.gm : hopeFear.players) { + const updates = []; + if (hope !== 0) updates.push({ key: 'hope', value: hope, enabled: true }); + if (stress !== 0) updates.push({ key: 'stress', value: -1 * stress, enabled: true }); + if (fear !== 0) updates.push({ key: 'fear', value: fear, enabled: true }) + + const resourceUpdates = new ResourceUpdateMap(actor); + resourceUpdates.addResources(updates); + resourceUpdates.updateResources(); + } + + if (countdownAutomation) { + const updates = []; + if (fear !== 0) { + updates.push({ + type: CONFIG.DH.GENERAL.countdownProgressionTypes.fear.id, + reverseDirection: fear === 1 ? false : true + }); + } + + game.system.api.applications.ui.DhCountdowns.updateCountdowns(...updates); + } }