diff --git a/daggerheart.mjs b/daggerheart.mjs index f4dba5a3..649de232 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -311,7 +311,7 @@ Hooks.on('chatMessage', (_, message) => { target, difficulty, title, - label: game.i18n.localize('DAGGERHEART.GENERAL.dualityRoll'), + label: 'test', actionType: null, advantage }); diff --git a/lang/en.json b/lang/en.json index ccf03029..b8f811ac 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2135,7 +2135,6 @@ "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 f6ab33a9..6021f607 100644 --- a/module/applications/dialogs/deathMove.mjs +++ b/module/applications/dialogs/deathMove.mjs @@ -44,13 +44,11 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV const target = this.actor.uuid; const config = await enrichedFateRoll({ target, - title: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.avoidDeath.name'), - label: `${game.i18n.localize('DAGGERHEART.GENERAL.hope')} ${game.i18n.localize('DAGGERHEART.GENERAL.fateRoll')}`, + title: 'Avoid Death Hope Fate Roll', + label: 'test', 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; @@ -71,30 +69,36 @@ 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: this.actor, + target: null, difficulty: null, - title: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.riskItAll.name'), - label: game.i18n.localize('DAGGERHEART.GENERAL.dualityDice'), + title: 'Risk It All', + label: 'test', actionType: null, - advantage: null, - customConfig: { skips: { resources: true } } + advantage: null }); - if (!config.roll.result) return; - - const clearAllStressAndHitpointsUpdates = [ - { key: 'hitPoints', clear: true }, - { key: 'stress', clear: true } - ]; - - let chatMessage = ''; if (config.roll.isCritical) { - config.resourceUpdates.addResources(clearAllStressAndHitpointsUpdates); - chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllCritical'); + this.clearAllStressAndHitpoints(); + return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllCritical'); } if (config.roll.result.duality == 1) { @@ -104,18 +108,15 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV config.roll.hope.value >= this.actor.system.resources.hitPoints.value + this.actor.system.resources.stress.value ) { - config.resourceUpdates.addResources(clearAllStressAndHitpointsUpdates); - chatMessage = 'Hope roll value is more than the marked Stress and Hit Points, clearing both.'; + this.clearAllStressAndHitpoints(); + return 'Hope roll value is more than the marked Stress and Hit Points, clearing both.'; } - chatMessage = 'TODO - need to clear Stress and/or Hit Points up to: ' + config.roll.hope.value; + return 'TODO - need to clear Stress and/or Hit Points up to: ' + config.roll.hope.value; } if (config.roll.result.duality == -1) { - chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure'); + return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure'); } - - await config.resourceUpdates.updateResources(); - return chatMessage; } async handleBlazeOfGlory() { @@ -161,8 +162,6 @@ 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 1e449ee8..dac4cf68 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 || resource.clear) { - this.set(resource.key, resource); - } else if (!existing?.clear) { + if (existing) { 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/data/fields/action/rollField.mjs b/module/data/fields/action/rollField.mjs index 63d48990..e2196c1c 100644 --- a/module/data/fields/action/rollField.mjs +++ b/module/data/fields/action/rollField.mjs @@ -87,7 +87,7 @@ export class DHActionRollData extends foundry.abstract.DataModel { if (this.type === CONFIG.DH.GENERAL.rollTypes.attack.id) modifiers.push({ label: 'Bonus to Hit', - value: this.bonus ?? this.parent.actor.system.attack.roll.bonus ?? 0 + value: this.bonus ?? this.parent.actor.system.attack.roll.bonus }); break; default: diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 3ddd8027..f679d725 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -35,9 +35,7 @@ export default class D20Roll extends DHRoll { get isCritical() { if (!this.d20._evaluated) return; - - const criticalThreshold = this.options.actionType === 'reaction' ? 20 : this.data.system.criticalThreshold; - return this.d20.total >= criticalThreshold; + return this.d20.total >= this.data.system.criticalThreshold; } get hasAdvantage() { diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index 3091deaf..c429d033 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -133,13 +133,11 @@ export default class DualityRoll extends D20Roll { return; } - this.terms[0] = new foundry.dice.terms.Die({ - faces: this.data.rules.dualityRoll?.defaultHopeDice ?? 12 - }); + const { defaultHopeDice, defaultFearDice } = this.data.rules.dualityRoll; + + this.terms[0] = new foundry.dice.terms.Die({ faces: defaultHopeDice }); this.terms[1] = new foundry.dice.terms.OperatorTerm({ operator: '+' }); - this.terms[2] = new foundry.dice.terms.Die({ - faces: this.data.rules.dualityRoll?.defaultFearDice ?? 12 - }); + this.terms[2] = new foundry.dice.terms.Die({ faces: defaultFearDice }); } applyAdvantage() { @@ -278,8 +276,6 @@ export default class DualityRoll extends D20Roll { } static async handleTriggers(roll, config) { - if (!config.source?.actor) return; - const updates = []; const dualityUpdates = await game.system.registeredTriggers.runTrigger( CONFIG.DH.TRIGGER.triggers.dualityRoll.id, diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 300bd14c..1a4153ad 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -754,24 +754,16 @@ 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( - valueFunc( - game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear), - r - ) + game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value ); break; case 'armor': if (this.system.armor?.system?.marks) { updates.armor.resources['system.marks.value'] = Math.max( - Math.min(valueFunc(this.system.armor.system.marks, r), this.system.armorScore), + Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore), 0 ); } @@ -780,7 +772,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( - valueFunc(this.system.resources[r.key], r, this.system.resources[r.key].max), + this.system.resources[r.key].value + r.value, this.system.resources[r.key].max ), 0 diff --git a/module/enrichers/DualityRollEnricher.mjs b/module/enrichers/DualityRollEnricher.mjs index 1ba4c792..b56984fc 100644 --- a/module/enrichers/DualityRollEnricher.mjs +++ b/module/enrichers/DualityRollEnricher.mjs @@ -80,29 +80,28 @@ export const renderDualityButton = async event => { }; export const enrichedDualityRoll = async ( - { reaction, traitValue, target, difficulty, title, label, advantage, customConfig }, + { reaction, traitValue, target, difficulty, title, label, advantage }, event ) => { const config = { event: event ?? {}, title: title, - headerTitle: label, roll: { trait: traitValue && target ? traitValue : null, + label: label, difficulty: difficulty, advantage, type: reaction ? 'reaction' : null }, type: 'trait', - hasRoll: true, - ...(customConfig ?? {}) + hasRoll: true }; if (target) { await target.diceRoll(config); } else { // For no target, call DualityRoll directly with basic data - config.data = { experiences: {}, traits: {}, rules: {} }; + config.data = { experiences: {}, traits: {} }; config.source = { actor: null }; await CONFIG.Dice.daggerheart.DualityRoll.build(config); } diff --git a/module/enrichers/FateRollEnricher.mjs b/module/enrichers/FateRollEnricher.mjs index c1b73bae..6d24ae18 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,37 +15,27 @@ 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'); @@ -66,11 +56,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; } @@ -86,12 +76,16 @@ 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, - headerTitle: label, - roll: {}, + roll: { + label: label, + }, hasRoll: true, fateType: fateType };