This commit is contained in:
Dapoolp 2025-09-02 00:02:10 +02:00
parent c6741b1c7a
commit 7cbe4b7580
4 changed files with 83 additions and 24 deletions

View file

@ -3,6 +3,11 @@ export default class BaseEffect extends foundry.abstract.TypeDataModel {
const fields = foundry.data.fields;
return {
conditional: new fields.SchemaField({
field: new fields.StringField({required: true, nullable: true}),
operator: new fields.StringField({required: true, choices: foundry.applications.ux.SearchFilter.OPERATORS, initial: 'EQUALS'}),
value: new fields.StringField({required: true})
}),
rangeDependence: new fields.SchemaField({
enabled: new fields.BooleanField({
required: true,

View file

@ -1,6 +1,19 @@
import { itemAbleRollParse } from '../helpers/utils.mjs';
export default class DhActiveEffect extends foundry.documents.ActiveEffect {
/* -------------------------------------------- */
/** @inheritdoc */
// static defineSchema() {
// const fields = foundry.data.fields;
// return {
// ...super.defineSchema(),
// test: new fields.StringField()
// }
// }
/* -------------------------------------------- */
/* Properties */
/* -------------------------------------------- */
@ -85,6 +98,14 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
change.value = evalValue ?? change.value;
super.applyField(model, change, field);
}
/**@inheritdoc*/
apply(actor, change) {
if(!this.verifyConditional(actor)) return {};
// const changes = super.apply(actor, change);
// console.log(actor, change, changes);
return super.apply(actor, change);
}
/**
* Altered Foundry safeEval to allow non-numeric return
@ -104,6 +125,13 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
return result;
}
verifyConditional(actor) {
if(!this.system.conditional.key) return true;
// const prop = foundry.utils.getProperty(actor, this.system.conditional.key);
// if(prop === undefined) return false;
return foundry.applications.ux.SearchFilter.evaluateFilter(actor, this.system.conditional);
}
/**
* Generates a list of localized tags based on this item's type-specific properties.
* @returns {string[]} An array of localized tag strings.