This commit is contained in:
WBHarry 2026-02-06 09:59:06 +01:00
parent 593105b163
commit 7bc5ea4910
12 changed files with 198 additions and 5 deletions

View file

@ -1,11 +1,13 @@
import BaseEffect from './baseEffect.mjs';
import BeastformEffect from './beastformEffect.mjs';
import HordeEffect from './hordeEffect.mjs';
import ArmorEffect from './armorEffect.mjs';
export { BaseEffect, BeastformEffect, HordeEffect };
export { BaseEffect, BeastformEffect, HordeEffect, ArmorEffect };
export const config = {
base: BaseEffect,
beastform: BeastformEffect,
horde: HordeEffect
horde: HordeEffect,
armor: ArmorEffect
};

View file

@ -0,0 +1,64 @@
export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
changes: new fields.ArrayField(
new fields.SchemaField({
type: new fields.StringField({
required: true,
blank: false,
choices: CONFIG.DH.GENERAL.activeEffectModes,
initial: CONFIG.DH.GENERAL.activeEffectModes.add.id,
validate: ArmorEffect.#validateType
}),
phase: new fields.StringField({ required: true, blank: false, initial: 'initial' }),
priority: new fields.NumberField(),
marked: new fields.NumberField({
required: true,
integer: true,
initial: 0,
min: 0,
label: 'DAGGERHEART.GENERAL.value'
}),
max: new fields.NumberField({
required: true,
integer: true,
initial: 1,
min: 1,
label: 'DAGGERHEART.GENERAL.max'
})
})
)
};
}
static applyChangeField(model, change, field) {
return [model, change, field];
}
prepareBaseData() {
for (const change of this.changes) {
change.key = 'system.armorTest';
change.value = Math.max(change.max - change.marked, change.max);
}
}
/**
* Validate that an {@link EffectChangeData#type} string is well-formed.
* @param {string} type The string to be validated
* @returns {true}
* @throws {Error} An error if the type string is malformed
*/
static #validateType(type) {
if (type.length < 3) throw new Error('must be at least three characters long');
if (!/^custom\.-?\d+$/.test(type) && !type.split('.').every(s => /^[a-z0-9]+$/i.test(s))) {
throw new Error(
'A change type must either be a sequence of dot-delimited, alpha-numeric substrings or of the form' +
' "custom.{number}"'
);
}
return true;
}
}