@@ -69,7 +69,7 @@ public sealed class MindSystem : SharedMindSystem
|
||||
TransferTo(mindId, null, createGhost: false, mind: mind);
|
||||
DebugTools.AssertNull(mind.OwnedEntity);
|
||||
|
||||
if (!component.GhostOnShutdown || mind.Session == null || _gameTicker.RunLevel == GameRunLevel.PreRoundLobby)
|
||||
if (!component.GhostOnShutdown || _gameTicker.RunLevel == GameRunLevel.PreRoundLobby)
|
||||
return;
|
||||
|
||||
var ghost = _ghosts.SpawnGhost((mindId, mind), uid);
|
||||
@@ -93,16 +93,6 @@ public sealed class MindSystem : SharedMindSystem
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICommonSession? GetSession(MindComponent mind)
|
||||
{
|
||||
return mind.Session;
|
||||
}
|
||||
|
||||
public bool TryGetSession(MindComponent mind, [NotNullWhen(true)] out ICommonSession? session)
|
||||
{
|
||||
return (session = GetSession(mind)) != null;
|
||||
}
|
||||
|
||||
public override void WipeAllMinds()
|
||||
{
|
||||
base.WipeAllMinds();
|
||||
@@ -144,10 +134,10 @@ public sealed class MindSystem : SharedMindSystem
|
||||
|
||||
// Do this AFTER the entity changes above as this will fire off a player-detached event
|
||||
// which will run ghosting twice.
|
||||
if (GetSession(mind) is { } session)
|
||||
if (_players.TryGetSessionById(mind.UserId, out var session))
|
||||
_players.SetAttachedEntity(session, entity);
|
||||
|
||||
Log.Info($"Session {mind.Session?.Name} visiting entity {entity}.");
|
||||
Log.Info($"Session {session?.Name} visiting entity {entity}.");
|
||||
}
|
||||
|
||||
public override void UnVisit(EntityUid mindId, MindComponent? mind = null)
|
||||
@@ -162,17 +152,19 @@ public sealed class MindSystem : SharedMindSystem
|
||||
|
||||
RemoveVisitingEntity(mindId, mind);
|
||||
|
||||
if (mind.Session == null || mind.Session.AttachedEntity == mind.VisitingEntity)
|
||||
if (mind.UserId == null || !_players.TryGetSessionById(mind.UserId.Value, out var session))
|
||||
return;
|
||||
|
||||
if (session.AttachedEntity == mind.VisitingEntity)
|
||||
return;
|
||||
|
||||
var owned = mind.OwnedEntity;
|
||||
if (GetSession(mind) is { } session)
|
||||
_players.SetAttachedEntity(session, owned);
|
||||
_players.SetAttachedEntity(session, owned);
|
||||
|
||||
if (owned.HasValue)
|
||||
{
|
||||
_adminLogger.Add(LogType.Mind, LogImpact.Low,
|
||||
$"{mind.Session.Name} returned to {ToPrettyString(owned.Value)}");
|
||||
$"{session.Name} returned to {ToPrettyString(owned.Value)}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +191,8 @@ public sealed class MindSystem : SharedMindSystem
|
||||
if (TryComp<ActorComponent>(entity.Value, out var actor))
|
||||
{
|
||||
// Happens when transferring to your currently visited entity.
|
||||
if (actor.PlayerSession != mind.Session)
|
||||
if (!_players.TryGetSessionByEntity(entity.Value, out var session) ||
|
||||
mind.UserId == null || actor.PlayerSession != session )
|
||||
{
|
||||
throw new ArgumentException("Visit target already has a session.", nameof(entity));
|
||||
}
|
||||
@@ -253,12 +246,12 @@ public sealed class MindSystem : SharedMindSystem
|
||||
}
|
||||
|
||||
// Player is CURRENTLY connected.
|
||||
var session = GetSession(mind);
|
||||
if (session != null && !alreadyAttached && mind.VisitingEntity == null)
|
||||
if (mind.UserId != null && _players.TryGetSessionById(mind.UserId.Value, out var userSession)
|
||||
&& !alreadyAttached && mind.VisitingEntity == null)
|
||||
{
|
||||
_players.SetAttachedEntity(session, entity, true);
|
||||
DebugTools.Assert(session.AttachedEntity == entity, $"Failed to attach entity.");
|
||||
Log.Info($"Session {session.Name} transferred to entity {entity}.");
|
||||
_players.SetAttachedEntity(userSession, entity, true);
|
||||
DebugTools.Assert(userSession.AttachedEntity == entity, "Failed to attach entity.");
|
||||
Log.Info($"Session {userSession.Name} transferred to entity {entity}.");
|
||||
}
|
||||
|
||||
if (entity != null)
|
||||
@@ -288,18 +281,18 @@ public sealed class MindSystem : SharedMindSystem
|
||||
return;
|
||||
|
||||
Dirty(mindId, mind);
|
||||
var netMind = GetNetEntity(mindId);
|
||||
_pvsOverride.ClearOverride(netMind);
|
||||
|
||||
if (userId != null && !_players.TryGetPlayerData(userId.Value, out _))
|
||||
{
|
||||
Log.Error($"Attempted to set mind user to invalid value {userId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mind.Session != null)
|
||||
// Clear any existing entity attachment
|
||||
if (_players.TryGetSessionById(mind.UserId, out var oldSession))
|
||||
{
|
||||
_players.SetAttachedEntity(GetSession(mind), null);
|
||||
mind.Session = null;
|
||||
_players.SetAttachedEntity(oldSession, null);
|
||||
_pvsOverride.RemoveSessionOverride(mindId, oldSession);
|
||||
}
|
||||
|
||||
if (mind.UserId != null)
|
||||
@@ -311,10 +304,7 @@ public sealed class MindSystem : SharedMindSystem
|
||||
}
|
||||
|
||||
if (userId == null)
|
||||
{
|
||||
DebugTools.AssertNull(mind.Session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UserMinds.TryGetValue(userId.Value, out var oldMindId) &&
|
||||
TryComp(oldMindId, out MindComponent? oldMind))
|
||||
@@ -333,11 +323,10 @@ public sealed class MindSystem : SharedMindSystem
|
||||
if (_players.GetPlayerData(userId.Value).ContentData() is { } data)
|
||||
data.Mind = mindId;
|
||||
|
||||
if (_players.TryGetSessionById(userId.Value, out var ret))
|
||||
if (_players.TryGetSessionById(userId.Value, out var session))
|
||||
{
|
||||
mind.Session = ret;
|
||||
_pvsOverride.AddSessionOverride(mindId, ret);
|
||||
_players.SetAttachedEntity(ret, mind.CurrentEntity);
|
||||
_pvsOverride.AddSessionOverride(mindId, session);
|
||||
_players.SetAttachedEntity(session, mind.CurrentEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user