forked from OpenWF/SpaceNinjaServer
Closes #1072 This whole system is a bit weird to me. It seems the RushPlatinum is not used by the client at all, so the server just adjusts the CompletionTime. We seem to be about 1% off, but I'm not quite sure why. Reviewed-on: OpenWF/SpaceNinjaServer#1075
37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
import { getDojoClient, getGuildForRequestEx, scaleRequiredCount } from "@/src/services/guildService";
|
|
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
import { RequestHandler } from "express";
|
|
import { ExportDojoRecipes } from "warframe-public-export-plus";
|
|
|
|
export const dojoComponentRushController: RequestHandler = async (req, res) => {
|
|
const accountId = await getAccountIdForRequest(req);
|
|
const inventory = await getInventory(accountId);
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
|
const request = JSON.parse(String(req.body)) as IDojoComponentRushRequest;
|
|
const component = guild.DojoComponents.id(request.ComponentId)!;
|
|
const componentMeta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf)!;
|
|
|
|
const fullPlatinumCost = scaleRequiredCount(componentMeta.skipTimePrice);
|
|
const fullDurationSeconds = componentMeta.time;
|
|
const secondsPerPlatinum = fullDurationSeconds / fullPlatinumCost;
|
|
component.CompletionTime = new Date(
|
|
component.CompletionTime!.getTime() - secondsPerPlatinum * request.Amount * 1000
|
|
);
|
|
const inventoryChanges = updateCurrency(inventory, request.Amount, true);
|
|
|
|
await guild.save();
|
|
await inventory.save();
|
|
res.json({
|
|
...getDojoClient(guild, 0, component._id),
|
|
InventoryChanges: inventoryChanges
|
|
});
|
|
};
|
|
|
|
interface IDojoComponentRushRequest {
|
|
ComponentId: string;
|
|
Amount: number;
|
|
VaultAmount: number;
|
|
AllianceVaultAmount: number;
|
|
}
|