From 8ddad763be991f106a30b69f555ba07d5077d722 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 30 Nov 2023 13:44:43 +0000 Subject: [PATCH] Cleanup of `handleScavCase()` --- project/src/controllers/HideoutController.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 9be4c369..cfb5af65 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -943,35 +943,38 @@ export class HideoutController // Create rewards for scav case const scavCaseRewards = this.scavCaseRewardGenerator.generate(request.recipeId); + // Add scav case rewards to player profile pmcData.Hideout.Production[prodId].Products = scavCaseRewards; // Remove the old production from output object before its sent to client delete output.profileChanges[sessionID].production[request.recipeId]; + // Get array of item created + count of them after completing hideout craft const itemsToAdd = pmcData.Hideout.Production[prodId].Products.map( (x: { _tpl: string; upd?: { StackObjectsCount?: number; }; }) => { - let id = x._tpl; - if (this.presetHelper.hasPreset(id)) - { - id = this.presetHelper.getDefaultPreset(id)._id; - } + const itemTpl = this.presetHelper.hasPreset(x._tpl) + ? this.presetHelper.getDefaultPreset(x._tpl)._id + : x._tpl; + + // Count of items crafted const numOfItems = !x.upd?.StackObjectsCount ? 1 : x.upd.StackObjectsCount; // eslint-disable-next-line @typescript-eslint/naming-convention - return { item_id: id, count: numOfItems }; + return { item_id: itemTpl, count: numOfItems }; }, ); const newReq = { items: itemsToAdd, tid: "ragfair" }; - const callback = () => { - // Flag as complete - will be cleaned up later by update() process + // Flag as complete - will be cleaned up later by hideoutController.update() pmcData.Hideout.Production[prodId].sptIsComplete = true; + // Crafting complete, flag as such pmcData.Hideout.Production[prodId].inProgress = false; }; + // Add crafted item to player inventory return this.inventoryHelper.addItem(pmcData, newReq, output, sessionID, callback, true); }