mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-23 16:03:39 +02:00
Fixed weapons
This commit is contained in:
parent
286944d2e6
commit
ee89d5cb9e
5 changed files with 115 additions and 56 deletions
|
|
@ -763,32 +763,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
static async #toggleEquipItem(_event, button) {
|
static async #toggleEquipItem(_event, button) {
|
||||||
const item = await getDocFromElement(button);
|
const item = await getDocFromElement(button);
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
if (item.system.equipped) {
|
|
||||||
await item.update({ 'system.equipped': false });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (item.type) {
|
const changedData = await this.document.toggleEquipItem(item);
|
||||||
case 'armor':
|
const removedData = changedData.filter(x => !x.add);
|
||||||
const currentArmor = this.document.system.armor;
|
this.document.update({
|
||||||
if (currentArmor) {
|
'system.sidebarFavorites': [
|
||||||
await currentArmor.update({ 'system.equipped': false });
|
...this.document.system.sidebarFavorites.filter(x => removedData.every(r => r.item.id !== x.id))
|
||||||
}
|
]
|
||||||
|
});
|
||||||
await item.update({ 'system.equipped': true });
|
|
||||||
break;
|
|
||||||
case 'weapon':
|
|
||||||
if (this.document.effects.find(x => !x.disabled && x.type === 'beastform')) {
|
|
||||||
return ui.notifications.warn(
|
|
||||||
game.i18n.localize('DAGGERHEART.UI.Notifications.beastformEquipWeapon')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(item);
|
|
||||||
|
|
||||||
await item.update({ 'system.equipped': true });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1042,6 +1024,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
|
|
||||||
if (this.document.system.sidebarFavorites.some(x => x.id === item.id)) return;
|
if (this.document.system.sidebarFavorites.some(x => x.id === item.id)) return;
|
||||||
|
|
||||||
this.document.update({ 'system.sidebarFavorites': [...this.document.system.sidebarFavorites, item] });
|
this.document.setFavoriteItem(item, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -547,13 +547,20 @@ export default function DHApplicationMixin(Base) {
|
||||||
name: 'Unfavorite',
|
name: 'Unfavorite',
|
||||||
icon: 'fa-regular fa-star',
|
icon: 'fa-regular fa-star',
|
||||||
condition: target => {
|
condition: target => {
|
||||||
return this.document.type === 'character' && target.closest('.items-sidebar-list');
|
const doc = getDocFromElementSync(target);
|
||||||
|
const isFavorited = this.document.system.sidebarFavorites.some(x => x.id === doc.id);
|
||||||
|
return this.document.type === 'character' && isFavorited;
|
||||||
},
|
},
|
||||||
callback: async (target, _event) => {
|
callback: async (target, _event) => {
|
||||||
const doc = await getDocFromElement(target);
|
const doc = await getDocFromElement(target);
|
||||||
this.document.update({
|
if (doc.type === 'domainCard') {
|
||||||
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(x => x.id !== doc.id)
|
} else {
|
||||||
});
|
this.document.update({
|
||||||
|
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(
|
||||||
|
x => x.id !== doc.id
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -562,17 +569,16 @@ export default function DHApplicationMixin(Base) {
|
||||||
icon: 'fa-solid fa-star',
|
icon: 'fa-solid fa-star',
|
||||||
condition: target => {
|
condition: target => {
|
||||||
const doc = getDocFromElementSync(target);
|
const doc = getDocFromElementSync(target);
|
||||||
|
const isFavorited = this.document.system.sidebarFavorites.some(x => x.id === doc.id);
|
||||||
return (
|
return (
|
||||||
!(doc instanceof game.system.api.documents.DhActiveEffect) &&
|
!(doc instanceof game.system.api.documents.DhActiveEffect) &&
|
||||||
this.document.type === 'character' &&
|
this.document.type === 'character' &&
|
||||||
!target.closest('.items-sidebar-list')
|
!isFavorited
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
callback: async (target, _event) => {
|
callback: async (target, _event) => {
|
||||||
const doc = await getDocFromElement(target);
|
const doc = await getDocFromElement(target);
|
||||||
this.document.update({
|
this.document.setFavoriteItem(doc, true);
|
||||||
'system.sidebarFavorites': [...this.document.system.sidebarFavorites, doc]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -578,28 +578,6 @@ export default class DhCharacter extends BaseDataActor {
|
||||||
return diceTypes[attackDiceIndex];
|
return diceTypes[attackDiceIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
static async unequipBeforeEquip(itemToEquip) {
|
|
||||||
const primary = this.primaryWeapon,
|
|
||||||
secondary = this.secondaryWeapon;
|
|
||||||
if (itemToEquip.system.secondary) {
|
|
||||||
if (primary && primary.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
|
|
||||||
await primary.update({ 'system.equipped': false });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secondary) {
|
|
||||||
await secondary.update({ 'system.equipped': false });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (secondary && itemToEquip.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
|
|
||||||
await secondary.update({ 'system.equipped': false });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (primary) {
|
|
||||||
await primary.update({ 'system.equipped': false });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareBaseData() {
|
prepareBaseData() {
|
||||||
this.evasion += this.class.value?.system?.evasion ?? 0;
|
this.evasion += this.class.value?.system?.evasion ?? 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -992,4 +992,91 @@ export default class DhpActor extends Actor {
|
||||||
|
|
||||||
return allTokens;
|
return allTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async unequipBeforeEquip(itemToEquip, options = { render: true }) {
|
||||||
|
const { render } = options;
|
||||||
|
|
||||||
|
const primary = this.system.primaryWeapon,
|
||||||
|
secondary = this.system.secondaryWeapon;
|
||||||
|
let unequippedItems = [];
|
||||||
|
if (itemToEquip.system.secondary) {
|
||||||
|
if (primary && primary.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
|
||||||
|
unequippedItems.push(primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secondary) {
|
||||||
|
unequippedItems.push(secondary);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (secondary && itemToEquip.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
|
||||||
|
unequippedItems.push(secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (primary) {
|
||||||
|
unequippedItems.push(primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const item of unequippedItems) await item?.update({ 'system.equipped': false }, { render });
|
||||||
|
|
||||||
|
return unequippedItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
async toggleEquipItem(item, options = { render: true }) {
|
||||||
|
const { render } = options;
|
||||||
|
const changedItems = [];
|
||||||
|
const updateAndAddChangedItem = async (item, equip) => {
|
||||||
|
changedItems.push({ item, add: equip });
|
||||||
|
await item.update({ 'system.equipped': equip }, { render });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (item.system.equipped) {
|
||||||
|
await updateAndAddChangedItem(item, false);
|
||||||
|
return changedItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (item.type) {
|
||||||
|
case 'armor':
|
||||||
|
const currentArmor = this.system.armor;
|
||||||
|
if (currentArmor) {
|
||||||
|
await updateAndAddChangedItem(currentArmor, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateAndAddChangedItem(item, true);
|
||||||
|
break;
|
||||||
|
case 'weapon':
|
||||||
|
if (this.effects.find(x => !x.disabled && x.type === 'beastform')) {
|
||||||
|
return ui.notifications.warn(
|
||||||
|
game.i18n.localize('DAGGERHEART.UI.Notifications.beastformEquipWeapon')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const unequippedItems = await this.unequipBeforeEquip(item, { render });
|
||||||
|
changedItems.push(...unequippedItems.map(x => ({ item: x, add: false })));
|
||||||
|
await updateAndAddChangedItem(item, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changedItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
async setFavoriteItem(item, setFavorited) {
|
||||||
|
const favoritesToRemove = [];
|
||||||
|
const favoritesToAdd = [];
|
||||||
|
if (item.type === 'weapon') {
|
||||||
|
const changedData = await this.toggleEquipItem(item, { render: false });
|
||||||
|
for (const data of changedData) {
|
||||||
|
if (data.add) favoritesToAdd.push(data.item);
|
||||||
|
else favoritesToRemove.push(data.item);
|
||||||
|
}
|
||||||
|
} else if (setFavorited) favoritesToAdd.push(item);
|
||||||
|
else favoritesToRemove.push(item);
|
||||||
|
|
||||||
|
this.update({
|
||||||
|
'system.sidebarFavorites': [
|
||||||
|
...this.system.sidebarFavorites.filter(x => favoritesToRemove.every(r => r.id !== x.id)),
|
||||||
|
...favoritesToAdd
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -226,5 +226,11 @@ export default class DHItem extends foundry.documents.Item {
|
||||||
|
|
||||||
async _preDelete() {
|
async _preDelete() {
|
||||||
this.deleteTriggers();
|
this.deleteTriggers();
|
||||||
|
|
||||||
|
if (this.parent?.type === 'character') {
|
||||||
|
const filteredFavorites = this.parent.system.sidebarFavorites.filter(x => x.id !== this.id);
|
||||||
|
if (this.parent.system.sidebarFavorites.length !== filteredFavorites.length)
|
||||||
|
this.parent.update({ 'system.sidebarFavorites': filteredFavorites });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue