diff --git a/src/module/active-effect.ts b/src/module/active-effect.ts new file mode 100644 index 00000000..1ae6eccc --- /dev/null +++ b/src/module/active-effect.ts @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + +import { DS4Actor } from "./actor/actor"; + +declare global { + interface DocumentClassConfig { + ActiveEffect: typeof DS4ActiveEffect; + } +} + +export class DS4ActiveEffect extends ActiveEffect { + /** @override */ + apply(actor: DS4Actor, change: foundry.data.ActiveEffectData["changes"][number]): unknown { + change.value = Roll.replaceFormulaData(change.value, actor.data); + try { + change.value = Roll.safeEval(change.value).toString(); + } catch (e) { + // this is a valid case, e.g., if the effect change simply is a string + } + return super.apply(actor, change); + } +} diff --git a/src/module/hooks/init.ts b/src/module/hooks/init.ts index 8db11fe2..881c6690 100644 --- a/src/module/hooks/init.ts +++ b/src/module/hooks/init.ts @@ -4,6 +4,7 @@ // // SPDX-License-Identifier: MIT +import { DS4ActiveEffect } from "../active-effect"; import { DS4Actor } from "../actor/actor"; import { DS4CharacterActorSheet } from "../actor/sheets/character-sheet"; import { DS4CreatureActorSheet } from "../actor/sheets/creature-sheet"; @@ -43,6 +44,7 @@ async function init() { CONFIG.Actor.documentClass = DS4Actor; CONFIG.Item.documentClass = DS4Item; + CONFIG.ActiveEffect.documentClass = DS4ActiveEffect; CONFIG.Actor.typeLabels = DS4.i18n.actorTypes; CONFIG.Item.typeLabels = DS4.i18n.itemTypes;