diff --git a/project/src/callbacks/ItemEventCallbacks.ts b/project/src/callbacks/ItemEventCallbacks.ts index ad396ff9..cd12742a 100644 --- a/project/src/callbacks/ItemEventCallbacks.ts +++ b/project/src/callbacks/ItemEventCallbacks.ts @@ -24,17 +24,38 @@ export class ItemEventCallbacks ): IGetBodyResponseData { const eventResponse = this.itemEventRouter.handleEvents(info, sessionID); - const result = (eventResponse.warnings.length > 0) + const result = (this.isCriticalError(eventResponse.warnings)) ? this.httpResponse.getBody( eventResponse, this.getErrorCode(eventResponse.warnings), eventResponse.warnings[0].errmsg, - ) // TODO: map 228 to its enum value + ) : this.httpResponse.getBody(eventResponse); return result; } + /** + * Return true if the passed in list of warnings contains critical issues + * @param warnings The list of warnings to check for critical errors + * @returns + */ + private isCriticalError(warnings: Warning[]): boolean + { + // List of non-critical error codes, we return true if any error NOT included is passed in + const nonCriticalErrorCodes: BackendErrorCodes[] = [BackendErrorCodes.NOTENOUGHSPACE]; + + for (const warning of warnings) + { + if (!nonCriticalErrorCodes.includes(+warning.code)) + { + return true; + } + } + + return false; + } + protected getErrorCode(warnings: Warning[]): number { if (warnings[0]?.code) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 1c15bbfb..889fdee6 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -35,6 +35,7 @@ import { IRecordShootingRangePoints } from "@spt-aki/models/eft/hideout/IRecordS import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest"; import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; +import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { HideoutAreas } from "@spt-aki/models/enums/HideoutAreas"; import { SkillTypes } from "@spt-aki/models/enums/SkillTypes"; @@ -674,9 +675,11 @@ export class HideoutController } // @Important: Here we need to be very exact: - // - normal recipe: Production time value is stored in attribute "productionType" with small "p" - // - scav case recipe: Production time value is stored in attribute "ProductionType" with capital "P" - const modifiedScavCaseTime = this.getScavCaseTime(pmcData, recipe.ProductionTime); + // - normal recipe: Production time value is stored in attribute "productionTime" with small "p" + // - scav case recipe: Production time value is stored in attribute "ProductionTime" with capital "P" + const adjustedCraftTime = recipe.ProductionTime + - this.hideoutHelper.getCraftingSkillProductionTimeReduction(pmcData, recipe.ProductionTime); + const modifiedScavCaseTime = this.getScavCaseTime(pmcData, adjustedCraftTime); pmcData.Hideout.Production[body.recipeId] = this.hideoutHelper.initProduction( body.recipeId, @@ -949,7 +952,11 @@ export class HideoutController const totalResultItems = toolsToSendToPlayer.concat(itemAndChildrenToSendToPlayer); if (!this.inventoryHelper.canPlaceItemsInInventory(sessionID, totalResultItems)) { - this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + BackendErrorCodes.NOTENOUGHSPACE, + ); return; } diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 45250717..1698789e 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -999,7 +999,7 @@ export class HideoutHelper * @param productionTime Time to complete hideout craft in seconds * @returns Adjusted craft time in seconds */ - protected getCraftingSkillProductionTimeReduction(pmcData: IPmcData, productionTime: number): number + public getCraftingSkillProductionTimeReduction(pmcData: IPmcData, productionTime: number): number { const craftingSkill = pmcData.Skills.Common.find((skill) => skill.Id === SkillTypes.CRAFTING); if (!craftingSkill) diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index 1cdd0fbe..64da9edc 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -20,6 +20,7 @@ import { IInventoryRemoveRequestData } from "@spt-aki/models/eft/inventory/IInve import { IInventorySplitRequestData } from "@spt-aki/models/eft/inventory/IInventorySplitRequestData"; import { IInventoryTransferRequestData } from "@spt-aki/models/eft/inventory/IInventoryTransferRequestData"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; +import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes"; import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { BonusType } from "@spt-aki/models/enums/BonusType"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; @@ -88,7 +89,11 @@ export class InventoryHelper if (!this.canPlaceItemsInInventory(sessionId, request.itemsWithModsToAdd)) { // No space, exit - this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + BackendErrorCodes.NOTENOUGHSPACE, + ); return; } @@ -470,7 +475,11 @@ export class InventoryHelper } else { - this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + BackendErrorCodes.NOTENOUGHSPACE, + ); return; } diff --git a/project/src/models/enums/BackendErrorCodes.ts b/project/src/models/enums/BackendErrorCodes.ts index 81f00650..3a9eff12 100644 --- a/project/src/models/enums/BackendErrorCodes.ts +++ b/project/src/models/enums/BackendErrorCodes.ts @@ -63,6 +63,7 @@ export enum BackendErrorCodes BANNEDERRORCODE = 1513, INSUFFICIENTNUMBERINSTOCK = 1516, TOOMANYITEMSTOSELL = 1517, + INCORRECTCLIENTPRICE = 1519, EXAMINATIONFAILED = 22001, ITEMALREADYEXAMINED = 22002, UNKNOWNNGINXERROR = 9000, @@ -83,4 +84,5 @@ export enum BackendErrorCodes PLAYERALREADYLOOKINGFORGAME = 503001, PLAYERINRAID = 503002, LIMITFORPRESETSREACHED = 504001, + PLAYERPROFILENOTFOUND = 505001, }