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
This commit is contained in:
Dev 2023-10-28 15:53:13 +01:00
parent f4fce0612e
commit 0316278b15
6 changed files with 53 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import { HideoutController } from "@spt-aki/controllers/HideoutController";
import { OnUpdate } from "@spt-aki/di/OnUpdate"; import { OnUpdate } from "@spt-aki/di/OnUpdate";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData"; 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 { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutContinuousProductionStartRequestData";
import { IHideoutImproveAreaRequestData } from "@spt-aki/models/eft/hideout/IHideoutImproveAreaRequestData"; import { IHideoutImproveAreaRequestData } from "@spt-aki/models/eft/hideout/IHideoutImproveAreaRequestData";
import { IHideoutPutItemInRequestData } from "@spt-aki/models/eft/hideout/IHideoutPutItemInRequestData"; 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); 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<boolean> public async onUpdate(timeSinceLastRun: number): Promise<boolean>
{ {
if (timeSinceLastRun > this.hideoutConfig.runIntervalSeconds) if (timeSinceLastRun > this.hideoutConfig.runIntervalSeconds)

View File

@ -12,6 +12,7 @@ import { Upd } from "@spt-aki/models/eft/common/tables/IItem";
import { HideoutUpgradeCompleteRequestData } from "@spt-aki/models/eft/hideout/HideoutUpgradeCompleteRequestData"; import { HideoutUpgradeCompleteRequestData } from "@spt-aki/models/eft/hideout/HideoutUpgradeCompleteRequestData";
import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData"; import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData";
import { IHideoutArea, Stage } from "@spt-aki/models/eft/hideout/IHideoutArea"; 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 { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutContinuousProductionStartRequestData";
import { IHideoutImproveAreaRequestData } from "@spt-aki/models/eft/hideout/IHideoutImproveAreaRequestData"; import { IHideoutImproveAreaRequestData } from "@spt-aki/models/eft/hideout/IHideoutImproveAreaRequestData";
import { IHideoutProduction } from "@spt-aki/models/eft/hideout/IHideoutProduction"; 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); const hideoutData = this.databaseServer.getTables().hideout.areas.find(area => area.type === request.areaType);
if (!hideoutData) if (!hideoutData)
{ {
this.logger.error(this.localisationService.getText("hideout-unable_to_find_area_in_database", request.areaType)); 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; const ctime = hideoutData.stages[hideoutArea.level + 1].constructionTime;
if (ctime > 0) if (ctime > 0)
{ {
const timestamp = this.timeUtil.getTimestamp(); const timestamp = this.timeUtil.getTimestamp();
@ -832,7 +831,6 @@ export class HideoutController
return this.hideoutHelper.registerProduction(pmcData, request, sessionID); return this.hideoutHelper.registerProduction(pmcData, request, sessionID);
} }
/** /**
* Get quick time event list for hideout * Get quick time event list for hideout
* // TODO - implement this * // TODO - implement this
@ -909,8 +907,8 @@ export class HideoutController
/** /**
* Handle client/game/profile/items/moving - HideoutImproveArea * Handle client/game/profile/items/moving - HideoutImproveArea
* @param sessionId Session id * @param sessionId Session id
* @param pmcData profile to improve area in * @param pmcData Profile to improve area in
* @param request improve area request data * @param request Improve area request data
*/ */
public improveArea(sessionId: string, pmcData: IPmcData, request: IHideoutImproveAreaRequestData): IItemEventRouterResponse public improveArea(sessionId: string, pmcData: IPmcData, request: IHideoutImproveAreaRequestData): IItemEventRouterResponse
{ {
@ -980,6 +978,34 @@ export class HideoutController
return output; 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 * Function called every x seconds as part of onUpdate event
*/ */

View File

@ -383,7 +383,7 @@ export interface Productive
ProductionTime?: number ProductionTime?: number
GivenItemsInStart?: string[] GivenItemsInStart?: string[]
Interrupted?: boolean Interrupted?: boolean
/** Used in hideout prodiction.json */ /** Used in hideout production.json */
needFuelForAllProductionTime?: boolean needFuelForAllProductionTime?: boolean
/** Used when sending data to client */ /** Used when sending data to client */
NeedFuelForAllProductionTime?: boolean NeedFuelForAllProductionTime?: boolean

View File

@ -0,0 +1,6 @@
export interface IHideoutCancelProductionRequestData
{
Action: "HideoutCancelProductionCommand"
recipeId: string
timestamp: number
}

View File

@ -10,5 +10,6 @@ export enum HideoutEventActions
HIDEOUT_CONTINUOUS_PRODUCTION_START = "HideoutContinuousProductionStart", HIDEOUT_CONTINUOUS_PRODUCTION_START = "HideoutContinuousProductionStart",
HIDEOUT_TAKE_PRODUCTION = "HideoutTakeProduction", HIDEOUT_TAKE_PRODUCTION = "HideoutTakeProduction",
HIDEOUT_RECORD_SHOOTING_RANGE_POINTS = "RecordShootingRangePoints", HIDEOUT_RECORD_SHOOTING_RANGE_POINTS = "RecordShootingRangePoints",
HIDEOUT_IMPROVE_AREA = "HideoutImproveArea" HIDEOUT_IMPROVE_AREA = "HideoutImproveArea",
HIDEOUT_CANCEL_PRODUCTION_COMMAND = "HideoutCancelProductionCommand"
} }

View File

@ -29,7 +29,8 @@ export class HideoutItemEventRouter extends ItemEventRouterDefinition
new HandledRoute(HideoutEventActions.HIDEOUT_CONTINUOUS_PRODUCTION_START, false), new HandledRoute(HideoutEventActions.HIDEOUT_CONTINUOUS_PRODUCTION_START, false),
new HandledRoute(HideoutEventActions.HIDEOUT_TAKE_PRODUCTION, false), new HandledRoute(HideoutEventActions.HIDEOUT_TAKE_PRODUCTION, false),
new HandledRoute(HideoutEventActions.HIDEOUT_RECORD_SHOOTING_RANGE_POINTS, 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); return this.hideoutCallbacks.recordShootingRangePoints(pmcData, body, sessionID);
case HideoutEventActions.HIDEOUT_IMPROVE_AREA: case HideoutEventActions.HIDEOUT_IMPROVE_AREA:
return this.hideoutCallbacks.improveArea(pmcData, body, sessionID); return this.hideoutCallbacks.improveArea(pmcData, body, sessionID);
case HideoutEventActions.HIDEOUT_CANCEL_PRODUCTION_COMMAND:
return this.hideoutCallbacks.cancelProduction(pmcData, body, sessionID);
} }
} }
} }