Fix some TryGetMind overrides relying on player data (#26992)
* Fix some TryGetMind overrides relying on player data * A * Rider has bamboozled me * Update `data.Mind` before attaching to entity.
This commit is contained in:
@@ -357,16 +357,17 @@ public sealed class MindSystem : SharedMindSystem
|
||||
mind.UserId = userId;
|
||||
mind.OriginalOwnerUserId ??= userId;
|
||||
|
||||
// The UserId may not have a current session, but user data may still exist for disconnected players.
|
||||
// So we cannot combine this with the TryGetSessionById() check below.
|
||||
if (_players.GetPlayerData(userId.Value).ContentData() is { } data)
|
||||
data.Mind = mindId;
|
||||
|
||||
if (_players.TryGetSessionById(userId.Value, out var ret))
|
||||
{
|
||||
mind.Session = ret;
|
||||
_pvsOverride.AddSessionOverride(netMind, ret);
|
||||
_players.SetAttachedEntity(ret, mind.CurrentEntity);
|
||||
}
|
||||
|
||||
// session may be null, but user data may still exist for disconnected players.
|
||||
if (_players.GetPlayerData(userId.Value).ContentData() is { } data)
|
||||
data.Mind = mindId;
|
||||
}
|
||||
|
||||
public void ControlMob(EntityUid user, EntityUid target)
|
||||
|
||||
@@ -26,6 +26,7 @@ public abstract class SharedMindSystem : EntitySystem
|
||||
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
|
||||
[Dependency] private readonly SharedPlayerSystem _player = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metadata = default!;
|
||||
[Dependency] private readonly ISharedPlayerManager _playerMan = default!;
|
||||
|
||||
[ViewVariables]
|
||||
protected readonly Dictionary<NetUserId, EntityUid> UserMinds = new();
|
||||
@@ -107,6 +108,7 @@ public abstract class SharedMindSystem : EntitySystem
|
||||
TryComp(mindIdValue, out mind))
|
||||
{
|
||||
DebugTools.Assert(mind.UserId == user);
|
||||
|
||||
mindId = mindIdValue;
|
||||
return true;
|
||||
}
|
||||
@@ -422,29 +424,26 @@ public abstract class SharedMindSystem : EntitySystem
|
||||
return TryComp(mindId, out mind);
|
||||
}
|
||||
|
||||
public bool TryGetMind(
|
||||
ContentPlayerData contentPlayer,
|
||||
out EntityUid mindId,
|
||||
[NotNullWhen(true)] out MindComponent? mind)
|
||||
{
|
||||
mindId = contentPlayer.Mind ?? default;
|
||||
return TryComp(mindId, out mind);
|
||||
}
|
||||
|
||||
// TODO MIND make this return a nullable EntityUid or Entity<MindComponent>
|
||||
public bool TryGetMind(
|
||||
ICommonSession? player,
|
||||
out EntityUid mindId,
|
||||
[NotNullWhen(true)] out MindComponent? mind)
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
mindId = default;
|
||||
mind = null;
|
||||
if (_player.ContentData(player) is not { } data)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryGetMind(data, out mindId, out mind))
|
||||
if (TryGetMind(player.UserId, out var mindUid, out mind))
|
||||
{
|
||||
mindId = mindUid.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
DebugTools.AssertNull(data.Mind);
|
||||
mindId = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user