GodModeCommand.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.Damage.Systems;
  4. using Robust.Shared.Console;
  5. namespace Content.Server.Damage.Commands
  6. {
  7. [AdminCommand(AdminFlags.Fun)]
  8. public sealed class GodModeCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. public string Command => "godmode";
  12. public string Description => "Makes your entity or another invulnerable to almost anything. May have irreversible changes.";
  13. public string Help => $"Usage: {Command} / {Command} <entityUid>";
  14. public void Execute(IConsoleShell shell, string argStr, string[] args)
  15. {
  16. var player = shell.Player;
  17. EntityUid entity;
  18. switch (args.Length)
  19. {
  20. case 0:
  21. if (player == null)
  22. {
  23. shell.WriteLine("An entity needs to be specified when the command isn't used by a player.");
  24. return;
  25. }
  26. if (player.AttachedEntity == null)
  27. {
  28. shell.WriteLine("An entity needs to be specified when you aren't attached to an entity.");
  29. return;
  30. }
  31. entity = player.AttachedEntity.Value;
  32. break;
  33. case 1:
  34. if (!NetEntity.TryParse(args[0], out var idNet) || !_entManager.TryGetEntity(idNet, out var id))
  35. {
  36. shell.WriteLine($"{args[0]} isn't a valid entity id.");
  37. return;
  38. }
  39. if (!_entManager.EntityExists(id))
  40. {
  41. shell.WriteLine($"No entity found with id {id}.");
  42. return;
  43. }
  44. entity = id.Value;
  45. break;
  46. default:
  47. shell.WriteLine(Help);
  48. return;
  49. }
  50. var godmodeSystem = _entManager.System<SharedGodmodeSystem>();
  51. var enabled = godmodeSystem.ToggleGodmode(entity);
  52. var name = _entManager.GetComponent<MetaDataComponent>(entity).EntityName;
  53. shell.WriteLine(enabled
  54. ? $"Enabled godmode for entity {name} with id {entity}"
  55. : $"Disabled godmode for entity {name} with id {entity}");
  56. }
  57. }
  58. }