diff --git a/Libraries/Core/Generators/BotGenerator.cs b/Libraries/Core/Generators/BotGenerator.cs index 3514c13e..208ffe6a 100644 --- a/Libraries/Core/Generators/BotGenerator.cs +++ b/Libraries/Core/Generators/BotGenerator.cs @@ -230,7 +230,7 @@ public class BotGenerator( bot.Info.Experience = botLevel.Exp; bot.Info.Level = botLevel.Level; - bot.Info.Settings.Experience = GetExperienceRewardForKillByDifficulty( + bot.Info.Settings.Experience = (int)GetExperienceRewardForKillByDifficulty( botJsonTemplate.BotExperience.Reward, botGenerationDetails.BotDifficulty, botGenerationDetails.Role diff --git a/Libraries/Core/Models/Eft/Common/Tables/BotBase.cs b/Libraries/Core/Models/Eft/Common/Tables/BotBase.cs index ae67cdef..e12d0b1f 100644 --- a/Libraries/Core/Models/Eft/Common/Tables/BotBase.cs +++ b/Libraries/Core/Models/Eft/Common/Tables/BotBase.cs @@ -196,7 +196,7 @@ public record BotInfoSettings { public string? Role { get; set; } public string? BotDifficulty { get; set; } - public double? Experience { get; set; } + public int? Experience { get; set; } public double? StandingForKill { get; set; } public double? AggressorBonus { get; set; } public bool? UseSimpleAnimator { get; set; } diff --git a/Libraries/Core/Services/BotGenerationCacheService.cs b/Libraries/Core/Services/BotGenerationCacheService.cs index ec47911b..c64ccfd6 100644 --- a/Libraries/Core/Services/BotGenerationCacheService.cs +++ b/Libraries/Core/Services/BotGenerationCacheService.cs @@ -13,6 +13,7 @@ public class BotGenerationCacheService( { protected Dictionary> _storedBots = new Dictionary>(); protected Queue _activeBotsInRaid = []; + protected Lock _lock = new Lock(); /** @@ -21,11 +22,14 @@ public class BotGenerationCacheService( */ public void StoreBots(string key, List botsToStore) { - foreach (var bot in botsToStore) + lock (_lock) { - if (!_storedBots.TryAdd(key, [bot])) + foreach (var bot in botsToStore) { - _storedBots[key].Add(bot); + if (!_storedBots.TryAdd(key, [bot])) + { + _storedBots[key].Add(bot); + } } } } @@ -38,21 +42,24 @@ public class BotGenerationCacheService( */ public BotBase? GetBot(string key) { - if (_storedBots.TryGetValue(key, out var bots)) + lock (_lock) { - if (bots.Count > 0) + if (_storedBots.TryGetValue(key, out var bots)) { - try + if (bots.Count > 0) { - return bots.Pop(); - } - catch (Exception _) - { - _logger.Error(_localisationService.GetText("bot-cache_has_zero_bots_of_requested_type", key)); + return bots.PopFirst(); + try + { + } + catch (Exception _) + { + _logger.Error(_localisationService.GetText("bot-cache_has_zero_bots_of_requested_type", key)); + } } } } - + _logger.Error(_localisationService.GetText("bot-no_bot_type_in_cache", key)); return null; } @@ -63,7 +70,10 @@ public class BotGenerationCacheService( */ public void StoreUsedBot(BotBase botToStore) { - _activeBotsInRaid.Enqueue(botToStore); + lock (_lock) + { + _activeBotsInRaid.Enqueue(botToStore); + } } /** @@ -74,7 +84,10 @@ public class BotGenerationCacheService( */ public BotBase? GetUsedBot(string profileId) { - return _activeBotsInRaid.FirstOrDefault(x => x.Id == profileId); + lock (_lock) + { + return _activeBotsInRaid.FirstOrDefault(x => x.Id == profileId); + } } /** @@ -82,8 +95,11 @@ public class BotGenerationCacheService( */ public void ClearStoredBots() { - _storedBots.Clear(); - _activeBotsInRaid = []; + lock (_lock) + { + _storedBots.Clear(); + _activeBotsInRaid = []; + } } /** diff --git a/SptCommon/Extensions/ListExtensions.cs b/SptCommon/Extensions/ListExtensions.cs index c5833bdc..5c6e764b 100644 --- a/SptCommon/Extensions/ListExtensions.cs +++ b/SptCommon/Extensions/ListExtensions.cs @@ -9,10 +9,10 @@ public static class ListExtensions return items; } - public static T Pop(this List source) + public static T PopFirst(this List source) { - T r = source.Last(); - source.Remove(source.Last()); + T r = source.First(); + source.Remove(source.First()); return r; } }