Skip to content

Commit

Permalink
Fix Mind Transfer and Role Assignment Logic for Antagonists (#30711)
Browse files Browse the repository at this point in the history
* AntagSelectionSystemFix

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

* re-arrange

* undo indentation

---------

Co-authored-by: Nemanja <[email protected]>
  • Loading branch information
NakataRin and EmoGarbage404 authored Aug 7, 2024
1 parent 05630bd commit 5247878
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions Content.Server/Antag/AntagSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -231,7 +232,7 @@ public void ChooseAntags(Entity<AntagSelectionComponent> ent, IList<ICommonSessi

for (var i = 0; i < count; i++)
{
var session = (ICommonSession?) null;
var session = (ICommonSession?)null;
if (picking)
{
if (!playerPool.TryPickAndTake(RobustRandom, out session) && noSpawner)
Expand Down Expand Up @@ -341,13 +342,19 @@ public void MakeAntag(Entity<AntagSelectionComponent> 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<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);
}

Expand Down Expand Up @@ -460,7 +467,7 @@ public bool IsEntityValid(EntityUid? entity, AntagSelectionDefinition def)

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;
Expand Down

0 comments on commit 5247878

Please sign in to comment.