This commit is contained in:
Dapoolp 2025-08-17 11:52:12 +02:00
parent 1228eb0105
commit 810d74baa5
11 changed files with 220 additions and 17 deletions

View file

@ -3,7 +3,7 @@ import FormulaField from '../formulaField.mjs';
const fields = foundry.data.fields;
export default class DamageField extends fields.SchemaField {
static order = 50;
static order = 20;
constructor(options, context = {}) {
const damageFields = {

View file

@ -1,7 +1,7 @@
const fields = foundry.data.fields;
export default class EffectsField extends fields.ArrayField {
static order = 100;
static order = 60;
constructor(options = {}, context = {}) {
const element = new fields.SchemaField({
@ -20,4 +20,45 @@ export default class EffectsField extends fields.ArrayField {
return;
}
}
async applyEffects(data, targets) {
targets ??= data.system.targets;
const force = true; /* Where should this come from? */
if (!this.effects?.length || !targets.length) return;
let effects = this.effects;
targets.forEach(async token => {
if (!token.hit && !force) return;
if (this.hasSave && token.saved.success === true) {
effects = this.effects.filter(e => e.onSave === true);
}
if (!effects.length) return;
effects.forEach(async e => {
const actor = canvas.tokens.get(token.id)?.actor,
effect = this.item.effects.get(e._id);
if (!actor || !effect) return;
await this.applyEffect(effect, actor);
});
});
}
async applyEffect(effect, actor) {
const existingEffect = actor.effects.find(e => e.origin === effect.uuid);
if (existingEffect) {
return effect.update(
foundry.utils.mergeObject({
...effect.constructor.getInitialDuration(),
disabled: false
})
);
}
// Otherwise, create a new effect on the target
const effectData = foundry.utils.mergeObject({
...effect.toObject(),
disabled: false,
transfer: false,
origin: effect.uuid
});
await ActiveEffect.implementation.create(effectData, { parent: actor });
}
}

View file

@ -1,7 +1,7 @@
const fields = foundry.data.fields;
export default class MacroField extends fields.DocumentUUIDField {
static order = 200;
static order = 70;
constructor(context = {}) {
super({ type: "Macro" }, context);

View file

@ -1,7 +1,7 @@
const fields = foundry.data.fields;
export default class SaveField extends fields.SchemaField {
static order = 75;
static order = 50;
constructor(options = {}, context = {}) {
const saveFields = {