chore: add weapon to freestanding inventory
This commit is contained in:
parent
9544786e5c
commit
5d8643b187
@ -4,6 +4,7 @@ import { getInventory, addMiscItems, addEquipment } from "@/src/services/invento
|
|||||||
import { IMiscItem, TFocusPolarity, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
import { IMiscItem, TFocusPolarity, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { ExportFocusUpgrades } from "warframe-public-export-plus";
|
import { ExportFocusUpgrades } from "warframe-public-export-plus";
|
||||||
|
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||||
|
|
||||||
export const focusController: RequestHandler = async (req, res) => {
|
export const focusController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
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/SentAmpTrainingChassis",
|
||||||
"/Lotus/Weapons/Sentients/OperatorAmplifiers/SentTrainingAmplifier/SentAmpTrainingBarrel"
|
"/Lotus/Weapons/Sentients/OperatorAmplifiers/SentTrainingAmplifier/SentAmpTrainingBarrel"
|
||||||
];
|
];
|
||||||
const result = await addEquipment("OperatorAmps", request.StartingWeaponType, accountId, parts);
|
const inventory = await getInventory(accountId);
|
||||||
res.json(result);
|
const inventoryChanges = addEquipment(inventory, "OperatorAmps", request.StartingWeaponType, parts);
|
||||||
|
await inventory.save();
|
||||||
|
res.json((inventoryChanges.OperatorAmps as IEquipmentClient[])[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FocusOperation.UnbindUpgrade: {
|
case FocusOperation.UnbindUpgrade: {
|
||||||
|
@ -34,9 +34,10 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
|
|||||||
throw new Error(`unknown modular weapon type: ${data.WeaponType}`);
|
throw new Error(`unknown modular weapon type: ${data.WeaponType}`);
|
||||||
}
|
}
|
||||||
const category = modularWeaponTypes[data.WeaponType];
|
const category = modularWeaponTypes[data.WeaponType];
|
||||||
|
const inventory = await getInventory(accountId);
|
||||||
|
|
||||||
// Give weapon
|
// Give weapon
|
||||||
const weapon = await addEquipment(category, data.WeaponType, accountId, data.Parts);
|
const weapon = addEquipment(inventory, category, data.WeaponType, data.Parts);
|
||||||
|
|
||||||
// Remove credits & parts
|
// Remove credits & parts
|
||||||
const miscItemChanges = [];
|
const miscItemChanges = [];
|
||||||
@ -46,7 +47,6 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
|
|||||||
ItemCount: -1
|
ItemCount: -1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
const currencyChanges = updateCurrency(
|
const currencyChanges = updateCurrency(
|
||||||
inventory,
|
inventory,
|
||||||
category == "Hoverboards" || category == "MoaPets" ? 5000 : 4000,
|
category == "Hoverboards" || category == "MoaPets" ? 5000 : 4000,
|
||||||
|
@ -17,9 +17,11 @@ const addItemController: RequestHandler = async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case ItemType.Weapon: {
|
case ItemType.Weapon: {
|
||||||
|
const inventory = await getInventory(accountId);
|
||||||
const weaponType = getWeaponType(request.InternalName);
|
const weaponType = getWeaponType(request.InternalName);
|
||||||
const weapon = await addEquipment(weaponType, request.InternalName, accountId);
|
const inventoryChanges = addEquipment(inventory, weaponType, request.InternalName);
|
||||||
res.json(weapon);
|
await inventory.save();
|
||||||
|
res.json(inventoryChanges);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -263,13 +263,15 @@ export const addItem = async (
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Weapons": {
|
case "Weapons": {
|
||||||
|
const inventory = await getInventory(accountId);
|
||||||
const weaponType = getWeaponType(typeName);
|
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);
|
await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1);
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
WeaponBin: { count: 1, platinum: 0, Slots: -1 },
|
...inventoryChanges,
|
||||||
[weaponType]: [weapon]
|
WeaponBin: { count: 1, platinum: 0, Slots: -1 }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -562,23 +564,24 @@ export const updateTheme = async (data: IThemeUpdateRequest, accountId: string):
|
|||||||
await inventory.save();
|
await inventory.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addEquipment = async (
|
export const addEquipment = (
|
||||||
|
inventory: TInventoryDatabaseDocument,
|
||||||
category: TEquipmentKey,
|
category: TEquipmentKey,
|
||||||
type: string,
|
type: string,
|
||||||
accountId: string,
|
modularParts: string[] | undefined = undefined,
|
||||||
modularParts: string[] | undefined = undefined
|
inventoryChanges: IInventoryChanges = {}
|
||||||
): Promise<IEquipmentClient> => {
|
): IInventoryChanges => {
|
||||||
const inventory = await getInventory(accountId);
|
const index =
|
||||||
|
inventory[category].push({
|
||||||
const index = inventory[category].push({
|
|
||||||
ItemType: type,
|
ItemType: type,
|
||||||
Configs: [],
|
Configs: [],
|
||||||
XP: 0,
|
XP: 0,
|
||||||
ModularParts: modularParts
|
ModularParts: modularParts
|
||||||
});
|
}) - 1;
|
||||||
|
|
||||||
const changedInventory = await inventory.save();
|
inventoryChanges[category] ??= [];
|
||||||
return changedInventory[category][index - 1].toJSON() as object as IEquipmentClient;
|
(inventoryChanges[category] as IEquipmentClient[]).push(inventory[category][index].toJSON<IEquipmentClient>());
|
||||||
|
return inventoryChanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addCustomization = (
|
export const addCustomization = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user