From 4bbc17732920acf338e3daf8a5d0b3bee155ae3b Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sat, 23 Jan 2021 23:51:21 +0100 Subject: [PATCH] allow negative hit points with the token HUD --- src/module/actor/actor.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/module/actor/actor.ts b/src/module/actor/actor.ts index 0ad31fb8..270fee10 100644 --- a/src/module/actor/actor.ts +++ b/src/module/actor/actor.ts @@ -90,4 +90,27 @@ export class DS4Actor extends Actor .map((itemData) => itemData.armorValue) .reduce((a, b) => a + b, 0); } + + /** + * Handle how changes to a Token attribute bar are applied to the Actor. + * This only differs from the base implementation by also allowing negative values. + * @override + */ + async modifyTokenAttribute(attribute: string, value: number, isDelta = false, isBar = true): Promise { + const current = getProperty(this.data.data, attribute); + + // Determine the updates to make to the actor data + let updates: Record; + if (isBar) { + if (isDelta) value = Math.min(Number(current.value) + value, current.max); + updates = { [`data.${attribute}.value`]: value }; + } else { + if (isDelta) value = Number(current) + value; + updates = { [`data.${attribute}`]: value }; + } + + // Call a hook to handle token resource bar updates + const allowed = Hooks.call("modifyTokenAttribute", { attribute, value, isDelta, isBar }, updates); + return allowed !== false ? this.update(updates) : this; + } }