diff --git a/src/controllers/api/artifactTransmutationController.ts b/src/controllers/api/artifactTransmutationController.ts index 7a728e14..319f6441 100644 --- a/src/controllers/api/artifactTransmutationController.ts +++ b/src/controllers/api/artifactTransmutationController.ts @@ -59,9 +59,10 @@ export const artifactTransmutationController: RequestHandler = async (req, res) }; let forcedPolarity: string | undefined; payload.Consumed.forEach(upgrade => { + upgrade.ItemCount ??= 1; const meta = ExportUpgrades[upgrade.ItemType]; - counts[meta.rarity] += upgrade.ItemCount ? upgrade.ItemCount : 1; - if (fromOid(upgrade.ItemId) && fromOid(upgrade.ItemId) != "000000000000000000000000") { + counts[meta.rarity] += upgrade.ItemCount; + if (fromOid(upgrade.ItemId) != "" && fromOid(upgrade.ItemId) != "000000000000000000000000") { inventory.Upgrades.pull({ _id: fromOid(upgrade.ItemId) }); } else { addMods(inventory, [ diff --git a/src/controllers/api/artifactsController.ts b/src/controllers/api/artifactsController.ts index 9fbe5cb9..43555af4 100644 --- a/src/controllers/api/artifactsController.ts +++ b/src/controllers/api/artifactsController.ts @@ -8,7 +8,7 @@ import type { } from "../../types/inventoryTypes/inventoryTypes.ts"; import { addMods, getInventory } from "../../services/inventoryService.ts"; import { broadcastInventoryUpdate } from "../../services/wsService.ts"; -import { toLegacyOid, version_compare } from "../../helpers/inventoryHelpers.ts"; +import { fromOid, version_compare } from "../../helpers/inventoryHelpers.ts"; export const artifactsController: RequestHandler = async (req, res) => { const account = await getAccountForRequest(req); @@ -21,16 +21,13 @@ export const artifactsController: RequestHandler = async (req, res) => { const { Upgrades } = inventory; const { ItemType, UpgradeFingerprint, ItemId } = Upgrade; - if (account.BuildLabel && version_compare(account.BuildLabel, "2016.08.19.17.12") >= 0) { - if (version_compare(account.BuildLabel, "2016.12.21.19.13") <= 0) { - toLegacyOid(ItemId); - } + if (!account.BuildLabel || version_compare(account.BuildLabel, "2016.08.19.17.12") >= 0) { const safeUpgradeFingerprint = UpgradeFingerprint || '{"lvl":0}'; const parsedUpgradeFingerprint = JSON.parse(safeUpgradeFingerprint) as { lvl: number }; parsedUpgradeFingerprint.lvl += LevelDiff; const stringifiedUpgradeFingerprint = JSON.stringify(parsedUpgradeFingerprint); - let itemIndex = Upgrades.findIndex(upgrade => upgrade._id.equals(ItemId.$oid ?? ItemId.$id)); + let itemIndex = Upgrades.findIndex(upgrade => upgrade._id.equals(fromOid(ItemId))); if (itemIndex !== -1) { Upgrades[itemIndex].UpgradeFingerprint = stringifiedUpgradeFingerprint; @@ -104,7 +101,7 @@ export const artifactsController: RequestHandler = async (req, res) => { if (Consumed && Consumed.length > 0) { for (const upgrade of Consumed) { // The client does not send the expected information about the mods, so we have to check if it's an Upgrade or RawUpgrade manually. - if (Upgrades.find(u => u._id.equals(upgrade.ItemId.$id))) { + if (Upgrades.id(fromOid(upgrade.ItemId))) { Upgrades.pull({ _id: upgrade.ItemId.$id }); } else { addMods(inventory, [ diff --git a/src/services/missionInventoryUpdateService.ts b/src/services/missionInventoryUpdateService.ts index 1580ea81..367668c4 100644 --- a/src/services/missionInventoryUpdateService.ts +++ b/src/services/missionInventoryUpdateService.ts @@ -480,16 +480,12 @@ export const addMissionInventoryUpdates = async ( case "Upgrades": value.forEach(clientUpgrade => { const id = fromOid(clientUpgrade.ItemId); + // Really old builds (tested U7-U8) do not have the UpgradeFingerprint set for unranked mod drops + clientUpgrade.UpgradeFingerprint ??= "lvl=0|"; + // U11 and below also don't initialize ItemCount since RawUpgrade doesn't exist in them + clientUpgrade.ItemCount ??= 1; if (account.BuildLabel && version_compare(account.BuildLabel, "2016.08.19.17.12") < 0) { // Acquired Mods have a different UpgradeFingerprint format in pre-U18.18.0 builds, this converts them to the format the database expects - if (!clientUpgrade.UpgradeFingerprint) { - // Really old builds (tested U7-U8) do not have the UpgradeFingerprint set for unranked mod drops - clientUpgrade.UpgradeFingerprint = "lvl=0|"; - } - if (!clientUpgrade.ItemCount) { - // U11 and below also don't initialize ItemCount since RawUpgrade doesn't exist in them - clientUpgrade.ItemCount = 1; - } clientUpgrade.UpgradeFingerprint = `{"lvl":${clientUpgrade.UpgradeFingerprint.substring( clientUpgrade.UpgradeFingerprint.indexOf("=") + 1, clientUpgrade.UpgradeFingerprint.lastIndexOf("|") @@ -504,7 +500,12 @@ export const addMissionInventoryUpdates = async ( }); } else if (id == "") { // U19 does not provide RawUpgrades and instead interleaves them with riven progress here - addMods(inventory, [clientUpgrade]); + addMods(inventory, [ + { + ItemType: clientUpgrade.ItemType, + ItemCount: clientUpgrade.ItemCount + } + ]); } else { const upgrade = inventory.Upgrades.id(id)!; upgrade.UpgradeFingerprint = clientUpgrade.UpgradeFingerprint; // primitive way to copy over the riven challenge progress diff --git a/src/services/saveLoadoutService.ts b/src/services/saveLoadoutService.ts index 05a62994..df1266bd 100644 --- a/src/services/saveLoadoutService.ts +++ b/src/services/saveLoadoutService.ts @@ -199,31 +199,29 @@ export const handleInventoryItemConfigChange = async ( for (const [configId, config] of Object.entries(itemConfigEntries)) { if (/^[0-9]+$/.test(configId)) { const c = config as IItemConfig; - if (buildLabel) { - if (version_compare(buildLabel, "2014.04.10.17.47") < 0) { - if (c.Upgrades) { - // U10-U11 store mods in the item config as $id instead of a string, need to convert that here - const convertedUpgrades: string[] = []; - c.Upgrades.forEach(upgrade => { - const upgradeId = upgrade as { $id: string }; - convertedUpgrades.push(upgradeId.$id); - const rawUpgrade = inventory.RawUpgrades.id(upgradeId.$id); - if (rawUpgrade) { - addMods(inventory, [ - { - ItemType: rawUpgrade.ItemType, - ItemCount: -1 - } - ]); - inventory.Upgrades.push({ - UpgradeFingerprint: `{"lvl":0}`, + if (buildLabel && version_compare(buildLabel, "2014.04.10.17.47") < 0) { + if (c.Upgrades) { + // U10-U11 store mods in the item config as $id instead of a string, need to convert that here + const convertedUpgrades: string[] = []; + c.Upgrades.forEach(upgrade => { + const upgradeId = upgrade as { $id: string }; + convertedUpgrades.push(upgradeId.$id); + const rawUpgrade = inventory.RawUpgrades.id(upgradeId.$id); + if (rawUpgrade) { + addMods(inventory, [ + { ItemType: rawUpgrade.ItemType, - _id: upgradeId.$id - }); - } - }); - c.Upgrades = convertedUpgrades; - } + ItemCount: -1 + } + ]); + inventory.Upgrades.push({ + UpgradeFingerprint: `{"lvl":0}`, + ItemType: rawUpgrade.ItemType, + _id: upgradeId.$id + }); + } + }); + c.Upgrades = convertedUpgrades; } } inventoryItem.Configs[parseInt(configId)] = c as IItemConfigDatabase; diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 5c8cb8ee..c720e6e9 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -610,9 +610,9 @@ export interface IUpgradeFromClient { ItemType: string; ItemId: IOidWithLegacySupport; FromSKU?: boolean; - UpgradeFingerprint: string; + UpgradeFingerprint?: string; PendingRerollFingerprint: string; - ItemCount: number; + ItemCount?: number; LastAdded: IOidWithLegacySupport; }