Improve typing of DS4Item and DS4Actor

This commit is contained in:
Johannes Loher 2021-02-05 03:42:42 +01:00
parent b657633c7f
commit 5598255d6e
5 changed files with 94 additions and 63 deletions

View file

@ -1,6 +1,6 @@
import { ModifiableData } from "../common/common-data";
import { DS4Item } from "../item/item";
import { DS4Armor, DS4Shield, ItemType } from "../item/item-data";
import { ItemType } from "../item/item-data";
import { DS4ActorData } from "./actor-data";
export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
@ -84,10 +84,13 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
*/
private _calculateArmorValueOfEquippedItems(): number {
return this.items
.filter((item) => ["armor", "shield"].includes(item.type))
.map((item) => item.data.data as DS4Armor | DS4Shield)
.filter((itemData) => itemData.equipped)
.map((itemData) => itemData.armorValue)
.map((item) => {
if (item.data.type === "armor" || item.data.type === "shield") {
return item.data.data.equipped ? item.data.data.armorValue : 0;
} else {
return 0;
}
})
.reduce((a, b) => a + b, 0);
}