2024-06-18 13:02:29 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { getInventory, addMiscItems } from "@/src/services/inventoryService";
|
|
|
|
import { IOid } from "@/src/types/commonTypes";
|
2024-12-22 07:26:14 +01:00
|
|
|
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
|
|
import { ExportMisc } from "warframe-public-export-plus";
|
2024-06-18 13:02:29 +02:00
|
|
|
|
|
|
|
export const infestedFoundryController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
switch (req.query.mode) {
|
|
|
|
case "s": {
|
|
|
|
// shard installation
|
2024-06-24 12:37:28 +02:00
|
|
|
const request = getJSONfromString(String(req.body)) as IShardInstallRequest;
|
2024-06-18 13:02:29 +02:00
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
const suit = inventory.Suits.find(suit => suit._id.toString() == request.SuitId.$oid)!;
|
2024-06-30 13:13:26 +02:00
|
|
|
if (!suit.ArchonCrystalUpgrades || suit.ArchonCrystalUpgrades.length != 5) {
|
2024-06-18 13:02:29 +02:00
|
|
|
suit.ArchonCrystalUpgrades = [{}, {}, {}, {}, {}];
|
|
|
|
}
|
|
|
|
suit.ArchonCrystalUpgrades[request.Slot] = {
|
|
|
|
UpgradeType: request.UpgradeType,
|
|
|
|
Color: request.Color
|
|
|
|
};
|
|
|
|
const miscItemChanges = [
|
|
|
|
{
|
|
|
|
ItemType: colorToShard[request.Color],
|
|
|
|
ItemCount: -1
|
|
|
|
}
|
|
|
|
];
|
|
|
|
addMiscItems(inventory, miscItemChanges);
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
|
|
|
MiscItems: miscItemChanges
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "n": {
|
|
|
|
// name the beast
|
2024-06-24 12:37:28 +02:00
|
|
|
const request = getJSONfromString(String(req.body)) as IHelminthNameRequest;
|
2024-06-18 13:02:29 +02:00
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
inventory.InfestedFoundry ??= {};
|
2024-06-24 12:37:28 +02:00
|
|
|
inventory.InfestedFoundry.Name = request.newName;
|
2024-06-18 13:02:29 +02:00
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
|
|
|
InfestedFoundry: {
|
|
|
|
Name: inventory.InfestedFoundry.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-12-22 07:26:14 +01:00
|
|
|
case "c": {
|
|
|
|
// consume items
|
|
|
|
const request = getJSONfromString(String(req.body)) as IHelminthFeedRequest;
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
inventory.InfestedFoundry ??= {};
|
|
|
|
inventory.InfestedFoundry.Resources ??= [];
|
|
|
|
inventory.InfestedFoundry.XP ??= 0;
|
|
|
|
|
|
|
|
const miscItemChanges: IMiscItem[] = [];
|
|
|
|
let totalPercentagePointsGained = 0;
|
|
|
|
|
|
|
|
for (const contribution of request.ResourceContributions) {
|
|
|
|
const snack = ExportMisc.helminthSnacks[contribution.ItemType];
|
|
|
|
|
|
|
|
// Note: Currently ignoring loss of apetite
|
|
|
|
totalPercentagePointsGained += snack.gain / 0.01;
|
|
|
|
const resource = inventory.InfestedFoundry.Resources.find(x => x.ItemType == snack.type);
|
|
|
|
if (resource) {
|
|
|
|
resource.Count += Math.trunc(snack.gain * 1000);
|
|
|
|
} else {
|
|
|
|
inventory.InfestedFoundry.Resources.push({
|
|
|
|
ItemType: snack.type,
|
|
|
|
Count: Math.trunc(snack.gain * 1000)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// tally items for removal
|
|
|
|
const change = miscItemChanges.find(x => x.ItemType == contribution.ItemType);
|
|
|
|
if (change) {
|
|
|
|
change.ItemCount -= snack.count;
|
|
|
|
} else {
|
|
|
|
miscItemChanges.push({ ItemType: contribution.ItemType, ItemCount: snack.count * -1 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inventory.InfestedFoundry.XP += 666 * totalPercentagePointsGained;
|
|
|
|
addMiscItems(inventory, miscItemChanges);
|
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
|
|
|
InfestedFoundry: {
|
|
|
|
XP: inventory.InfestedFoundry.XP,
|
|
|
|
Resources: inventory.InfestedFoundry.Resources
|
|
|
|
}
|
|
|
|
},
|
|
|
|
MiscItems: miscItemChanges
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-06-18 13:02:29 +02:00
|
|
|
case "o": // offerings update
|
|
|
|
// {"OfferingsIndex":540,"SuitTypes":["/Lotus/Powersuits/PaxDuviricus/PaxDuviricusBaseSuit","/Lotus/Powersuits/Nezha/NezhaBaseSuit","/Lotus/Powersuits/Devourer/DevourerBaseSuit"],"Extra":false}
|
|
|
|
res.status(404).end();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Error(`unhandled infestedFoundry mode: ${req.query.mode}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IShardInstallRequest {
|
|
|
|
SuitId: IOid;
|
|
|
|
Slot: number;
|
|
|
|
UpgradeType: string;
|
|
|
|
Color: string;
|
|
|
|
}
|
|
|
|
|
2024-06-24 12:37:28 +02:00
|
|
|
interface IHelminthNameRequest {
|
|
|
|
newName: string;
|
|
|
|
}
|
|
|
|
|
2024-12-22 07:26:14 +01:00
|
|
|
interface IHelminthFeedRequest {
|
|
|
|
ResourceContributions: {
|
|
|
|
ItemType: string;
|
|
|
|
Date: number; // unix timestamp
|
|
|
|
}[];
|
|
|
|
}
|
|
|
|
|
2024-06-18 13:02:29 +02:00
|
|
|
const colorToShard: Record<string, string> = {
|
|
|
|
ACC_RED: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalAmar",
|
|
|
|
ACC_RED_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalAmarMythic",
|
|
|
|
ACC_YELLOW: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalNira",
|
|
|
|
ACC_YELLOW_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalNiraMythic",
|
|
|
|
ACC_BLUE: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalBoreal",
|
|
|
|
ACC_BLUE_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalBorealMythic",
|
|
|
|
ACC_GREEN: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalGreen",
|
|
|
|
ACC_GREEN_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalGreenMythic",
|
|
|
|
ACC_ORANGE: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalOrange",
|
|
|
|
ACC_ORANGE_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalOrangeMythic",
|
|
|
|
ACC_PURPLE: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalViolet",
|
|
|
|
ACC_PURPLE_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalVioletMythic"
|
|
|
|
};
|