MakeGhostRoleCommand.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Content.Server.Administration;
  2. using Content.Server.Ghost.Roles.Components;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Mind.Components;
  5. using Robust.Shared.Console;
  6. namespace Content.Server.Ghost.Roles
  7. {
  8. [AdminCommand(AdminFlags.Admin)]
  9. public sealed class MakeGhostRoleCommand : IConsoleCommand
  10. {
  11. [Dependency] private readonly IEntityManager _entManager = default!;
  12. public string Command => "makeghostrole";
  13. public string Description => "Turns an entity into a ghost role.";
  14. public string Help => $"Usage: {Command} <entity uid> <name> <description> [<rules>]";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. if (args.Length < 3 || args.Length > 4)
  18. {
  19. shell.WriteLine($"Invalid amount of arguments.\n{Help}");
  20. return;
  21. }
  22. if (!NetEntity.TryParse(args[0], out var uidNet) || !_entManager.TryGetEntity(uidNet, out var uid))
  23. {
  24. shell.WriteLine($"{args[0]} is not a valid entity uid.");
  25. return;
  26. }
  27. if (!_entManager.TryGetComponent(uid, out MetaDataComponent? metaData))
  28. {
  29. shell.WriteLine($"No entity found with uid {uid}");
  30. return;
  31. }
  32. if (_entManager.TryGetComponent(uid, out MindContainerComponent? mind) &&
  33. mind.HasMind)
  34. {
  35. shell.WriteLine($"Entity {metaData.EntityName} with id {uid} already has a mind.");
  36. return;
  37. }
  38. var name = args[1];
  39. var description = args[2];
  40. var rules = args.Length >= 4 ? args[3] : Loc.GetString("ghost-role-component-default-rules");
  41. if (_entManager.TryGetComponent(uid, out GhostRoleComponent? ghostRole))
  42. {
  43. shell.WriteLine($"Entity {metaData.EntityName} with id {uid} already has a {nameof(GhostRoleComponent)}");
  44. return;
  45. }
  46. if (_entManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
  47. {
  48. shell.WriteLine($"Entity {metaData.EntityName} with id {uid} already has a {nameof(GhostTakeoverAvailableComponent)}");
  49. return;
  50. }
  51. ghostRole = _entManager.AddComponent<GhostRoleComponent>(uid.Value);
  52. _entManager.AddComponent<GhostTakeoverAvailableComponent>(uid.Value);
  53. ghostRole.RoleName = name;
  54. ghostRole.RoleDescription = description;
  55. ghostRole.RoleRules = rules;
  56. shell.WriteLine($"Made entity {metaData.EntityName} a ghost role.");
  57. }
  58. }
  59. }