daggerheart/module/data/regionBehavior/applyActiveEffect.mjs
WBHarry 3eda3c4c05
Some checks are pending
Project CI / build (24.x) (push) Waiting to run
[Feature] Action Areas (#1815)
* Functioning setup

* .

* Fixes

* Completed

* Apply suggestions from code review

Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>

* using function.call instead of function.bind

* Run lint fix on action areas PR (#1820)

* .

* .

* Restructured getTemplateShape to be a lot more readable

* .

* .

* Changed from 'area' to 'areas'

* .

* Moved the areas button to the left

* Fix regression with actions list

* Updated all SRD adversaries

---------

Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>
Co-authored-by: Carlos Fernandez <cfern1990@gmail.com>
2026-04-21 22:27:52 +02:00

40 lines
1.6 KiB
JavaScript

export default class DhApplyActiveEffect extends CONFIG.RegionBehavior.dataModels.applyActiveEffect {
static async #getApplicableEffects(token) {
const effects = await Promise.all(this.effects.map(foundry.utils.fromUuid));
return effects.filter(
effect => !effect.system.targetDispositions.size || effect.system.targetDispositions.has(token.disposition)
);
}
static async #onTokenEnter(event) {
if (!event.user.isSelf) return;
const { token, movement } = event.data;
const actor = token.actor;
if (!actor) return;
const resumeMovement = movement ? token.pauseMovement() : undefined;
const effects = await DhApplyActiveEffect.#getApplicableEffects.bind(this)(event.data.token);
const toCreate = [];
for (const effect of effects) {
const data = effect.toObject();
delete data._id;
if (effect.compendium) {
data._stats.duplicateSource = null;
data._stats.compendiumSource = effect.uuid;
} else {
data._stats.duplicateSource = effect.uuid;
data._stats.compendiumSource = null;
}
data._stats.exportSource = null;
data.origin = this.parent.uuid;
toCreate.push(data);
}
if (toCreate.length) await actor.createEmbeddedDocuments('ActiveEffect', toCreate);
await resumeMovement?.();
}
/** @override */
static events = {
...CONFIG.RegionBehavior.dataModels.applyActiveEffect.events,
[CONST.REGION_EVENTS.TOKEN_ENTER]: this.#onTokenEnter
};
}