chore: add weapon to freestanding inventory

This commit is contained in:
Sainan 2025-01-03 07:16:07 +01:00
parent 9544786e5c
commit 5d8643b187
4 changed files with 31 additions and 23 deletions

View File

@ -4,6 +4,7 @@ import { getInventory, addMiscItems, addEquipment } from "@/src/services/invento
import { IMiscItem, TFocusPolarity, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
import { logger } from "@/src/utils/logger";
import { ExportFocusUpgrades } from "warframe-public-export-plus";
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
export const focusController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
@ -102,8 +103,10 @@ export const focusController: RequestHandler = async (req, res) => {
"/Lotus/Weapons/Sentients/OperatorAmplifiers/SentTrainingAmplifier/SentAmpTrainingChassis",
"/Lotus/Weapons/Sentients/OperatorAmplifiers/SentTrainingAmplifier/SentAmpTrainingBarrel"
];
const result = await addEquipment("OperatorAmps", request.StartingWeaponType, accountId, parts);
res.json(result);
const inventory = await getInventory(accountId);
const inventoryChanges = addEquipment(inventory, "OperatorAmps", request.StartingWeaponType, parts);
await inventory.save();
res.json((inventoryChanges.OperatorAmps as IEquipmentClient[])[0]);
break;
}
case FocusOperation.UnbindUpgrade: {

View File

@ -34,9 +34,10 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
throw new Error(`unknown modular weapon type: ${data.WeaponType}`);
}
const category = modularWeaponTypes[data.WeaponType];
const inventory = await getInventory(accountId);
// Give weapon
const weapon = await addEquipment(category, data.WeaponType, accountId, data.Parts);
const weapon = addEquipment(inventory, category, data.WeaponType, data.Parts);
// Remove credits & parts
const miscItemChanges = [];
@ -46,7 +47,6 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
ItemCount: -1
});
}
const inventory = await getInventory(accountId);
const currencyChanges = updateCurrency(
inventory,
category == "Hoverboards" || category == "MoaPets" ? 5000 : 4000,

View File

@ -17,9 +17,11 @@ const addItemController: RequestHandler = async (req, res) => {
return;
}
case ItemType.Weapon: {
const inventory = await getInventory(accountId);
const weaponType = getWeaponType(request.InternalName);
const weapon = await addEquipment(weaponType, request.InternalName, accountId);
res.json(weapon);
const inventoryChanges = addEquipment(inventory, weaponType, request.InternalName);
await inventory.save();
res.json(inventoryChanges);
break;
}
default:

View File

@ -263,13 +263,15 @@ export const addItem = async (
}
break;
case "Weapons": {
const inventory = await getInventory(accountId);
const weaponType = getWeaponType(typeName);
const weapon = await addEquipment(weaponType, typeName, accountId);
const inventoryChanges = addEquipment(inventory, weaponType, typeName);
await inventory.save();
await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1);
return {
InventoryChanges: {
WeaponBin: { count: 1, platinum: 0, Slots: -1 },
[weaponType]: [weapon]
...inventoryChanges,
WeaponBin: { count: 1, platinum: 0, Slots: -1 }
}
};
}
@ -562,23 +564,24 @@ export const updateTheme = async (data: IThemeUpdateRequest, accountId: string):
await inventory.save();
};
export const addEquipment = async (
export const addEquipment = (
inventory: TInventoryDatabaseDocument,
category: TEquipmentKey,
type: string,
accountId: string,
modularParts: string[] | undefined = undefined
): Promise<IEquipmentClient> => {
const inventory = await getInventory(accountId);
const index = inventory[category].push({
modularParts: string[] | undefined = undefined,
inventoryChanges: IInventoryChanges = {}
): IInventoryChanges => {
const index =
inventory[category].push({
ItemType: type,
Configs: [],
XP: 0,
ModularParts: modularParts
});
}) - 1;
const changedInventory = await inventory.save();
return changedInventory[category][index - 1].toJSON() as object as IEquipmentClient;
inventoryChanges[category] ??= [];
(inventoryChanges[category] as IEquipmentClient[]).push(inventory[category][index].toJSON<IEquipmentClient>());
return inventoryChanges;
};
export const addCustomization = (