2025-04-16 06:31:00 -07:00
|
|
|
import { addCrewShipSalvagedWeaponSkin, addCrewShipRawSalvage, getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { RequestHandler } from "express";
|
2025-04-16 10:38:27 -07:00
|
|
|
import { ICrewShipComponentFingerprint } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-04-16 06:31:00 -07:00
|
|
|
import { ExportCustoms } from "warframe-public-export-plus";
|
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
2025-04-16 10:38:27 -07:00
|
|
|
import { getRandomInt } from "@/src/services/rngService";
|
2025-04-16 06:31:00 -07:00
|
|
|
|
|
|
|
export const crewShipIdentifySalvageController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const inventory = await getInventory(accountId, "CrewShipSalvagedWeaponSkins CrewShipRawSalvage");
|
|
|
|
const payload = getJSONfromString<ICrewShipIdentifySalvageRequest>(String(req.body));
|
|
|
|
|
2025-04-16 10:38:27 -07:00
|
|
|
const meta = ExportCustoms[payload.ItemType];
|
|
|
|
let upgradeFingerprint: ICrewShipComponentFingerprint = { compat: payload.ItemType, buffs: [] };
|
|
|
|
if (meta.subroutines) {
|
|
|
|
upgradeFingerprint = {
|
|
|
|
SubroutineIndex: getRandomInt(0, meta.subroutines.length - 1),
|
|
|
|
...upgradeFingerprint
|
|
|
|
};
|
|
|
|
}
|
|
|
|
for (const upgrade of meta.randomisedUpgrades!) {
|
|
|
|
upgradeFingerprint.buffs.push({ Tag: upgrade.tag, Value: Math.trunc(Math.random() * 0x40000000) });
|
2025-04-16 06:31:00 -07:00
|
|
|
}
|
|
|
|
const inventoryChanges: IInventoryChanges = addCrewShipSalvagedWeaponSkin(
|
|
|
|
inventory,
|
|
|
|
payload.ItemType,
|
2025-04-16 10:38:27 -07:00
|
|
|
JSON.stringify(upgradeFingerprint)
|
2025-04-16 06:31:00 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
inventoryChanges.CrewShipRawSalvage = [
|
|
|
|
{
|
|
|
|
ItemType: payload.ItemType,
|
|
|
|
ItemCount: -1
|
|
|
|
}
|
|
|
|
];
|
|
|
|
addCrewShipRawSalvage(inventory, inventoryChanges.CrewShipRawSalvage);
|
|
|
|
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: inventoryChanges
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ICrewShipIdentifySalvageRequest {
|
|
|
|
ItemType: string;
|
|
|
|
}
|