2021-02-01 16:49:43 -08:00
#nullable enable
2020-09-13 14:23:52 +02:00
using System.Linq ;
2020-08-25 08:54:23 -04:00
using System.Threading.Tasks ;
2021-06-09 22:19:39 +02:00
using Content.Server.Cuffs.Components ;
using Content.Server.Hands.Components ;
using Content.Shared.Body.Components ;
2020-08-25 08:54:23 -04:00
using NUnit.Framework ;
2021-02-01 16:49:43 -08:00
using Robust.Server.Console ;
2021-02-11 01:13:03 -08:00
using Robust.Shared.GameObjects ;
2020-08-25 08:54:23 -04:00
using Robust.Shared.IoC ;
using Robust.Shared.Map ;
2021-04-13 13:17:10 +02:00
using Robust.Shared.Maths ;
2020-08-25 08:54:23 -04:00
namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
{
[TestFixture]
[TestOf(typeof(CuffableComponent))]
[TestOf(typeof(HandcuffComponent))]
2021-02-06 03:11:21 +11:00
public class HandCuffTest : ContentIntegrationTest
2020-08-25 08:54:23 -04:00
{
2021-02-09 22:04:47 +01:00
private const string Prototypes = @ "
2020-11-18 15:30:36 +01:00
- type : entity
name : HumanDummy
id : HumanDummy
components :
- type : Cuffable
- type : Hands
- type : Body
template : HumanoidTemplate
preset : HumanPreset
centerSlot : torso
- type : entity
name : HandcuffsDummy
id : HandcuffsDummy
components :
- type : Handcuff
";
2020-08-25 08:54:23 -04:00
[Test]
public async Task Test ( )
{
2021-02-09 22:04:47 +01:00
var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes } ;
2021-11-06 11:49:59 +01:00
var server = StartServer ( options ) ;
2020-08-25 08:54:23 -04:00
IEntity human ;
IEntity otherHuman ;
IEntity cuffs ;
2020-11-18 15:30:36 +01:00
IEntity secondCuffs ;
2020-08-25 08:54:23 -04:00
CuffableComponent cuffed ;
2021-11-08 15:08:24 +01:00
HandsComponent hands ;
2020-08-25 08:54:23 -04:00
server . Assert ( ( ) = >
{
var mapManager = IoCManager . Resolve < IMapManager > ( ) ;
2021-04-13 13:17:10 +02:00
var mapId = mapManager . CreateMap ( ) ;
var coordinates = new MapCoordinates ( Vector2 . Zero , mapId ) ;
2020-08-25 08:54:23 -04:00
var entityManager = IoCManager . Resolve < IEntityManager > ( ) ;
// Spawn the entities
2021-04-13 13:17:10 +02:00
human = entityManager . SpawnEntity ( "HumanDummy" , coordinates ) ;
otherHuman = entityManager . SpawnEntity ( "HumanDummy" , coordinates ) ;
cuffs = entityManager . SpawnEntity ( "HandcuffsDummy" , coordinates ) ;
secondCuffs = entityManager . SpawnEntity ( "HandcuffsDummy" , coordinates ) ;
2020-08-25 08:54:23 -04:00
2021-12-03 15:53:09 +01:00
IoCManager . Resolve < IEntityManager > ( ) . GetComponent < TransformComponent > ( human ) . WorldPosition = IoCManager . Resolve < IEntityManager > ( ) . GetComponent < TransformComponent > ( otherHuman ) . WorldPosition ;
2020-08-25 08:54:23 -04:00
// Test for components existing
2021-12-03 14:17:01 +01:00
ref CuffableComponent ? comp = ref cuffed ! ;
2021-12-03 15:53:09 +01:00
Assert . True ( IoCManager . Resolve < IEntityManager > ( ) . TryGetComponent ( human , out comp ) , $"Human has no {nameof(CuffableComponent)}" ) ;
2021-12-03 14:17:01 +01:00
ref HandsComponent ? comp1 = ref hands ! ;
2021-12-03 15:53:09 +01:00
Assert . True ( IoCManager . Resolve < IEntityManager > ( ) . TryGetComponent ( human , out comp1 ) , $"Human has no {nameof(HandsComponent)}" ) ;
Assert . True ( IoCManager . Resolve < IEntityManager > ( ) . TryGetComponent ( human , out SharedBodyComponent ? _ ) , $"Human has no {nameof(SharedBodyComponent)}" ) ;
Assert . True ( IoCManager . Resolve < IEntityManager > ( ) . TryGetComponent ( cuffs , out HandcuffComponent ? _ ) , $"Handcuff has no {nameof(HandcuffComponent)}" ) ;
Assert . True ( IoCManager . Resolve < IEntityManager > ( ) . TryGetComponent ( secondCuffs , out HandcuffComponent ? _ ) , $"Second handcuffs has no {nameof(HandcuffComponent)}" ) ;
2020-08-25 08:54:23 -04:00
// Test to ensure cuffed players register the handcuffs
2021-02-06 03:11:21 +11:00
cuffed . TryAddNewCuffs ( human , cuffs ) ;
2020-08-25 08:54:23 -04:00
Assert . True ( cuffed . CuffedHandCount > 0 , "Handcuffing a player did not result in their hands being cuffed" ) ;
// Test to ensure a player with 4 hands will still only have 2 hands cuffed
2020-10-10 15:25:13 +02:00
AddHand ( cuffed . Owner ) ;
AddHand ( cuffed . Owner ) ;
2021-06-21 02:21:20 -07:00
2021-04-05 14:54:51 +02:00
Assert . That ( cuffed . CuffedHandCount , Is . EqualTo ( 2 ) ) ;
2021-06-21 02:21:20 -07:00
Assert . That ( hands . HandNames . Count ( ) , Is . EqualTo ( 4 ) ) ;
2020-08-25 08:54:23 -04:00
// Test to give a player with 4 hands 2 sets of cuffs
2021-02-06 03:11:21 +11:00
cuffed . TryAddNewCuffs ( human , secondCuffs ) ;
2020-08-25 08:54:23 -04:00
Assert . True ( cuffed . CuffedHandCount = = 4 , "Player doesn't have correct amount of hands cuffed" ) ;
} ) ;
await server . WaitIdleAsync ( ) ;
}
2020-10-10 15:25:13 +02:00
private void AddHand ( IEntity to )
2020-08-25 08:54:23 -04:00
{
2021-02-01 16:49:43 -08:00
var host = IoCManager . Resolve < IServerConsoleHost > ( ) ;
2021-12-03 15:53:09 +01:00
host . ExecuteCommand ( null , $"addhand {to}" ) ;
2020-08-25 08:54:23 -04:00
}
}
}