Add the possibility to reference actor properties in the values of effects
Additionally, this also adds the possibility to do math inside the values of effects. All math functions that are available for rolls are also available here.
This commit is contained in:
parent
3b75b17c99
commit
844744e4dc
2 changed files with 26 additions and 0 deletions
24
src/module/active-effect.ts
Normal file
24
src/module/active-effect.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import { DS4ActiveEffect } from "../active-effect";
|
||||||
import { DS4Actor } from "../actor/actor";
|
import { DS4Actor } from "../actor/actor";
|
||||||
import { DS4CharacterActorSheet } from "../actor/sheets/character-sheet";
|
import { DS4CharacterActorSheet } from "../actor/sheets/character-sheet";
|
||||||
import { DS4CreatureActorSheet } from "../actor/sheets/creature-sheet";
|
import { DS4CreatureActorSheet } from "../actor/sheets/creature-sheet";
|
||||||
|
@ -43,6 +44,7 @@ async function init() {
|
||||||
|
|
||||||
CONFIG.Actor.documentClass = DS4Actor;
|
CONFIG.Actor.documentClass = DS4Actor;
|
||||||
CONFIG.Item.documentClass = DS4Item;
|
CONFIG.Item.documentClass = DS4Item;
|
||||||
|
CONFIG.ActiveEffect.documentClass = DS4ActiveEffect;
|
||||||
|
|
||||||
CONFIG.Actor.typeLabels = DS4.i18n.actorTypes;
|
CONFIG.Actor.typeLabels = DS4.i18n.actorTypes;
|
||||||
CONFIG.Item.typeLabels = DS4.i18n.itemTypes;
|
CONFIG.Item.typeLabels = DS4.i18n.itemTypes;
|
||||||
|
|
Loading…
Reference in a new issue