feat: handle defaultUpgrades for moas and hounds #1012

Merged
OrdisPrime merged 1 commits from weapon-defaultUpgrades into main 2025-02-25 04:41:15 -08:00
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 { getAccountIdForRequest } from "@/src/services/loginService";
import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes"; 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> = { const modularWeaponTypes: Record<string, TEquipmentKey> = {
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns", "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns",
@ -36,8 +43,11 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
const category = modularWeaponTypes[data.WeaponType]; const category = modularWeaponTypes[data.WeaponType];
const inventory = await getInventory(accountId); 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 // 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 // Remove credits & parts
const miscItemChanges = []; const miscItemChanges = [];
@ -58,8 +68,8 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
// Tell client what we did // Tell client what we did
res.json({ res.json({
InventoryChanges: { InventoryChanges: {
...inventoryChanges,
...currencyChanges, ...currencyChanges,
[category]: [weapon],
MiscItems: miscItemChanges MiscItems: miscItemChanges
} }
}); });

View File

@ -51,6 +51,7 @@ import {
ExportSyndicates, ExportSyndicates,
ExportUpgrades, ExportUpgrades,
ExportWeapons, ExportWeapons,
IDefaultUpgrade,
TStandingLimitBin TStandingLimitBin
} from "warframe-public-export-plus"; } from "warframe-public-export-plus";
import { createShip } from "./shipService"; import { createShip } from "./shipService";
@ -520,6 +521,28 @@ export const addItems = async (
return inventoryChanges; 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 //TODO: maybe genericMethod for all the add methods, they share a lot of logic
export const addSentinel = ( export const addSentinel = (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
@ -531,23 +554,9 @@ export const addSentinel = (
addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges); addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
} }
const modsToGive: IRawUpgrade[] = [];
const configs: IItemConfig[] = [];
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (ExportSentinels[sentinelName]?.defaultUpgrades) { const configs: IItemConfig[] = applyDefaultUpgrades(inventory, 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 });
}
}
addMods(inventory, modsToGive);
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1; const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1;
inventoryChanges.Sentinels ??= []; inventoryChanges.Sentinels ??= [];
inventoryChanges.Sentinels.push(inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>()); inventoryChanges.Sentinels.push(inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>());