From e18b8e09eaa4de45678471806d59b452882011ea Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Thu, 10 Jul 2025 20:59:32 -0700 Subject: [PATCH] fix: properly track xp for modular items (#2460) Closes #2454 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2460 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/services/inventoryService.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 766ee4b1..30db6edc 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -1635,6 +1635,15 @@ export const addEmailItem = async ( return inventoryChanges; }; +const xpEarningParts: readonly string[] = [ + "LWPT_BLADE", + "LWPT_GUN_BARREL", + "LWPT_AMP_OCULUS", + "LWPT_MOA_HEAD", + "LWPT_ZANUKA_HEAD", + "LWPT_HB_DECK" +]; + export const applyClientEquipmentUpdates = ( inventory: TInventoryDatabaseDocument, gearArray: IEquipmentClient[], @@ -1653,13 +1662,26 @@ export const applyClientEquipmentUpdates = ( item.XP ??= 0; item.XP += XP; - const xpinfoIndex = inventory.XPInfo.findIndex(x => x.ItemType == item.ItemType); + let xpItemType = item.ItemType; + if (item.ModularParts) { + for (const part of item.ModularParts) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + const partType = ExportWeapons[part]?.partType; + if (partType !== undefined && xpEarningParts.indexOf(partType) != -1) { + xpItemType = part; + break; + } + } + logger.debug(`adding xp to ${xpItemType} for modular item ${fromOid(ItemId)} (${item.ItemType})`); + } + + const xpinfoIndex = inventory.XPInfo.findIndex(x => x.ItemType == xpItemType); if (xpinfoIndex !== -1) { const xpinfo = inventory.XPInfo[xpinfoIndex]; xpinfo.XP += XP; } else { inventory.XPInfo.push({ - ItemType: item.ItemType, + ItemType: xpItemType, XP: XP }); }