Fixed issue where server would enter infinite loop when selling item to trader and stash contained no money

This commit is contained in:
Dev 2024-06-14 19:18:55 +01:00
parent 31a19852c8
commit bc3649d2a1

View File

@ -1305,22 +1305,28 @@ export class InventoryHelper
*/ */
public isItemInStash(pmcData: IPmcData, itemToCheck: Item): boolean public isItemInStash(pmcData: IPmcData, itemToCheck: Item): boolean
{ {
const container = itemToCheck; // Create recursive helper function
const isParentInStash = (itemId: string): boolean =>
while ("parentId" in container)
{ {
if (container.parentId === pmcData.Inventory.stash && container.slotId === "hideout") // Item not found / has no parent
const item = pmcData.Inventory.items.find((item) => item._id === itemId);
if (!item || !item.parentId)
{
return false;
}
// Root level. Items parent is the stash with slotId "hideout"
if (item.parentId === pmcData.Inventory.stash && item.slotId === "hideout")
{ {
return true; return true;
} }
if (!pmcData.Inventory.items.some((item) => item._id === container.parentId)) // Recursive case: Check the items parent
{ return isParentInStash(item.parentId);
break; };
}
}
return false; // Start recursive check
return isParentInStash(itemToCheck._id);
} }
} }