ignore contributions to a finished component

This commit is contained in:
Sainan 2025-03-04 12:21:36 +01:00
parent 0869bbfb27
commit fdf8d1a788

View File

@ -13,6 +13,9 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
// Any clan member should have permission to contribute although notably permission is denied if they have not crafted the dojo key and were simply invited in.
const request = JSON.parse(String(req.body)) as IContributeToDojoComponentRequest;
const component = guild.DojoComponents.id(request.ComponentId)!;
const inventoryChanges: IInventoryChanges = {};
if (!component.CompletionTime) {
const componentMeta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf)!;
component.RegularCredits ??= 0;
@ -20,14 +23,17 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
request.RegularCredits = scaleRequiredCount(componentMeta.price) - component.RegularCredits;
}
component.RegularCredits += request.RegularCredits;
const inventoryChanges: IInventoryChanges = updateCurrency(inventory, request.RegularCredits, false);
inventoryChanges.RegularCredits = -request.RegularCredits;
updateCurrency(inventory, request.RegularCredits, false);
component.MiscItems ??= [];
const miscItemChanges: IMiscItem[] = [];
for (const ingredientContribution of request.IngredientContributions) {
const componentMiscItem = component.MiscItems.find(x => x.ItemType == ingredientContribution.ItemType);
if (componentMiscItem) {
const ingredientMeta = componentMeta.ingredients.find(x => x.ItemType == ingredientContribution.ItemType)!;
const ingredientMeta = componentMeta.ingredients.find(
x => x.ItemType == ingredientContribution.ItemType
)!;
if (
componentMiscItem.ItemCount + ingredientContribution.ItemCount >
scaleRequiredCount(ingredientMeta.ItemCount)
@ -62,6 +68,7 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
component.CompletionTime = new Date(Date.now() + componentMeta.time * 1000);
}
}
}
await guild.save();
await inventory.save();