2024-09-01 14:00:53 +03:00
using System.Diagnostics ;
2023-08-02 16:09:08 -05:00
using System.Linq ;
using Content.Server.Administration ;
2024-01-03 19:34:47 -05:00
using Content.Server.Cargo.Systems ;
2023-08-02 16:09:08 -05:00
using Content.Server.Station.Components ;
using Content.Server.Station.Systems ;
using Content.Shared.Administration ;
using Robust.Shared.Toolshed ;
using Robust.Shared.Toolshed.Errors ;
using Robust.Shared.Toolshed.Syntax ;
using Robust.Shared.Utility ;
namespace Content.Server.Station.Commands ;
[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
public sealed class StationsCommand : ToolshedCommand
{
private StationSystem ? _station ;
2024-01-03 19:34:47 -05:00
private CargoSystem ? _cargo ;
2023-08-02 16:09:08 -05:00
[CommandImplementation("list")]
public IEnumerable < EntityUid > List ( )
{
_station ? ? = GetSys < StationSystem > ( ) ;
return _station . GetStationsSet ( ) ;
}
[CommandImplementation("get")]
2024-12-21 17:45:48 +11:00
public EntityUid Get ( IInvocationContext ctx )
2023-08-02 16:09:08 -05:00
{
_station ? ? = GetSys < StationSystem > ( ) ;
var set = _station . GetStationsSet ( ) ;
if ( set . Count > 1 | | set . Count = = 0 )
ctx . ReportError ( new OnlyOneStationsError ( ) ) ;
return set . FirstOrDefault ( ) ;
}
[CommandImplementation("getowningstation")]
public IEnumerable < EntityUid ? > GetOwningStation ( [ PipedArgument ] IEnumerable < EntityUid > input )
= > input . Select ( GetOwningStation ) ;
[CommandImplementation("getowningstation")]
public EntityUid ? GetOwningStation ( [ PipedArgument ] EntityUid input )
{
_station ? ? = GetSys < StationSystem > ( ) ;
return _station . GetOwningStation ( input ) ;
}
[CommandImplementation("largestgrid")]
public EntityUid ? LargestGrid ( [ PipedArgument ] EntityUid input )
{
_station ? ? = GetSys < StationSystem > ( ) ;
return _station . GetLargestGrid ( Comp < StationDataComponent > ( input ) ) ;
}
[CommandImplementation("largestgrid")]
public IEnumerable < EntityUid ? > LargestGrid ( [ PipedArgument ] IEnumerable < EntityUid > input )
= > input . Select ( LargestGrid ) ;
[CommandImplementation("grids")]
public IEnumerable < EntityUid > Grids ( [ PipedArgument ] EntityUid input )
= > Comp < StationDataComponent > ( input ) . Grids ;
[CommandImplementation("grids")]
public IEnumerable < EntityUid > Grids ( [ PipedArgument ] IEnumerable < EntityUid > input )
= > input . SelectMany ( Grids ) ;
[CommandImplementation("config")]
public StationConfig ? Config ( [ PipedArgument ] EntityUid input )
= > Comp < StationDataComponent > ( input ) . StationConfig ;
[CommandImplementation("config")]
public IEnumerable < StationConfig ? > Config ( [ PipedArgument ] IEnumerable < EntityUid > input )
= > input . Select ( Config ) ;
[CommandImplementation("addgrid")]
2024-12-21 17:45:48 +11:00
public void AddGrid ( [ PipedArgument ] EntityUid input , EntityUid grid )
2023-08-02 16:09:08 -05:00
{
_station ? ? = GetSys < StationSystem > ( ) ;
2024-12-21 17:45:48 +11:00
_station . AddGridToStation ( input , grid ) ;
2023-08-02 16:09:08 -05:00
}
[CommandImplementation("rmgrid")]
2024-12-21 17:45:48 +11:00
public void RmGrid ( [ PipedArgument ] EntityUid input , EntityUid grid )
2023-08-02 16:09:08 -05:00
{
_station ? ? = GetSys < StationSystem > ( ) ;
2024-12-21 17:45:48 +11:00
_station . RemoveGridFromStation ( input , grid ) ;
2023-08-02 16:09:08 -05:00
}
[CommandImplementation("rename")]
2024-12-21 17:45:48 +11:00
public void Rename ( [ PipedArgument ] EntityUid input , string name )
2023-08-02 16:09:08 -05:00
{
_station ? ? = GetSys < StationSystem > ( ) ;
2024-12-21 17:45:48 +11:00
_station . RenameStation ( input , name ) ;
2023-08-02 16:09:08 -05:00
}
2024-01-03 19:34:47 -05:00
[CommandImplementation("rerollBounties")]
2024-12-21 17:45:48 +11:00
public void RerollBounties ( [ PipedArgument ] EntityUid input )
2024-01-03 19:34:47 -05:00
{
_cargo ? ? = GetSys < CargoSystem > ( ) ;
_cargo . RerollBountyDatabase ( input ) ;
}
2023-08-02 16:09:08 -05:00
}
public record struct OnlyOneStationsError : IConError
{
public FormattedMessage DescribeInner ( )
{
2024-09-01 14:00:53 +03:00
return FormattedMessage . FromMarkupOrThrow ( "This command doesn't function if there is more than one or no stations, explicitly specify a station with the ent command or similar." ) ;
2023-08-02 16:09:08 -05:00
}
public string? Expression { get ; set ; }
public Vector2i ? IssueSpan { get ; set ; }
public StackTrace ? Trace { get ; set ; }
}