2025-03-14 07:09:28 -07:00
|
|
|
import { getDojoClient, getGuildForRequestEx, hasAccessToDojo, hasGuildPermission } from "@/src/services/guildService";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { GuildPermission } from "@/src/types/guildTypes";
|
2025-03-05 23:54:47 -08:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { Types } from "mongoose";
|
|
|
|
import { ExportDojoRecipes } from "warframe-public-export-plus";
|
|
|
|
|
|
|
|
export const placeDecoInComponentController: RequestHandler = async (req, res) => {
|
2025-03-14 07:09:28 -07:00
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const inventory = await getInventory(accountId, "GuildId LevelKeys");
|
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
|
|
|
if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Decorator))) {
|
|
|
|
res.json({ DojoRequestStatus: -1 });
|
|
|
|
return;
|
|
|
|
}
|
2025-03-05 23:54:47 -08:00
|
|
|
const request = JSON.parse(String(req.body)) as IPlaceDecoInComponentRequest;
|
|
|
|
const component = guild.DojoComponents.id(request.ComponentId)!;
|
|
|
|
|
|
|
|
if (component.DecoCapacity === undefined) {
|
|
|
|
component.DecoCapacity = Object.values(ExportDojoRecipes.rooms).find(
|
|
|
|
x => x.resultType == component.pf
|
|
|
|
)!.decoCapacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
component.Decos ??= [];
|
2025-03-25 03:26:32 -07:00
|
|
|
const deco =
|
|
|
|
component.Decos[
|
|
|
|
component.Decos.push({
|
|
|
|
_id: new Types.ObjectId(),
|
|
|
|
Type: request.Type,
|
|
|
|
Pos: request.Pos,
|
|
|
|
Rot: request.Rot,
|
|
|
|
Name: request.Name
|
|
|
|
}) - 1
|
|
|
|
];
|
2025-03-05 23:54:47 -08:00
|
|
|
|
|
|
|
const meta = Object.values(ExportDojoRecipes.decos).find(x => x.resultType == request.Type);
|
2025-03-25 03:26:32 -07:00
|
|
|
if (meta) {
|
|
|
|
if (meta.capacityCost) {
|
|
|
|
component.DecoCapacity -= meta.capacityCost;
|
|
|
|
}
|
|
|
|
if (meta.price == 0 && meta.ingredients.length == 0) {
|
|
|
|
deco.CompletionTime = new Date();
|
|
|
|
}
|
2025-03-05 23:54:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
await guild.save();
|
2025-03-06 07:19:01 -08:00
|
|
|
res.json(await getDojoClient(guild, 0, component._id));
|
2025-03-05 23:54:47 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
interface IPlaceDecoInComponentRequest {
|
|
|
|
ComponentId: string;
|
|
|
|
Revision: number;
|
|
|
|
Type: string;
|
|
|
|
Pos: number[];
|
|
|
|
Rot: number[];
|
|
|
|
Name?: string;
|
|
|
|
}
|