From c247e14f5fceffb758a289c16e44eba7ccc23c6c Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Wed, 22 May 2024 15:44:23 +0200 Subject: [PATCH] Enable bots before disposing --- Fika.Core/Coop/Custom/FikaDynamicAI.cs | 21 +++++++++++++++++++-- Fika.Core/Coop/Players/CoopBot.cs | 2 ++ Fika.Core/Networking/FikaClient.cs | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Fika.Core/Coop/Custom/FikaDynamicAI.cs b/Fika.Core/Coop/Custom/FikaDynamicAI.cs index 4728bdb1..59081045 100644 --- a/Fika.Core/Coop/Custom/FikaDynamicAI.cs +++ b/Fika.Core/Coop/Custom/FikaDynamicAI.cs @@ -59,10 +59,16 @@ protected void Awake() private void Spawner_OnBotRemoved(BotOwner botOwner) { - if (!bots.Remove((CoopBot)botOwner.GetPlayer)) + CoopBot bot = (CoopBot)botOwner.GetPlayer; + if (!bots.Remove(bot)) { logger.LogWarning($"Could not remove {botOwner.gameObject.name} from bots list."); } + + if (disabledBots.Contains(bot)) + { + disabledBots.Remove(bot); + } } private void Spawner_OnBotCreated(BotOwner botOwner) @@ -184,7 +190,7 @@ private void CheckForPlayers(CoopBot bot) } } - public void SettingChanged(bool value) + public void EnabledChange(bool value) { if (!value) { @@ -196,5 +202,16 @@ public void SettingChanged(bool value) disabledBots.Clear(); } } + + internal void RateChanged(FikaPlugin.DynamicAIRates value) + { + resetCounter = value switch + { + FikaPlugin.DynamicAIRates.Low => 600, + FikaPlugin.DynamicAIRates.Medium => 300, + FikaPlugin.DynamicAIRates.High => 120, + _ => 300, + }; + } } } diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index 6b9dc07b..9b10fa7b 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -311,6 +311,8 @@ public override void OnDestroy() CoopGame coopGame = (CoopGame)Singleton.Instance; if (coopGame != null && coopGame.Status == GameStatus.Started) { + coopGame.DynamicAI.RemoveBot(this); + FikaServer server = Singleton.Instance; GenericPacket packet = new(EPackageType.DisposeBot) { diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index ec69f925..81d1c141 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -436,6 +436,10 @@ private void OnGenericPacketReceived(GenericPacket packet) { if (CoopHandler.Players.TryGetValue(packet.BotNetId, out CoopPlayer botToDispose)) { + if (!botToDispose.gameObject.activeSelf) + { + botToDispose.gameObject.SetActive(true); + } if (CoopHandler.Players.Remove(packet.BotNetId)) {