diff --git a/Content.Server/Power/DrainAllBatteriesCommand.cs b/Content.Server/Power/DrainAllBatteriesCommand.cs deleted file mode 100644 index 6e6b3fb354..0000000000 --- a/Content.Server/Power/DrainAllBatteriesCommand.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Content.Server.Administration; -using Content.Server.Power.Components; -using Content.Shared.Administration; -using Robust.Shared.Console; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; - -namespace Content.Server.Power -{ - [AdminCommand(AdminFlags.Admin)] - public class DrainAllBatteriesCommand : IConsoleCommand - { - public string Command => "drainallbatteries"; - public string Description => "Drains *all* batteries. Useful to make sure that an engine provides enough power to sustain the station."; - public string Help => $"{Command}"; - - public void Execute(IConsoleShell shell, string argStr, string[] args) - { - if (args.Length != 0) - { - shell.WriteLine($"Invalid amount of arguments: {args.Length}.\n{Help}"); - return; - } - - var entMan = IoCManager.Resolve(); - foreach (var batteryComp in entMan.EntityQuery()) - { - batteryComp.CurrentCharge = 0; - } - - shell.WriteLine("Done!"); - } - } -} diff --git a/Content.Server/Power/SetBatteryPercentCommand.cs b/Content.Server/Power/SetBatteryPercentCommand.cs new file mode 100644 index 0000000000..5fff0ca941 --- /dev/null +++ b/Content.Server/Power/SetBatteryPercentCommand.cs @@ -0,0 +1,49 @@ +using Content.Server.Administration; +using Content.Server.Power.Components; +using Content.Server.Items; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; + +namespace Content.Server.Power +{ + [AdminCommand(AdminFlags.Admin)] + public class SetBatteryPercentCommand : IConsoleCommand + { + public string Command => "setbatterypercent"; + public string Description => "Drains or recharges a battery by entity uid and percentage, i.e.: forall with Battery do setbatterypercent $ID 0"; + public string Help => $"{Command} "; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 2) + { + shell.WriteLine($"Invalid amount of arguments.\n{Help}"); + return; + } + + if (!EntityUid.TryParse(args[0], out var id)) + { + shell.WriteLine($"{args[0]} is not a valid entity id."); + return; + } + + if (!float.TryParse(args[1], out var percent)) + { + shell.WriteLine($"{args[1]} is not a valid float (percentage)."); + return; + } + + var entityManager = IoCManager.Resolve(); + + if (!entityManager.TryGetComponent(id, out var battery)) + { + shell.WriteLine($"No battery found with id {id}."); + return; + } + battery.CurrentCharge = (battery.MaxCharge * percent) / 100; + // Don't acknowledge b/c people WILL forall this + } + } +}