diff --git a/daggerheart.mjs b/daggerheart.mjs index 9b537989..855ae5e2 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -132,7 +132,6 @@ const preloadHandlebarsTemplates = async function () { 'systems/daggerheart/templates/sheets/parts/gold.hbs', 'systems/daggerheart/templates/sheets/parts/health.hbs', 'systems/daggerheart/templates/sheets/parts/hope.hbs', - 'systems/daggerheart/templates/sheets/parts/inventory.hbs', 'systems/daggerheart/templates/sheets/parts/weapons.hbs', 'systems/daggerheart/templates/sheets/parts/domainCard.hbs', 'systems/daggerheart/templates/sheets/parts/heritage.hbs', diff --git a/lang/en.json b/lang/en.json index 08ad8781..a8b365a8 100644 --- a/lang/en.json +++ b/lang/en.json @@ -83,8 +83,6 @@ "Info": { "ClassCanOnlyHaveTwoDomains": "A class can only have 2 domains!", "NoTargetsSelected": "No targets are selected.", - "SecondaryEquipWhileTwohanded": "A secondary weapon can't be equipped together with a Two-Handed weapon.", - "TwohandedEquipWhileSecondary": "Can't equip a Two-Handed weapon together with a secondary weapon.", "SelectClassBeforeSubclass": "Select a Class before selecting a Subclass.", "SubclassNotOfClass": "This Subclass doesn't belong to your current Class.", "AttackTargetDoesNotExist": "The target token no longer exists" diff --git a/module/applications/sheets/pc.mjs b/module/applications/sheets/pc.mjs index add6c3cf..16bd362f 100644 --- a/module/applications/sheets/pc.mjs +++ b/module/applications/sheets/pc.mjs @@ -952,27 +952,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { await item.update({ 'system.equipped': true }); break; case 'weapon': - const currentWeapons = this.document.system.equippedWeapons; - if (item.system.secondary) { - if ( - currentWeapons.primary && - currentWeapons.primary.burden === SYSTEM.GENERAL.burden.twoHanded.value - ) { - await this.document.items.get(currentWeapons.primary.id).update({ 'system.equipped': false }); - } - - if (currentWeapons.secondary) { - await this.document.items.get(currentWeapons.secondary.id).update({ 'system.equipped': false }); - } - } else { - if (currentWeapons.secondary && item.system.burden === SYSTEM.GENERAL.burden.twoHanded.value) { - await this.document.items.get(currentWeapons.secondary.id).update({ 'system.equipped': false }); - } - - if (currentWeapons.primary) { - await this.document.items.get(currentWeapons.primary.id).update({ 'system.equipped': false }); - } - } + await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(item); await item.update({ 'system.equipped': true }); break; @@ -1202,46 +1182,8 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { if (!element) return; if (element.classList.contains('weapon-section')) { - if ( - item.system.secondary && - this.document.system.equippedWeapons.burden === SYSTEM.GENERAL.burden.twoHanded.value - ) { - ui.notifications.info( - game.i18n.localize('DAGGERHEART.Notification.Info.SecondaryEquipWhileTwohanded') - ); - return; - } else if ( - item.system.burden === SYSTEM.GENERAL.burden.twoHanded.value && - this.document.system.equippedWeapons.secondary - ) { - ui.notifications.info( - game.i18n.localize('DAGGERHEART.Notification.Info.TwohandedEquipWhileSecondary') - ); - return; - } - - const existing = - this.document.system.equippedWeapons.primary && !item.system.secondary - ? await fromUuid(this.document.system.equippedWeapons.primary.uuid) - : this.document.system.equippedWeapons.secondary && item.system.secondary - ? await fromUuid(this.document.system.equippedWeapons.secondary.uuid) - : null; - await existing?.delete(); - itemData.system.active = true; - } else if (element.classList.contains('inventory-weapon-section-first')) { - const existing = this.document.system.inventoryWeapons.first - ? await fromUuid(this.document.system.inventoryWeapons.first.uuid) - : null; - await existing?.delete(); - - itemData.system.inventoryWeapon = 1; - } else if (element.classList.contains('inventory-weapon-section-second')) { - const existing = this.document.system.inventoryWeapons.second - ? await fromUuid(this.document.system.inventoryWeapons.second.uuid) - : null; - await existing?.delete(); - - itemData.system.inventoryWeapon = 2; + await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(itemData); + itemData.system.equipped = true; } } @@ -1252,7 +1194,8 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { const existing = this.document.system.armor ? await fromUuid(this.document.system.armor.uuid) : null; - await existing?.delete(); + await existing?.update({ 'system.equipped': false }); + itemData.system.equipped = true; } } diff --git a/module/data/pc.mjs b/module/data/pc.mjs index 6f6073bd..b68f0a03 100644 --- a/module/data/pc.mjs +++ b/module/data/pc.mjs @@ -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( diff --git a/templates/sheets/parts/inventory.hbs b/templates/sheets/parts/inventory.hbs deleted file mode 100644 index 8e72f848..00000000 --- a/templates/sheets/parts/inventory.hbs +++ /dev/null @@ -1,41 +0,0 @@ -
\ No newline at end of file diff --git a/templates/sheets/pc/pc.hbs b/templates/sheets/pc/pc.hbs index 53cb0501..f3890b9f 100644 --- a/templates/sheets/pc/pc.hbs +++ b/templates/sheets/pc/pc.hbs @@ -90,7 +90,6 @@ {{> "systems/daggerheart/templates/sheets/parts/attributes.hbs" }} {{> "systems/daggerheart/templates/sheets/parts/weapons.hbs" weapons=document.system.equippedWeapons proficiency=document.system.proficiency.value }} {{> "systems/daggerheart/templates/sheets/parts/armor.hbs" armor=document.system.armor }} - {{> "systems/daggerheart/templates/sheets/parts/inventory.hbs" weapons=document.system.inventoryWeapons }}