Fixed so that scrolltexts for armor changes work again

This commit is contained in:
WBHarry 2026-03-21 10:40:19 +01:00
parent e83d3f7d44
commit 9635387779
4 changed files with 28 additions and 14 deletions

View file

@ -12,6 +12,7 @@
* "Anything that uses another data model value as its value": +1 - Effects that increase traits have to be calculated first at Base priority. (EX: Raise evasion by half your agility)
*/
import { getScrollTextData } from '../../helpers/utils.mjs';
import { changeTypes } from './_module.mjs';
export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
@ -130,4 +131,27 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
}
};
}
async _preUpdate(changed, options, userId) {
const allowed = await super._preUpdate(changed, options, userId);
if (allowed === false) return false;
const autoSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
if (autoSettings.resourceScrollTexts && this.parent.actor?.type === 'character') {
const newArmorTotal = (changed.system?.changes ?? []).reduce((acc, change) => {
if (change.type === 'armor') acc += change.value.current;
return acc;
}, 0);
const armorData = getScrollTextData(this.parent.actor, { value: newArmorTotal }, 'armor');
options.scrollingTextData = [armorData];
}
}
_onUpdate(changed, options, userId) {
super._onUpdate(changed, options, userId);
if (this.parent.actor && options.scrollingTextData)
this.parent.actor.queueScrollText(options.scrollingTextData);
}
}

View file

@ -68,14 +68,12 @@ export default class ArmorChange extends foundry.abstract.DataModel {
}
}
static getInitialValue(locked) {
static getInitialValue() {
return {
key: 'Armor',
type: CONFIG.DH.GENERAL.activeEffectModes.armor.id,
value: {
current: 0,
max: 0,
locked
max: 0
},
phase: 'initial',
priority: 20
@ -87,7 +85,7 @@ export default class ArmorChange extends foundry.abstract.DataModel {
name: game.i18n.localize('DAGGERHEART.EFFECTS.ChangeTypes.armor.newArmorEffect'),
img: 'icons/equipment/chest/breastplate-helmet-metal.webp',
system: {
changes: [ArmorChange.getInitialValue(true)]
changes: [ArmorChange.getInitialValue()]
}
};
}