Misc mind tweaks and fixes (#20614)

This commit is contained in:
Leon Friedrich
2023-10-07 12:00:48 +11:00
committed by GitHub
parent ec452aa4a3
commit 427cae2d25
6 changed files with 98 additions and 12 deletions

View File

@@ -8,13 +8,11 @@ using Content.Shared.Interaction.Events;
using Content.Shared.Mind.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Objectives;
using Content.Shared.Objectives.Systems;
using Content.Shared.Players;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Mind;
@@ -25,6 +23,7 @@ public abstract class SharedMindSystem : EntitySystem
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
[Dependency] private readonly SharedPlayerSystem _player = default!;
[Dependency] private readonly MetaDataSystem _metadata = default!;
// This is dictionary is required to track the minds of disconnected players that may have had their entity deleted.
protected readonly Dictionary<NetUserId, EntityUid> UserMinds = new();
@@ -132,12 +131,11 @@ public abstract class SharedMindSystem : EntitySystem
public EntityUid CreateMind(NetUserId? userId, string? name = null)
{
var mindId = Spawn(null, MapCoordinates.Nullspace);
_metadata.SetEntityName(mindId, name == null ? "mind" : $"mind ({name})");
var mind = EnsureComp<MindComponent>(mindId);
mind.CharacterName = name;
SetUserId(mindId, userId, mind);
Dirty(mindId, MetaData(mindId));
return mindId;
}
@@ -343,7 +341,14 @@ public abstract class SharedMindSystem : EntitySystem
{
mindId = default;
mind = null;
return _player.ContentData(player) is { } data && TryGetMind(data, out mindId, out mind);
if (_player.ContentData(player) is not { } data)
return false;
if (TryGetMind(data, out mindId, out mind))
return true;
DebugTools.AssertNull(data.Mind);
return false;
}
/// <summary>