Added the ability for effects to automatically activate/deactivate depending on range between tokens

This commit is contained in:
WBHarry 2025-07-29 14:50:14 +02:00
parent 4defe69c21
commit b80f598625
13 changed files with 218 additions and 30 deletions

View file

@ -27,7 +27,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
header: { template: 'systems/daggerheart/templates/sheets/activeEffect/header.hbs' },
tabs: { template: 'templates/generic/tab-navigation.hbs' },
details: { template: 'systems/daggerheart/templates/sheets/activeEffect/details.hbs', scrollable: [''] },
duration: { template: 'systems/daggerheart/templates/sheets/activeEffect/duration.hbs' },
settings: { template: 'systems/daggerheart/templates/sheets/activeEffect/settings.hbs' },
changes: {
template: 'systems/daggerheart/templates/sheets/activeEffect/changes.hbs',
scrollable: ['ol[data-changes]']
@ -39,7 +39,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
sheet: {
tabs: [
{ id: 'details', icon: 'fa-solid fa-book' },
{ id: 'duration', icon: 'fa-solid fa-clock' },
{ id: 'settings', icon: 'fa-solid fa-bars', label: 'DAGGERHEART.GENERAL.Tabs.settings' },
{ id: 'changes', icon: 'fa-solid fa-gears' }
],
initial: 'details',

View file

@ -43,25 +43,6 @@ export const actionTypes = {
}
};
export const targetTypes = {
self: {
id: 'self',
label: 'Self'
},
friendly: {
id: 'friendly',
label: 'Friendly'
},
hostile: {
id: 'hostile',
label: 'Hostile'
},
any: {
id: 'any',
label: 'Any'
}
};
export const damageOnSave = {
none: {
id: 'none',

View file

@ -43,6 +43,52 @@ export const range = {
}
};
export const compareOperator = {
lessThan: {
id: 'lessThan',
label: 'DAGGERHEART.CONFIG.CompareOperator.lessThan'
},
lessThanEqual: {
id: 'lessThanEqual',
label: 'DAGGERHEART.CONFIG.CompareOperator.lessThanEqual'
},
equal: {
id: 'equal',
label: 'DAGGERHEART.CONFIG.CompareOperator.equal'
},
moreThanEqual: {
id: 'moreThanEqual',
label: 'DAGGERHEART.CONFIG.CompareOperator.moreThanEqual'
},
moreThan: {
id: 'moreThan',
label: 'DAGGERHEART.CONFIG.CompareOperator.moreThan'
}
};
export const otherTargetTypes = {
friendly: {
id: 'friendly',
label: 'Friendly'
},
hostile: {
id: 'hostile',
label: 'Hostile'
},
any: {
id: 'any',
label: 'Any'
}
};
export const targetTypes = {
self: {
id: 'self',
label: 'Self'
},
...otherTargetTypes
};
export const burden = {
oneHanded: {
value: 'oneHanded',

View file

@ -1,7 +1,9 @@
import BaseEffect from './baseEffect.mjs';
import BeastformEffect from './beastformEffect.mjs';
export { BeastformEffect };
export { BaseEffect, BeastformEffect };
export const config = {
base: BaseEffect,
beastform: BeastformEffect
};

View file

@ -0,0 +1,33 @@
export default class BaseEffect extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
rangeDependence: new fields.SchemaField({
enabled: new fields.BooleanField({
required: true,
initial: false,
label: 'DAGGERHEART.GENERAL.enabled'
}),
type: new fields.StringField({
required: true,
choices: CONFIG.DH.GENERAL.compareOperator,
initial: CONFIG.DH.GENERAL.compareOperator.lessThanEqual.id,
label: 'DAGGERHEART.GENERAL.type'
}),
target: new fields.StringField({
required: true,
choices: CONFIG.DH.GENERAL.otherTargetTypes,
initial: CONFIG.DH.GENERAL.otherTargetTypes.hostile.id,
label: 'DAGGERHEART.GENERAL.Target.single'
}),
range: new fields.StringField({
required: true,
choices: CONFIG.DH.GENERAL.range,
initial: CONFIG.DH.GENERAL.range.melee.id,
label: 'DAGGERHEART.GENERAL.range'
})
})
};
}
}

View file

@ -1,6 +1,7 @@
import { updateActorTokens } from '../../helpers/utils.mjs';
import BaseEffect from './baseEffect.mjs';
export default class BeastformEffect extends foundry.abstract.TypeDataModel {
export default class BeastformEffect extends BaseEffect {
static defineSchema() {
const fields = foundry.data.fields;
return {

View file

@ -4,8 +4,8 @@ export default class TargetField extends fields.SchemaField {
constructor(options = {}, context = {}) {
const targetFields = {
type: new fields.StringField({
choices: CONFIG.DH.ACTIONS.targetTypes,
initial: CONFIG.DH.ACTIONS.targetTypes.any.id,
choices: CONFIG.DH.GENERAL.targetTypes,
initial: CONFIG.DH.GENERAL.targetTypes.any.id,
nullable: true
}),
amount: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
@ -16,11 +16,11 @@ export default class TargetField extends fields.SchemaField {
static prepareConfig(config) {
if (!this.target?.type) return [];
let targets;
if (this.target?.type === CONFIG.DH.ACTIONS.targetTypes.self.id)
if (this.target?.type === CONFIG.DH.GENERAL.targetTypes.self.id)
targets = [this.actor.token ?? this.actor.prototypeToken];
else {
targets = Array.from(game.user.targets);
if (this.target.type !== CONFIG.DH.ACTIONS.targetTypes.any.id) {
if (this.target.type !== CONFIG.DH.GENERAL.targetTypes.any.id) {
targets = targets.filter(t => TargetField.isTargetFriendly.call(this, t));
if (this.target.amount && targets.length > this.target.amount) targets = [];
}
@ -43,9 +43,9 @@ export default class TargetField extends fields.SchemaField {
: this.actor.prototypeToken.disposition,
targetDisposition = target.document.disposition;
return (
(this.target.type === CONFIG.DH.ACTIONS.targetTypes.friendly.id &&
(this.target.type === CONFIG.DH.GENERAL.targetTypes.friendly.id &&
actorDisposition === targetDisposition) ||
(this.target.type === CONFIG.DH.ACTIONS.targetTypes.hostile.id &&
(this.target.type === CONFIG.DH.GENERAL.targetTypes.hostile.id &&
actorDisposition + targetDisposition === 0)
);
}

View file

@ -23,6 +23,12 @@ export default class DhAutomation extends foundry.abstract.DataModel {
required: true,
initial: true,
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.hordeDamage.label'
}),
effects: new fields.SchemaField({
rangeDependent: new fields.BooleanField({
initial: true,
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.effects.rangeDependent.label'
})
})
};
}

View file

@ -321,3 +321,18 @@ export const arraysEqual = (a, b) =>
[...new Set([...a, ...b])].every(v => a.filter(e => e === v).length === b.filter(e => e === v).length);
export const setsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value));
export function compareValues(a, b, compare) {
switch (compare) {
case CONFIG.DH.GENERAL.compareOperator.lessThan.id:
return a < b;
case CONFIG.DH.GENERAL.compareOperator.lessThanEqual.id:
return a <= b;
case CONFIG.DH.GENERAL.compareOperator.equal.id:
return a === b;
case CONFIG.DH.GENERAL.compareOperator.moreThanEqual.id:
return a >= b;
case CONFIG.DH.GENERAL.compareOperator.moreThan.id:
return a > b;
}
}