Merge branch '075-make-it-possible-to-reference-actor-properties-in-effects' into 'master'
Add the possibility to reference actor properties in the values of effects Closes #75 See merge request dungeonslayers/ds4!126
This commit is contained in:
commit
803ab950ae
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
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue