Skip to content

Commit

Permalink
Merge pull request #38 from DeadLeavez/decouple-despawn-from-spawning
Browse files Browse the repository at this point in the history
decouple despawnbot from spawning bots.
  • Loading branch information
Lacyway authored May 7, 2024
2 parents afa3690 + c82be89 commit adc194e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBotGame>.Instance;
BotOwner botOwner = bot.AIData.BotOwner;

Expand All @@ -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);
}

/// <summary>
Expand Down

0 comments on commit adc194e

Please sign in to comment.