From 2132ea7adbbbb9e3a2adfe1a0f2e91b8ed3221a3 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 20 Nov 2023 10:14:21 +0000 Subject: [PATCH] Fix issue with hideout crafts being collectable twice --- project/src/controllers/HideoutController.ts | 23 +++++++++++-------- .../src/models/eft/common/tables/IBotBase.ts | 2 ++ project/src/routers/EventOutputHolder.ts | 21 ++++++++++------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index c01df79d..28c5908b 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -721,19 +721,20 @@ export class HideoutController ): IItemEventRouterResponse { const output = this.eventOutputHolder.getOutput(sessionID); + const hideoutDb = this.databaseServer.getTables().hideout; if (request.recipeId === HideoutHelper.bitcoinFarm) { return this.hideoutHelper.getBTC(pmcData, request, sessionID); } - const recipe = this.databaseServer.getTables().hideout.production.find((r) => r._id === request.recipeId); + const recipe = hideoutDb.production.find((r) => r._id === request.recipeId); if (recipe) { return this.handleRecipe(sessionID, recipe, pmcData, request, output); } - const scavCase = this.databaseServer.getTables().hideout.scavcase.find((r) => r._id === request.recipeId); + const scavCase = hideoutDb.scavcase.find((r) => r._id === request.recipeId); if (scavCase) { return this.handleScavCase(sessionID, pmcData, request, output); @@ -831,7 +832,7 @@ export class HideoutController return this.httpResponse.appendErrorToOutput(output); } - // check if the recipe is the same as the last one + // Check if the recipe is the same as the last one const area = pmcData.Hideout.Areas.find((x) => x.type === recipe.areaType); if (area && request.recipeId !== area.lastRecipe) { @@ -848,13 +849,13 @@ export class HideoutController hoursCrafting -= this.hideoutConfig.hoursForSkillCrafting * multiplierCrafting; } - // increment + // Increment // if addItem passes validation: // - increment skill point for crafting // - delete the production in profile Hideout.Production const callback = () => { - // manager Hideout skill + // Manager Hideout skill // ? use a configuration variable for the value? const globals = this.databaseServer.getTables().globals; this.profileHelper.addSkillPointsToPlayer( @@ -876,12 +877,16 @@ export class HideoutController area.lastRecipe = request.recipeId; counterHoursCrafting.value = hoursCrafting; - // Null production data now it's complete - will be cleaned up later by update() process + // Continuous crafts have special handling in EventOutputHolder.updateOutputProperties() pmcData.Hideout.Production[prodId].sptIsComplete = true; - }; + pmcData.Hideout.Production[prodId].sptIsContinuous = recipe.continuous; - // Remove the old production from output object before its sent to client - delete output.profileChanges[sessionID].production[request.recipeId]; + // Flag normal crafts as complete + if (!recipe.continuous) + { + pmcData.Hideout.Production[prodId].inProgress = false; + } + }; // Handle the isEncoded flag from recipe if (recipe.isEncoded) diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index 4b283a28..fba422cb 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -390,6 +390,8 @@ export interface Productive sptIsScavCase?: boolean; /** Some crafts are always inProgress, but need to be reset, e.g. water collector */ sptIsComplete?: boolean; + /** Is the craft a Continuous, e.g bitcoins/water collector */ + sptIsContinuous?: boolean; } export interface Production extends Productive diff --git a/project/src/routers/EventOutputHolder.ts b/project/src/routers/EventOutputHolder.ts index 17676f21..27a9beed 100644 --- a/project/src/routers/EventOutputHolder.ts +++ b/project/src/routers/EventOutputHolder.ts @@ -84,8 +84,8 @@ export class EventOutputHolder profileChanges.improvements = this.jsonUtil.clone(this.getImprovementsFromProfileAndFlagComplete(pmcData)); profileChanges.traderRelations = this.constructTraderRelations(pmcData.TradersInfo); - // Fixes container craft from water collector not resetting after collection - this.resetSptIsCompleteFlaggedCrafts(pmcData.Hideout.Production); + // Fixes container craft from water collector not resetting after collection + removed completed normal crafts + this.cleanUpCompleteCraftsInProfile(pmcData.Hideout.Production); } /** @@ -156,9 +156,8 @@ export class EventOutputHolder continue; } - // Complete and is a water collector craft - // Needed as canister craft (water collector) is continuous - if (production.sptIsComplete && productionKey === "5d5589c1f934db045e6c5492") + // Complete and is Continuous e.g. water collector + if (production.sptIsComplete && production.sptIsContinuous) { continue; } @@ -184,7 +183,7 @@ export class EventOutputHolder } } - // Return null of there's no crafts to send to client to match live behaviour + // Return null if there's no crafts to send to client to match live behaviour return (Object.keys(productions).length > 0) ? productions : null } @@ -192,17 +191,23 @@ export class EventOutputHolder * Required as continuous productions don't reset and stay at 100% completion but client thinks it hasn't started * @param productions Productions in a profile */ - protected resetSptIsCompleteFlaggedCrafts(productions: Record): void + protected cleanUpCompleteCraftsInProfile(productions: Record): void { for (const productionKey in productions) { const production = productions[productionKey]; - if (production.sptIsComplete) + if (production.sptIsComplete && production.sptIsContinuous) { + // Water collector / Bitcoin etc production.sptIsComplete = false; production.Progress = 0; production.StartTimestamp = this.timeUtil.getTimestamp(); } + else if (!production.inProgress) + { + // Normal completed craft, delete + delete productions[productionKey]; + } } } }