2025-03-04 10:33:38 -08:00
|
|
|
import { getDojoClient, getGuildForRequestEx, scaleRequiredCount } from "@/src/services/guildService";
|
|
|
|
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-03-05 23:54:47 -08:00
|
|
|
import { IDojoContributable } from "@/src/types/guildTypes";
|
2025-03-04 10:33:38 -08:00
|
|
|
import { RequestHandler } from "express";
|
2025-03-08 01:44:30 -08:00
|
|
|
import { ExportDojoRecipes, IDojoBuild } from "warframe-public-export-plus";
|
2025-03-05 23:54:47 -08:00
|
|
|
|
|
|
|
interface IDojoComponentRushRequest {
|
|
|
|
DecoType?: string;
|
|
|
|
DecoId?: string;
|
|
|
|
ComponentId: string;
|
|
|
|
Amount: number;
|
|
|
|
VaultAmount: number;
|
|
|
|
AllianceVaultAmount: number;
|
|
|
|
}
|
2025-03-04 10:33:38 -08:00
|
|
|
|
|
|
|
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)!;
|
|
|
|
|
2025-03-08 04:34:00 -08:00
|
|
|
let platinumDonated = request.Amount;
|
|
|
|
const inventoryChanges = updateCurrency(inventory, request.Amount, true);
|
|
|
|
if (request.VaultAmount) {
|
|
|
|
platinumDonated += request.VaultAmount;
|
|
|
|
guild.VaultPremiumCredits! -= request.VaultAmount;
|
|
|
|
}
|
|
|
|
|
2025-03-05 23:54:47 -08:00
|
|
|
if (request.DecoId) {
|
|
|
|
const deco = component.Decos!.find(x => x._id.equals(request.DecoId))!;
|
|
|
|
const meta = Object.values(ExportDojoRecipes.decos).find(x => x.resultType == deco.Type)!;
|
2025-03-08 04:34:00 -08:00
|
|
|
processContribution(deco, meta, platinumDonated);
|
2025-03-05 23:54:47 -08:00
|
|
|
} else {
|
|
|
|
const meta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf)!;
|
2025-03-08 04:34:00 -08:00
|
|
|
processContribution(component, meta, platinumDonated);
|
2025-03-14 02:07:08 -07:00
|
|
|
|
|
|
|
const entry = guild.RoomChanges?.find(x => x.componentId.equals(component._id));
|
|
|
|
if (entry) {
|
|
|
|
entry.dateTime = component.CompletionTime!;
|
|
|
|
}
|
2025-03-05 23:54:47 -08:00
|
|
|
}
|
|
|
|
|
2025-03-04 10:33:38 -08:00
|
|
|
await guild.save();
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
2025-03-06 07:19:01 -08:00
|
|
|
...(await getDojoClient(guild, 0, component._id)),
|
2025-03-04 10:33:38 -08:00
|
|
|
InventoryChanges: inventoryChanges
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2025-03-08 01:44:30 -08:00
|
|
|
const processContribution = (component: IDojoContributable, meta: IDojoBuild, platinumDonated: number): void => {
|
2025-03-05 23:54:47 -08:00
|
|
|
const fullPlatinumCost = scaleRequiredCount(meta.skipTimePrice);
|
|
|
|
const fullDurationSeconds = meta.time;
|
|
|
|
const secondsPerPlatinum = fullDurationSeconds / fullPlatinumCost;
|
|
|
|
component.CompletionTime = new Date(
|
|
|
|
component.CompletionTime!.getTime() - secondsPerPlatinum * platinumDonated * 1000
|
|
|
|
);
|
2025-03-06 21:24:25 -08:00
|
|
|
component.RushPlatinum ??= 0;
|
|
|
|
component.RushPlatinum += platinumDonated;
|
2025-03-05 23:54:47 -08:00
|
|
|
};
|