Refactor minds to be entities with components, make roles components (#19591)

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2023-08-28 16:53:24 -07:00
committed by GitHub
parent e0ee397af7
commit 15c0211fb2
119 changed files with 1445 additions and 1289 deletions

View File

@@ -1,6 +1,5 @@
using Content.Server.GameTicking;
using Content.Server.Mind;
using Content.Server.Players;
using Content.Shared.Administration;
using Content.Shared.Ghost;
using Robust.Server.Player;
@@ -26,20 +25,18 @@ namespace Content.Server.Administration.Commands
return;
}
var mind = player.ContentData()?.Mind;
if (mind == null)
var mindSystem = _entities.System<MindSystem>();
if (!mindSystem.TryGetMind(player, out var mindId, out var mind))
{
shell.WriteLine("You can't ghost here!");
return;
}
var mindSystem = _entities.System<MindSystem>();
var metaDataSystem = _entities.System<MetaDataSystem>();
if (mind.VisitingEntity != default && _entities.TryGetComponent<GhostComponent>(mind.VisitingEntity, out var oldGhostComponent))
{
mindSystem.UnVisit(mind);
mindSystem.UnVisit(mindId, mind);
// If already an admin ghost, then return to body.
if (oldGhostComponent.CanGhostInteract)
return;
@@ -61,12 +58,12 @@ namespace Content.Server.Administration.Commands
else if (!string.IsNullOrWhiteSpace(mind.Session?.Name))
metaDataSystem.SetEntityName(ghost, mind.Session.Name);
mindSystem.Visit(mind, ghost);
mindSystem.Visit(mindId, ghost, mind);
}
else
{
metaDataSystem.SetEntityName(ghost, player.Name);
mindSystem.TransferTo(mind, ghost);
mindSystem.TransferTo(mindId, ghost, mind: mind);
}
var comp = _entities.GetComponent<GhostComponent>(ghost);

View File

@@ -1,10 +1,7 @@
using Content.Server.Mind;
using Content.Server.Mind.Components;
using Content.Server.Players;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Utility;
namespace Content.Server.Administration.Commands
{
@@ -45,18 +42,14 @@ namespace Content.Server.Administration.Commands
return;
}
if (!_entities.HasComponent<MindContainerComponent>(target))
var mindSystem = _entities.System<MindSystem>();
if (!mindSystem.TryGetMind(target, out var mindId, out var mind))
{
shell.WriteLine(Loc.GetString("shell-entity-is-not-mob"));
return;
}
var mind = player.ContentData()?.Mind;
DebugTools.AssertNotNull(mind);
var mindSystem = _entities.System<MindSystem>();
mindSystem.TransferTo(mind!, target);
mindSystem.TransferTo(mindId, target, mind: mind);
}
}
}

View File

@@ -68,13 +68,9 @@ namespace Content.Server.Administration.Commands
}
var mindSystem = entityManager.System<MindSystem>();
var metadata = entityManager.GetComponent<MetaDataComponent>(eUid);
var mind = playerCData.Mind;
if (mind == null)
{
mind = mindSystem.CreateMind(session.UserId);
mind.CharacterName = entityManager.GetComponent<MetaDataComponent>(eUid).EntityName;
}
var mind = playerCData.Mind ?? mindSystem.CreateMind(session.UserId, metadata.EntityName);
mindSystem.TransferTo(mind, eUid, ghostOverride);
}