Files
crystall-punk-14/Content.Server/Ghost/Roles/MakeGhostRoleCommand.cs

71 lines
2.7 KiB
C#
Raw Normal View History

using Content.Server.Administration;
2021-06-09 22:19:39 +02:00
using Content.Server.Ghost.Roles.Components;
2021-02-16 09:51:27 +01:00
using Content.Shared.Administration;
using Content.Shared.Mind.Components;
2021-02-16 09:51:27 +01:00
using Robust.Shared.Console;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Ghost.Roles
2021-02-16 09:51:27 +01:00
{
[AdminCommand(AdminFlags.Admin)]
public sealed class MakeGhostRoleCommand : IConsoleCommand
2021-02-16 09:51:27 +01:00
{
[Dependency] private readonly IEntityManager _entManager = default!;
2021-02-16 09:51:27 +01:00
public string Command => "makeghostrole";
public string Description => "Turns an entity into a ghost role.";
public string Help => $"Usage: {Command} <entity uid> <name> <description> [<rules>]";
2021-02-16 09:51:27 +01:00
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 3 || args.Length > 4)
2021-02-16 09:51:27 +01:00
{
shell.WriteLine($"Invalid amount of arguments.\n{Help}");
return;
}
if (!NetEntity.TryParse(args[0], out var uidNet) || !_entManager.TryGetEntity(uidNet, out var uid))
2021-02-16 09:51:27 +01:00
{
shell.WriteLine($"{args[0]} is not a valid entity uid.");
return;
}
if (!_entManager.TryGetComponent(uid, out MetaDataComponent? metaData))
2021-02-16 09:51:27 +01:00
{
shell.WriteLine($"No entity found with uid {uid}");
return;
}
if (_entManager.TryGetComponent(uid, out MindContainerComponent? mind) &&
2021-02-16 09:51:27 +01:00
mind.HasMind)
{
2021-11-09 15:50:55 +01:00
shell.WriteLine($"Entity {metaData.EntityName} with id {uid} already has a mind.");
2021-02-16 09:51:27 +01:00
return;
}
var name = args[1];
var description = args[2];
var rules = args.Length >= 4 ? args[3] : Loc.GetString("ghost-role-component-default-rules");
2021-02-16 09:51:27 +01:00
if (_entManager.TryGetComponent(uid, out GhostRoleComponent? ghostRole))
{
shell.WriteLine($"Entity {metaData.EntityName} with id {uid} already has a {nameof(GhostRoleComponent)}");
return;
}
if (_entManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
2021-02-16 09:51:27 +01:00
{
2021-11-09 15:50:55 +01:00
shell.WriteLine($"Entity {metaData.EntityName} with id {uid} already has a {nameof(GhostTakeoverAvailableComponent)}");
2021-02-16 09:51:27 +01:00
return;
}
ghostRole = _entManager.AddComponent<GhostRoleComponent>(uid.Value);
_entManager.AddComponent<GhostTakeoverAvailableComponent>(uid.Value);
ghostRole.RoleName = name;
ghostRole.RoleDescription = description;
ghostRole.RoleRules = rules;
2021-02-16 09:51:27 +01:00
2021-11-09 15:50:55 +01:00
shell.WriteLine($"Made entity {metaData.EntityName} a ghost role.");
2021-02-16 09:51:27 +01:00
}
}
}