]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Ensure correct number of thieves are selected (#23270)
authorRainfey <11758391+Rainfey@users.noreply.github.com>
Mon, 1 Jan 2024 02:25:28 +0000 (02:25 +0000)
committerGitHub <noreply@github.com>
Mon, 1 Jan 2024 02:25:28 +0000 (21:25 -0500)
Fix thief selection

Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Content.Server/GameTicking/Rules/ThiefRuleSystem.cs

index 27e0cb592d8cc748cdfbea6b7274c41cf6cfab92..11ce2314a16d3691e2b6d2a588be722050ed3ab9 100644 (file)
@@ -81,11 +81,19 @@ public sealed class ThiefRuleSystem : GameRuleSystem<ThiefRuleComponent>
         var startThiefCount = Math.Min(component.MaxAllowThief, component.StartCandidates.Count);
         var thiefPool = _antagSelection.FindPotentialAntags(component.StartCandidates, component.ThiefPrototypeId);
         //TO DO: When voxes specifies are added, increase their chance of becoming a thief by 4 times >:)
-        var selectedThieves = _antagSelection.PickAntag(_random.Next(1, startThiefCount), thiefPool);
 
-        foreach(var thief in selectedThieves)
+        //Add 1, as Next() is exclusive of maxValue
+        var numberOfThievesToSelect = _random.Next(1, startThiefCount + 1);
+
+        //While we dont have the correct number of thieves, and there are potential thieves remaining
+        while (component.ThievesMinds.Count < numberOfThievesToSelect && thiefPool.Count > 0)
         {
-            MakeThief(component, thief, component.PacifistThieves);
+            Log.Info($"{numberOfThievesToSelect} thieves required, {component.ThievesMinds.Count} currently chosen, {thiefPool.Count} potentials");
+            var selectedThieves = _antagSelection.PickAntag(numberOfThievesToSelect - component.ThievesMinds.Count, thiefPool);
+            foreach (var thief in selectedThieves)
+            {
+                MakeThief(component, thief, component.PacifistThieves);
+            }
         }
     }