Weapons and Armor are now stored like any other item on the PC. Added equip/unequip logic.

This commit is contained in:
WBHarry 2025-05-25 20:56:11 +02:00
parent 71319f2b74
commit 8e92b5f6d9
13 changed files with 121 additions and 70 deletions

View file

@ -2,6 +2,7 @@ export default class DhpArmor extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
equipped: new fields.BooleanField({ initial: false }),
baseScore: new fields.NumberField({ initial: 1, integer: true }),
feature: new fields.StringField({
choices: SYSTEM.ITEM.armorFeatures,
@ -16,6 +17,7 @@ export default class DhpArmor extends foundry.abstract.TypeDataModel {
major: new fields.NumberField({ initial: 0, integer: true }),
severe: new fields.NumberField({ initial: 0, integer: true })
}),
quantity: new fields.NumberField({ initial: 1, integer: true }),
description: new fields.HTMLField({})
};
}

View file

@ -242,15 +242,15 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
}
get armor() {
return this.parent.items.find(x => x.type === 'armor');
return this.parent.items.find(x => x.type === 'armor' && x.system.equipped);
}
get activeWeapons() {
get equippedWeapons() {
const primaryWeapon = this.parent.items.find(
x => x.type === 'weapon' && x.system.active && !x.system.secondary
x => x.type === 'weapon' && x.system.equipped && !x.system.secondary
);
const secondaryWeapon = this.parent.items.find(
x => x.type === 'weapon' && x.system.active && x.system.secondary
x => x.type === 'weapon' && x.system.equipped && x.system.secondary
);
return {
primary: this.#weaponData(primaryWeapon),
@ -325,16 +325,19 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
);
}
//Should not be done in data?
#weaponData(weapon) {
return weapon
? {
id: weapon.id,
name: weapon.name,
trait: CONFIG.daggerheart.ACTOR.abilities[weapon.system.trait].name, //Should not be done in data?
trait: game.i18n.localize(CONFIG.daggerheart.ACTOR.abilities[weapon.system.trait].label),
range: CONFIG.daggerheart.GENERAL.range[weapon.system.range],
damage: {
value: weapon.system.damage.value,
type: CONFIG.daggerheart.GENERAL.damageTypes[weapon.system.damage.type]
},
burden: weapon.system.burden,
feature: CONFIG.daggerheart.ITEM.weaponFeatures[weapon.system.feature],
img: weapon.img,
uuid: weapon.uuid

View file

@ -2,7 +2,7 @@ export default class DhpWeapon extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
active: new fields.BooleanField({ initial: false }),
equipped: new fields.BooleanField({ initial: false }),
inventoryWeapon: new fields.NumberField({ initial: null, nullable: true, integer: true }),
secondary: new fields.BooleanField({ initial: false }),
trait: new fields.StringField({ choices: SYSTEM.ACTOR.abilities, integer: false }),