ElectrocuteCommand.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.StatusEffect;
  4. using Robust.Shared.Console;
  5. namespace Content.Server.Electrocution
  6. {
  7. [AdminCommand(AdminFlags.Fun)]
  8. public sealed class ElectrocuteCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. public string Command => "electrocute";
  12. public string Description => Loc.GetString("electrocute-command-description");
  13. public string Help => $"{Command} <uid> <seconds> <damage>";
  14. [ValidatePrototypeId<StatusEffectPrototype>]
  15. public const string ElectrocutionStatusEffect = "Electrocution";
  16. public void Execute(IConsoleShell shell, string argStr, string[] args)
  17. {
  18. if (args.Length < 1)
  19. {
  20. // TODO: Localize this.
  21. shell.WriteError("Not enough arguments!");
  22. return;
  23. }
  24. if (!NetEntity.TryParse(args[0], out var uidNet) ||
  25. !_entManager.TryGetEntity(uidNet, out var uid) ||
  26. !_entManager.EntityExists(uid))
  27. {
  28. shell.WriteError($"Invalid entity specified!");
  29. return;
  30. }
  31. if (!_entManager.EntitySysManager.GetEntitySystem<StatusEffectsSystem>().CanApplyEffect(uid.Value, ElectrocutionStatusEffect))
  32. {
  33. shell.WriteError(Loc.GetString("electrocute-command-entity-cannot-be-electrocuted"));
  34. return;
  35. }
  36. if (args.Length < 2 || !int.TryParse(args[1], out var seconds))
  37. {
  38. seconds = 10;
  39. }
  40. if (args.Length < 3 || !int.TryParse(args[2], out var damage))
  41. {
  42. damage = 10;
  43. }
  44. _entManager.EntitySysManager.GetEntitySystem<ElectrocutionSystem>()
  45. .TryDoElectrocution(uid.Value, null, damage, TimeSpan.FromSeconds(seconds), refresh: true, ignoreInsulation: true);
  46. }
  47. }
  48. }