feat: track DecoCapacity
All checks were successful
Build / build (18) (push) Successful in 41s
Build / build (22) (push) Successful in 54s
Build / build (20) (push) Successful in 54s
Build / build (18) (pull_request) Successful in 41s
Build / build (20) (pull_request) Successful in 52s
Build / build (22) (pull_request) Successful in 51s
All checks were successful
Build / build (18) (push) Successful in 41s
Build / build (22) (push) Successful in 54s
Build / build (20) (push) Successful in 54s
Build / build (18) (pull_request) Successful in 41s
Build / build (20) (pull_request) Successful in 52s
Build / build (22) (pull_request) Successful in 51s
This commit is contained in:
parent
cc61cc6257
commit
efa9900dd3
@ -1,4 +1,4 @@
|
|||||||
import { getDojoClient, getGuildForRequestEx, removeDojoRoom } from "@/src/services/guildService";
|
import { getDojoClient, getGuildForRequestEx, removeDojoDeco, removeDojoRoom } from "@/src/services/guildService";
|
||||||
import { getInventory } from "@/src/services/inventoryService";
|
import { getInventory } from "@/src/services/inventoryService";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
@ -8,14 +8,14 @@ export const abortDojoComponentController: RequestHandler = async (req, res) =>
|
|||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const guild = await getGuildForRequestEx(req, inventory);
|
const guild = await getGuildForRequestEx(req, inventory);
|
||||||
const request = JSON.parse(String(req.body)) as IAbortDojoComponentRequest;
|
const request = JSON.parse(String(req.body)) as IAbortDojoComponentRequest;
|
||||||
|
|
||||||
// TODO: Move already-contributed credits & items to the clan vault
|
// TODO: Move already-contributed credits & items to the clan vault
|
||||||
if (request.DecoId) {
|
if (request.DecoId) {
|
||||||
const component = guild.DojoComponents.id(request.ComponentId)!;
|
removeDojoDeco(guild, request.ComponentId, request.DecoId);
|
||||||
const decoIndex = component.Decos!.findIndex(x => x._id.equals(request.DecoId));
|
|
||||||
component.Decos!.splice(decoIndex, 1);
|
|
||||||
} else {
|
} else {
|
||||||
removeDojoRoom(guild, request.ComponentId);
|
removeDojoRoom(guild, request.ComponentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
await guild.save();
|
await guild.save();
|
||||||
res.json(getDojoClient(guild, 0));
|
res.json(getDojoClient(guild, 0));
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { getDojoClient, getGuildForRequest } from "@/src/services/guildService";
|
import { getDojoClient, getGuildForRequest, removeDojoDeco } from "@/src/services/guildService";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
export const destroyDojoDecoController: RequestHandler = async (req, res) => {
|
export const destroyDojoDecoController: RequestHandler = async (req, res) => {
|
||||||
const guild = await getGuildForRequest(req);
|
const guild = await getGuildForRequest(req);
|
||||||
const request = JSON.parse(String(req.body)) as IDestroyDojoDecoRequest;
|
const request = JSON.parse(String(req.body)) as IDestroyDojoDecoRequest;
|
||||||
const component = guild.DojoComponents.id(request.ComponentId)!;
|
|
||||||
const decoIndex = component.Decos!.findIndex(x => x._id.equals(request.DecoId));
|
removeDojoDeco(guild, request.ComponentId, request.DecoId);
|
||||||
component.Decos!.splice(decoIndex, 1);
|
|
||||||
// TODO: The client says this is supposed to refund the resources to the clan vault, so we should probably do that.
|
// TODO: The client says this is supposed to refund the resources to the clan vault, so we should probably do that.
|
||||||
|
|
||||||
await guild.save();
|
await guild.save();
|
||||||
res.json(getDojoClient(guild, 0));
|
res.json(getDojoClient(guild, 0));
|
||||||
};
|
};
|
||||||
|
@ -24,6 +24,11 @@ export const placeDecoInComponentController: RequestHandler = async (req, res) =
|
|||||||
Name: request.Name
|
Name: request.Name
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const meta = Object.values(ExportDojoRecipes.decos).find(x => x.resultType == request.Type);
|
||||||
|
if (meta && meta.capacityCost) {
|
||||||
|
component.DecoCapacity -= meta.capacityCost;
|
||||||
|
}
|
||||||
|
|
||||||
await guild.save();
|
await guild.save();
|
||||||
res.json(getDojoClient(guild, 0));
|
res.json(getDojoClient(guild, 0));
|
||||||
};
|
};
|
||||||
|
@ -94,7 +94,7 @@ export const scaleRequiredCount = (count: number): number => {
|
|||||||
|
|
||||||
export const removeDojoRoom = (guild: TGuildDatabaseDocument, componentId: string): void => {
|
export const removeDojoRoom = (guild: TGuildDatabaseDocument, componentId: string): void => {
|
||||||
const component = guild.DojoComponents.splice(
|
const component = guild.DojoComponents.splice(
|
||||||
guild.DojoComponents.findIndex(x => x._id.toString() === componentId),
|
guild.DojoComponents.findIndex(x => x._id.equals(componentId)),
|
||||||
1
|
1
|
||||||
)[0];
|
)[0];
|
||||||
const meta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
|
const meta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
|
||||||
@ -103,3 +103,15 @@ export const removeDojoRoom = (guild: TGuildDatabaseDocument, componentId: strin
|
|||||||
guild.DojoEnergy -= meta.energy;
|
guild.DojoEnergy -= meta.energy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const removeDojoDeco = (guild: TGuildDatabaseDocument, componentId: string, decoId: string): void => {
|
||||||
|
const component = guild.DojoComponents.id(componentId)!;
|
||||||
|
const deco = component.Decos!.splice(
|
||||||
|
component.Decos!.findIndex(x => x._id.equals(decoId)),
|
||||||
|
1
|
||||||
|
)[0];
|
||||||
|
const meta = Object.values(ExportDojoRecipes.decos).find(x => x.resultType == deco.Type);
|
||||||
|
if (meta && meta.capacityCost) {
|
||||||
|
component.DecoCapacity! += meta.capacityCost;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user