From 23bc33a7aa929727564dde706699d462228ccef4 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Thu, 13 May 2021 00:12:36 +0100 Subject: [PATCH] `drainallbatteries` - a command for testing low-power conditions (#3983) --- .../Commands/DrainAllBatteriesCommand.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Content.Server/Commands/DrainAllBatteriesCommand.cs diff --git a/Content.Server/Commands/DrainAllBatteriesCommand.cs b/Content.Server/Commands/DrainAllBatteriesCommand.cs new file mode 100644 index 0000000000..1a5a639cdf --- /dev/null +++ b/Content.Server/Commands/DrainAllBatteriesCommand.cs @@ -0,0 +1,35 @@ +#nullable enable +using Content.Server.Administration; +using Content.Server.GameObjects.Components.Power; +using Content.Shared.Administration; +using Content.Shared.GameObjects.Components; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; + +namespace Content.Server.Commands +{ + [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 entityManager = IoCManager.Resolve(); + foreach (var ent in entityManager.GetEntities(new TypeEntityQuery(typeof(BatteryComponent)))) + { + ent.GetComponent().CurrentCharge = 0; + } + shell.WriteLine("Done!"); + } + } +}