From c82be899e0adf90534e6b5f3161c43efbfcb0cdd Mon Sep 17 00:00:00 2001 From: DeadLeavez Date: Tue, 7 May 2024 20:45:26 +0200 Subject: [PATCH] decouple despawnbot from spawning bots. --- Fika.Core/Coop/GameMode/CoopGame.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index fa8dfbd2..891f929a 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -443,13 +443,19 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c #endif return false; } - 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."); #endif + DespawnBot(coopHandler, bot); +#if DEBUG + Logger.LogWarning($"Bot {bot.Profile.Info.Settings.Role} despawned successfully."); +#endif + return true; + } + private void DespawnBot(CoopHandler coopHandler, Player bot) + { IBotGame botGame = Singleton.Instance; BotOwner botOwner = bot.AIData.BotOwner; @@ -458,13 +464,9 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c BotUnspawn(botOwner); botOwner?.Dispose(); - Bots.Remove(botKey); CoopPlayer coopPlayer = (CoopPlayer)bot; coopHandler.Players.Remove(coopPlayer.NetId); -#if DEBUG - Logger.LogWarning($"Bot {bot.Profile.Info.Settings.Role} despawned successfully."); -#endif - return true; + Bots.Remove(bot.ProfileId); } ///