ds4/src/module/actor/actor.ts

59 lines
2 KiB
TypeScript
Raw Normal View History

import { ModifiableData } from "../common/common-data";
2020-12-29 00:33:43 +01:00
import { DS4Item } from "../item/item";
import { DS4ItemDataType, ItemType } from "../item/item-data";
import { DS4ActorDataType } from "./actor-data";
2020-12-23 18:23:26 +01:00
2020-12-29 00:33:43 +01:00
export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item> {
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;
const attributes = data.data.attributes;
Object.values(attributes).forEach(
(attribute: ModifiableData<number>) => (attribute.total = attribute.base + attribute.mod),
2020-12-23 16:52:20 +01:00
);
const traits = data.data.traits;
Object.values(traits).forEach((trait: ModifiableData<number>) => (trait.total = trait.base + trait.mod));
2020-12-23 16:52:20 +01:00
const combatValues = data.data.combatValues;
Object.values(combatValues).forEach(
(combatValue: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
);
2021-01-07 12:47:38 +01:00
combatValues.hitPoints.max = combatValues.hitPoints.total;
2020-12-23 16:52:20 +01:00
}
/**
* The list of item types that can be owned by this actor.
*/
get ownableItemTypes(): Array<ItemType> {
switch (this.data.type) {
case "character":
return [
"weapon",
"armor",
"shield",
"trinket",
"equipment",
"spell",
"talent",
"racialAbility",
"language",
"alphabet",
];
case "creature":
return ["weapon", "armor", "shield", "trinket", "equipment", "spell", "specialCreatureAbility"];
default:
2021-01-18 19:03:08 +01:00
return [];
}
}
/**
* Checks whether or not the given item type can be owned by the actor.
* @param itemType the item type to check
*/
canOwnItemType(itemType: ItemType): boolean {
return this.ownableItemTypes.includes(itemType);
}
2020-12-23 16:52:20 +01:00
}