From 3157fd450f07b6a10168272f4f4c83c235cd900a Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Sun, 26 Apr 2026 11:20:20 +0200 Subject: [PATCH] [Fix] V13 - Companion Fixes (#1840) * Fixed companion initial max stress. Cleaned up prepareData flow * Clamped adversary resources --- module/config/resourceConfig.mjs | 8 +------- module/data/actor/adversary.mjs | 3 +++ module/data/actor/character.mjs | 6 +++++- module/data/actor/companion.mjs | 6 +++--- module/data/actor/creature.mjs | 10 ---------- module/data/fields/actorField.mjs | 12 ++++++++++++ 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/module/config/resourceConfig.mjs b/module/config/resourceConfig.mjs index 56ef6cd5..1306d327 100644 --- a/module/config/resourceConfig.mjs +++ b/module/config/resourceConfig.mjs @@ -57,16 +57,10 @@ const companionBaseResources = Object.freeze({ stress: { id: 'stress', initial: 0, - max: 0, + max: 3, reverse: true, label: 'DAGGERHEART.GENERAL.stress' }, - hope: { - id: 'hope', - initial: 0, - reverse: false, - label: 'DAGGERHEART.GENERAL.hope' - } }); export const character = { diff --git a/module/data/actor/adversary.mjs b/module/data/actor/adversary.mjs index 2053ac99..dd41f290 100644 --- a/module/data/actor/adversary.mjs +++ b/module/data/actor/adversary.mjs @@ -189,6 +189,9 @@ export default class DhpAdversary extends DhCreature { prepareDerivedData() { super.prepareDerivedData(); this.attack.roll.isStandardAttack = true; + + // Clamp resources (must be done last to ensure all updates occur) + this.resources.clamp(); } _getTags() { diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index cde7d280..bea3a3ec 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -660,6 +660,8 @@ export default class DhCharacter extends DhCreature { prepareDerivedData() { super.prepareDerivedData(); + + this.resources.hope.max -= this.scars; if (this.companion) { for (let levelKey in this.companion.system.levelData.levelups) { const level = this.companion.system.levelData.levelups[levelKey]; @@ -673,7 +675,6 @@ export default class DhCharacter extends DhCreature { } } - this.resources.hope.max -= this.scars; this.attack.roll.trait = this.rules.attack.roll.trait ?? this.attack.roll.trait; this.resources.armor = { @@ -684,6 +685,9 @@ export default class DhCharacter extends DhCreature { }; this.attack.damage.parts[0].value.custom.formula = `@prof${this.basicAttackDamageDice}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`; + + // Clamp resources (must be done last to ensure all updates occur) + this.resources.clamp(); } getRollData() { diff --git a/module/data/actor/companion.mjs b/module/data/actor/companion.mjs index 7a8f0e64..c6768e95 100644 --- a/module/data/actor/companion.mjs +++ b/module/data/actor/companion.mjs @@ -130,9 +130,6 @@ export default class DhCompanion extends DhCreature { const level = this.levelData.levelups[levelKey]; for (let selection of level.selections) { switch (selection.type) { - case 'hope': - this.resources.hope += selection.value; - break; case 'vicious': if (selection.data[0] === 'damage') { this.attack.damage.parts[0].value.dice = adjustDice(this.attack.damage.parts[0].value.dice); @@ -167,6 +164,9 @@ export default class DhCompanion extends DhCreature { return acc; }, this.partner.system.companionData.levelupChoices); } + + // Clamp resources (must be done last to ensure all updates occur) + this.resources.clamp(); } async _preUpdate(changes, options, userId) { diff --git a/module/data/actor/creature.mjs b/module/data/actor/creature.mjs index 88646301..601068ad 100644 --- a/module/data/actor/creature.mjs +++ b/module/data/actor/creature.mjs @@ -60,14 +60,4 @@ export default class DhCreature extends BaseDataActor { } } } - - prepareDerivedData() { - const minLimitResource = resource => { - if (resource) resource.value = Math.min(resource.value, resource.max); - }; - - minLimitResource(this.resources.stress); - minLimitResource(this.resources.hitPoints); - minLimitResource(this.resources.hope); - } } diff --git a/module/data/fields/actorField.mjs b/module/data/fields/actorField.mjs index a3c17281..ac7dd5ef 100644 --- a/module/data/fields/actorField.mjs +++ b/module/data/fields/actorField.mjs @@ -80,6 +80,18 @@ class ResourcesField extends fields.TypedObjectField { value.isReversed = resources[key].reverse; value.max = typeof resource.max === 'number' ? (value.max ?? resource.max) : null; } + Object.defineProperty(data, 'clamp', { + value: function () { + for (const key of Object.keys(this)) { + const resource = this[key]; + if (typeof resource?.max === 'number') { + resource.value = Math.clamp(resource.value, 0, resource.max); + } + } + }, + enumerable: false + }); + return data; }