Skip to content

Commit

Permalink
Enable bots before disposing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 22, 2024
1 parent cbd4be7 commit c247e14
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Fika.Core/Coop/Custom/FikaDynamicAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -184,7 +190,7 @@ private void CheckForPlayers(CoopBot bot)
}
}

public void SettingChanged(bool value)
public void EnabledChange(bool value)
{
if (!value)
{
Expand All @@ -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,
};
}
}
}
2 changes: 2 additions & 0 deletions Fika.Core/Coop/Players/CoopBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public override void OnDestroy()
CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
if (coopGame != null && coopGame.Status == GameStatus.Started)
{
coopGame.DynamicAI.RemoveBot(this);

Check failure on line 314 in Fika.Core/Coop/Players/CoopBot.cs

View workflow job for this annotation

GitHub Actions / test

'FikaDynamicAI' does not contain a definition for 'RemoveBot' and no accessible extension method 'RemoveBot' accepting a first argument of type 'FikaDynamicAI' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 314 in Fika.Core/Coop/Players/CoopBot.cs

View workflow job for this annotation

GitHub Actions / test

'FikaDynamicAI' does not contain a definition for 'RemoveBot' and no accessible extension method 'RemoveBot' accepting a first argument of type 'FikaDynamicAI' could be found (are you missing a using directive or an assembly reference?)

FikaServer server = Singleton<FikaServer>.Instance;
GenericPacket packet = new(EPackageType.DisposeBot)
{
Expand Down
4 changes: 4 additions & 0 deletions Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit c247e14

Please sign in to comment.