From 0c5ecefc410ebdff11a47e1ce7cf2102d51b85cb Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 20 Nov 2024 09:48:42 +0000 Subject: [PATCH] Refactored scavcase reward code to use correct data and interfaces --- project/src/callbacks/DataCallbacks.ts | 9 ----- project/src/controllers/HideoutController.ts | 8 ++-- .../src/generators/ScavCaseRewardGenerator.ts | 16 ++++---- .../models/eft/hideout/IHideoutProduction.ts | 1 - .../models/eft/hideout/IHideoutScavCase.ts | 20 ---------- .../models/spt/callbacks/IDataCallbacks.ts | 40 ------------------- project/src/models/spt/hideout/IHideout.ts | 2 - .../src/routers/static/DataStaticRouter.ts | 12 ------ .../src/services/CircleOfCultistService.ts | 4 +- 9 files changed, 15 insertions(+), 97 deletions(-) delete mode 100644 project/src/models/eft/hideout/IHideoutScavCase.ts delete mode 100644 project/src/models/spt/callbacks/IDataCallbacks.ts diff --git a/project/src/callbacks/DataCallbacks.ts b/project/src/callbacks/DataCallbacks.ts index 5d14303c..2a4e4ab6 100644 --- a/project/src/callbacks/DataCallbacks.ts +++ b/project/src/callbacks/DataCallbacks.ts @@ -8,7 +8,6 @@ import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase"; import { IGetItemPricesResponse } from "@spt/models/eft/game/IGetItemPricesResponse"; import { IHideoutArea } from "@spt/models/eft/hideout/IHideoutArea"; import { IHideoutProductionData } from "@spt/models/eft/hideout/IHideoutProduction"; -import { IHideoutScavCase } from "@spt/models/eft/hideout/IHideoutScavCase"; import { IHideoutSettingsBase } from "@spt/models/eft/hideout/IHideoutSettingsBase"; import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData"; import { ISettingsBase } from "@spt/models/spt/server/ISettingsBase"; @@ -122,14 +121,6 @@ export class DataCallbacks { return this.httpResponse.getBody(this.databaseService.getHideout().production); } - public getHideoutScavcase( - url: string, - info: IEmptyRequestData, - sessionID: string, - ): IGetBodyResponseData { - return this.httpResponse.getBody(this.databaseService.getHideout().scavcase); - } - /** * Handle client/languages */ diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index e1c97a23..45552271 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -692,7 +692,7 @@ export class HideoutController { } } - const recipe = this.databaseService.getHideout().scavcase.find((r) => r._id === body.recipeId); + const recipe = this.databaseService.getHideout().production.scavRecipes.find((r) => r._id === body.recipeId); if (!recipe) { this.logger.error( this.localisationService.getText("hideout-unable_to_find_scav_case_recipie_in_database", body.recipeId), @@ -705,10 +705,10 @@ export class HideoutController { // - 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 - + recipe.productionTime - this.hideoutHelper.getSkillProductionTimeReduction( pmcData, - recipe.ProductionTime, + recipe.productionTime, SkillTypes.CRAFTING, this.databaseService.getGlobals().config.SkillsSettings.Crafting.CraftTimeReductionPerLevel, ); @@ -799,7 +799,7 @@ export class HideoutController { return output; } - const scavCase = hideoutDb.scavcase.find((r) => r._id === request.recipeId); + const scavCase = hideoutDb.production.scavRecipes.find((r) => r._id === request.recipeId); if (scavCase) { this.handleScavCase(sessionID, pmcData, request, output); diff --git a/project/src/generators/ScavCaseRewardGenerator.ts b/project/src/generators/ScavCaseRewardGenerator.ts index 56d2621b..8c1b5753 100644 --- a/project/src/generators/ScavCaseRewardGenerator.ts +++ b/project/src/generators/ScavCaseRewardGenerator.ts @@ -2,7 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper"; import { PresetHelper } from "@spt/helpers/PresetHelper"; import { IItem } from "@spt/models/eft/common/tables/IItem"; import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem"; -import { IHideoutScavCase } from "@spt/models/eft/hideout/IHideoutScavCase"; +import { IScavRecipe } from "@spt/models/eft/hideout/IHideoutProduction"; import { BaseClasses } from "@spt/models/enums/BaseClasses"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; import { Money } from "@spt/models/enums/Money"; @@ -54,7 +54,9 @@ export class ScavCaseRewardGenerator { this.cacheDbItems(); // Get scavcase details from hideout/scavcase.json - const scavCaseDetails = this.databaseService.getHideout().scavcase.find((r) => r._id === recipeId); + const scavCaseDetails = this.databaseService + .getHideout() + .production.scavRecipes.find((r) => r._id === recipeId); const rewardItemCounts = this.getScavCaseRewardCountsAndPrices(scavCaseDetails); // Get items that fit the price criteria as set by the scavCase config @@ -347,18 +349,18 @@ export class ScavCaseRewardGenerator { /** * Gathers the reward min and max count params for each reward quality level from config and scavcase.json into a single object - * @param scavCaseDetails scavcase.json values + * @param scavCaseDetails production.json/scavRecipes object * @returns ScavCaseRewardCountsAndPrices object */ - protected getScavCaseRewardCountsAndPrices(scavCaseDetails: IHideoutScavCase): IScavCaseRewardCountsAndPrices { - const rewardTypes = Object.keys(scavCaseDetails.EndProducts) as Array; // Default is ["Common", "Rare", "Superrare"]; + protected getScavCaseRewardCountsAndPrices(scavCaseDetails: IScavRecipe): IScavCaseRewardCountsAndPrices { + const rewardTypes = Object.keys(scavCaseDetails.endProducts) as Array; // Default is ["Common", "Rare", "Superrare"]; const result: Partial = {}; // Make partial object as we're going to add all the data immediately after // Create reward min/max counts for each type for (const rewardType of rewardTypes) { result[rewardType] = { - minCount: scavCaseDetails.EndProducts[rewardType].min, - maxCount: scavCaseDetails.EndProducts[rewardType].max, + minCount: scavCaseDetails.endProducts[rewardType].min, + maxCount: scavCaseDetails.endProducts[rewardType].max, minPriceRub: this.scavCaseConfig.rewardItemValueRangeRub[rewardType.toLowerCase()].min, maxPriceRub: this.scavCaseConfig.rewardItemValueRangeRub[rewardType.toLowerCase()].max, }; diff --git a/project/src/models/eft/hideout/IHideoutProduction.ts b/project/src/models/eft/hideout/IHideoutProduction.ts index 1e565d41..64c3f6ce 100644 --- a/project/src/models/eft/hideout/IHideoutProduction.ts +++ b/project/src/models/eft/hideout/IHideoutProduction.ts @@ -1,4 +1,3 @@ -import { inherits } from "util"; import { MinMax } from "@spt/models/common/MinMax"; export interface IHideoutProductionData { diff --git a/project/src/models/eft/hideout/IHideoutScavCase.ts b/project/src/models/eft/hideout/IHideoutScavCase.ts deleted file mode 100644 index 6809263f..00000000 --- a/project/src/models/eft/hideout/IHideoutScavCase.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MinMax } from "@spt/models/common/MinMax"; - -export interface IHideoutScavCase { - _id: string; - ProductionTime: number; - Requirements: IRequirement[]; - EndProducts: IEndProducts; -} -export interface IRequirement { - templateId: string; - count: number; - isFunctional: boolean; - type: string; -} - -export interface IEndProducts { - Common: MinMax; - Rare: MinMax; - Superrare: MinMax; -} diff --git a/project/src/models/spt/callbacks/IDataCallbacks.ts b/project/src/models/spt/callbacks/IDataCallbacks.ts deleted file mode 100644 index 0d7bc816..00000000 --- a/project/src/models/spt/callbacks/IDataCallbacks.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData"; -import { IGlobals } from "@spt/models/eft/common/IGlobals"; -import { IHideoutArea } from "@spt/models/eft/hideout/IHideoutArea"; -import { IHideoutProduction } from "@spt/models/eft/hideout/IHideoutProduction"; -import { IHideoutScavCase } from "@spt/models/eft/hideout/IHideoutScavCase"; -import { IHideoutSettingsBase } from "@spt/models/eft/hideout/IHideoutSettingsBase"; -import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData"; -import { ISettingsBase } from "@spt/models/spt/server/ISettingsBase"; - -export interface IDataCallbacks { - getSettings(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - getGlobals(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - getTemplateItems(url: string, info: IEmptyRequestData, sessionID: string): string; - getTemplateHandbook(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - getTemplateSuits(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - getTemplateCharacter(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - getHideoutSettings( - url: string, - info: IEmptyRequestData, - sessionID: string, - ): IGetBodyResponseData; - getHideoutAreas(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - gethideoutProduction( - url: string, - info: IEmptyRequestData, - sessionID: string, - ): IGetBodyResponseData; - getHideoutScavcase( - url: string, - info: IEmptyRequestData, - sessionID: string, - ): IGetBodyResponseData; - getLocalesLanguages( - url: string, - info: IEmptyRequestData, - sessionID: string, - ): IGetBodyResponseData>; - getLocalesMenu(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData; - getLocalesGlobal(url: string, info: IEmptyRequestData, sessionID: string): string; -} diff --git a/project/src/models/spt/hideout/IHideout.ts b/project/src/models/spt/hideout/IHideout.ts index d37eecda..db1b45e9 100644 --- a/project/src/models/spt/hideout/IHideout.ts +++ b/project/src/models/spt/hideout/IHideout.ts @@ -1,13 +1,11 @@ import { IHideoutArea } from "@spt/models/eft/hideout/IHideoutArea"; import { IHideoutProductionData } from "@spt/models/eft/hideout/IHideoutProduction"; -import { IHideoutScavCase } from "@spt/models/eft/hideout/IHideoutScavCase"; import { IHideoutSettingsBase } from "@spt/models/eft/hideout/IHideoutSettingsBase"; import { IQteData } from "@spt/models/eft/hideout/IQteData"; export interface IHideout { areas: IHideoutArea[]; production: IHideoutProductionData; - scavcase: IHideoutScavCase[]; settings: IHideoutSettingsBase; qte: IQteData[]; } diff --git a/project/src/routers/static/DataStaticRouter.ts b/project/src/routers/static/DataStaticRouter.ts index 4abecd7e..7c49042a 100644 --- a/project/src/routers/static/DataStaticRouter.ts +++ b/project/src/routers/static/DataStaticRouter.ts @@ -5,7 +5,6 @@ import { ICustomizationItem } from "@spt/models/eft/common/tables/ICustomization import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase"; import { IHideoutArea } from "@spt/models/eft/hideout/IHideoutArea"; import { IHideoutProductionData } from "@spt/models/eft/hideout/IHideoutProduction"; -import { IHideoutScavCase } from "@spt/models/eft/hideout/IHideoutScavCase"; import { IHideoutSettingsBase } from "@spt/models/eft/hideout/IHideoutSettingsBase"; import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData"; import { ISettingsBase } from "@spt/models/spt/server/ISettingsBase"; @@ -109,17 +108,6 @@ export class DataStaticRouter extends StaticRouter { return this.dataCallbacks.getHideoutAreas(url, info, sessionID); }, ), - new RouteAction( - "/client/hideout/production/scavcase/recipes", - async ( - url: string, - info: any, - sessionID: string, - output: string, - ): Promise> => { - return this.dataCallbacks.getHideoutScavcase(url, info, sessionID); - }, - ), new RouteAction( "/client/languages", async ( diff --git a/project/src/services/CircleOfCultistService.ts b/project/src/services/CircleOfCultistService.ts index 62989983..2eea8082 100644 --- a/project/src/services/CircleOfCultistService.ts +++ b/project/src/services/CircleOfCultistService.ts @@ -509,10 +509,10 @@ export class CircleOfCultistService { const hasScavCaseAreaUnlocked = pmcData.Hideout.Areas[HideoutAreas.SCAV_CASE]?.level > 0; if (hasScavCaseAreaUnlocked) { // Gather up items used to start scav case crafts - const scavCaseCrafts = hideoutDbData.scavcase; + const scavCaseCrafts = hideoutDbData.production.scavRecipes; for (const craft of scavCaseCrafts) { // Find the item requirements from each craft - const itemRequirements = this.getItemRequirements(craft.Requirements); + const itemRequirements = this.getItemRequirements(craft.requirements); for (const requirement of itemRequirements) { if (itemRewardBlacklist.includes(requirement.templateId)) { continue;