diff --git a/Core/Helpers/BotHelper.cs b/Core/Helpers/BotHelper.cs index 60cc7871..b0352be9 100644 --- a/Core/Helpers/BotHelper.cs +++ b/Core/Helpers/BotHelper.cs @@ -1,8 +1,12 @@ using Core.Annotations; using Core.Models.Common; using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.Match; +using Core.Models.Enums; using Core.Models.Spt.Config; +using Core.Servers; using Core.Services; +using Core.Utils; using ILogger = Core.Models.Utils.ILogger; namespace Core.Helpers; @@ -12,14 +16,30 @@ public class BotHelper { private readonly ILogger _logger; private readonly DatabaseService _databaseService; + private readonly RandomUtil _randomUtil; + private readonly ConfigServer _configServer; - public BotHelper( + private readonly BotConfig _botConfig; + private readonly PmcConfig _pmcConfig; + + private readonly List _pmcNames = ["usec", "bear", "pmc", "pmcbear", "pmcusec"]; + + public BotHelper + ( ILogger logger, - DatabaseService databaseService) + DatabaseService databaseService, + RandomUtil randomUtil, + ConfigServer configServer + ) { _logger = logger; _databaseService = databaseService; + _randomUtil = randomUtil; + _configServer = configServer; + _botConfig = configServer.GetConfig(ConfigTypes.BOT); + _pmcConfig = configServer.GetConfig(ConfigTypes.PMC); } + /// /// Get a template object for the specified botRole from bots.types db /// @@ -44,17 +64,17 @@ public class BotHelper /// true if is pmc public bool IsBotPmc(string botRole) { - throw new NotImplementedException(); + return _pmcNames.Contains(botRole?.ToLower()); } public bool IsBotBoss(string botRole) { - throw new NotImplementedException(); + return _botConfig.Bosses.Any(x => x.ToLower() == botRole.ToLower()); } public bool IsBotFollower(string botRole) { - throw new NotImplementedException(); + return botRole?.ToLower().StartsWith("follower") ?? false; } /// @@ -64,7 +84,15 @@ public class BotHelper /// bot type to add to friendly list public void AddBotToFriendlyList(DifficultyCategories difficultySettings, string typeToAdd) { - throw new NotImplementedException(); + var friendlyBotTypesKey = "FRIENDLY_BOT_TYPES"; + + // Null guard + if (difficultySettings.Mind[friendlyBotTypesKey] is null) + { + difficultySettings.Mind[friendlyBotTypesKey] = new List(); + } + + ((List)difficultySettings.Mind[friendlyBotTypesKey]).Add(typeToAdd); } /// @@ -74,17 +102,44 @@ public class BotHelper /// bot type to add to revenge list public void AddBotToRevengeList(DifficultyCategories difficultySettings, string[] typesToAdd) { - throw new NotImplementedException(); + var revengePropKey = "REVENGE_BOT_TYPES"; + + // Nothing to add + if (typesToAdd is null) + { + return; + } + + // Null guard + if (difficultySettings.Mind[revengePropKey] is null) + { + difficultySettings.Mind[revengePropKey] = new List(); + } + + var revengeArray = (List)difficultySettings.Mind[revengePropKey]; + foreach (var botTypeToAdd in typesToAdd) + { + if (!revengeArray.Contains(botTypeToAdd)) + { + revengeArray.Add(botTypeToAdd); + } + } } public bool RollChanceToBePmc(MinMax botConvertMinMax) { - throw new NotImplementedException(); + return _randomUtil.GetChance100(_randomUtil.GetInt((int)botConvertMinMax.Min, (int)botConvertMinMax.Max)); } - protected void GetPmcConversionValuesForLocation(string location) + protected Dictionary GetPmcConversionValuesForLocation(string location) { - throw new NotImplementedException(); + var result = _pmcConfig.ConvertIntoPmcChance[location.ToLower()]; + if (result is null) + { + _pmcConfig.ConvertIntoPmcChance = new(); + } + + return result; } /// @@ -94,7 +149,10 @@ public class BotHelper /// True if role is PMC public bool BotRoleIsPmc(string botRole) { - throw new NotImplementedException(); + List ListToCheck = [_pmcConfig.UsecType.ToLower(), _pmcConfig.BearType.ToLower()]; + return ListToCheck.Contains( + botRole.ToLower() + ); } /// @@ -105,7 +163,15 @@ public class BotHelper /// RandomisationDetails public RandomisationDetails GetBotRandomizationDetails(int botLevel, EquipmentFilters botEquipConfig) { - throw new NotImplementedException(); + // No randomisation details found, skip + if (botEquipConfig is null || botEquipConfig.Randomisation is null) + { + return null; + } + + return botEquipConfig.Randomisation.FirstOrDefault( + (randDetails) => botLevel >= randDetails.LevelRange.Min && botLevel <= randDetails.LevelRange.Max + ); } /// @@ -114,7 +180,7 @@ public class BotHelper /// pmc role public string GetRandomizedPmcRole() { - throw new NotImplementedException(); + return _randomUtil.GetChance100(_pmcConfig.IsUsec) ? _pmcConfig.UsecType : _pmcConfig.BearType; } /// @@ -124,7 +190,13 @@ public class BotHelper /// side (usec/bear) public string GetPmcSideByRole(string botRole) { - throw new NotImplementedException(); + if (_pmcConfig.BearType.ToLower() == botRole.ToLower()) + return "Bear"; + + if (_pmcConfig.UsecType.ToLower() == botRole.ToLower()) + return "Usec"; + + return GetRandomizedPmcSide(); } /// @@ -133,7 +205,7 @@ public class BotHelper /// pmc side as string protected string GetRandomizedPmcSide() { - throw new NotImplementedException(); + return _randomUtil.GetChance100(_pmcConfig.IsUsec) ? "Usec" : "Bear"; } /// @@ -144,6 +216,15 @@ public class BotHelper /// name of PMC public string GetPmcNicknameOfMaxLength(int maxLength, string side = null) { - throw new NotImplementedException(); + var randomType = (side is not null) ? side : (_randomUtil.GetInt(0, 1) == 0) ? "usec" : "bear"; + var allNames = _databaseService.GetBots().Types[randomType.ToLower()].FirstNames; + var filteredNames = allNames.Where((name) => name.Length <= maxLength); + if (filteredNames.Count() == 0) { + _logger.Warning($"Unable to filter: {randomType} PMC names to only those under: {maxLength}, none found that match that criteria, selecting from entire name pool instead`,\n"); + + return _randomUtil.GetStringCollectionValue(allNames); + } + + return _randomUtil.GetStringCollectionValue(filteredNames); } }