diff --git a/src/controllers/api/modularWeaponCraftingController.ts b/src/controllers/api/modularWeaponCraftingController.ts index 37b400fb..0c2487f8 100644 --- a/src/controllers/api/modularWeaponCraftingController.ts +++ b/src/controllers/api/modularWeaponCraftingController.ts @@ -11,8 +11,8 @@ import { occupySlot, productCategoryToInventoryBin } from "@/src/services/inventoryService"; -import { ExportWeapons } from "warframe-public-export-plus"; import { IInventoryChanges } from "@/src/types/purchaseTypes"; +import { getDefaultUpgrades } from "@/src/services/itemDataService"; const modularWeaponTypes: Record = { "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns", @@ -46,8 +46,7 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res) const category = modularWeaponTypes[data.WeaponType]; const inventory = await getInventory(accountId); - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - const configs = applyDefaultUpgrades(inventory, ExportWeapons[data.Parts[0]]?.defaultUpgrades); + const configs = applyDefaultUpgrades(inventory, getDefaultUpgrades(data.Parts)); // Give weapon const inventoryChanges: IInventoryChanges = { diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 416adc7f..b1a1a297 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -29,6 +29,7 @@ import { ExportSentinels, ExportWarframes, ExportWeapons, + IDefaultUpgrade, IInboxMessage, IMissionReward, IPowersuit, @@ -256,3 +257,15 @@ export const toStoreItem = (type: string): string => { export const fromStoreItem = (type: string): string => { return "/Lotus/" + type.substring("/Lotus/StoreItems/".length); }; + +export const getDefaultUpgrades = (parts: string[]): IDefaultUpgrade[] | undefined => { + const allDefaultUpgrades: IDefaultUpgrade[] = []; + for (const part of parts) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + const defaultUpgrades = ExportWeapons[part]?.defaultUpgrades; + if (defaultUpgrades) { + allDefaultUpgrades.push(...defaultUpgrades); + } + } + return allDefaultUpgrades.length == 0 ? undefined : allDefaultUpgrades; +};