diff --git a/Content.Server/Antag/AntagSelectionSystem.cs b/Content.Server/Antag/AntagSelectionSystem.cs index 9409019a0b5..6e0f51b5dc2 100644 --- a/Content.Server/Antag/AntagSelectionSystem.cs +++ b/Content.Server/Antag/AntagSelectionSystem.cs @@ -225,11 +225,13 @@ public void ChooseAntags(Entity ent, IList 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) @@ -238,15 +240,17 @@ public void ChooseAntags(Entity ent, IList= count) + break; + playerPool = playerPool.Where((session_) => { return !ent.Comp.SelectedSessions.Contains(session_) && !failed.Contains(session_); }); - count = countFailed; retry++; } }