Files
crystall-punk-14/Content.Server/Administration/Commands/AGhost.cs

73 lines
2.8 KiB
C#
Raw Normal View History

using Content.Server.GameTicking;
using Content.Shared.Administration;
2021-08-06 00:02:36 -07:00
using Content.Shared.Ghost;
using Content.Shared.Mind;
using Robust.Shared.Console;
2018-09-20 18:19:04 +02:00
namespace Content.Server.Administration.Commands
2018-09-20 18:19:04 +02:00
{
[AdminCommand(AdminFlags.Admin)]
public sealed class AGhost : IConsoleCommand
2018-09-20 18:19:04 +02:00
{
2021-12-05 18:09:01 +01:00
[Dependency] private readonly IEntityManager _entities = default!;
2018-09-20 18:19:04 +02:00
public string Command => "aghost";
public string Description => "Makes you an admin ghost.";
public string Help => "aghost";
public void Execute(IConsoleShell shell, string argStr, string[] args)
2018-09-20 18:19:04 +02:00
{
var player = shell.Player;
2018-09-20 18:19:04 +02:00
if (player == null)
{
shell.WriteLine("Nah");
2018-09-20 18:19:04 +02:00
return;
}
var mindSystem = _entities.System<SharedMindSystem>();
if (!mindSystem.TryGetMind(player, out var mindId, out var mind))
{
shell.WriteLine("You can't ghost here!");
return;
}
var metaDataSystem = _entities.System<MetaDataSystem>();
2023-06-18 11:33:19 -07:00
if (mind.VisitingEntity != default && _entities.TryGetComponent<GhostComponent>(mind.VisitingEntity, out var oldGhostComponent))
2018-09-20 18:19:04 +02:00
{
mindSystem.UnVisit(mindId, mind);
2023-06-18 11:33:19 -07:00
// If already an admin ghost, then return to body.
if (oldGhostComponent.CanGhostInteract)
return;
2018-09-20 18:19:04 +02:00
}
var canReturn = mind.CurrentEntity != null
&& !_entities.HasComponent<GhostComponent>(mind.CurrentEntity);
2021-12-06 15:34:46 +01:00
var coordinates = player.AttachedEntity != null
? _entities.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates
2021-12-05 18:09:01 +01:00
: EntitySystem.Get<GameTicker>().GetObserverSpawnPoint();
var ghost = _entities.SpawnEntity(GameTicker.AdminObserverPrototypeName, coordinates);
_entities.GetComponent<TransformComponent>(ghost).AttachToGridOrMap();
if (canReturn)
{
// TODO: Remove duplication between all this and "GamePreset.OnGhostAttempt()"...
if (!string.IsNullOrWhiteSpace(mind.CharacterName))
metaDataSystem.SetEntityName(ghost, mind.CharacterName);
else if (!string.IsNullOrWhiteSpace(mind.Session?.Name))
metaDataSystem.SetEntityName(ghost, mind.Session.Name);
mindSystem.Visit(mindId, ghost, mind);
2018-09-20 18:19:04 +02:00
}
else
{
metaDataSystem.SetEntityName(ghost, player.Name);
mindSystem.TransferTo(mindId, ghost, mind: mind);
}
2021-12-05 18:09:01 +01:00
var comp = _entities.GetComponent<GhostComponent>(ghost);
2021-08-06 00:02:36 -07:00
EntitySystem.Get<SharedGhostSystem>().SetCanReturnToBody(comp, canReturn);
2018-09-20 18:19:04 +02:00
}
}
}