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;
for (var i = 0; i < count; i++)
{
- var session = (ICommonSession?) null;
+ var session = (ICommonSession?)null;
if (picking)
{
if (!playerPool.TryPickAndTake(RobustRandom, out session) && noSpawner)
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);
}
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;