Power stat and nuke codes commands get some LEC love. (#38585)

* commit

* requested changes.
This commit is contained in:
Kyle Tyo
2025-06-29 21:41:55 -04:00
committed by GitHub
parent cd2ce56aef
commit 34825464dc
4 changed files with 57 additions and 59 deletions

View File

@@ -1,55 +1,48 @@
using Content.Server.Administration; using Content.Server.Administration;
using Content.Server.Station.Components; using Content.Server.Station.Components;
using Content.Shared.Administration; using Content.Shared.Administration;
using JetBrains.Annotations;
using Robust.Shared.Console; using Robust.Shared.Console;
namespace Content.Server.Nuke.Commands namespace Content.Server.Nuke.Commands;
[AdminCommand(AdminFlags.Fun)]
public sealed class SendNukeCodesCommand : LocalizedEntityCommands
{ {
[UsedImplicitly] [Dependency] private readonly NukeCodePaperSystem _nukeCodeSystem = default!;
[AdminCommand(AdminFlags.Fun)]
public sealed class SendNukeCodesCommand : IConsoleCommand public override string Command => "nukecodes";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
public string Command => "nukecodes"; if (args.Length != 1)
public string Description => "Send nuke codes to a station's communication consoles";
public string Help => "nukecodes [station EntityUid]";
[Dependency] private readonly IEntityManager _entityManager = default!;
public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
if (args.Length != 1) shell.WriteError(Loc.GetString("shell-need-exactly-one-argument"));
{ return;
shell.WriteError(Loc.GetString("shell-need-exactly-one-argument"));
return;
}
if (!NetEntity.TryParse(args[0], out var uidNet) || !_entityManager.TryGetEntity(uidNet, out var uid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
_entityManager.System<NukeCodePaperSystem>().SendNukeCodes(uid.Value);
} }
public CompletionResult GetCompletion(IConsoleShell shell, string[] args) if (!NetEntity.TryParse(args[0], out var uidNet) || !EntityManager.TryGetEntity(uidNet, out var uid))
{ {
if (args.Length != 1) shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
{ return;
return CompletionResult.Empty;
}
var stations = new List<CompletionOption>();
var query = _entityManager.EntityQueryEnumerator<StationDataComponent>();
while (query.MoveNext(out var uid, out var stationData))
{
var meta = _entityManager.GetComponent<MetaDataComponent>(uid);
stations.Add(new CompletionOption(uid.ToString(), meta.EntityName));
}
return CompletionResult.FromHintOptions(stations, null);
} }
_nukeCodeSystem.SendNukeCodes(uid.Value);
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length != 1)
return CompletionResult.Empty;
var stations = new List<CompletionOption>();
var query = EntityManager.EntityQueryEnumerator<StationDataComponent>();
while (query.MoveNext(out var uid, out _))
{
var meta = EntityManager.GetComponent<MetaDataComponent>(uid);
stations.Add(new CompletionOption(uid.ToString(), meta.EntityName));
}
return CompletionResult.FromHintOptions(stations, null);
} }
} }

View File

@@ -3,25 +3,22 @@ using Content.Server.Power.EntitySystems;
using Content.Shared.Administration; using Content.Shared.Administration;
using Robust.Shared.Console; using Robust.Shared.Console;
namespace Content.Server.Power.Commands namespace Content.Server.Power.Commands;
[AdminCommand(AdminFlags.Debug)]
public sealed class PowerStatCommand : LocalizedEntityCommands
{ {
[AdminCommand(AdminFlags.Debug)] [Dependency] private readonly PowerNetSystem _powerNet = default!;
public sealed class PowerStatCommand : IConsoleCommand
public override string Command => "powerstat";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
[Dependency] private readonly IEntityManager _e = default!; var stats = _powerNet.GetStatistics();
shell.WriteLine(Loc.GetString("cmd-powerstat-output",
public string Command => "powerstat"; ("networks", stats.CountNetworks),
public string Description => "Shows statistics for pow3r"; ("loads", stats.CountLoads),
public string Help => "Usage: powerstat"; ("supplies", stats.CountSupplies),
("batteries", stats.CountBatteries)));
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var stats = _e.System<PowerNetSystem>().GetStatistics();
shell.WriteLine($"networks: {stats.CountNetworks}");
shell.WriteLine($"loads: {stats.CountLoads}");
shell.WriteLine($"supplies: {stats.CountSupplies}");
shell.WriteLine($"batteries: {stats.CountBatteries}");
}
} }
} }

View File

@@ -0,0 +1,2 @@
cmd-nukecodes-desc = Send nuke codes to a station's communication consoles.
cmd-nukecodes-help = Usage: nukecodes <entityUid>

View File

@@ -0,0 +1,6 @@
cmd-powerstat-desc = Shows statistics for pow3r.
cmd-powerstat-help = Usage: powerstat
cmd-powerstat-output = Networks: {$networks}
Loads: {$loads}
Supplies: {$supplies}
Batteries: {$batteries}