mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
Fixed drag equip and extracted unequipBeforeEquip logic
This commit is contained in:
parent
9ce77c126a
commit
1099948a9b
6 changed files with 27 additions and 107 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
<fieldset class="left-main-container" style="flex: 1; display: flex; flex-direction: column;">
|
||||
<legend class="legend inventory-legend">
|
||||
{{localize "DAGGERHEART.Sheets.PC.Inventory.Title"}}
|
||||
</legend>
|
||||
<div class="inventory-items">
|
||||
<div class="inventory-weapon-section-first item-section">
|
||||
<h2 class="armor-container">
|
||||
{{localize "DAGGERHEART.Sheets.PC.Inventory.InventoryWeapon"}}
|
||||
</h2>
|
||||
<div class="active-item-container">
|
||||
<div class="flexrow">
|
||||
<input value="{{weapons.first.name}}" type="text" />
|
||||
<input value="{{localize weapons.first.trait}}" type="text" />
|
||||
<input value="{{localize weapons.first.range.name}}" type="text" />
|
||||
<input value="{{weapons.first.damage.value}} {{#if weapons.first}}({{localize weapons.first.damage.type.abbreviation}}){{/if}}" type="text" />
|
||||
</div>
|
||||
<input value="{{localize weapons.first.feature.name}} {{#if weapons.first.feature}}({{localize weapons.first.feature.description}}){{/if}}" type="text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="inventory-weapon-section-second item-section">
|
||||
<h2 class="armor-container">
|
||||
{{localize "DAGGERHEART.Sheets.PC.Inventory.InventoryWeapon"}}
|
||||
{{#if weapons.second}}
|
||||
<div data-action="viewObject" data-value="{{weapons.second.uuid}}" class="active-item-label-chip">
|
||||
<img src="{{weapons.second.img}}" />
|
||||
<button data-action="removeInventoryWeapon" data-item="{{weapons.second.uuid}}"><i class="fa-solid fa-x"></i></button>
|
||||
</div>
|
||||
{{/if}}
|
||||
</h2>
|
||||
<div class="active-item-container">
|
||||
<div class="flexrow">
|
||||
<input value="{{weapons.second.name}}" type="text" />
|
||||
<input value="{{localize weapons.second.trait}}" type="text" />
|
||||
<input value="{{localize weapons.second.range.name}}" type="text" />
|
||||
<input value="{{weapons.second.damage.value}} {{#if weapons.second}}({{localize weapons.second.damage.type.abbreviation}}){{/if}}" type="text" />
|
||||
</div>
|
||||
<input value="{{localize weapons.second.feature.name}} {{#if weapons.second.feature}}({{localize weapons.second.feature.description}}){{/if}}" type="text" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
|
@ -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 }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue