1
0

SetBatteryPercentCommand.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Server.Administration;
  2. using Content.Server.Power.Components;
  3. using Content.Server.Power.EntitySystems;
  4. using Content.Shared.Administration;
  5. using Robust.Shared.Console;
  6. namespace Content.Server.Power
  7. {
  8. [AdminCommand(AdminFlags.Debug)]
  9. public sealed class SetBatteryPercentCommand : IConsoleCommand
  10. {
  11. [Dependency] private readonly IEntityManager _entManager = default!;
  12. public string Command => "setbatterypercent";
  13. public string Description => "Drains or recharges a battery by entity uid and percentage, i.e.: forall with Battery do setbatterypercent $ID 0";
  14. public string Help => $"{Command} <id> <percent>";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. if (args.Length != 2)
  18. {
  19. shell.WriteLine($"Invalid amount of arguments.\n{Help}");
  20. return;
  21. }
  22. if (!NetEntity.TryParse(args[0], out var netEnt) || !_entManager.TryGetEntity(netEnt, out var id))
  23. {
  24. shell.WriteLine($"{args[0]} is not a valid entity id.");
  25. return;
  26. }
  27. if (!float.TryParse(args[1], out var percent))
  28. {
  29. shell.WriteLine($"{args[1]} is not a valid float (percentage).");
  30. return;
  31. }
  32. if (!_entManager.TryGetComponent<BatteryComponent>(id, out var battery))
  33. {
  34. shell.WriteLine($"No battery found with id {id}.");
  35. return;
  36. }
  37. var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<BatterySystem>();
  38. system.SetCharge(id.Value, battery.MaxCharge * percent / 100, battery);
  39. // Don't acknowledge b/c people WILL forall this
  40. }
  41. }
  42. }