2020-10-30 16:06:48 +01:00
using Content.Server.Administration ;
using Content.Shared.Administration ;
2021-06-09 22:19:39 +02:00
using Content.Shared.Body.Components ;
2021-02-11 01:13:03 -08:00
using Robust.Server.Player ;
2021-02-01 16:49:43 -08:00
using Robust.Shared.Console ;
2020-10-25 23:16:57 +01:00
using Robust.Shared.GameObjects ;
using Robust.Shared.IoC ;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Body.Commands
2020-10-25 23:16:57 +01:00
{
2020-10-30 16:06:48 +01:00
[AdminCommand(AdminFlags.Fun)]
2022-02-16 00:23:23 -07:00
public sealed class AttachBodyPartCommand : IConsoleCommand
2020-10-25 23:16:57 +01:00
{
public string Command = > "attachbodypart" ;
public string Description = > "Attaches a body part to you or someone else." ;
public string Help = > $"{Command} <partEntityUid> / {Command} <entityUid> <partEntityUid>" ;
2021-02-01 16:49:43 -08:00
public void Execute ( IConsoleShell shell , string argStr , string [ ] args )
2020-10-25 23:16:57 +01:00
{
2021-02-01 16:49:43 -08:00
var player = shell . Player as IPlayerSession ;
2020-10-25 23:16:57 +01:00
var entityManager = IoCManager . Resolve < IEntityManager > ( ) ;
2021-12-05 18:09:01 +01:00
EntityUid entity ;
2020-10-25 23:16:57 +01:00
EntityUid partUid ;
switch ( args . Length )
{
case 1 :
if ( player = = null )
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"You need to specify an entity to attach the part to if you aren't a player.\n{Help}" ) ;
2020-10-25 23:16:57 +01:00
return ;
}
if ( player . AttachedEntity = = null )
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"You need to specify an entity to attach the part to if you aren't attached to an entity.\n{Help}" ) ;
2020-10-25 23:16:57 +01:00
return ;
}
if ( ! EntityUid . TryParse ( args [ 0 ] , out partUid ) )
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"{args[0]} is not a valid entity uid." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-06 15:34:46 +01:00
entity = player . AttachedEntity . Value ;
2020-10-25 23:16:57 +01:00
break ;
case 2 :
if ( ! EntityUid . TryParse ( args [ 0 ] , out var entityUid ) )
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"{args[0]} is not a valid entity uid." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
if ( ! EntityUid . TryParse ( args [ 1 ] , out partUid ) )
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"{args[1]} is not a valid entity uid." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-05 18:09:01 +01:00
if ( ! entityManager . EntityExists ( entityUid ) )
2020-10-25 23:16:57 +01:00
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"{entityUid} is not a valid entity." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-05 18:09:01 +01:00
entity = entityUid ;
2020-10-25 23:16:57 +01:00
break ;
default :
2021-02-01 16:49:43 -08:00
shell . WriteLine ( Help ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-05 18:09:01 +01:00
if ( ! entityManager . TryGetComponent ( entity , out SharedBodyComponent ? body ) )
2020-10-25 23:16:57 +01:00
{
2021-12-05 18:09:01 +01:00
shell . WriteLine ( $"Entity {entityManager.GetComponent<MetaDataComponent>(entity).EntityName} with uid {entity} does not have a {nameof(SharedBodyComponent)} component." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-05 18:09:01 +01:00
if ( ! entityManager . EntityExists ( partUid ) )
2020-10-25 23:16:57 +01:00
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( $"{partUid} is not a valid entity." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-05 18:09:01 +01:00
if ( ! entityManager . TryGetComponent ( partUid , out SharedBodyPartComponent ? part ) )
2020-10-25 23:16:57 +01:00
{
2021-12-05 18:09:01 +01:00
shell . WriteLine ( $"Entity {entityManager.GetComponent<MetaDataComponent>(partUid).EntityName} with uid {args[0]} does not have a {nameof(SharedBodyPartComponent)} component." ) ;
2020-10-25 23:16:57 +01:00
return ;
}
if ( body . HasPart ( part ) )
{
2021-12-05 18:09:01 +01:00
shell . WriteLine ( $"Body part {entityManager.GetComponent<MetaDataComponent>(partUid).EntityName} with uid {partUid} is already attached to entity {entityManager.GetComponent<MetaDataComponent>(entity).EntityName} with uid {entity}" ) ;
2020-10-25 23:16:57 +01:00
return ;
}
2021-12-05 18:09:01 +01:00
body . SetPart ( $"AttachBodyPartVerb-{partUid}" , part ) ;
2020-10-25 23:16:57 +01:00
}
}
}