ds4/src/module/actor/actor.ts

44 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-12-23 18:23:26 +01:00
import { DS4ActorDataType } from "./actor-data";
2020-12-23 16:52:20 +01:00
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
2020-12-23 18:23:26 +01:00
export class DS4Actor extends Actor<DS4ActorDataType> {
2020-12-23 16:52:20 +01:00
/** @override */
2020-12-23 18:23:26 +01:00
prepareDerivedData(): void {
2020-12-23 16:52:20 +01:00
const data = this.data;
this._prepareCombatValues(data);
}
2020-12-23 18:23:26 +01:00
_prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
2020-12-23 16:52:20 +01:00
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
setProperty(
data,
"data.combatValues.hitPoints.max",
2020-12-23 18:23:26 +01:00
data.data["attributes"]["body"].initial + // TODO: replace ["..."]
data.data["traits"]["constitution"].initial + // TODO: replace ["..."]
10 +
hitPointsModifier,
2020-12-23 16:52:20 +01:00
);
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
setProperty(
data,
"data.combatValues.defense.value",
2020-12-23 18:23:26 +01:00
data.data["attributes"]["body"].initial + // TODO: replace ["..."]
data.data["traits"]["constitution"].initial + // TODO: replace ["..."]
2020-12-23 16:52:20 +01:00
this._getArmorValue() +
2020-12-23 18:23:26 +01:00
defenseModifier,
2020-12-23 16:52:20 +01:00
);
}
2020-12-23 18:23:26 +01:00
_getArmorValue(): number {
2020-12-23 16:52:20 +01:00
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);
}
}