2020-12-28 15:51:00 +01:00
|
|
|
import { DS4ActorData, DS4ActorDataType } from "./actor-data";
|
2020-12-23 18:23:26 +01:00
|
|
|
|
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;
|
2020-12-28 15:51:00 +01:00
|
|
|
// data.data seems to get initialized with the enitity's data
|
|
|
|
const actorData = (data.data as unknown) as DS4ActorData;
|
2020-12-23 16:52:20 +01:00
|
|
|
setProperty(
|
|
|
|
data,
|
|
|
|
"data.combatValues.hitPoints.max",
|
2020-12-28 15:51:00 +01:00
|
|
|
actorData.attributes.body.initial + actorData.traits.constitution.initial + 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-28 15:51:00 +01:00
|
|
|
actorData.attributes.body.initial +
|
|
|
|
actorData.traits.constitution.initial +
|
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);
|
|
|
|
}
|
|
|
|
}
|