diff --git a/src/controllers/api/modularWeaponCraftingController.ts b/src/controllers/api/modularWeaponCraftingController.ts index d70f48cad..4be0d980b 100644 --- a/src/controllers/api/modularWeaponCraftingController.ts +++ b/src/controllers/api/modularWeaponCraftingController.ts @@ -2,7 +2,14 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes"; -import { getInventory, updateCurrency, addEquipment, addMiscItems } from "@/src/services/inventoryService"; +import { + getInventory, + updateCurrency, + addEquipment, + addMiscItems, + applyDefaultUpgrades +} from "@/src/services/inventoryService"; +import { ExportWeapons } from "warframe-public-export-plus"; const modularWeaponTypes: Record = { "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns", @@ -36,8 +43,11 @@ 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); + // Give weapon - const weapon = addEquipment(inventory, category, data.WeaponType, data.Parts); + const inventoryChanges = addEquipment(inventory, category, data.WeaponType, data.Parts, {}, { Configs: configs }); // Remove credits & parts const miscItemChanges = []; @@ -58,8 +68,8 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res) // Tell client what we did res.json({ InventoryChanges: { + ...inventoryChanges, ...currencyChanges, - [category]: [weapon], MiscItems: miscItemChanges } }); diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 7977818aa..1f895825f 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -52,6 +52,7 @@ import { ExportSyndicates, ExportUpgrades, ExportWeapons, + IDefaultUpgrade, TStandingLimitBin } from "warframe-public-export-plus"; import { createShip } from "./shipService"; @@ -532,6 +533,28 @@ export const addItems = async ( return inventoryChanges; }; +export const applyDefaultUpgrades = ( + inventory: TInventoryDatabaseDocument, + defaultUpgrades: IDefaultUpgrade[] | undefined +): IItemConfig[] => { + const modsToGive: IRawUpgrade[] = []; + const configs: IItemConfig[] = []; + if (defaultUpgrades) { + const upgrades = []; + for (const defaultUpgrade of defaultUpgrades) { + modsToGive.push({ ItemType: defaultUpgrade.ItemType, ItemCount: 1 }); + if (defaultUpgrade.Slot != -1) { + upgrades[defaultUpgrade.Slot] = defaultUpgrade.ItemType; + } + } + if (upgrades.length != 0) { + configs.push({ Upgrades: upgrades }); + } + } + addMods(inventory, modsToGive); + return configs; +}; + //TODO: maybe genericMethod for all the add methods, they share a lot of logic export const addSentinel = ( inventory: TInventoryDatabaseDocument, @@ -543,23 +566,9 @@ export const addSentinel = ( addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges); } - const modsToGive: IRawUpgrade[] = []; - const configs: IItemConfig[] = []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (ExportSentinels[sentinelName]?.defaultUpgrades) { - const upgrades = []; - for (const defaultUpgrade of ExportSentinels[sentinelName].defaultUpgrades) { - modsToGive.push({ ItemType: defaultUpgrade.ItemType, ItemCount: 1 }); - if (defaultUpgrade.Slot != -1) { - upgrades[defaultUpgrade.Slot] = defaultUpgrade.ItemType; - } - } - if (upgrades.length != 0) { - configs.push({ Upgrades: upgrades }); - } - } + const configs: IItemConfig[] = applyDefaultUpgrades(inventory, ExportSentinels[sentinelName]?.defaultUpgrades); - addMods(inventory, modsToGive); const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1; inventoryChanges.Sentinels ??= []; inventoryChanges.Sentinels.push(inventory.Sentinels[sentinelIndex].toJSON());