2025-02-26 15:42:25 -08:00
|
|
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
2025-03-08 04:34:41 -08:00
|
|
|
import { createVeiledRivenFingerprint, rivenRawToRealWeighted } from "@/src/helpers/rivenHelper";
|
2025-01-06 05:35:57 +01:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { addMods, getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-03-08 04:34:41 -08:00
|
|
|
import { getRandomElement } from "@/src/services/rngService";
|
2025-01-06 05:35:57 +01:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { ExportUpgrades } from "warframe-public-export-plus";
|
|
|
|
|
|
|
|
export const activateRandomModController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const inventory = await getInventory(accountId);
|
2025-01-24 14:27:10 +01:00
|
|
|
const request = getJSONfromString<IActiveRandomModRequest>(String(req.body));
|
2025-01-06 05:35:57 +01:00
|
|
|
addMods(inventory, [
|
|
|
|
{
|
|
|
|
ItemType: request.ItemType,
|
|
|
|
ItemCount: -1
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
const rivenType = getRandomElement(rivenRawToRealWeighted[request.ItemType]);
|
2025-03-08 04:34:41 -08:00
|
|
|
const fingerprint = createVeiledRivenFingerprint(ExportUpgrades[rivenType]);
|
2025-01-06 05:35:57 +01:00
|
|
|
const upgradeIndex =
|
|
|
|
inventory.Upgrades.push({
|
|
|
|
ItemType: rivenType,
|
2025-03-08 04:34:41 -08:00
|
|
|
UpgradeFingerprint: JSON.stringify(fingerprint)
|
2025-01-06 05:35:57 +01:00
|
|
|
}) - 1;
|
|
|
|
await inventory.save();
|
2025-02-26 15:42:25 -08:00
|
|
|
// For some reason, in this response, the UpgradeFingerprint is simply a nested object and not a string
|
2025-01-06 05:35:57 +01:00
|
|
|
res.json({
|
2025-02-26 15:42:25 -08:00
|
|
|
NewMod: {
|
2025-03-08 04:34:41 -08:00
|
|
|
UpgradeFingerprint: fingerprint,
|
|
|
|
ItemType: rivenType,
|
2025-02-26 15:42:25 -08:00
|
|
|
ItemId: toOid(inventory.Upgrades[upgradeIndex]._id)
|
|
|
|
}
|
2025-01-06 05:35:57 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IActiveRandomModRequest {
|
|
|
|
ItemType: string;
|
|
|
|
}
|