]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix Mind Transfer and Role Assignment Logic for Antagonists (#30711)
authorNakataRin <45946146+NakataRin@users.noreply.github.com>
Wed, 7 Aug 2024 03:38:47 +0000 (07:38 +0400)
committerGitHub <noreply@github.com>
Wed, 7 Aug 2024 03:38:47 +0000 (23:38 -0400)
* AntagSelectionSystemFix

* readded the stuff that shouldn've been deleted in the first place

* re-arrange

* undo indentation

---------

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Content.Server/Antag/AntagSelectionSystem.cs

index 64b26509c48edac48383c3b4ea1282388751f874..270b39b3a28eaeb1914851bc014e93cf83c2e97b 100644 (file)
@@ -18,6 +18,7 @@ using Content.Shared.GameTicking;
 using Content.Shared.GameTicking.Components;
 using Content.Shared.Ghost;
 using Content.Shared.Humanoid;
+using Content.Shared.Mind;
 using Content.Shared.Players;
 using Content.Shared.Preferences.Loadouts;
 using Content.Shared.Roles;
@@ -231,7 +232,7 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
 
         for (var i = 0; i < count; i++)
         {
-            var session = (ICommonSession?) null;
+            var session = (ICommonSession?)null;
             if (picking)
             {
                 if (!playerPool.TryPickAndTake(RobustRandom, out session) && noSpawner)
@@ -341,13 +342,19 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
 
         if (session != null)
         {
-            var curMind = _mind.CreateMind(session.UserId, Name(antagEnt.Value));
-            _mind.SetUserId(curMind, session.UserId);
-
-            _mind.TransferTo(curMind, antagEnt, ghostCheckOverride: true);
-            _role.MindAddRoles(curMind, def.MindComponents, null, true);
-            ent.Comp.SelectedMinds.Add((curMind, Name(player)));
+            var curMind = session.GetMind();
+            
+            if (curMind == null || 
+                !TryComp<MindComponent>(curMind.Value, out var mindComp) ||
+                mindComp.OwnedEntity != antagEnt)
+            {
+                curMind = _mind.CreateMind(session.UserId, Name(antagEnt.Value));
+                _mind.SetUserId(curMind.Value, session.UserId);
+            }
 
+            _mind.TransferTo(curMind.Value, antagEnt, ghostCheckOverride: true);
+            _role.MindAddRoles(curMind.Value, def.MindComponents, null, true);
+            ent.Comp.SelectedMinds.Add((curMind.Value, Name(player)));
             SendBriefing(session, def.Briefing);
         }
 
@@ -460,7 +467,7 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
 
     private void OnObjectivesTextGetInfo(Entity<AntagSelectionComponent> ent, ref ObjectivesTextGetInfoEvent args)
     {
-        if (ent.Comp.AgentName is not {} name)
+        if (ent.Comp.AgentName is not { } name)
             return;
 
         args.Minds = ent.Comp.SelectedMinds;