diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 7a609825..a068bcb6 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -265,13 +265,11 @@ private float GetDistanceFromPlayers(Vector3 position, List humanPla return distance; } - private string GetFurthestBot(Dictionary bots, CoopHandler coopHandler, out float furthestDistance) + private string GetFurthestBot(Dictionary bots, CoopHandler coopHandler, List humanPlayers, out float furthestDistance) { string furthestBot = string.Empty; furthestDistance = 0f; - List humanPlayers = GetPlayers(coopHandler); - foreach (var botKeyValuePair in Bots) { if (IsInvalidBotForDespawning(botKeyValuePair)) @@ -361,7 +359,7 @@ private async Task CreateBot(Profile profile, Vector3 position) if (!isSpecial && !despawned) { #if DEBUG - Logger.LogWarning($"Stopping spawn of bot {profile.Nickname}, max count reached and enforced limits enabled. Current: {botsController_0.AliveAndLoadingBotsCount}, Max: {botsController_0.BotSpawner.MaxBots}"); + Logger.LogWarning($"Stopping spawn of bot {profile.Nickname}, max count reached and enforced limits enabled. Current: {Bots.Count}, Max: {botsController_0.BotSpawner.MaxBots}, Alive & Loading: {botsController_0.BotSpawner.AliveAndLoadingBotsCount}"); #endif return null; } @@ -492,7 +490,9 @@ private async Task WaitForPlayersToLoadBotProfile(int netId) private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler coopHandler) { - string botKey = GetFurthestBot(Bots, coopHandler, out float furthestDistance); + List humanPlayers = GetPlayers(coopHandler); + + string botKey = GetFurthestBot(Bots, coopHandler, humanPlayers, out float furthestDistance); if (botKey == string.Empty) { @@ -502,7 +502,7 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c return false; } - if (furthestDistance > GetDistanceFromPlayers(position, GetPlayers(coopHandler))) + if (furthestDistance > GetDistanceFromPlayers(position, humanPlayers)) { #if DEBUG Logger.LogWarning($"We're not despawning anything. The furthest bot is closer than the one we wanted to spawn."); @@ -520,7 +520,7 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c } Player bot = Bots[botKey]; #if DEBUG - Logger.LogWarning($"Removing {bot.Profile.Info.Settings.Role} at a distance of {Math.Sqrt(furthestDistance)}m from ITs nearest player."); + Logger.LogWarning($"Removing {bot.Profile.Info.Settings.Role} at a distance of {Math.Sqrt(furthestDistance)}m from its nearest player."); #endif DespawnBot(coopHandler, bot); #if DEBUG