diff --git a/changelog.md b/changelog.md index 140a189a..3a89e0a5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Item Piles Changelog +## Version 2.8.20 + +- Reverted some changes that caused errors in some systems with item based currencies + ## Version 2.8.19 - Added several currency related methods and hooks (thank you p4535992 on GitHub!) diff --git a/src/helpers/transaction.js b/src/helpers/transaction.js index 69f84492..22c7cb47 100644 --- a/src/helpers/transaction.js +++ b/src/helpers/transaction.js @@ -42,9 +42,7 @@ export default class Transaction { const incomingQuantity = set ? Math.abs(data.quantity ?? Utilities.getItemQuantity(itemData)) : Math.abs(data.quantity ?? Utilities.getItemQuantity(itemData)) * (remove ? -1 : 1); - // Remove is ignored because when you remove a item the cost cannot change - const incomingCost = Math.abs(data.cost ?? Utilities.getItemCost(itemData)); - + let itemId = itemData._id ?? itemData.id; let actorHasItem = false; let actorExistingItem = false; @@ -63,8 +61,7 @@ export default class Transaction { PileUtilities.areItemsColliding(item, itemData) ) }); - } - else { + } else { actorHasItem = this.actor.items.get(itemId); actorExistingItem = actorHasItem || Utilities.findSimilarItem(this.actor.items, itemData); } @@ -82,12 +79,10 @@ export default class Transaction { if (actorExistingItem) { const itemQuantity = Utilities.getItemQuantity(actorExistingItem); - const itemCost = Utilities.getItemCost(actorExistingItem); if (itemQuantity > 1 || canItemStack) { const newQuantity = itemQuantity + incomingQuantity; - const newCost = itemCost + incomingCost; const existingItemUpdate = remove ? this.itemsToUpdate.find(item => item._id === itemId) @@ -97,15 +92,11 @@ export default class Transaction { Utilities.setItemQuantity(existingItemUpdate, newQuantity); if (keepIfZero && type !== "currency") { setProperty(existingItemUpdate, CONSTANTS.FLAGS.ITEM + ".notForSale", newQuantity === 0); - } else if(keepIfZero && type === "currency"){ - Utilities.setItemCost(existingItemUpdate, newCost); } } else { const update = Utilities.setItemQuantity(actorExistingItem.toObject(), newQuantity); if (keepIfZero && type !== "currency") { setProperty(update, CONSTANTS.FLAGS.ITEM + ".notForSale", newQuantity === 0); - } else if(keepIfZero && type === "currency"){ - Utilities.setItemCost(update, newCost); } this.itemTypeMap.set(actorExistingItem.id, type) this.itemsToUpdate.push(update); @@ -124,7 +115,6 @@ export default class Transaction { itemData._id = randomID(); } Utilities.setItemQuantity(itemData, incomingQuantity); - Utilities.setItemCost(itemData, incomingCost); this.itemsToCreate.push(itemData); this.itemTypeMap.set(itemData._id, type) @@ -135,15 +125,11 @@ export default class Transaction { if (existingItemCreation && canItemStack) { const newQuantity = Utilities.getItemQuantity(existingItemCreation) + incomingQuantity; Utilities.setItemQuantity(existingItemCreation, newQuantity); - - const newCost = Utilities.getItemCost(existingItemCreation) + incomingCost; - Utilities.setItemCost(existingItemCreation, newCost); } else { if (!itemData._id) { itemData._id = randomID(); } Utilities.setItemQuantity(itemData, incomingQuantity); - Utilities.setItemCost(itemData, incomingCost); this.itemsToCreate.push(itemData); this.itemTypeMap.set(itemData._id, type) } @@ -151,8 +137,9 @@ export default class Transaction { } } - async appendActorChanges(attributes, { - set = false, remove = false, type = "attribute", onlyDelta = false } = {}) { + async appendActorChanges(attributes, { + set = false, remove = false, type = "attribute", onlyDelta = false + } = {}) { if (!Array.isArray(attributes)) { attributes = Object.entries(attributes).map(entry => ({ path: entry[0], quantity: entry[1] })); }