diff --git a/src/API/chat-api.js b/src/API/chat-api.js index ccf341d8..047fb6e8 100644 --- a/src/API/chat-api.js +++ b/src/API/chat-api.js @@ -439,7 +439,7 @@ export default class ChatAPI { return this._createNewChatMessage(game.user.id, { user: game.user.id, - type: isPrivate && CONSTANTS.IS_V12 ? CHAT_MESSAGE_STYLES.WHISPER : CHAT_MESSAGE_STYLES.OTHER, + type: isPrivate && !CONSTANTS.IS_V12 ? CHAT_MESSAGE_STYLES.WHISPER : CHAT_MESSAGE_STYLES.OTHER, content: chatCardHtml, flavor: "Item Piles" + (isPrivate ? ": " + game.i18n.localize("ITEM-PILES.Chat.PrivateTrade") : ""), speaker: ChatMessage.getSpeaker({ alias: game.user.name }), diff --git a/src/API/private-api.js b/src/API/private-api.js index 6417d75d..dc576a1e 100644 --- a/src/API/private-api.js +++ b/src/API/private-api.js @@ -1033,16 +1033,21 @@ export default class PrivateAPI { let itemsDropped; + foundry.utils.setProperty(itemData.item, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE, itemData?.quantity ?? 1); + const items = [itemData.item]; + const item = fromUuidSync(itemData.uuid); + const handler = Utilities.getItemTypeHandler(CONSTANTS.ITEM_TYPE_METHODS.TRANSFER, item.type); + if (handler) handler({ item, items }); + // If there's a source of the item (it wasn't dropped from the item bar) if (sourceUuid) { - foundry.utils.setProperty(itemData.item, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE, itemData.quantity); - // If there's a target token, add the item to it, otherwise create a new pile at the drop location if (targetUuid) { - itemsDropped = await this._transferItems(sourceUuid, targetUuid, [itemData.item], userId); + itemsDropped = await this._transferItems(sourceUuid, targetUuid, items, userId); } else { - itemsDropped = (await this._removeItems(sourceUuid, [itemData.item], userId)).map(item => { + + itemsDropped = (await this._removeItems(sourceUuid, items, userId)).map(item => { item.quantity = Math.abs(item.quantity) Utilities.setItemQuantity(item.item, Math.abs(item.quantity), true); return item; @@ -1050,7 +1055,7 @@ export default class PrivateAPI { targetUuid = await this._createItemPile({ sceneId, position, items: itemsDropped, tokenOverrides: { elevation: elevation || fromUuidSync(sourceUuid)?.elevation || 0 - } + }, checkContainers: false }) } @@ -1059,10 +1064,10 @@ export default class PrivateAPI { // If there's a target token, add the item to it, otherwise create a new pile at the drop location if (targetUuid) { - itemsDropped = await this._addItems(targetUuid, [itemData], userId); + itemsDropped = await this._addItems(targetUuid, items, userId); } else { targetUuid = await this._createItemPile({ - sceneId, position, items: [itemData], tokenOverrides: { elevation: elevation || 0 } + sceneId, position, items, tokenOverrides: { elevation: elevation || 0 } }); } @@ -1083,7 +1088,7 @@ export default class PrivateAPI { tokenOverrides = {}, actorOverrides = {}, itemPileFlags = {}, - folders = false, + folders = false } = {}) { let returns = {}; @@ -1186,8 +1191,6 @@ export default class PrivateAPI { await game.settings.set(CONSTANTS.MODULE_NAME, SETTINGS.DEFAULT_ITEM_PILE_ACTOR_ID, pileActor.id); - } else { - } } else { @@ -1210,16 +1213,6 @@ export default class PrivateAPI { } items[i] = itemData; } - if (SYSTEMS.DATA.ITEM_TYPE_HANDLERS) { - const newItems = []; - for (const itemData of items) { - const item = new Item.implementation(itemData); - const handler = Utilities.getItemTypeHandler(CONSTANTS.ITEM_TYPE_METHODS.TRANSFER, item.type); - if (!handler) continue; - handler({ item, items: newItems }); - } - items = items.concat(newItems); - } } else { items = [] } @@ -1660,7 +1653,7 @@ export default class PrivateAPI { const dropData = { source: false, target: data?.target ?? false, elevation: data?.elevation, itemData: { - item: itemData, quantity: 1, + item: itemData, quantity: 1, uuid: data?.uuid }, position: false }; diff --git a/src/helpers/transaction.js b/src/helpers/transaction.js index fd4b1e99..cfb70859 100644 --- a/src/helpers/transaction.js +++ b/src/helpers/transaction.js @@ -44,6 +44,8 @@ export default class Transaction { ? Math.abs(data.quantity ?? Utilities.getItemQuantity(itemData)) : Math.abs(data.quantity ?? Utilities.getItemQuantity(itemData)) * (remove ? -1 : 1); + console.log(itemData.name, incomingQuantity); + let itemId = itemData._id ?? itemData.id; let documentHasItem = false; let documentExistingItem = false; diff --git a/src/socket.js b/src/socket.js index b409d104..71c3a5aa 100644 --- a/src/socket.js +++ b/src/socket.js @@ -236,7 +236,13 @@ const Requests = { return false; } Requests._addTimeout(handler); - const result = await method(); + let result; + try { + result = await method(); + } catch (err) { + Requests._clearPendingTimeout(handler); + return false; + } Requests._clearPendingTimeout(handler); Requests._unresponsiveGM = false; Requests._lastGmUnresponsiveTimestamp = false;