From 0316278b155f0462ffb294cbbebb94400a8380db Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 28 Oct 2023 15:53:13 +0100 Subject: [PATCH] First pass at handling the cancellation of a hideout craft. Doesnt explode server with unhandled exception error Does remove craft from profile Doesnt remove it from client screen until client refresh --- project/src/callbacks/HideoutCallbacks.ts | 9 +++++ project/src/controllers/HideoutController.ts | 36 ++++++++++++++++--- .../src/models/eft/common/tables/IBotBase.ts | 2 +- .../IHideoutCancelProductionRequestData.ts | 6 ++++ .../src/models/enums/HideoutEventActions.ts | 3 +- .../item_events/HideoutItemEventRouter.ts | 5 ++- 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 project/src/models/eft/hideout/IHideoutCancelProductionRequestData.ts diff --git a/project/src/callbacks/HideoutCallbacks.ts b/project/src/callbacks/HideoutCallbacks.ts index bf9023a8..58581c8a 100644 --- a/project/src/callbacks/HideoutCallbacks.ts +++ b/project/src/callbacks/HideoutCallbacks.ts @@ -4,6 +4,7 @@ import { HideoutController } from "@spt-aki/controllers/HideoutController"; import { OnUpdate } from "@spt-aki/di/OnUpdate"; import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData"; +import { IHideoutCancelProductionRequestData } from "@spt-aki/models/eft/hideout/IHideoutCancelProductionRequestData"; import { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutContinuousProductionStartRequestData"; import { IHideoutImproveAreaRequestData } from "@spt-aki/models/eft/hideout/IHideoutImproveAreaRequestData"; import { IHideoutPutItemInRequestData } from "@spt-aki/models/eft/hideout/IHideoutPutItemInRequestData"; @@ -129,6 +130,14 @@ export class HideoutCallbacks implements OnUpdate return this.hideoutController.improveArea(sessionId, pmcData, request); } + /** + * Handle client/game/profile/items/moving - HideoutCancelProductionCommand + */ + public cancelProduction(pmcData: IPmcData, request: IHideoutCancelProductionRequestData, sessionId: string): IItemEventRouterResponse + { + return this.hideoutController.cancelProduction(sessionId, pmcData, request); + } + public async onUpdate(timeSinceLastRun: number): Promise { if (timeSinceLastRun > this.hideoutConfig.runIntervalSeconds) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 1e6474ba..2f617c55 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -12,6 +12,7 @@ import { Upd } from "@spt-aki/models/eft/common/tables/IItem"; import { HideoutUpgradeCompleteRequestData } from "@spt-aki/models/eft/hideout/HideoutUpgradeCompleteRequestData"; import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData"; import { IHideoutArea, Stage } from "@spt-aki/models/eft/hideout/IHideoutArea"; +import { IHideoutCancelProductionRequestData } from "@spt-aki/models/eft/hideout/IHideoutCancelProductionRequestData"; import { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutContinuousProductionStartRequestData"; import { IHideoutImproveAreaRequestData } from "@spt-aki/models/eft/hideout/IHideoutImproveAreaRequestData"; import { IHideoutProduction } from "@spt-aki/models/eft/hideout/IHideoutProduction"; @@ -125,7 +126,6 @@ export class HideoutController } const hideoutData = this.databaseServer.getTables().hideout.areas.find(area => area.type === request.areaType); - if (!hideoutData) { this.logger.error(this.localisationService.getText("hideout-unable_to_find_area_in_database", request.areaType)); @@ -133,7 +133,6 @@ export class HideoutController } const ctime = hideoutData.stages[hideoutArea.level + 1].constructionTime; - if (ctime > 0) { const timestamp = this.timeUtil.getTimestamp(); @@ -832,7 +831,6 @@ export class HideoutController return this.hideoutHelper.registerProduction(pmcData, request, sessionID); } - /** * Get quick time event list for hideout * // TODO - implement this @@ -909,8 +907,8 @@ export class HideoutController /** * Handle client/game/profile/items/moving - HideoutImproveArea * @param sessionId Session id - * @param pmcData profile to improve area in - * @param request improve area request data + * @param pmcData Profile to improve area in + * @param request Improve area request data */ public improveArea(sessionId: string, pmcData: IPmcData, request: IHideoutImproveAreaRequestData): IItemEventRouterResponse { @@ -980,6 +978,34 @@ export class HideoutController return output; } + /** + * Handle client/game/profile/items/moving HideoutCancelProductionCommand + * @param sessionId Session id + * @param pmcData Profile with craft to cancel + * @param request Cancel production request data + * @returns + */ + public cancelProduction(sessionId: string, pmcData: IPmcData, request: IHideoutCancelProductionRequestData): IItemEventRouterResponse + { + const output = this.eventOutputHolder.getOutput(sessionId); + + const craftToCancel = pmcData.Hideout.Production[request.recipeId]; + if (!craftToCancel) + { + const errorMessage = `Unable to find craft ${request.recipeId} to cancel`; + this.logger.error(errorMessage); + + return this.httpResponse.appendErrorToOutput(output, errorMessage); + } + + // Remove production from profile + delete pmcData.Hideout.Production[request.recipeId]; + + // TODO - handle timestamp somehow? + + return output; + } + /** * Function called every x seconds as part of onUpdate event */ diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index 8709384a..f279df12 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -383,7 +383,7 @@ export interface Productive ProductionTime?: number GivenItemsInStart?: string[] Interrupted?: boolean - /** Used in hideout prodiction.json */ + /** Used in hideout production.json */ needFuelForAllProductionTime?: boolean /** Used when sending data to client */ NeedFuelForAllProductionTime?: boolean diff --git a/project/src/models/eft/hideout/IHideoutCancelProductionRequestData.ts b/project/src/models/eft/hideout/IHideoutCancelProductionRequestData.ts new file mode 100644 index 00000000..e076acd7 --- /dev/null +++ b/project/src/models/eft/hideout/IHideoutCancelProductionRequestData.ts @@ -0,0 +1,6 @@ +export interface IHideoutCancelProductionRequestData +{ + Action: "HideoutCancelProductionCommand" + recipeId: string + timestamp: number +} diff --git a/project/src/models/enums/HideoutEventActions.ts b/project/src/models/enums/HideoutEventActions.ts index f87efcf8..fc0424e8 100644 --- a/project/src/models/enums/HideoutEventActions.ts +++ b/project/src/models/enums/HideoutEventActions.ts @@ -10,5 +10,6 @@ export enum HideoutEventActions HIDEOUT_CONTINUOUS_PRODUCTION_START = "HideoutContinuousProductionStart", HIDEOUT_TAKE_PRODUCTION = "HideoutTakeProduction", HIDEOUT_RECORD_SHOOTING_RANGE_POINTS = "RecordShootingRangePoints", - HIDEOUT_IMPROVE_AREA = "HideoutImproveArea" + HIDEOUT_IMPROVE_AREA = "HideoutImproveArea", + HIDEOUT_CANCEL_PRODUCTION_COMMAND = "HideoutCancelProductionCommand" } \ No newline at end of file diff --git a/project/src/routers/item_events/HideoutItemEventRouter.ts b/project/src/routers/item_events/HideoutItemEventRouter.ts index aea41178..0dd12165 100644 --- a/project/src/routers/item_events/HideoutItemEventRouter.ts +++ b/project/src/routers/item_events/HideoutItemEventRouter.ts @@ -29,7 +29,8 @@ export class HideoutItemEventRouter extends ItemEventRouterDefinition new HandledRoute(HideoutEventActions.HIDEOUT_CONTINUOUS_PRODUCTION_START, false), new HandledRoute(HideoutEventActions.HIDEOUT_TAKE_PRODUCTION, false), new HandledRoute(HideoutEventActions.HIDEOUT_RECORD_SHOOTING_RANGE_POINTS, false), - new HandledRoute(HideoutEventActions.HIDEOUT_IMPROVE_AREA, false) + new HandledRoute(HideoutEventActions.HIDEOUT_IMPROVE_AREA, false), + new HandledRoute(HideoutEventActions.HIDEOUT_CANCEL_PRODUCTION_COMMAND, false) ]; } @@ -59,6 +60,8 @@ export class HideoutItemEventRouter extends ItemEventRouterDefinition return this.hideoutCallbacks.recordShootingRangePoints(pmcData, body, sessionID); case HideoutEventActions.HIDEOUT_IMPROVE_AREA: return this.hideoutCallbacks.improveArea(pmcData, body, sessionID); + case HideoutEventActions.HIDEOUT_CANCEL_PRODUCTION_COMMAND: + return this.hideoutCallbacks.cancelProduction(pmcData, body, sessionID); } } } \ No newline at end of file