Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jan 22, 2024
1 parent 46295cb commit 4681e11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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!)
Expand Down
23 changes: 5 additions & 18 deletions src/helpers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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)

Expand All @@ -135,24 +125,21 @@ 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)
}
}
}
}

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] }));
}
Expand Down

0 comments on commit 4681e11

Please sign in to comment.