From 1fde680855e9d95ecf09281ed5f221d011fda488 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 23 Jan 2025 16:58:42 +0000 Subject: [PATCH] Cleanup of GetBotDifficultySettings --- Libraries/Core/Helpers/BotDifficultyHelper.cs | 17 +++++++++-------- Libraries/Core/Helpers/BotHelper.cs | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Libraries/Core/Helpers/BotDifficultyHelper.cs b/Libraries/Core/Helpers/BotDifficultyHelper.cs index c18e7b37..b16f0361 100644 --- a/Libraries/Core/Helpers/BotDifficultyHelper.cs +++ b/Libraries/Core/Helpers/BotDifficultyHelper.cs @@ -1,4 +1,4 @@ -using SptCommon.Annotations; +using SptCommon.Annotations; using Core.Models.Eft.Common.Tables; using Core.Models.Spt.Bots; using Core.Models.Spt.Config; @@ -27,29 +27,30 @@ public class BotDifficultyHelper( /// Get difficulty settings for desired bot type, if not found use assault bot types /// /// bot type to retrieve difficulty of - /// difficulty to get settings for (easy/normal etc) + /// difficulty to get settings for (easy/normal etc) /// bots from database /// Difficulty object - public DifficultyCategories GetBotDifficultySettings(string type, string difficulty, Bots botDb) + public DifficultyCategories GetBotDifficultySettings(string type, string desiredDifficulty, Bots botDb) { var desiredType = type.ToLower(); - if (!botDb.Types.TryGetValue(desiredType, out var _)) { + if (!botDb.Types.ContainsKey(desiredType)) { // No bot found, get fallback difficulty values _logger.Warning(_localisationService.GetText("bot-unable_to_get_bot_fallback_to_assault", type)); botDb.Types[desiredType] = _cloner.Clone(botDb.Types["assault"]); } // Get settings from raw bot json template file - var difficultySettings = _botHelper.GetBotTemplate(desiredType).BotDifficulty[difficulty]; + var botTemplate = _botHelper.GetBotTemplate(desiredType); + botTemplate.BotDifficulty.TryGetValue(desiredDifficulty, out var difficultySettings); if (difficultySettings is null) { // No bot settings found, use 'assault' bot difficulty instead _logger.Warning( _localisationService.GetText("bot-unable_to_get_bot_difficulty_fallback_to_assault", new { botType = desiredType, - difficulty = difficulty, + difficulty = desiredDifficulty, })); - botDb.Types[desiredType].BotDifficulty[difficulty] = _cloner.Clone( - botDb.Types["assault"].BotDifficulty[difficulty] + botDb.Types[desiredType].BotDifficulty[desiredDifficulty] = _cloner.Clone( + botDb.Types["assault"].BotDifficulty[desiredDifficulty] ); } diff --git a/Libraries/Core/Helpers/BotHelper.cs b/Libraries/Core/Helpers/BotHelper.cs index 64bfc73c..ecf699f7 100644 --- a/Libraries/Core/Helpers/BotHelper.cs +++ b/Libraries/Core/Helpers/BotHelper.cs @@ -27,7 +27,7 @@ public class BotHelper( /// /// botRole to get template for /// BotType object - public BotType GetBotTemplate(string role) + public BotType? GetBotTemplate(string role) { if (!_databaseService.GetBots().Types.TryGetValue(role?.ToLower(), out var bot)) {