From 5247878060a9245240bf51deb14b5bbc78e8bea8 Mon Sep 17 00:00:00 2001 From: NakataRin <45946146+NakataRin@users.noreply.github.com> Date: Wed, 7 Aug 2024 07:38:47 +0400 Subject: [PATCH] Fix Mind Transfer and Role Assignment Logic for Antagonists (#30711) * 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 | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Content.Server/Antag/AntagSelectionSystem.cs b/Content.Server/Antag/AntagSelectionSystem.cs index 64b26509c48e..270b39b3a28e 100644 --- a/Content.Server/Antag/AntagSelectionSystem.cs +++ b/Content.Server/Antag/AntagSelectionSystem.cs @@ -18,6 +18,7 @@ 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 void ChooseAntags(Entity ent, IList ent, ICommonSession? sessi 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(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 bool IsEntityValid(EntityUid? entity, AntagSelectionDefinition def) private void OnObjectivesTextGetInfo(Entity ent, ref ObjectivesTextGetInfoEvent args) { - if (ent.Comp.AgentName is not {} name) + if (ent.Comp.AgentName is not { } name) return; args.Minds = ent.Comp.SelectedMinds;