From f3b105e8af0ed4000214e085adfd6abb78d7de15 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Fri, 17 May 2024 17:02:40 +0200 Subject: [PATCH] Do not send state from disabled bots --- Fika.Core/Coop/Custom/FikaDynamicAI.cs | 9 ++++++--- Fika.Core/Coop/Custom/FikaNewDynamicAI.cs | 4 +++- Fika.Core/Coop/PacketHandlers/BotPacketSender.cs | 13 ++++++++++--- Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs | 7 ++++--- Fika.Core/Coop/PacketHandlers/IPacketSender.cs | 1 + .../Coop/PacketHandlers/ObservedPacketSender.cs | 5 +++-- Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs | 9 +++++---- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Fika.Core/Coop/Custom/FikaDynamicAI.cs b/Fika.Core/Coop/Custom/FikaDynamicAI.cs index 2484d699..6fd2de6e 100644 --- a/Fika.Core/Coop/Custom/FikaDynamicAI.cs +++ b/Fika.Core/Coop/Custom/FikaDynamicAI.cs @@ -43,15 +43,16 @@ private void Start() switch (FikaPlugin.DynamicAIRate.Value) { case FikaPlugin.DynamicAIRates.Low: - resetCount = 300; + resetCount = 600; break; case FikaPlugin.DynamicAIRates.Medium: - resetCount = 150; + resetCount = 300; break; case FikaPlugin.DynamicAIRates.High: - resetCount = 75; + resetCount = 120; break; default: + resetCount = 300; break; } } @@ -86,6 +87,7 @@ private void FixedUpdate() private void DeactivateBot() { + bot.PacketSender.Enabled = false; botOwner.BotState = EBotState.NonActive; botOwner.ShootData.EndShoot(); botOwner.ShootData.SetCanShootByState(false); @@ -95,6 +97,7 @@ private void DeactivateBot() private void ActivateBot() { + bot.PacketSender.Enabled = true; botOwner.BotState = EBotState.Active; botOwner.ShootData.SetCanShootByState(true); } diff --git a/Fika.Core/Coop/Custom/FikaNewDynamicAI.cs b/Fika.Core/Coop/Custom/FikaNewDynamicAI.cs index 488374d6..b1383acd 100644 --- a/Fika.Core/Coop/Custom/FikaNewDynamicAI.cs +++ b/Fika.Core/Coop/Custom/FikaNewDynamicAI.cs @@ -95,6 +95,7 @@ private void DeactivateBot(CoopPlayer bot) bot.AIData.BotOwner.ShootData.EndShoot(); bot.AIData.BotOwner.ShootData.SetCanShootByState(false); bot.AIData.BotOwner.DecisionQueue.Clear(); + bot.AIData.BotOwner.PatrollingData.Pause(); bot.AIData.BotOwner.Memory.GoalEnemy = null; bot.gameObject.SetActive(false); } @@ -104,9 +105,10 @@ private void ActivateBot(CoopPlayer bot) #if DEBUG logger.LogWarning($"Enabling {bot.gameObject.name}"); #endif + bot.gameObject.SetActive(true); bot.AIData.BotOwner.BotState = EBotState.Active; bot.AIData.BotOwner.ShootData.SetCanShootByState(true); - bot.gameObject.SetActive(true); + bot.AIData.BotOwner.PatrollingData.Unpause(); } private void CheckForPlayers(CoopBot bot) diff --git a/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs b/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs index cba9122a..02fc1b1e 100644 --- a/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs @@ -14,6 +14,7 @@ public class BotPacketSender : MonoBehaviour, IPacketSender { private CoopPlayer player; + public bool Enabled { get; set; } = true; public FikaServer Server { get; set; } = Singleton.Instance; public FikaClient Client { get; set; } public NetDataWriter Writer { get; set; } = new(); @@ -23,13 +24,19 @@ public class BotPacketSender : MonoBehaviour, IPacketSender public Queue CommonPlayerPackets { get; set; } = new(50); public Queue HealthSyncPackets { get; set; } = new(50); - private void Awake() + protected void Awake() { player = GetComponent(); } - private void FixedUpdate() + protected void FixedUpdate() { + if (!Enabled) + { + player.LastDirection = Vector2.zero; + return; + } + if (player == null || Writer == null) { return; @@ -48,7 +55,7 @@ private void FixedUpdate() player.LastDirection = Vector2.zero; // Bots give a constant input for some odd reason, resetting on FixedUpdate should be ok from my testing and does not cause sliding for clients } - private void Update() + protected void Update() { int firearmPackets = FirearmPackets.Count; if (firearmPackets > 0) diff --git a/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs index 3a7aeca6..c545e3d6 100644 --- a/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs @@ -19,6 +19,7 @@ public class ClientPacketSender : MonoBehaviour, IPacketSender { private CoopPlayer player; + public bool Enabled { get; set; } = true; public FikaServer Server { get; set; } public FikaClient Client { get; set; } public NetDataWriter Writer { get; set; } = new(); @@ -28,7 +29,7 @@ public class ClientPacketSender : MonoBehaviour, IPacketSender public Queue CommonPlayerPackets { get; set; } = new(50); public Queue HealthSyncPackets { get; set; } = new(50); - private void Awake() + protected void Awake() { player = GetComponent(); Client = Singleton.Instance; @@ -37,7 +38,7 @@ private void Awake() StartCoroutine(SyncWeather()); } - private void FixedUpdate() + protected void FixedUpdate() { if (player == null || Writer == null) { @@ -60,7 +61,7 @@ private void FixedUpdate() } } - private void Update() + protected void Update() { int firearmPackets = FirearmPackets.Count; if (firearmPackets > 0) diff --git a/Fika.Core/Coop/PacketHandlers/IPacketSender.cs b/Fika.Core/Coop/PacketHandlers/IPacketSender.cs index bf14e663..bf832a3f 100644 --- a/Fika.Core/Coop/PacketHandlers/IPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/IPacketSender.cs @@ -8,6 +8,7 @@ namespace Fika.Core.Coop.PacketHandlers { public interface IPacketSender { + public bool Enabled { get; set; } public FikaServer Server { get; set; } public FikaClient Client { get; set; } public NetDataWriter Writer { get; set; } diff --git a/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs index 95f641c9..ed74228d 100644 --- a/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs @@ -15,6 +15,7 @@ public class ObservedPacketSender : MonoBehaviour, IPacketSender { private CoopPlayer player; private bool isServer; + public bool Enabled { get; set; } = true; public FikaServer Server { get; set; } public FikaClient Client { get; set; } public NetDataWriter Writer { get; set; } = new(); @@ -24,7 +25,7 @@ public class ObservedPacketSender : MonoBehaviour, IPacketSender public Queue CommonPlayerPackets { get; set; } = new(50); public Queue HealthSyncPackets { get; set; } = new(50); - private void Awake() + protected void Awake() { player = GetComponent(); isServer = MatchmakerAcceptPatches.IsServer; @@ -38,7 +39,7 @@ private void Awake() } } - private void Update() + protected void Update() { if (player == null || Writer == null) { diff --git a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs index 142cecdd..99f40b1e 100644 --- a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs @@ -22,6 +22,7 @@ public class ServerPacketSender : MonoBehaviour, IPacketSender { private CoopPlayer player; + public bool Enabled { get; set; } = true; public FikaServer Server { get; set; } = Singleton.Instance; public FikaClient Client { get; set; } public NetDataWriter Writer { get; set; } = new(); @@ -33,18 +34,18 @@ public class ServerPacketSender : MonoBehaviour, IPacketSender private ManualLogSource logger; - private void Awake() + protected void Awake() { logger = BepInEx.Logging.Logger.CreateLogSource("ServerPacketSender"); player = GetComponent(); } - private void Start() + protected void Start() { StartCoroutine(SendTrainTime()); } - private void FixedUpdate() + protected void FixedUpdate() { if (player == null || Writer == null) { @@ -67,7 +68,7 @@ private void FixedUpdate() } } - private void Update() + protected void Update() { int firearmPackets = FirearmPackets.Count; if (firearmPackets > 0)