diff --git a/project/src/callbacks/BotCallbacks.ts b/project/src/callbacks/BotCallbacks.ts index 52c4d551..d5aaeff1 100644 --- a/project/src/callbacks/BotCallbacks.ts +++ b/project/src/callbacks/BotCallbacks.ts @@ -1,9 +1,12 @@ +import { ApplicationContext } from "@spt/context/ApplicationContext"; +import { ContextVariableType } from "@spt/context/ContextVariableType"; import { BotController } from "@spt/controllers/BotController"; import { IGenerateBotsRequestData } from "@spt/models/eft/bot/IGenerateBotsRequestData"; import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData"; import { IBotBase } from "@spt/models/eft/common/tables/IBotBase"; import { Difficulties } from "@spt/models/eft/common/tables/IBotType"; import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData"; +import { IGetRaidConfigurationRequestData } from "@spt/models/eft/match/IGetRaidConfigurationRequestData"; import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil"; import { inject, injectable } from "tsyringe"; @@ -12,6 +15,7 @@ export class BotCallbacks { constructor( @inject("BotController") protected botController: BotController, @inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil, + @inject("ApplicationContext") protected applicationContext: ApplicationContext, ) {} /** @@ -36,7 +40,12 @@ export class BotCallbacks { if (difficulty === "core") { return this.httpResponse.noBody(this.botController.getBotCoreDifficulty()); } - return this.httpResponse.noBody(this.botController.getBotDifficulty(type, difficulty)); + + const raidConfig = this.applicationContext + .getLatestValue(ContextVariableType.RAID_CONFIGURATION) + ?.getValue(); + + return this.httpResponse.noBody(this.botController.getBotDifficulty(type, difficulty, raidConfig)); } /** diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index c5a13bdd..fbbdf0fe 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -86,15 +86,18 @@ export class BotController { * Adjust PMC settings to ensure they engage the correct bot types * @param type what bot the server is requesting settings for * @param diffLevel difficulty level server requested settings for + * @param raidConfig OPTIONAL - applicationContext Data stored at start of raid * @param ignoreRaidSettings should raid settings chosen pre-raid be ignored * @returns Difficulty object */ - public getBotDifficulty(type: string, diffLevel: string, ignoreRaidSettings = false): Difficulty { + public getBotDifficulty( + type: string, + diffLevel: string, + raidConfig?: IGetRaidConfigurationRequestData, + ignoreRaidSettings = false, + ): Difficulty { let difficulty = diffLevel.toLowerCase(); - const raidConfig = this.applicationContext - .getLatestValue(ContextVariableType.RAID_CONFIGURATION) - ?.getValue(); if (!(raidConfig || ignoreRaidSettings)) { this.logger.error( this.localisationService.getText("bot-missing_application_context", "RAID_CONFIGURATION"), @@ -109,31 +112,8 @@ export class BotController { this.botDifficultyHelper.convertBotDifficultyDropdownToBotDifficulty(botDifficultyDropDownValue); } - let difficultySettings: Difficulty; - const lowercasedBotType = type.toLowerCase(); - switch (lowercasedBotType) { - case this.pmcConfig.bearType.toLowerCase(): - difficultySettings = this.botDifficultyHelper.getPmcDifficultySettings( - "bear", - difficulty, - this.pmcConfig.usecType, - this.pmcConfig.bearType, - ); - break; - case this.pmcConfig.usecType.toLowerCase(): - difficultySettings = this.botDifficultyHelper.getPmcDifficultySettings( - "usec", - difficulty, - this.pmcConfig.usecType, - this.pmcConfig.bearType, - ); - break; - default: - difficultySettings = this.botDifficultyHelper.getBotDifficultySettings(type, difficulty); - break; - } - - return difficultySettings; + const botDb = this.databaseService.getBots(); + return this.botDifficultyHelper.getBotDifficultySettings(type, difficulty, botDb); } public getAllBotDifficulties(): Record { @@ -156,7 +136,7 @@ export class BotController { const botDifficulties = Object.keys(botDetails.difficulty); result[enumType] = {}; for (const difficulty of botDifficulties) { - result[enumType][difficulty] = this.getBotDifficulty(enumType, difficulty, true); + result[enumType][difficulty] = this.getBotDifficulty(enumType, difficulty, null, true); } } diff --git a/project/src/generators/BotWeaponGenerator.ts b/project/src/generators/BotWeaponGenerator.ts index 28ad28f0..a9afe442 100644 --- a/project/src/generators/BotWeaponGenerator.ts +++ b/project/src/generators/BotWeaponGenerator.ts @@ -207,7 +207,7 @@ export class BotWeaponGenerator { weaponItemTemplate._props.Chambers[0]?._props?.filters[0]?.Filter?.includes(ammoTpl) ) { // Guns have variety of possible Chamber ids, patron_in_weapon/patron_in_weapon_000/patron_in_weapon_001 - const chamberSlotNames = weaponItemTemplate._props.Chambers.map((x) => x._name); + const chamberSlotNames = weaponItemTemplate._props.Chambers.map((chamberSlot) => chamberSlot._name); this.addCartridgeToChamber(weaponWithModsArray, ammoTpl, chamberSlotNames); } diff --git a/project/src/helpers/BotDifficultyHelper.ts b/project/src/helpers/BotDifficultyHelper.ts index 4663658c..0bfa3778 100644 --- a/project/src/helpers/BotDifficultyHelper.ts +++ b/project/src/helpers/BotDifficultyHelper.ts @@ -1,6 +1,7 @@ import { BotHelper } from "@spt/helpers/BotHelper"; import { Difficulty } from "@spt/models/eft/common/tables/IBotType"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; +import { IBots } from "@spt/models/spt/bots/IBots"; import { IPmcConfig } from "@spt/models/spt/config/IPmcConfig"; import { ILogger } from "@spt/models/spt/utils/ILogger"; import { ConfigServer } from "@spt/servers/ConfigServer"; @@ -26,66 +27,14 @@ export class BotDifficultyHelper { this.pmcConfig = this.configServer.getConfig(ConfigTypes.PMC); } - /** - * Get a difficulty object modified to handle fighting other PMCs - * @param pmcType 'bear or 'usec' - * @param difficulty easy / normal / hard / impossible - * @param usecType pmcUSEC - * @param bearType pmcBEAR - * @returns Difficulty object - */ - public getPmcDifficultySettings( - pmcType: "bear" | "usec", - difficulty: string, - usecType: string, - bearType: string, - ): Difficulty { - const difficultySettings = this.getDifficultySettings(pmcType, difficulty); - - const friendlyType = pmcType === "bear" ? bearType : usecType; - - // Add all non-PMC types to PMCs enemy list - this.addBotToEnemyList(difficultySettings, this.pmcConfig.enemyTypes, friendlyType); - - return difficultySettings; - } - - /** - * Add bot types to ENEMY_BOT_TYPES array - * @param difficultySettings Bot settings to alter - * @param typesToAdd Bot types to add to enemy list - * @param typeBeingEdited Bot type to ignore and not add to enemy list - */ - protected addBotToEnemyList(difficultySettings: Difficulty, typesToAdd: string[], typeBeingEdited?: string): void { - const enemyBotTypesKey = "ENEMY_BOT_TYPES"; - - // Null guard - if (!difficultySettings.Mind[enemyBotTypesKey]) { - difficultySettings.Mind[enemyBotTypesKey] = []; - } - - const enemyArray = difficultySettings.Mind[enemyBotTypesKey]; - for (const botTypeToAdd of typesToAdd) { - if (typeBeingEdited?.toLowerCase() === botTypeToAdd.toLowerCase()) { - this.logger.debug(`unable to add enemy ${botTypeToAdd} to its own enemy list, skipping`); - continue; - } - - if (!enemyArray.includes(botTypeToAdd)) { - enemyArray.push(botTypeToAdd); - } - } - } - /** * Get difficulty settings for desired bot type, if not found use assault bot types * @param type bot type to retrieve difficulty of * @param difficulty difficulty to get settings for (easy/normal etc) + * @param botDb bots from database * @returns Difficulty object */ - public getBotDifficultySettings(type: string, difficulty: string): Difficulty { - const botDb = this.databaseService.getBots(); - + public getBotDifficultySettings(type: string, difficulty: string, botDb: IBots): Difficulty { const desiredType = type.toLowerCase(); const bot = botDb.types[desiredType]; if (!bot) {