diff --git a/daggerheart.mjs b/daggerheart.mjs index 064b1670..33d54874 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -3,6 +3,7 @@ import * as applications from './module/applications/_module.mjs'; import * as data from './module/data/_module.mjs'; import * as models from './module/data/_module.mjs'; import * as documents from './module/documents/_module.mjs'; +import * as regionBehaviors from './module/data/regionBehavior/_module.mjs'; import { macros } from './module/_module.mjs'; import * as collections from './module/documents/collections/_module.mjs'; import * as dice from './module/dice/_module.mjs'; @@ -45,6 +46,8 @@ CONFIG.ActiveEffect.documentClass = documents.DhActiveEffect; CONFIG.ActiveEffect.dataModels = models.activeEffects.config; CONFIG.ActiveEffect.changeTypes = { ...CONFIG.ActiveEffect.changeTypes, ...models.activeEffects.changeEffects }; +CONFIG.RegionBehavior.documentClass = documents.DhRegionBehavior; + CONFIG.Combat.documentClass = documents.DhpCombat; CONFIG.Combat.dataModels = { base: models.DhCombat }; CONFIG.Combatant.documentClass = documents.DHCombatant; diff --git a/module/config/generalConfig.mjs b/module/config/generalConfig.mjs index 93807334..95b628b7 100644 --- a/module/config/generalConfig.mjs +++ b/module/config/generalConfig.mjs @@ -1103,3 +1103,9 @@ export const fallAndCollisionDamage = { damageFormula: '1d20 + 5' } }; + +export const simpleDispositions = { + HOSTILE: -1, + NEUTRAL: 0, + FRIENDLY: 1 +}; \ No newline at end of file diff --git a/module/data/activeEffect/baseEffect.mjs b/module/data/activeEffect/baseEffect.mjs index 2ddedc35..0b5e94e1 100644 --- a/module/data/activeEffect/baseEffect.mjs +++ b/module/data/activeEffect/baseEffect.mjs @@ -112,6 +112,9 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel { initial: CONFIG.DH.GENERAL.range.veryClose.id, label: 'DAGGERHEART.ACTIVEEFFECT.Config.area.size' }), + targetDispositions: new fields.SetField(new fields.NumberField({ + + })), }, { nullable: true, initial: null }) }; } diff --git a/module/data/regionBehavior/_module.mjs b/module/data/regionBehavior/_module.mjs new file mode 100644 index 00000000..7a8893de --- /dev/null +++ b/module/data/regionBehavior/_module.mjs @@ -0,0 +1 @@ +export { default as applyActiveEffect } from './applyActiveEffect.mjs'; \ No newline at end of file diff --git a/module/data/regionBehavior/applyActiveEffect.mjs b/module/data/regionBehavior/applyActiveEffect.mjs new file mode 100644 index 00000000..1a2b7be2 --- /dev/null +++ b/module/data/regionBehavior/applyActiveEffect.mjs @@ -0,0 +1,14 @@ +export default class DhApplyActiveEffect extends CONFIG.RegionBehavior.dataModels.applyActiveEffect { + static #tokenDispositionChecker = (eventFunction) => (event) => { + const { token } = event.data; + if (token.disposition === -1) { + eventFunction.bind(this)(event); + } + } + + /** @override */ + static events = Object.entries(super.events).reduce((acc, [key, func]) => { + acc[key] = DhApplyActiveEffect.#tokenDispositionChecker(func); + return acc; + }, {}); +} \ No newline at end of file diff --git a/module/documents/_module.mjs b/module/documents/_module.mjs index aa08f0f4..de0deb7c 100644 --- a/module/documents/_module.mjs +++ b/module/documents/_module.mjs @@ -9,3 +9,4 @@ export { default as DhScene } from './scene.mjs'; export { default as DhToken } from './token.mjs'; export { default as DhTooltipManager } from './tooltipManager.mjs'; export { default as DhTokenManager } from './tokenManager.mjs'; +export { default as DhRegionBehavior } from './regionBehavior.mjs'; \ No newline at end of file diff --git a/module/documents/regionBehavior.mjs b/module/documents/regionBehavior.mjs new file mode 100644 index 00000000..4482cd66 --- /dev/null +++ b/module/documents/regionBehavior.mjs @@ -0,0 +1,28 @@ +export default class DhRegionBehavior extends RegionBehavior { + /**@inheritDoc */ + async _handleRegionEvent(event) { + if (!(this.system instanceof foundry.data.regionBehaviors.RegionBehaviorType)) return; + + // Optionally prevent event if not applicable + // Currently only caring about statically registered events + if (event.name in this.system.constructor.events) { + if (this.isEventApplicable(event) === false) return; + super._handleRegionEvent(event); + } + } + + isEventApplicable(event) { + switch(this.type) { + case 'applyActiveEffect': + /* If reworked to an area, we'll probably still have to override the onEnter/onExit methods to filter which effects apply */ + const effects = this.system.effects.map(effect => foundry.utils.fromUuidSync(effect)).filter(x => x); + const applicableDispositions = effects.first().system.area?.targetDispositions??[]; + if(!applicableDispositions.size) return true; + + return event.data.token.disposition === CONST.TOKEN_DISPOSITIONS.SECRET || + applicableDispositions.has(event.data.token.disposition); + default: + return true; + } + } +} \ No newline at end of file diff --git a/templates/sheets/activeEffect/settings.hbs b/templates/sheets/activeEffect/settings.hbs index c1b76a7d..b6f902fd 100644 --- a/templates/sheets/activeEffect/settings.hbs +++ b/templates/sheets/activeEffect/settings.hbs @@ -55,21 +55,19 @@ {{#if document.system.area}} - - {{formGroup systemFields.area.fields.type value=source.system.area.type localize=true blank=false }} - {{formGroup systemFields.area.fields.shape value=source.system.area.shape localize=true blank=false }} -