Merge branch '063-allow-negative-hit-points' into 'master'
allow negative hit points with the token HUD Closes #63 See merge request dungeonslayers/ds4!64
This commit is contained in:
commit
2c8878bd94
1 changed files with 23 additions and 0 deletions
|
@ -90,4 +90,27 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
|
||||||
.map((itemData) => itemData.armorValue)
|
.map((itemData) => itemData.armorValue)
|
||||||
.reduce((a, b) => a + b, 0);
|
.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<DS4Actor> {
|
||||||
|
const current = getProperty(this.data.data, attribute);
|
||||||
|
|
||||||
|
// Determine the updates to make to the actor data
|
||||||
|
let updates: Record<string, number>;
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue