Implement most of shield functionality using the armour implementation as a backbone

This commit is contained in:
Oliver-Akins 2025-01-19 16:13:28 -07:00
parent 27d924e336
commit 9d48794b83
9 changed files with 60 additions and 29 deletions

View file

@ -143,6 +143,7 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi
static async prepareArmor(ctx) {
ctx.armours = {};
const equipped = ctx.actor.system.equippedArmour;
const shield = ctx.actor.system.equippedShield;
const defenses = ctx.actor.system.defense;
for (const slot of Object.values(gameTerms.Anatomy)) {
const item = equipped[slot];
@ -150,9 +151,16 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi
name: item?.name ?? ``,
uuid: item?.uuid ?? ``,
defense: defenses[slot],
shielded: false,
shielded: shield?.system.location.has(slot) ?? false,
};
};
ctx.shield = {
name: shield?.name ?? ``,
uuid: shield?.uuid ?? ``,
bonus: shield?.system.protection ?? 0,
};
return ctx;
};

View file

@ -165,7 +165,8 @@ export class HeroData extends foundry.abstract.TypeDataModel {
};
get equippedShield() {
return null;
const shields = this.parent.itemTypes.shield;
return shields.find(item => item.system.equipped);
};
get defense() {
@ -175,7 +176,13 @@ export class HeroData extends foundry.abstract.TypeDataModel {
defenses[slot] = armour[slot]?.system.protection ?? 0;
};
// TODO: add shield defenses
const shield = this.equippedShield;
if (shield) {
for (const location of [...shield.system.location.values()]) {
const slot = location.toLowerCase();
defenses[slot] += shield.system.protection;
};
};
return defenses;
};

View file

@ -32,6 +32,7 @@ Hooks.once(`init`, () => {
// #region Datamodels
CONFIG.Actor.dataModels.hero = HeroData;
CONFIG.Item.dataModels.armour = ProtectorData;
CONFIG.Item.dataModels.shield = ProtectorData;
CONFIG.Item.dataModels.weapon = WeaponData;
// #endregion