Files
crystall-punk-14/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs

363 lines
13 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
2021-06-09 22:19:39 +02:00
using Content.Server.Buckle.Components;
using Content.Server.Hands.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Buckle.Components;
2022-03-17 20:13:31 +13:00
using Content.Shared.Hands.EntitySystems;
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
using Content.Shared.Item;
using Content.Shared.Standing;
2020-07-17 10:43:10 +02:00
using NUnit.Framework;
using Robust.Shared.GameObjects;
2020-07-17 10:43:10 +02:00
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests.Buckle
2020-07-17 10:43:10 +02:00
{
[TestFixture]
[TestOf(typeof(BuckleComponent))]
[TestOf(typeof(StrapComponent))]
public sealed class BuckleTest : ContentIntegrationTest
2020-07-17 10:43:10 +02:00
{
private const string BuckleDummyId = "BuckleDummy";
private const string StrapDummyId = "StrapDummy";
private const string ItemDummyId = "ItemDummy";
private static readonly string Prototypes = $@"
- type: entity
name: {BuckleDummyId}
id: {BuckleDummyId}
components:
- type: Buckle
- type: Hands
- type: Body
template: HumanoidTemplate
preset: HumanPreset
centerSlot: torso
- type: StandingState
- type: entity
name: {StrapDummyId}
id: {StrapDummyId}
components:
- type: Strap
- type: entity
name: {ItemDummyId}
id: {ItemDummyId}
components:
- type: Item
";
2020-07-17 10:43:10 +02:00
[Test]
public async Task BuckleUnbuckleCooldownRangeTest()
2020-07-17 10:43:10 +02:00
{
var cOptions = new ClientIntegrationOptions {ExtraPrototypes = Prototypes};
var sOptions = new ServerIntegrationOptions {ExtraPrototypes = Prototypes};
var (_, server) = await StartConnectedServerClientPair(cOptions, sOptions);
2020-07-17 10:43:10 +02:00
2021-12-05 18:09:01 +01:00
EntityUid human = default;
EntityUid chair = default;
2020-07-17 10:43:10 +02:00
BuckleComponent buckle = null;
StrapComponent strap = null;
await server.WaitAssertion(() =>
2020-07-17 10:43:10 +02:00
{
var mapManager = IoCManager.Resolve<IMapManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var standingState = EntitySystem.Get<StandingStateSystem>();
2020-07-17 10:43:10 +02:00
Add test pooling (#4961) * Add test pooling * WIP test pooling changes * Fix Destructible tests * Don't pool unpooled or dummy ticker instances * Change ServerPathfindingDebugSystem to replace existing entries * Fix SaveLoadSaveTest comment * Don't pool StartTest * Comment out global setup * Fix puddle tests * Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit * Update RobustToolbox * Finish fixing tests, make test threads background threads * Bring back pooling * Fix nullable * Update RobustToolbox * Set cvars on server return * Un-pool tests with custom cvars * Update RobustToolbox * Update RobustToolbox * Change where the main tile coordinates are * Remove DisposalUnitTest grid check * Fix test pooling being a fickle bitch * Fix EntitySystemExtensionsTest * Update RobustToolbox * Update RobustToolbox * Make nullable pool settings true * Update RobustToolbox * Wait other way around * We are unitystation now * Update RobustToolbox * Create global setup * Pool some more tests * Fix not properly disconnecting clients before restarting the round * Give more info on ran tests * Standardize default test cvars * Update RobustToolbox * Update RobustToolbox * Pool clients * Fix test order issue * Fix cvars in character creation test not being set properly * Update RobustToolbox * Update RobustToolbox * Rider shut * Update RobustToolbox * Format tests ran better * Update RobustToolbox * Reset RobustToolbox * Reset RobustToolbox harder * Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00
var grid = GetMainGrid(mapManager);
2021-12-05 18:09:01 +01:00
var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0);
human = entityManager.SpawnEntity(BuckleDummyId, coordinates);
chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
2020-07-17 10:43:10 +02:00
// Default state, unbuckled
2021-12-05 18:09:01 +01:00
Assert.True(entityManager.TryGetComponent(human, out buckle));
2020-07-17 10:43:10 +02:00
Assert.NotNull(buckle);
Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled);
2021-12-03 15:53:09 +01:00
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
2021-12-05 18:09:01 +01:00
Assert.True(standingState.Down(human));
Assert.True(standingState.Stand(human));
2020-07-17 10:43:10 +02:00
// Default state, no buckled entities, strap
2021-12-05 18:09:01 +01:00
Assert.True(entityManager.TryGetComponent(chair, out strap));
2020-07-17 10:43:10 +02:00
Assert.NotNull(strap);
Assert.IsEmpty(strap.BuckledEntities);
Assert.Zero(strap.OccupiedSize);
// Side effects of buckling
Assert.True(buckle.TryBuckle(human, chair));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
Assert.True(((BuckleComponentState) buckle.GetComponentState()).Buckled);
2021-12-03 15:53:09 +01:00
Assert.False(actionBlocker.CanMove(human));
Assert.False(actionBlocker.CanChangeDirection(human));
2021-12-05 18:09:01 +01:00
Assert.False(standingState.Down(human));
Assert.That((entityManager.GetComponent<TransformComponent>(human).WorldPosition - entityManager.GetComponent<TransformComponent>(chair).WorldPosition).Length, Is.LessThanOrEqualTo(buckle.BuckleOffset.Length));
2020-07-17 10:43:10 +02:00
// Side effects of buckling for the strap
Assert.That(strap.BuckledEntities, Does.Contain(human));
Assert.That(strap.OccupiedSize, Is.EqualTo(buckle.Size));
Assert.Positive(strap.OccupiedSize);
// Trying to buckle while already buckled fails
Assert.False(buckle.TryBuckle(human, chair));
// Trying to unbuckle too quickly fails
Assert.False(buckle.TryUnbuckle(human));
Assert.False(buckle.ToggleBuckle(human, chair));
Assert.True(buckle.Buckled);
});
// Wait enough ticks for the unbuckling cooldown to run out
await server.WaitRunTicks(60);
2020-07-17 10:43:10 +02:00
await server.WaitAssertion(() =>
2020-07-17 10:43:10 +02:00
{
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var standingState = EntitySystem.Get<StandingStateSystem>();
2020-07-17 10:43:10 +02:00
// Still buckled
Assert.True(buckle.Buckled);
// Unbuckle
Assert.True(buckle.TryUnbuckle(human));
Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled);
2021-12-03 15:53:09 +01:00
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
2021-12-05 18:09:01 +01:00
Assert.True(standingState.Down(human));
2020-07-17 10:43:10 +02:00
// Unbuckle, strap
Assert.IsEmpty(strap.BuckledEntities);
Assert.Zero(strap.OccupiedSize);
// Re-buckling has no cooldown
Assert.True(buckle.TryBuckle(human, chair));
Assert.True(buckle.Buckled);
// On cooldown
Assert.False(buckle.TryUnbuckle(human));
Assert.True(buckle.Buckled);
Assert.False(buckle.ToggleBuckle(human, chair));
Assert.True(buckle.Buckled);
Assert.False(buckle.ToggleBuckle(human, chair));
Assert.True(buckle.Buckled);
});
// Wait enough ticks for the unbuckling cooldown to run out
await server.WaitRunTicks(60);
2020-07-17 10:43:10 +02:00
await server.WaitAssertion(() =>
2020-07-17 10:43:10 +02:00
{
2021-12-05 18:09:01 +01:00
var entityManager = IoCManager.Resolve<IEntityManager>();
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var standingState = EntitySystem.Get<StandingStateSystem>();
2020-07-17 10:43:10 +02:00
// Still buckled
Assert.True(buckle.Buckled);
// Unbuckle
Assert.True(buckle.TryUnbuckle(human));
Assert.False(buckle.Buckled);
// Move away from the chair
2021-12-05 18:09:01 +01:00
entityManager.GetComponent<TransformComponent>(human).WorldPosition += (1000, 1000);
2020-07-17 10:43:10 +02:00
// Out of range
Assert.False(buckle.TryBuckle(human, chair));
Assert.False(buckle.TryUnbuckle(human));
Assert.False(buckle.ToggleBuckle(human, chair));
// Move near the chair
2021-12-05 18:09:01 +01:00
entityManager.GetComponent<TransformComponent>(human).WorldPosition = entityManager.GetComponent<TransformComponent>(chair).WorldPosition + (0.5f, 0);
2020-07-17 10:43:10 +02:00
// In range
Assert.True(buckle.TryBuckle(human, chair));
Assert.True(buckle.Buckled);
Assert.False(buckle.TryUnbuckle(human));
Assert.True(buckle.Buckled);
Assert.False(buckle.ToggleBuckle(human, chair));
Assert.True(buckle.Buckled);
// Force unbuckle
Assert.True(buckle.TryUnbuckle(human, true));
Assert.False(buckle.Buckled);
2021-12-03 15:53:09 +01:00
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
2021-12-05 18:09:01 +01:00
Assert.True(standingState.Down(human));
// Re-buckle
Assert.True(buckle.TryBuckle(human, chair));
// Move away from the chair
2021-12-05 18:09:01 +01:00
entityManager.GetComponent<TransformComponent>(human).WorldPosition += (1, 0);
});
await server.WaitRunTicks(1);
await server.WaitAssertion(() =>
{
// No longer buckled
Assert.False(buckle.Buckled);
Assert.Null(buckle.BuckledTo);
Assert.IsEmpty(strap.BuckledEntities);
2020-07-17 10:43:10 +02:00
});
}
[Test]
public async Task BuckledDyingDropItemsTest()
{
var options = new ServerContentIntegrationOption {ExtraPrototypes = Prototypes};
var server = StartServer(options);
2021-12-05 18:09:01 +01:00
EntityUid human = default;
BuckleComponent buckle = null;
HandsComponent hands = null;
SharedBodyComponent body = null;
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
var mapManager = IoCManager.Resolve<IMapManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
Add test pooling (#4961) * Add test pooling * WIP test pooling changes * Fix Destructible tests * Don't pool unpooled or dummy ticker instances * Change ServerPathfindingDebugSystem to replace existing entries * Fix SaveLoadSaveTest comment * Don't pool StartTest * Comment out global setup * Fix puddle tests * Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit * Update RobustToolbox * Finish fixing tests, make test threads background threads * Bring back pooling * Fix nullable * Update RobustToolbox * Set cvars on server return * Un-pool tests with custom cvars * Update RobustToolbox * Update RobustToolbox * Change where the main tile coordinates are * Remove DisposalUnitTest grid check * Fix test pooling being a fickle bitch * Fix EntitySystemExtensionsTest * Update RobustToolbox * Update RobustToolbox * Make nullable pool settings true * Update RobustToolbox * Wait other way around * We are unitystation now * Update RobustToolbox * Create global setup * Pool some more tests * Fix not properly disconnecting clients before restarting the round * Give more info on ran tests * Standardize default test cvars * Update RobustToolbox * Update RobustToolbox * Pool clients * Fix test order issue * Fix cvars in character creation test not being set properly * Update RobustToolbox * Update RobustToolbox * Rider shut * Update RobustToolbox * Format tests ran better * Update RobustToolbox * Reset RobustToolbox * Reset RobustToolbox harder * Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00
var grid = GetMainGrid(mapManager);
2021-12-05 18:09:01 +01:00
var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0);
human = entityManager.SpawnEntity(BuckleDummyId, coordinates);
2021-12-05 18:09:01 +01:00
var chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Component sanity check
2021-12-05 18:09:01 +01:00
Assert.True(entityManager.TryGetComponent(human, out buckle));
Assert.True(entityManager.HasComponent<StrapComponent>(chair));
Assert.True(entityManager.TryGetComponent(human, out hands));
Assert.True(entityManager.TryGetComponent(human, out body));
// Buckle
Assert.True(buckle.TryBuckle(human, chair));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
// Put an item into every hand
for (var i = 0; i < hands.Count; i++)
{
var akms = entityManager.SpawnEntity(ItemDummyId, coordinates);
2022-03-17 20:13:31 +13:00
Assert.True(EntitySystem.Get<SharedHandsSystem>().TryPickupAnyHand(human, akms));
}
});
await server.WaitRunTicks(10);
await server.WaitAssertion(() =>
{
// Still buckled
Assert.True(buckle.Buckled);
// With items in all hands
2022-03-17 20:13:31 +13:00
foreach (var hand in hands.Hands.Values)
{
2022-03-17 20:13:31 +13:00
Assert.NotNull(hands.ActiveHandEntity);
}
var legs = body.GetPartsOfType(BodyPartType.Leg);
// Break our guy's kneecaps
foreach (var leg in legs)
{
body.RemovePart(leg);
}
});
await server.WaitRunTicks(10);
await server.WaitAssertion(() =>
{
// Still buckled
Assert.True(buckle.Buckled);
// Now with no item in any hand
2022-03-17 20:13:31 +13:00
foreach (var hand in hands.Hands.Values)
{
2022-03-17 20:13:31 +13:00
Assert.Null(hands.ActiveHandEntity);
}
buckle.TryUnbuckle(human, true);
});
}
[Test]
public async Task ForceUnbuckleBuckleTest()
{
var options = new ServerContentIntegrationOption
{
ExtraPrototypes = Prototypes
};
var server = StartServer(options);
2021-12-05 18:09:01 +01:00
EntityUid human = default;
EntityUid chair = default;
BuckleComponent buckle = null;
await server.WaitAssertion(() =>
{
var mapManager = IoCManager.Resolve<IMapManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
Add test pooling (#4961) * Add test pooling * WIP test pooling changes * Fix Destructible tests * Don't pool unpooled or dummy ticker instances * Change ServerPathfindingDebugSystem to replace existing entries * Fix SaveLoadSaveTest comment * Don't pool StartTest * Comment out global setup * Fix puddle tests * Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit * Update RobustToolbox * Finish fixing tests, make test threads background threads * Bring back pooling * Fix nullable * Update RobustToolbox * Set cvars on server return * Un-pool tests with custom cvars * Update RobustToolbox * Update RobustToolbox * Change where the main tile coordinates are * Remove DisposalUnitTest grid check * Fix test pooling being a fickle bitch * Fix EntitySystemExtensionsTest * Update RobustToolbox * Update RobustToolbox * Make nullable pool settings true * Update RobustToolbox * Wait other way around * We are unitystation now * Update RobustToolbox * Create global setup * Pool some more tests * Fix not properly disconnecting clients before restarting the round * Give more info on ran tests * Standardize default test cvars * Update RobustToolbox * Update RobustToolbox * Pool clients * Fix test order issue * Fix cvars in character creation test not being set properly * Update RobustToolbox * Update RobustToolbox * Rider shut * Update RobustToolbox * Format tests ran better * Update RobustToolbox * Reset RobustToolbox * Reset RobustToolbox harder * Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00
var grid = GetMainGrid(mapManager);
2021-12-05 18:09:01 +01:00
var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0);
human = entityManager.SpawnEntity(BuckleDummyId, coordinates);
chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Component sanity check
2021-12-05 18:09:01 +01:00
Assert.True(entityManager.TryGetComponent(human, out buckle));
Assert.True(entityManager.HasComponent<StrapComponent>(chair));
// Buckle
Assert.True(buckle.TryBuckle(human, chair));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
// Move the buckled entity away
2021-12-05 18:09:01 +01:00
entityManager.GetComponent<TransformComponent>(human).WorldPosition += (100, 0);
});
await WaitUntil(server, () => !buckle.Buckled, 10);
Assert.False(buckle.Buckled);
await server.WaitAssertion(() =>
{
2021-12-05 18:09:01 +01:00
var entityManager = IoCManager.Resolve<IEntityManager>();
// Move the now unbuckled entity back onto the chair
2021-12-05 18:09:01 +01:00
entityManager.GetComponent<TransformComponent>(human).WorldPosition -= (100, 0);
// Buckle
Assert.True(buckle.TryBuckle(human, chair));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
});
await server.WaitRunTicks(60);
await server.WaitAssertion(() =>
{
// Still buckled
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
});
}
2020-07-17 10:43:10 +02:00
}
}