From 52a5380c3361de60598ae4477862b4a150c46800 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 6 Jan 2024 15:19:04 +0000 Subject: [PATCH] Add `botRelativeLevelDeltaMin` to pmc.json to allow configuration of lowest level of pmc relative to player --- project/assets/configs/pmc.json | 1 + project/src/controllers/BotController.ts | 1 + project/src/generators/BotGenerator.ts | 1 + project/src/generators/BotLevelGenerator.ts | 33 ++++++++++++++++++- .../models/spt/bots/BotGenerationDetails.ts | 4 ++- project/src/models/spt/config/IPmcConfig.ts | 2 ++ 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/project/assets/configs/pmc.json b/project/assets/configs/pmc.json index f7cf9bc5..8aff3b57 100644 --- a/project/assets/configs/pmc.json +++ b/project/assets/configs/pmc.json @@ -173,6 +173,7 @@ "useDifficultyOverride": false, "difficulty": "AsOnline", "botRelativeLevelDeltaMax": 10, + "botRelativeLevelDeltaMin": 70, "_isUsec": "Percentage chance PMC will be USEC", "isUsec": 50, "chanceSameSideIsHostilePercent": 80, diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index 03f810af..f1c5332a 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -153,6 +153,7 @@ export class BotController role: condition.Role, playerLevel: pmcProfile.Info.Level, botRelativeLevelDeltaMax: this.pmcConfig.botRelativeLevelDeltaMax, + botRelativeLevelDeltaMin: this.pmcConfig.botRelativeLevelDeltaMin, botCountToGenerate: this.botConfig.presetBatch[condition.Role], botDifficulty: condition.Difficulty, isPlayerScav: false, diff --git a/project/src/generators/BotGenerator.ts b/project/src/generators/BotGenerator.ts index 200bb8be..e82086a1 100644 --- a/project/src/generators/BotGenerator.ts +++ b/project/src/generators/BotGenerator.ts @@ -83,6 +83,7 @@ export class BotGenerator role: role, playerLevel: 0, botRelativeLevelDeltaMax: 0, + botRelativeLevelDeltaMin: 0, botCountToGenerate: 1, botDifficulty: difficulty, isPlayerScav: true, diff --git a/project/src/generators/BotLevelGenerator.ts b/project/src/generators/BotLevelGenerator.ts index 38778504..6ac8d71c 100644 --- a/project/src/generators/BotLevelGenerator.ts +++ b/project/src/generators/BotLevelGenerator.ts @@ -39,10 +39,15 @@ export class BotLevelGenerator levelDetails, expTable, ); + const lowestLevel = this.getLowestRelativeBotLevel( + botGenerationDetails.playerLevel, + botGenerationDetails.botRelativeLevelDeltaMin, + levelDetails, + expTable); // Get random level based on the exp table. let exp = 0; - const level = this.randomUtil.getInt(1, highestLevel); + const level = this.randomUtil.getInt(lowestLevel, highestLevel); for (let i = 0; i < level; i++) { @@ -71,6 +76,7 @@ export class BotLevelGenerator expTable: IExpTable[], ): number { + // Some bots have a max level of 1 const maxPossibleLevel = Math.min(levelDetails.max, expTable.length); let level = playerLevel + relativeDeltaMax; @@ -81,4 +87,29 @@ export class BotLevelGenerator return level; } + + /** + * Get the highest level a bot can be relative to the players level, but no further than the max size from globals.exp_table + * @param playerLevel Players current level + * @param relativeDeltaMax max delta above player level to go + * @returns highest level possible for bot + */ + protected getLowestRelativeBotLevel( + playerLevel: number, + relativeDeltaMin: number, + levelDetails: MinMax, + expTable: IExpTable[], + ): number + { + // Some bots have a max level of 1 + const minPossibleLevel = Math.min(levelDetails.min, expTable.length); + + let level = playerLevel - relativeDeltaMin; + if (level < minPossibleLevel) + { + level = minPossibleLevel; + } + + return level; + } } diff --git a/project/src/models/spt/bots/BotGenerationDetails.ts b/project/src/models/spt/bots/BotGenerationDetails.ts index 90596346..c1158ebb 100644 --- a/project/src/models/spt/bots/BotGenerationDetails.ts +++ b/project/src/models/spt/bots/BotGenerationDetails.ts @@ -8,8 +8,10 @@ export interface BotGenerationDetails side: string; /** Active players current level */ playerLevel: number; - /** Delta of highest level of bot */ + /** 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 */ + botRelativeLevelDeltaMin: number; /** How many to create and store */ botCountToGenerate: number; /** Desired difficulty of the bot */ diff --git a/project/src/models/spt/config/IPmcConfig.ts b/project/src/models/spt/config/IPmcConfig.ts index fff537e1..c57276ca 100644 --- a/project/src/models/spt/config/IPmcConfig.ts +++ b/project/src/models/spt/config/IPmcConfig.ts @@ -44,6 +44,8 @@ export interface IPmcConfig extends IBaseConfig enemyTypes: string[]; /** How many levels above player level can a PMC be */ botRelativeLevelDeltaMax: number; + /** How many levels below player level can a PMC be */ + botRelativeLevelDeltaMin: number; /** Force a number of healing items into PMCs secure container to ensure they can heal */ forceHealingItemsIntoSecure: boolean; addPrefixToSameNamePMCAsPlayerChance: number;