From 89ba2409983a3e16d5b298dc5fee918011c5301d Mon Sep 17 00:00:00 2001 From: WBHarry Date: Tue, 13 Jan 2026 23:10:28 +0100 Subject: [PATCH] Fixed RiskItAll resource handling method --- lang/en.json | 1 + module/applications/dialogs/deathMove.mjs | 55 ++++++++++++----------- module/data/action/baseAction.mjs | 6 +-- module/documents/actor.mjs | 14 ++++-- module/enrichers/DualityRollEnricher.mjs | 5 ++- module/enrichers/FateRollEnricher.mjs | 46 ++++++++++--------- 6 files changed, 72 insertions(+), 55 deletions(-) diff --git a/lang/en.json b/lang/en.json index b8f811ac..ccf03029 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2135,6 +2135,7 @@ "dropActorsHere": "Drop Actors here", "dropFeaturesHere": "Drop Features here", "duality": "Duality", + "dualityDice": "Duality Dice", "dualityRoll": "Duality Roll", "enabled": "Enabled", "evasion": "Evasion", diff --git a/module/applications/dialogs/deathMove.mjs b/module/applications/dialogs/deathMove.mjs index 6021f607..f6ab33a9 100644 --- a/module/applications/dialogs/deathMove.mjs +++ b/module/applications/dialogs/deathMove.mjs @@ -44,11 +44,13 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV const target = this.actor.uuid; const config = await enrichedFateRoll({ target, - title: 'Avoid Death Hope Fate Roll', - label: 'test', + title: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.avoidDeath.name'), + label: `${game.i18n.localize('DAGGERHEART.GENERAL.hope')} ${game.i18n.localize('DAGGERHEART.GENERAL.fateRoll')}`, fateType: 'Hope' }); + if (!config.roll.fate) return; + if (config.roll.fate.value <= this.actor.system.levelData.level.current) { // apply scarring - for now directly apply - later add a button. const newScarAmount = this.actor.system.scars + 1; @@ -69,36 +71,30 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.avoidScar'); } - async clearAllStressAndHitpoints() { - await this.actor.update({ - system: { - resources: { - hitPoints: { - value: 0 - }, - stress: { - value: 0 - } - } - } - }); - } - async handleRiskItAll() { const config = await enrichedDualityRoll({ reaction: true, traitValue: null, - target: null, + target: this.actor, difficulty: null, - title: 'Risk It All', - label: 'test', + title: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.riskItAll.name'), + label: game.i18n.localize('DAGGERHEART.GENERAL.dualityDice'), actionType: null, - advantage: null + advantage: null, + customConfig: { skips: { resources: true } } }); + if (!config.roll.result) return; + + const clearAllStressAndHitpointsUpdates = [ + { key: 'hitPoints', clear: true }, + { key: 'stress', clear: true } + ]; + + let chatMessage = ''; if (config.roll.isCritical) { - this.clearAllStressAndHitpoints(); - return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllCritical'); + config.resourceUpdates.addResources(clearAllStressAndHitpointsUpdates); + chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllCritical'); } if (config.roll.result.duality == 1) { @@ -108,15 +104,18 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV config.roll.hope.value >= this.actor.system.resources.hitPoints.value + this.actor.system.resources.stress.value ) { - this.clearAllStressAndHitpoints(); - return 'Hope roll value is more than the marked Stress and Hit Points, clearing both.'; + config.resourceUpdates.addResources(clearAllStressAndHitpointsUpdates); + chatMessage = 'Hope roll value is more than the marked Stress and Hit Points, clearing both.'; } - return 'TODO - need to clear Stress and/or Hit Points up to: ' + config.roll.hope.value; + chatMessage = 'TODO - need to clear Stress and/or Hit Points up to: ' + config.roll.hope.value; } if (config.roll.result.duality == -1) { - return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure'); + chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure'); } + + await config.resourceUpdates.updateResources(); + return chatMessage; } async handleBlazeOfGlory() { @@ -162,6 +161,8 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV result = await this.handleRiskItAll(); } + if (!result) return; + const autoExpandDescription = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance) .expandRollMessage?.desc; const cls = getDocumentClass('ChatMessage'); diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index dac4cf68..1e449ee8 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -364,14 +364,14 @@ export class ResourceUpdateMap extends Map { if (!resource.key) continue; const existing = this.get(resource.key); - if (existing) { + if (!existing || resource.clear) { + this.set(resource.key, resource); + } else if (!existing?.clear) { this.set(resource.key, { ...existing, value: existing.value + (resource.value ?? 0), total: existing.total + (resource.total ?? 0) }); - } else { - this.set(resource.key, resource); } } } diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 1a4153ad..300bd14c 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -754,16 +754,24 @@ export default class DhpActor extends Actor { }; } } else { + const valueFunc = (base, resource, baseMax) => { + if (resource.clear) return baseMax && base.inverted ? baseMax : 0; + + return (base.value ?? base) + resource.value; + }; switch (r.key) { case 'fear': ui.resources.updateFear( - game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value + valueFunc( + game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear), + r + ) ); break; case 'armor': if (this.system.armor?.system?.marks) { updates.armor.resources['system.marks.value'] = Math.max( - Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore), + Math.min(valueFunc(this.system.armor.system.marks, r), this.system.armorScore), 0 ); } @@ -772,7 +780,7 @@ export default class DhpActor extends Actor { if (this.system.resources?.[r.key]) { updates.actor.resources[`system.resources.${r.key}.value`] = Math.max( Math.min( - this.system.resources[r.key].value + r.value, + valueFunc(this.system.resources[r.key], r, this.system.resources[r.key].max), this.system.resources[r.key].max ), 0 diff --git a/module/enrichers/DualityRollEnricher.mjs b/module/enrichers/DualityRollEnricher.mjs index a794ca4c..1ba4c792 100644 --- a/module/enrichers/DualityRollEnricher.mjs +++ b/module/enrichers/DualityRollEnricher.mjs @@ -80,7 +80,7 @@ export const renderDualityButton = async event => { }; export const enrichedDualityRoll = async ( - { reaction, traitValue, target, difficulty, title, label, advantage }, + { reaction, traitValue, target, difficulty, title, label, advantage, customConfig }, event ) => { const config = { @@ -94,7 +94,8 @@ export const enrichedDualityRoll = async ( type: reaction ? 'reaction' : null }, type: 'trait', - hasRoll: true + hasRoll: true, + ...(customConfig ?? {}) }; if (target) { diff --git a/module/enrichers/FateRollEnricher.mjs b/module/enrichers/FateRollEnricher.mjs index 6d24ae18..c1b73bae 100644 --- a/module/enrichers/FateRollEnricher.mjs +++ b/module/enrichers/FateRollEnricher.mjs @@ -6,7 +6,7 @@ export default function DhFateRollEnricher(match, _options) { const fateTypeFromRoll = getFateType(roll?.type); - if (fateTypeFromRoll == "BAD") { + if (fateTypeFromRoll == 'BAD') { ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing')); return; } @@ -15,27 +15,37 @@ export default function DhFateRollEnricher(match, _options) { } export function getFateType(fateTypeValue) { - const fateTypeFromValue = fateTypeValue ? - (fateTypeValue.toLowerCase() == "fear" ? "Fear" : - (fateTypeValue.toLowerCase() == "hope" ? "Hope" : "BAD")) : "Hope"; - + const fateTypeFromValue = fateTypeValue + ? fateTypeValue.toLowerCase() == 'fear' + ? 'Fear' + : fateTypeValue.toLowerCase() == 'hope' + ? 'Hope' + : 'BAD' + : 'Hope'; return fateTypeFromValue; } function getFateMessage(roll, flavor) { const fateType = getFateType(roll?.type); - - if (fateType == "BAD") { + + if (fateType == 'BAD') { ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing')); return ''; } - const fateTypeLocalized = fateType === "Hope" ? game.i18n.localize("DAGGERHEART.GENERAL.hope") : game.i18n.localize("DAGGERHEART.GENERAL.fear"); + const fateTypeLocalized = + fateType === 'Hope' + ? game.i18n.localize('DAGGERHEART.GENERAL.hope') + : game.i18n.localize('DAGGERHEART.GENERAL.fear'); - const title = flavor ?? fateTypeLocalized + ' ' + - game.i18n.localize('DAGGERHEART.GENERAL.fate') + ' ' + - game.i18n.localize('DAGGERHEART.GENERAL.roll'); + const title = + flavor ?? + fateTypeLocalized + + ' ' + + game.i18n.localize('DAGGERHEART.GENERAL.fate') + + ' ' + + game.i18n.localize('DAGGERHEART.GENERAL.roll'); const dataLabel = game.i18n.localize('DAGGERHEART.GENERAL.fate'); @@ -56,11 +66,11 @@ function getFateMessage(roll, flavor) { export const renderFateButton = async event => { const button = event.currentTarget, target = getCommandTarget({ allowNull: true }); - console.log("button", button); + console.log('button', button); const fateTypeFromButton = getFateType(button.dataset?.fatetype); - if (fateTypeFromButton == "BAD") { + if (fateTypeFromButton == 'BAD') { ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing')); return; } @@ -76,16 +86,12 @@ export const renderFateButton = async event => { ); }; -export const enrichedFateRoll = async ( - { target, title, label, fateType }, - event -) => { +export const enrichedFateRoll = async ({ target, title, label, fateType }, event) => { const config = { event: event ?? {}, title: title, - roll: { - label: label, - }, + headerTitle: label, + roll: {}, hasRoll: true, fateType: fateType };