mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
.
This commit is contained in:
parent
4aab5d315a
commit
bafc53488f
11 changed files with 270 additions and 4 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import BaseEffect from './baseEffect.mjs';
|
||||
import BeastformEffect from './beastformEffect.mjs';
|
||||
import HordeEffect from './hordeEffect.mjs';
|
||||
import { EffectConditionals, EffectConditional } from './effectConditional.mjs';
|
||||
|
||||
export { BaseEffect, BeastformEffect, HordeEffect };
|
||||
export { BaseEffect, BeastformEffect, HordeEffect, EffectConditionals, EffectConditional };
|
||||
|
||||
export const config = {
|
||||
base: BaseEffect,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { EffectConditionals } from './effectConditional.mjs';
|
||||
|
||||
/** -- Changes Type Priorities --
|
||||
* - Base Number -
|
||||
* Custom: 0
|
||||
|
|
@ -33,6 +35,7 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
|||
priority: new fields.NumberField()
|
||||
})
|
||||
),
|
||||
conditionals: new EffectConditionals(),
|
||||
duration: new fields.SchemaField({
|
||||
type: new fields.StringField({
|
||||
choices: CONFIG.DH.GENERAL.activeEffectDurations,
|
||||
|
|
|
|||
80
module/data/activeEffect/effectConditional.mjs
Normal file
80
module/data/activeEffect/effectConditional.mjs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import { compareValues, itemAbleRollParse } from '../../helpers/utils.mjs';
|
||||
|
||||
export class EffectConditionals extends foundry.data.fields.ArrayField {
|
||||
constructor(context) {
|
||||
super(new EffectConditional(), context);
|
||||
}
|
||||
|
||||
static isConditionalSuspended(effect) {
|
||||
const actor =
|
||||
effect.parent.type === 'character'
|
||||
? effect.parent
|
||||
: effect.parent.parent?.type === 'character'
|
||||
? effect.parent.parent
|
||||
: null;
|
||||
if (!actor) return false;
|
||||
|
||||
for (const conditional of effect.system.conditionals) {
|
||||
switch (conditional.type) {
|
||||
case CONFIG.DH.GENERAL.activeEffectConditionalType.status.id:
|
||||
const hasStatus = Array.from(actor.allApplicableEffects()).some(
|
||||
x => !x.disabled && x.statuses.has(conditional.key)
|
||||
);
|
||||
if (!hasStatus) return true;
|
||||
case CONFIG.DH.GENERAL.activeEffectConditionalType.attribute.id:
|
||||
const actorValue = foundry.utils.getProperty(actor, conditional.key);
|
||||
const conditionalValue = game.system.api.documents.DhActiveEffect.effectSafeEval(
|
||||
itemAbleRollParse(conditional.value, actor)
|
||||
);
|
||||
if (!compareValues(actorValue, conditionalValue, conditional.comparator)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export class EffectConditional extends foundry.data.fields.SchemaField {
|
||||
constructor(context) {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
const schema = {
|
||||
target: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.GENERAL.activeEffectConditionalTarget,
|
||||
initial: CONFIG.DH.GENERAL.activeEffectConditionalTarget.self.id,
|
||||
label: 'DAGGERHEART.GENERAL.Target.single'
|
||||
}),
|
||||
type: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.GENERAL.activeEffectConditionalType,
|
||||
initial: CONFIG.DH.GENERAL.activeEffectConditionalType.status.id,
|
||||
label: 'DAGGERHEART.GENERAL.type'
|
||||
}),
|
||||
key: new fields.StringField({ required: true, label: 'EFFECT.FIELDS.changes.element.key.label' }),
|
||||
value: new fields.StringField({ nullable: true, label: 'EFFECT.FIELDS.changes.element.value.label' }),
|
||||
comparator: new fields.StringField({
|
||||
choices: CONFIG.DH.GENERAL.comparator,
|
||||
initial: CONFIG.DH.GENERAL.comparator.eq.id,
|
||||
label: 'DAGGERHEART.GENERAL.comparator'
|
||||
})
|
||||
};
|
||||
|
||||
super(schema, context);
|
||||
}
|
||||
|
||||
static getConditionalFieldUseage(conditionalType) {
|
||||
let usesValue = false;
|
||||
let usesComparator = false;
|
||||
|
||||
if ([CONFIG.DH.GENERAL.activeEffectConditionalType.attribute.id].includes(conditionalType)) {
|
||||
usesValue = true;
|
||||
usesComparator = true;
|
||||
}
|
||||
|
||||
return {
|
||||
usesValue,
|
||||
usesComparator
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue