Review Inventory (#55)

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

* Changed so that equip attempts always go through and the neccessary weapons are unequipped to fascilitate it

* Fixed drag equip and extracted unequipBeforeEquip logic
This commit is contained in:
WBHarry 2025-05-26 15:43:04 +02:00 committed by GitHub
parent d36520438a
commit cf51153432
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 106 additions and 143 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),
@ -259,6 +259,28 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
};
}
static async unequipBeforeEquip(itemToEquip) {
const equippedWeapons = this.equippedWeapons;
if (itemToEquip.system.secondary) {
if (equippedWeapons.primary && equippedWeapons.primary.burden === SYSTEM.GENERAL.burden.twoHanded.value) {
await this.parent.items.get(equippedWeapons.primary.id).update({ 'system.equipped': false });
}
if (equippedWeapons.secondary) {
await this.parent.items.get(equippedWeapons.secondary.id).update({ 'system.equipped': false });
}
} else {
if (equippedWeapons.secondary && itemToEquip.system.burden === SYSTEM.GENERAL.burden.twoHanded.value) {
await this.parent.items.get(equippedWeapons.secondary.id).update({ 'system.equipped': false });
}
if (equippedWeapons.primary) {
await this.parent.items.get(equippedWeapons.primary.id).update({ 'system.equipped': false });
}
}
}
get inventoryWeapons() {
const inventoryWeaponFirst = this.parent.items.find(x => x.type === 'weapon' && x.system.inventoryWeapon === 1);
const inventoryWeaponSecond = this.parent.items.find(
@ -325,16 +347,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 }),