]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix under-selecting antags (#28327)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 27 May 2024 22:43:17 +0000 (18:43 -0400)
committerGitHub <noreply@github.com>
Mon, 27 May 2024 22:43:17 +0000 (15:43 -0700)
Fix under selecting antags

Content.Server/Antag/AntagSelectionSystem.API.cs
Content.Server/Antag/AntagSelectionSystem.cs

index 3b5855cdf95c41dbc498d7a235952a550c237b5c..16d83c4f3fc437ecb06047bd0a20b4d4171fdbf1 100644 (file)
@@ -52,12 +52,26 @@ public sealed partial class AntagSelectionSystem
     /// Gets the number of antagonists that should be present for a given rule based on the provided pool.
     /// A null pool will simply use the player count.
     /// </summary>
-    public int GetTargetAntagCount(Entity<AntagSelectionComponent> ent, AntagSelectionPlayerPool? pool = null)
+    public int GetTargetAntagCount(Entity<AntagSelectionComponent> ent, int? playerCount = null)
     {
         var count = 0;
         foreach (var def in ent.Comp.Definitions)
         {
-            count += GetTargetAntagCount(ent, pool, def);
+            count += GetTargetAntagCount(ent, playerCount, def);
+        }
+
+        return count;
+    }
+
+    public int GetTotalPlayerCount(IList<ICommonSession> pool)
+    {
+        var count = 0;
+        foreach (var session in pool)
+        {
+            if (session.Status is SessionStatus.Disconnected or SessionStatus.Zombie)
+                continue;
+
+            count++;
         }
 
         return count;
@@ -67,14 +81,13 @@ public sealed partial class AntagSelectionSystem
     /// Gets the number of antagonists that should be present for a given antag definition based on the provided pool.
     /// A null pool will simply use the player count.
     /// </summary>
-    public int GetTargetAntagCount(Entity<AntagSelectionComponent> ent, AntagSelectionPlayerPool? pool, AntagSelectionDefinition def)
+    public int GetTargetAntagCount(Entity<AntagSelectionComponent> ent, int? playerCount, AntagSelectionDefinition def)
     {
         // TODO ANTAG
         // make pool non-nullable
         // Review uses and ensure that people are INTENTIONALLY including players in the lobby if this is a mid-round
         // antag selection.
-        var poolSize = pool?.Count ?? _playerManager.Sessions
-            .Count(s => s.State.Status is not SessionStatus.Disconnected and not SessionStatus.Zombie);
+        var poolSize = playerCount ?? GetTotalPlayerCount(_playerManager.Sessions);
 
         // factor in other definitions' affect on the count.
         var countOffset = 0;
index 5b6c891ddfc5c7b594cf603ad68a38144de1b27e..a86611bedb399769a3b99b987d4afb98c17f30e9 100644 (file)
@@ -203,7 +203,7 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
     public void ChooseAntags(Entity<AntagSelectionComponent> ent, IList<ICommonSession> pool, AntagSelectionDefinition def)
     {
         var playerPool = GetPlayerPool(ent, pool, def);
-        var count = GetTargetAntagCount(ent, playerPool, def);
+        var count = GetTargetAntagCount(ent, GetTotalPlayerCount(pool), def);
 
         for (var i = 0; i < count; i++)
         {