From 297e35a1ffe78da86146ab7f07bea9009cc48be1 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 30 Apr 2024 21:52:26 +0100 Subject: [PATCH] Added system to set min level for PMCs spawned on sandbox_high to 20 --- project/src/controllers/BotController.ts | 30 +++++++++++++++++ project/src/generators/BotGenerator.ts | 1 + project/src/generators/BotLevelGenerator.ts | 32 +++++++++++-------- .../models/spt/bots/BotGenerationDetails.ts | 2 ++ 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index 9309ae01..05803ee2 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -17,6 +17,7 @@ import { WildSpawnTypeNumber } from "@spt-aki/models/enums/WildSpawnTypeNumber"; import { BotGenerationDetails } from "@spt-aki/models/spt/bots/BotGenerationDetails"; import { IBotConfig } from "@spt-aki/models/spt/config/IBotConfig"; import { IPmcConfig } from "@spt-aki/models/spt/config/IPmcConfig"; +import { IRaidChanges } from "@spt-aki/models/spt/location/IRaidChanges"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ConfigServer } from "@spt-aki/servers/ConfigServer"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; @@ -208,6 +209,12 @@ export class BotController // Clear bot cache before any work starts this.botGenerationCacheService.clearStoredBots(); + const minimumPmcLevel = this.getMinimumPmcLevelForRaid( + this.applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)?.getValue< + IGetRaidConfigurationRequestData + >(), + ); + const allPmcsHaveSameNameAsPlayer = this.randomUtil.getChance100( this.pmcConfig.allPMCsHavePlayerNameWithRandomPrefixChance, ); @@ -224,6 +231,7 @@ export class BotController botRelativeLevelDeltaMin: this.pmcConfig.botRelativeLevelDeltaMin, botCountToGenerate: this.botConfig.presetBatch[condition.Role], botDifficulty: condition.Difficulty, + minimumPmcLevel: minimumPmcLevel, isPlayerScav: false, allPmcsHaveSameNameAsPlayer: allPmcsHaveSameNameAsPlayer, }; @@ -236,6 +244,21 @@ export class BotController return []; } + /** + * Get the lowest level a bot can be generated with + * @param raidConfig IGetRaidConfigurationRequestData from applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION) + * @returns Number + */ + protected getMinimumPmcLevelForRaid(raidConfig: IGetRaidConfigurationRequestData): number + { + if (raidConfig?.location.toLowerCase() === "sandbox_high") + { + return 20; + } + + return 1; + } + /** * Generate many bots and store then on the cache * @param condition the condition details to generate the bots with @@ -315,6 +338,12 @@ export class BotController const pmcProfile = this.profileHelper.getPmcProfile(sessionId); const requestedBot = request.conditions[0]; + const minimumPmcLevel = this.getMinimumPmcLevelForRaid( + this.applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)?.getValue< + IGetRaidConfigurationRequestData + >(), + ); + // Create gen request for when cache is empty const botGenerationDetails: BotGenerationDetails = { isPmc: false, @@ -326,6 +355,7 @@ export class BotController botRelativeLevelDeltaMin: this.pmcConfig.botRelativeLevelDeltaMin, botCountToGenerate: this.botConfig.presetBatch[requestedBot.Role], botDifficulty: requestedBot.Difficulty, + minimumPmcLevel: minimumPmcLevel, isPlayerScav: false, }; diff --git a/project/src/generators/BotGenerator.ts b/project/src/generators/BotGenerator.ts index dc572a86..d9daacbe 100644 --- a/project/src/generators/BotGenerator.ts +++ b/project/src/generators/BotGenerator.ts @@ -86,6 +86,7 @@ export class BotGenerator botRelativeLevelDeltaMin: 0, botCountToGenerate: 1, botDifficulty: difficulty, + minimumPmcLevel: 1, // unused here isPlayerScav: true, }; diff --git a/project/src/generators/BotLevelGenerator.ts b/project/src/generators/BotLevelGenerator.ts index 4342bf41..164beab0 100644 --- a/project/src/generators/BotLevelGenerator.ts +++ b/project/src/generators/BotLevelGenerator.ts @@ -21,9 +21,9 @@ export class BotLevelGenerator /** * Return a randomised bot level and exp value - * @param levelDetails min and max of level for bot + * @param levelDetails Min and max of level for bot * @param botGenerationDetails Deatils to help generate a bot - * @param bot being level is being generated for + * @param bot Bot the level is being generated for * @returns IRandomisedBotLevelResult object */ public generateBotLevel( @@ -39,12 +39,7 @@ export class BotLevelGenerator levelDetails, expTable, ); - const lowestLevel = this.getLowestRelativeBotLevel( - botGenerationDetails.playerLevel, - botGenerationDetails.botRelativeLevelDeltaMin, - levelDetails, - expTable, - ); + const lowestLevel = this.getLowestRelativeBotLevel(botGenerationDetails, levelDetails, expTable); // Get random level based on the exp table. let exp = 0; @@ -93,19 +88,30 @@ export class BotLevelGenerator * Get the lowest level a bot can be relative to the players level, but no lower than 1 * @param playerLevel Players current level * @param relativeDeltaMin Min delta below player level to go + * @param expTable exp table to calculate level * @returns lowest level possible for bot */ protected getLowestRelativeBotLevel( - playerLevel: number, - relativeDeltaMin: number, + botGenerationDetails: BotGenerationDetails, levelDetails: MinMax, expTable: IExpTable[], ): number { - // Some bots have a max level of 1 - const minPossibleLevel = Math.min(levelDetails.min, expTable.length); + let minPossibleLevel: number; + if (botGenerationDetails.isPmc) + { + minPossibleLevel = Math.min( + Math.max(levelDetails.min, botGenerationDetails.minimumPmcLevel), + expTable.length, + ); + } + else + { + // Some bots have a max level of 1 + minPossibleLevel = Math.min(levelDetails.min, expTable.length); + } - let level = playerLevel - relativeDeltaMin; + let level = botGenerationDetails.playerLevel - botGenerationDetails.botRelativeLevelDeltaMin; if (level < minPossibleLevel) { level = minPossibleLevel; diff --git a/project/src/models/spt/bots/BotGenerationDetails.ts b/project/src/models/spt/bots/BotGenerationDetails.ts index 7af2b2fe..165a6c88 100644 --- a/project/src/models/spt/bots/BotGenerationDetails.ts +++ b/project/src/models/spt/bots/BotGenerationDetails.ts @@ -9,6 +9,8 @@ export interface BotGenerationDetails /** Active players current level */ playerLevel?: number; playerName?: string; + /** Lowest level a PMC can be generated with */ + minimumPmcLevel: number; /** Delta of highest level of bot e.g. 50 means 50 levels above player */ botRelativeLevelDeltaMax: number; /** Delta of lowest level of bot e.g. 50 means 50 levels below player */