ds4/module/actor/actor.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-10-29 16:18:38 +01:00
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class DS4Actor extends Actor {
/** @override */
prepareDerivedData() {
const data = this.data;
this._prepareCombatValues(data);
2020-10-29 16:18:38 +01:00
}
_prepareCombatValues(data) {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
setProperty(
data,
"data.combatValues.hitPoints.max",
data.data.attributes.body.initial + data.data.traits.constitution.initial + 10 + hitPointsModifier
);
2020-10-29 16:18:38 +01:00
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
setProperty(
data,
"data.combatValues.defense.value",
data.data.attributes.body.initial +
data.data.traits.constitution.initial +
this._getArmorValue() +
defenseModifier
);
2020-10-29 16:18:38 +01:00
}
_getArmorValue() {
return this.data.items
.filter((item) => ["armor", "shield"].includes(item.type))
.filter((item) => item.data.equipped)
.map((item) => item.data.armorValue)
.reduce((a, b) => a + b, 0);
}
}