Skip to content

Commit

Permalink
Removes unnecessary variable and adds another early break
Browse files Browse the repository at this point in the history
  • Loading branch information
rbertoche committed Dec 22, 2024
1 parent bf56b5d commit 7633d42
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Content.Server/Antag/AntagSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ public void ChooseAntags(Entity<AntagSelectionComponent> ent, IList<ICommonSessi
var retry = 0;
List<ICommonSession> failed = [];

while (count != 0 && retry < maxRetries)
while (ent.Comp.SelectedSessions.Count < count && retry < maxRetries)
{
var countFailed = 0; // Not at the same scope as `failed`
var sessions = (ICommonSession[]?) null;
if (!playerPool.TryGetItems(RobustRandom, out sessions, count, false))
if (!playerPool.TryGetItems(RobustRandom,
out sessions,
count - ent.Comp.SelectedSessions.Count,
false))
break; // Ends early if there are no eligible sessions

foreach (var session in sessions)
Expand All @@ -238,15 +240,17 @@ public void ChooseAntags(Entity<AntagSelectionComponent> ent, IList<ICommonSessi
if (!ent.Comp.SelectedSessions.Contains(session))
{
failed.Add(session);
countFailed++;
}
}
// In case we're done
if (ent.Comp.SelectedSessions.Count >= count)
break;

playerPool = playerPool.Where((session_) =>
{
return !ent.Comp.SelectedSessions.Contains(session_) &&
!failed.Contains(session_);
});
count = countFailed;
retry++;
}
}
Expand Down

0 comments on commit 7633d42

Please sign in to comment.