Skip to content

Commit

Permalink
Do not send state from disabled bots
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 17, 2024
1 parent f177a8b commit f3b105e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
9 changes: 6 additions & 3 deletions Fika.Core/Coop/Custom/FikaDynamicAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -95,6 +97,7 @@ private void DeactivateBot()

private void ActivateBot()
{
bot.PacketSender.Enabled = true;
botOwner.BotState = EBotState.Active;
botOwner.ShootData.SetCanShootByState(true);
}
Expand Down
4 changes: 3 additions & 1 deletion Fika.Core/Coop/Custom/FikaNewDynamicAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions Fika.Core/Coop/PacketHandlers/BotPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BotPacketSender : MonoBehaviour, IPacketSender
{
private CoopPlayer player;

public bool Enabled { get; set; } = true;
public FikaServer Server { get; set; } = Singleton<FikaServer>.Instance;
public FikaClient Client { get; set; }
public NetDataWriter Writer { get; set; } = new();
Expand All @@ -23,13 +24,19 @@ public class BotPacketSender : MonoBehaviour, IPacketSender
public Queue<CommonPlayerPacket> CommonPlayerPackets { get; set; } = new(50);
public Queue<HealthSyncPacket> HealthSyncPackets { get; set; } = new(50);

private void Awake()
protected void Awake()
{
player = GetComponent<CoopPlayer>();
}

private void FixedUpdate()
protected void FixedUpdate()
{
if (!Enabled)
{
player.LastDirection = Vector2.zero;
return;
}

if (player == null || Writer == null)
{
return;
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -28,7 +29,7 @@ public class ClientPacketSender : MonoBehaviour, IPacketSender
public Queue<CommonPlayerPacket> CommonPlayerPackets { get; set; } = new(50);
public Queue<HealthSyncPacket> HealthSyncPackets { get; set; } = new(50);

private void Awake()
protected void Awake()
{
player = GetComponent<CoopPlayer>();
Client = Singleton<FikaClient>.Instance;
Expand All @@ -37,7 +38,7 @@ private void Awake()
StartCoroutine(SyncWeather());
}

private void FixedUpdate()
protected void FixedUpdate()
{
if (player == null || Writer == null)
{
Expand All @@ -60,7 +61,7 @@ private void FixedUpdate()
}
}

private void Update()
protected void Update()
{
int firearmPackets = FirearmPackets.Count;
if (firearmPackets > 0)
Expand Down
1 change: 1 addition & 0 deletions Fika.Core/Coop/PacketHandlers/IPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 3 additions & 2 deletions Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -24,7 +25,7 @@ public class ObservedPacketSender : MonoBehaviour, IPacketSender
public Queue<CommonPlayerPacket> CommonPlayerPackets { get; set; } = new(50);
public Queue<HealthSyncPacket> HealthSyncPackets { get; set; } = new(50);

private void Awake()
protected void Awake()
{
player = GetComponent<ObservedCoopPlayer>();
isServer = MatchmakerAcceptPatches.IsServer;
Expand All @@ -38,7 +39,7 @@ private void Awake()
}
}

private void Update()
protected void Update()
{
if (player == null || Writer == null)
{
Expand Down
9 changes: 5 additions & 4 deletions Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ServerPacketSender : MonoBehaviour, IPacketSender
{
private CoopPlayer player;

public bool Enabled { get; set; } = true;
public FikaServer Server { get; set; } = Singleton<FikaServer>.Instance;
public FikaClient Client { get; set; }
public NetDataWriter Writer { get; set; } = new();
Expand All @@ -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<CoopPlayer>();
}

private void Start()
protected void Start()
{
StartCoroutine(SendTrainTime());
}

private void FixedUpdate()
protected void FixedUpdate()
{
if (player == null || Writer == null)
{
Expand All @@ -67,7 +68,7 @@ private void FixedUpdate()
}
}

private void Update()
protected void Update()
{
int firearmPackets = FirearmPackets.Count;
if (firearmPackets > 0)
Expand Down

0 comments on commit f3b105e

Please sign in to comment.