Fixed so changing armor values and taking damage works again

This commit is contained in:
WBHarry 2026-03-21 09:58:41 +01:00
parent 809bdc8678
commit e83d3f7d44
7 changed files with 42 additions and 32 deletions

View file

@ -108,7 +108,7 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
const armorChange = this.armorChange;
if (!armorChange) return null;
return armorChange.getArmorData(armorChange);
return armorChange.getArmorData();
}
static getDefaultObject() {

View file

@ -23,7 +23,7 @@ export default class ArmorChange extends foundry.abstract.DataModel {
label: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.label',
hint: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.hint'
})
}),
})
};
}
@ -94,15 +94,15 @@ export default class ArmorChange extends foundry.abstract.DataModel {
/* Helpers */
getArmorData(parentChange) {
getArmorData() {
const actor = this.parent.parent?.actor?.type === 'character' ? this.parent.parent.actor : null;
const maxParse = actor ? itemAbleRollParse(this.max, actor, this.parent.parent.parent) : null;
const maxParse = actor ? itemAbleRollParse(this.value.max, actor, this.parent.parent.parent) : null;
const maxRoll = maxParse ? new Roll(maxParse).evaluateSync() : null;
const maxEvaluated = maxRoll ? (maxRoll.isDeterministic ? maxRoll.total : null) : null;
return {
value: parentChange.value,
max: maxEvaluated ?? this.max
current: this.value.current,
max: maxEvaluated ?? this.value.max
};
}
@ -110,8 +110,14 @@ export default class ArmorChange extends foundry.abstract.DataModel {
const newChanges = [
...this.parent.changes.map(change => ({
...change,
value: change.type === 'armor' ? Math.min(change.value, newMax) : change.value,
typeData: change.type === 'armor' ? { ...change.typeData, max: newMax } : change.typeData
value:
change.type === 'armor'
? {
...change.value,
current: Math.min(change.value.current, newMax),
max: newMax
}
: change.value
}))
];
await this.parent.parent.update({ 'system.changes': newChanges });

View file

@ -479,14 +479,14 @@ export default class DhCharacter extends DhCreature {
for (const armorEffect of orderedEffects) {
let usedArmorChange = 0;
if (clear) {
usedArmorChange -= armorEffect.system.armorChange.value;
usedArmorChange -= armorEffect.system.armorChange.value.current;
} else {
if (increasing) {
const remainingArmor = armorEffect.system.armorData.max - armorEffect.system.armorData.value;
const remainingArmor = armorEffect.system.armorData.max - armorEffect.system.armorData.current;
usedArmorChange = Math.min(remainingChange, remainingArmor);
remainingChange -= usedArmorChange;
} else {
const changeChange = Math.min(armorEffect.system.armorData.value, remainingChange);
const changeChange = Math.min(armorEffect.system.armorData.current, remainingChange);
usedArmorChange -= changeChange;
remainingChange -= changeChange;
}
@ -503,7 +503,10 @@ export default class DhCharacter extends DhCreature {
...change,
value:
change.type === 'armor'
? armorEffect.system.armorChange.value + usedArmorChange
? {
...change.value,
current: armorEffect.system.armorChange.value.current + usedArmorChange
}
: change.value
}))
});
@ -519,11 +522,12 @@ export default class DhCharacter extends DhCreature {
async updateArmorEffectValue({ uuid, value }) {
const effect = await foundry.utils.fromUuid(uuid);
const effectValue = effect.system.armorChange.value;
await effect.update({
'system.changes': [
{
...effect.system.armorChange,
value: effect.system.armorChange.value + value
value: { ...effectValue, current: effectValue.current + value }
}
]
});