ds4/src/module/actor/actor.ts

43 lines
1.5 KiB
TypeScript

import { DS4Item } from "../item/item";
import { DS4ItemDataType } from "../item/item-data";
import { DS4ActorDataType } from "./actor-data";
/**
* 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<DS4ActorDataType, DS4ItemDataType, DS4Item> {
/** @override */
prepareDerivedData(): void {
const data = this.data;
this._prepareCombatValues(data);
}
private _prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
const actorData = data.data;
setProperty(
data,
"data.combatValues.hitPoints.max",
actorData.attributes.body.initial + actorData.traits.constitution.initial + 10 + hitPointsModifier,
);
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
setProperty(
data,
"data.combatValues.defense.value",
actorData.attributes.body.initial +
actorData.traits.constitution.initial +
this._getArmorValue() +
defenseModifier,
);
}
private _getArmorValue(): number {
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);
}
}