From cc6061b8859e746aa27439d7c198f7c633edf893 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Fri, 9 Feb 2024 12:53:44 +0000 Subject: [PATCH] Resolve issue caused by quests pulling loose ammo from magazines (!218) If the item handed in for a quest has a numeric `location` property, this indicates it's inside a magazine or other "sequential" container. Re-calculate the `location` property of all children in the items parent in this case, to avoid gaps which break the profile Resolves: https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/455 Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/218 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/controllers/QuestController.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 23540612..9b8aadbc 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -835,7 +835,22 @@ export class QuestController { if (toRemove.includes(pmcData.Inventory.items[index]._id)) { - pmcData.Inventory.items.splice(index, 1); + // Remove the item + const removedItem = pmcData.Inventory.items.splice(index, 1)[0]; + + // If the removed item has a numeric `location` property, re-calculate all the child + // element `location` properties of the parent so they are sequential, while retaining order + if (typeof removedItem.location === "number") + { + const childItems = this.itemHelper.findAndReturnChildrenAsItems(pmcData.Inventory.items, removedItem.parentId); + childItems.shift(); // Remove the parent + + // Sort by the current `location` and update + childItems.sort((a, b) => a.location > b.location ? 1 : -1).forEach((item, index) => + { + item.location = index; + }); + } } } }