Files
crystall-punk-14/Content.Server/Shuttles/Commands/DockCommand.cs

68 lines
2.5 KiB
C#
Raw Normal View History

2022-01-26 10:36:19 +11:00
using Content.Server.Administration;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Systems;
2022-01-26 10:36:19 +11:00
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Shuttles.Commands;
2022-01-26 10:36:19 +11:00
[AdminCommand(AdminFlags.Mapping)]
public sealed class DockCommand : LocalizedEntityCommands
2022-01-26 10:36:19 +11:00
{
[Dependency] private readonly DockingSystem _dockSystem = default!;
2023-03-23 16:10:49 +11:00
public override string Command => "dock";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
2022-01-26 10:36:19 +11:00
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number-need-specific",
("properAmount", 2),
("currentAmount", args.Length)));
2022-01-26 10:36:19 +11:00
return;
}
if (!NetEntity.TryParse(args[0], out var airlock1Net) || !EntityManager.TryGetEntity(airlock1Net, out var airlock1))
2022-01-26 10:36:19 +11:00
{
shell.WriteError(Loc.GetString("shell-invalid-entity-uid", ("uid", args[0])));
2022-01-26 10:36:19 +11:00
return;
}
if (!NetEntity.TryParse(args[1], out var airlock2Net) || !EntityManager.TryGetEntity(airlock2Net, out var airlock2))
2022-01-26 10:36:19 +11:00
{
shell.WriteError(Loc.GetString("shell-invalid-entity-uid", ("uid", args[1])));
2022-01-26 10:36:19 +11:00
return;
}
if (!EntityManager.TryGetComponent(airlock1, out DockingComponent? dock1))
2022-01-26 10:36:19 +11:00
{
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", args[0]), ("componentName", nameof(DockingComponent))));
2022-01-26 10:36:19 +11:00
return;
}
if (!EntityManager.TryGetComponent(airlock2, out DockingComponent? dock2))
2022-01-26 10:36:19 +11:00
{
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", args[1]), ("componentName", nameof(DockingComponent))));
2022-01-26 10:36:19 +11:00
return;
}
_dockSystem.Dock((airlock1.Value, dock1), (airlock2.Value, dock2));
if (dock1.DockedWith == airlock2)
shell.WriteLine(Loc.GetString("cmd-dock-success"));
else
shell.WriteError(Loc.GetString("cmd-dock-fail"));
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
return args.Length switch
{
1 => CompletionResult.FromOptions(CompletionHelper.Components<DockingComponent>(args[0], EntityManager)),
2 => CompletionResult.FromOptions(CompletionHelper.Components<DockingComponent>(args[1], EntityManager)),
_ => CompletionResult.Empty,
};
2022-01-26 10:36:19 +11:00
}
}