Command resolve killing and LEC conversions batch 2 (#38367)

commit progress
This commit is contained in:
Kyle Tyo
2025-06-17 14:01:28 -04:00
committed by GitHub
parent 57babe15ee
commit 0e1ff2644f
18 changed files with 130 additions and 126 deletions

View File

@@ -7,41 +7,40 @@ using Robust.Shared.Console;
namespace Content.Server.Power
{
[AdminCommand(AdminFlags.Debug)]
public sealed class SetBatteryPercentCommand : IConsoleCommand
public sealed class SetBatteryPercentCommand : LocalizedEntityCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly BatterySystem _batterySystem = default!;
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} <id> <percent>";
public override string Command => "setbatterypercent";
public void Execute(IConsoleShell shell, string argStr, string[] args)
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteLine($"Invalid amount of arguments.\n{Help}");
shell.WriteLine(Loc.GetString($"shell-wrong-arguments-number-need-specific",
("properAmount", 2),
("currentAmount", args.Length)));
return;
}
if (!NetEntity.TryParse(args[0], out var netEnt) || !_entManager.TryGetEntity(netEnt, out var id))
if (!NetEntity.TryParse(args[0], out var netEnt) || !EntityManager.TryGetEntity(netEnt, out var id))
{
shell.WriteLine($"{args[0]} is not a valid entity id.");
shell.WriteLine(Loc.GetString($"shell-invalid-entity-uid", ("uid", args[0])));
return;
}
if (!float.TryParse(args[1], out var percent))
{
shell.WriteLine($"{args[1]} is not a valid float (percentage).");
shell.WriteLine(Loc.GetString($"cmd-setbatterypercent-not-valid-percent", ("arg", args[1])));
return;
}
if (!_entManager.TryGetComponent<BatteryComponent>(id, out var battery))
if (!EntityManager.TryGetComponent<BatteryComponent>(id, out var battery))
{
shell.WriteLine($"No battery found with id {id}.");
shell.WriteLine(Loc.GetString($"cmd-setbatterypercent-battery-not-found", ("id", id)));
return;
}
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<BatterySystem>();
system.SetCharge(id.Value, battery.MaxCharge * percent / 100, battery);
_batterySystem.SetCharge(id.Value, battery.MaxCharge * percent / 100, battery);
// Don't acknowledge b/c people WILL forall this
}
}