mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 07:36:26 +01:00
fix bug of item equiping and un equiping
This commit is contained in:
parent
577d9e6c48
commit
5992bc7c24
2 changed files with 47 additions and 5 deletions
|
|
@ -9,6 +9,46 @@ export default class DHItem extends foundry.documents.Item {
|
||||||
for (const action of this.system.actions ?? []) action.prepareData();
|
for (const action of this.system.actions ?? []) action.prepareData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async _preUpdate(changed, options, user) {
|
||||||
|
const result = await super._preUpdate(changed, options, user);
|
||||||
|
|
||||||
|
// Store the previous equipped status for attachment handling
|
||||||
|
if (changed.system?.equipped !== undefined) {
|
||||||
|
options.previousEquipped = this.system.equipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async _onUpdate(changed, options, user) {
|
||||||
|
await super._onUpdate(changed, options, user);
|
||||||
|
|
||||||
|
// Handle attachment effects when equipped status changes
|
||||||
|
if (changed.system?.equipped !== undefined && options.previousEquipped !== changed.system.equipped) {
|
||||||
|
const newEquippedStatus = changed.system.equipped;
|
||||||
|
const parentType = this.type === 'armor' ? 'armor' : this.type === 'weapon' ? 'weapon' : null;
|
||||||
|
|
||||||
|
if (parentType) {
|
||||||
|
try {
|
||||||
|
const { handleAttachmentEffectsOnEquipChange } = await import('../helpers/attachmentHelper.mjs');
|
||||||
|
await handleAttachmentEffectsOnEquipChange({
|
||||||
|
parentItem: this,
|
||||||
|
newEquippedStatus,
|
||||||
|
parentType
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('DH | Error in handleAttachmentEffectsOnEquipChange:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
* @param {object} options - Options which modify the getRollData method.
|
* @param {object} options - Options which modify the getRollData method.
|
||||||
|
|
|
||||||
|
|
@ -105,22 +105,24 @@ export async function removeAttachmentFromItem({ parentItem, attachedUuid, paren
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
export async function handleAttachmentEffectsOnEquipChange({ parentItem, newEquippedStatus, parentType }) {
|
export async function handleAttachmentEffectsOnEquipChange({ parentItem, newEquippedStatus, parentType }) {
|
||||||
const actor = parentItem.parent?.parent;
|
// Try to get the actor - it might be parentItem.parent instead of parentItem.parent.parent
|
||||||
if (!actor || !parentItem.system.attached?.length) return;
|
const actor = parentItem.parent?.type === 'character' ? parentItem.parent : parentItem.parent?.parent;
|
||||||
|
|
||||||
|
if (!actor || !parentItem.system.attached?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (newEquippedStatus) {
|
if (newEquippedStatus) {
|
||||||
// Item is being equipped - add attachment effects
|
// Item is being equipped - add attachment effects
|
||||||
const effectsToCreate = [];
|
|
||||||
for (const attachedUuid of parentItem.system.attached) {
|
for (const attachedUuid of parentItem.system.attached) {
|
||||||
const attachedItem = await fromUuid(attachedUuid);
|
const attachedItem = await fromUuid(attachedUuid);
|
||||||
if (attachedItem && attachedItem.effects.size > 0) {
|
if (attachedItem && attachedItem.effects.size > 0) {
|
||||||
const newEffects = await copyAttachmentEffectsToActor({
|
await copyAttachmentEffectsToActor({
|
||||||
parentItem,
|
parentItem,
|
||||||
attachedItem,
|
attachedItem,
|
||||||
attachedUuid,
|
attachedUuid,
|
||||||
parentType
|
parentType
|
||||||
});
|
});
|
||||||
effectsToCreate.push(...newEffects);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue