mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
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:
parent
d36520438a
commit
cf51153432
14 changed files with 106 additions and 143 deletions
|
|
@ -48,8 +48,6 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
useFeature: this.useFeature,
|
||||
takeShortRest: this.takeShortRest,
|
||||
takeLongRest: this.takeLongRest,
|
||||
removeActiveItem: this.removeActiveItem,
|
||||
removeInventoryWeapon: this.removeInventoryWeapon,
|
||||
addMiscItem: this.addMiscItem,
|
||||
deleteItem: this.deleteItem,
|
||||
addScar: this.addScar,
|
||||
|
|
@ -63,18 +61,12 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
useAbility: this.useAbility,
|
||||
useAdvancementCard: this.useAdvancementCard,
|
||||
useAdvancementAbility: this.useAdvancementAbility,
|
||||
selectFeatureSet: this.selectFeatureSet
|
||||
selectFeatureSet: this.selectFeatureSet,
|
||||
toggleEquipItem: this.toggleEquipItem
|
||||
},
|
||||
window: {
|
||||
//frame: boolean;
|
||||
//positioned: boolean;
|
||||
//title: string;
|
||||
//icon: string | false;
|
||||
//controls: ApplicationHeaderControlsEntry[];
|
||||
minimizable: false,
|
||||
resizable: true
|
||||
//contentTag: string;
|
||||
//contentClasses: string[];
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
|
|
@ -280,6 +272,20 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
quantity: game.i18n.localize('DAGGERHEART.Sheets.PC.InventoryTab.QuantityTitle')
|
||||
},
|
||||
items: this.document.items.filter(x => x.type === 'miscellaneous')
|
||||
},
|
||||
weapons: {
|
||||
titles: {
|
||||
name: game.i18n.localize('DAGGERHEART.Sheets.PC.InventoryTab.WeaponsTitle'),
|
||||
quantity: game.i18n.localize('DAGGERHEART.Sheets.PC.InventoryTab.QuantityTitle')
|
||||
},
|
||||
items: this.document.items.filter(x => x.type === 'weapon')
|
||||
},
|
||||
armor: {
|
||||
titles: {
|
||||
name: game.i18n.localize('DAGGERHEART.Sheets.PC.InventoryTab.ArmorsTitle'),
|
||||
quantity: game.i18n.localize('DAGGERHEART.Sheets.PC.InventoryTab.QuantityTitle')
|
||||
},
|
||||
items: this.document.items.filter(x => x.type === 'armor')
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -690,7 +696,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
(await game.packs.get('daggerheart.playtest-communities'))?.render(true);
|
||||
}
|
||||
|
||||
static async viewObject(button) {
|
||||
static async viewObject(_, button) {
|
||||
const object = await fromUuid(button.dataset.value);
|
||||
if (!object) return;
|
||||
|
||||
|
|
@ -712,18 +718,6 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
await this.minimize();
|
||||
}
|
||||
|
||||
static async removeActiveItem(_, event) {
|
||||
event.stopPropagation();
|
||||
const item = await fromUuid(event.currentTarget.dataset.item);
|
||||
await item.delete();
|
||||
}
|
||||
|
||||
static async removeInventoryWeapon(_, event) {
|
||||
event.stopPropagation();
|
||||
const item = await fromUuid(event.currentTarget.dataset.item);
|
||||
await item.delete();
|
||||
}
|
||||
|
||||
static async addMiscItem() {
|
||||
const result = await this.document.createEmbeddedDocuments('Item', [
|
||||
{
|
||||
|
|
@ -941,6 +935,31 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async toggleEquipItem(_, button) {
|
||||
const item = this.document.items.get(button.id);
|
||||
if (item.system.equipped) {
|
||||
await item.update({ 'system.equipped': false });
|
||||
return;
|
||||
}
|
||||
|
||||
switch (item.type) {
|
||||
case 'armor':
|
||||
const currentArmor = this.document.system.armor;
|
||||
if (currentArmor) {
|
||||
await currentArmor.update({ 'system.equipped': false });
|
||||
}
|
||||
|
||||
await item.update({ 'system.equipped': true });
|
||||
break;
|
||||
case 'weapon':
|
||||
await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(item);
|
||||
|
||||
await item.update({ 'system.equipped': true });
|
||||
break;
|
||||
}
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async close(options) {
|
||||
this.onVaultTab = false;
|
||||
super.close(options);
|
||||
|
|
@ -984,14 +1003,17 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
const itemObject = await fromUuid(item.uuid);
|
||||
switch (target) {
|
||||
case 'weapon-section':
|
||||
if (itemObject.system.secondary && this.document.system.activeWeapons.burden === 'twoHanded') {
|
||||
if (
|
||||
itemObject.system.secondary &&
|
||||
this.document.system.equippedWeapons.burden === 'twoHanded'
|
||||
) {
|
||||
ui.notifications.info(
|
||||
game.i18n.localize('DAGGERHEART.Notification.Info.SecondaryEquipWhileTwohanded')
|
||||
);
|
||||
return;
|
||||
} else if (
|
||||
itemObject.system.burden === 'twoHanded' &&
|
||||
this.document.system.activeWeapons.secondary
|
||||
this.document.system.equippedWeapons.secondary
|
||||
) {
|
||||
ui.notifications.info(
|
||||
game.i18n.localize('DAGGERHEART.Notification.Info.TwohandedEquipWhileSecondary')
|
||||
|
|
@ -1160,41 +1182,9 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
if (!element) return;
|
||||
|
||||
if (element.classList.contains('weapon-section')) {
|
||||
if (item.system.secondary && this.document.system.activeWeapons.burden === 'twoHanded') {
|
||||
ui.notifications.info(
|
||||
game.i18n.localize('DAGGERHEART.Notification.Info.SecondaryEquipWhileTwohanded')
|
||||
);
|
||||
return;
|
||||
} else if (item.system.burden === 'twoHanded' && this.document.system.activeWeapons.secondary) {
|
||||
ui.notifications.info(
|
||||
game.i18n.localize('DAGGERHEART.Notification.Info.TwohandedEquipWhileSecondary')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const existing =
|
||||
this.document.system.activeWeapons.primary && !item.system.secondary
|
||||
? await fromUuid(this.document.system.activeWeapons.primary.uuid)
|
||||
: this.document.system.activeWeapons.secondary && item.system.secondary
|
||||
? await fromUuid(this.document.system.activeWeapons.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;
|
||||
} else return [];
|
||||
await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(itemData);
|
||||
itemData.system.equipped = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.type === 'armor') {
|
||||
|
|
@ -1204,8 +1194,9 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
const existing = this.document.system.armor
|
||||
? await fromUuid(this.document.system.armor.uuid)
|
||||
: null;
|
||||
await existing?.delete();
|
||||
} else return;
|
||||
await existing?.update({ 'system.equipped': false });
|
||||
itemData.system.equipped = true;
|
||||
}
|
||||
}
|
||||
|
||||
const createdItem = await this._onDropItemCreate(itemData);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue