Skip to content

Commit

Permalink
Improvements to bot despawning
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 2, 2024
1 parent f739e22 commit ebb7f3c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,11 @@ private float GetDistanceFromPlayers(Vector3 position, List<CoopPlayer> humanPla
return distance;
}

private string GetFurthestBot(Dictionary<string, Player> bots, CoopHandler coopHandler, out float furthestDistance)
private string GetFurthestBot(Dictionary<string, Player> bots, CoopHandler coopHandler, List<CoopPlayer> humanPlayers, out float furthestDistance)
{
string furthestBot = string.Empty;
furthestDistance = 0f;

List<CoopPlayer> humanPlayers = GetPlayers(coopHandler);

foreach (var botKeyValuePair in Bots)
{
if (IsInvalidBotForDespawning(botKeyValuePair))
Expand Down Expand Up @@ -361,7 +359,7 @@ private async Task<LocalPlayer> CreateBot(Profile profile, Vector3 position)
if (!isSpecial && !despawned)
{
#if DEBUG
Logger.LogWarning($"Stopping spawn of bot {profile.Nickname}, max count reached and enforced limits enabled. Current: {botsController_0.AliveAndLoadingBotsCount}, Max: {botsController_0.BotSpawner.MaxBots}");
Logger.LogWarning($"Stopping spawn of bot {profile.Nickname}, max count reached and enforced limits enabled. Current: {Bots.Count}, Max: {botsController_0.BotSpawner.MaxBots}, Alive & Loading: {botsController_0.BotSpawner.AliveAndLoadingBotsCount}");
#endif
return null;
}
Expand Down Expand Up @@ -492,7 +490,9 @@ private async Task WaitForPlayersToLoadBotProfile(int netId)

private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler coopHandler)
{
string botKey = GetFurthestBot(Bots, coopHandler, out float furthestDistance);
List<CoopPlayer> humanPlayers = GetPlayers(coopHandler);

string botKey = GetFurthestBot(Bots, coopHandler, humanPlayers, out float furthestDistance);

if (botKey == string.Empty)
{
Expand All @@ -502,7 +502,7 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c
return false;
}

if (furthestDistance > GetDistanceFromPlayers(position, GetPlayers(coopHandler)))
if (furthestDistance > GetDistanceFromPlayers(position, humanPlayers))
{
#if DEBUG
Logger.LogWarning($"We're not despawning anything. The furthest bot is closer than the one we wanted to spawn.");
Expand All @@ -520,7 +520,7 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c
}
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.");
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
Expand Down

0 comments on commit ebb7f3c

Please sign in to comment.