feat: handle defaultUpgrades for moas and hounds (#1012)
Some checks failed
Build Docker image / docker (push) Waiting to run
Build / build (22) (push) Has been cancelled
Build / build (20) (push) Has been cancelled
Build / build (18) (push) Has been cancelled

Closes #997

Reviewed-on: #1012
Co-authored-by: Sainan <sainan@calamity.inc>
Co-committed-by: Sainan <sainan@calamity.inc>
This commit is contained in:
Sainan 2025-02-25 04:41:14 -08:00 committed by OrdisPrime
parent 3d82fee99e
commit e6ec144f1f
2 changed files with 37 additions and 18 deletions

View File

@ -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<string, TEquipmentKey> = {
"/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
}
});

View File

@ -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<IEquipmentClient>());