2024-06-20 13:05:07 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-01-03 00:48:54 +01:00
|
|
|
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
|
2024-06-20 13:05:07 +02:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
2025-01-03 00:48:54 +01:00
|
|
|
import { getRecipe, WeaponTypeInternal } from "@/src/services/itemDataService";
|
2024-06-20 13:05:07 +02:00
|
|
|
import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
|
|
|
|
|
|
|
export const evolveWeaponController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const inventory = await getInventory(accountId);
|
2025-01-24 14:27:10 +01:00
|
|
|
const payload = getJSONfromString<IEvolveWeaponRequest>(String(req.body));
|
2024-06-20 13:05:07 +02:00
|
|
|
|
2025-01-03 00:48:54 +01:00
|
|
|
const recipe = getRecipe(payload.Recipe)!;
|
2025-01-03 09:06:34 +01:00
|
|
|
if (payload.Action == "EWA_INSTALL") {
|
|
|
|
addMiscItems(
|
|
|
|
inventory,
|
|
|
|
recipe.ingredients.map(x => ({ ItemType: x.ItemType, ItemCount: x.ItemCount * -1 }))
|
|
|
|
);
|
|
|
|
|
|
|
|
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
|
|
|
|
item.Features ??= 0;
|
|
|
|
item.Features |= EquipmentFeatures.INCARNON_GENESIS;
|
|
|
|
|
|
|
|
item.SkillTree = "0";
|
|
|
|
|
|
|
|
inventory.EvolutionProgress ??= [];
|
|
|
|
if (!inventory.EvolutionProgress.find(entry => entry.ItemType == payload.EvoType)) {
|
|
|
|
inventory.EvolutionProgress.push({
|
|
|
|
Progress: 0,
|
|
|
|
Rank: 1,
|
|
|
|
ItemType: payload.EvoType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (payload.Action == "EWA_UNINSTALL") {
|
|
|
|
addMiscItems(inventory, [
|
|
|
|
{
|
|
|
|
ItemType: recipe.resultType,
|
|
|
|
ItemCount: 1
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
|
|
|
|
item.Features! &= ~EquipmentFeatures.INCARNON_GENESIS;
|
|
|
|
} else {
|
|
|
|
throw new Error(`unexpected evolve weapon action: ${payload.Action}`);
|
2024-06-20 13:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await inventory.save();
|
|
|
|
res.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IEvolveWeaponRequest {
|
2025-01-03 09:06:34 +01:00
|
|
|
Action: string;
|
2024-06-20 13:05:07 +02:00
|
|
|
Category: WeaponTypeInternal;
|
|
|
|
Recipe: string; // e.g. "/Lotus/Types/Items/MiscItems/IncarnonAdapters/UnlockerBlueprints/DespairIncarnonBlueprint"
|
|
|
|
UninstallRecipe: "";
|
|
|
|
EvoType: string; // e.g. "/Lotus/Weapons/Tenno/ThrowingWeapons/StalkerKunai"
|
|
|
|
}
|