fix: properly track xp for modular items #2460

Merged
Sainan merged 1 commits from modular-xp into main 2025-07-10 20:59:32 -07:00

View File

@ -1635,6 +1635,15 @@ export const addEmailItem = async (
return inventoryChanges; 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 = ( export const applyClientEquipmentUpdates = (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
gearArray: IEquipmentClient[], gearArray: IEquipmentClient[],
@ -1653,13 +1662,26 @@ export const applyClientEquipmentUpdates = (
item.XP ??= 0; item.XP ??= 0;
item.XP += XP; 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) { if (xpinfoIndex !== -1) {
const xpinfo = inventory.XPInfo[xpinfoIndex]; const xpinfo = inventory.XPInfo[xpinfoIndex];
xpinfo.XP += XP; xpinfo.XP += XP;
} else { } else {
inventory.XPInfo.push({ inventory.XPInfo.push({
ItemType: item.ItemType, ItemType: xpItemType,
XP: XP XP: XP
}); });
} }