mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-06-09 10:06:43 +02:00
d42adbf05d
* Pass 1. * i'm FREE * Prevent hangups. * okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing. * sigh. * fix singular trigger bug so LatheTest doesn't flake. * Remove SystemAttribute usage. * Poke * I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls. * Change the faulty store test into two tests, one of which is ignored for failing.
376 lines
14 KiB
C#
376 lines
14 KiB
C#
using System.Numerics;
|
|
using Content.IntegrationTests.Fixtures;
|
|
using Content.Shared.Buckle;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Buckle.Components;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Standing;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Content.IntegrationTests.Tests.Buckle
|
|
{
|
|
[TestFixture]
|
|
[TestOf(typeof(BuckleComponent))]
|
|
[TestOf(typeof(StrapComponent))]
|
|
public sealed partial class BuckleTest : GameTest
|
|
{
|
|
private const string BuckleDummyId = "BuckleDummy";
|
|
private const string StrapDummyId = "StrapDummy";
|
|
private const string ItemDummyId = "ItemDummy";
|
|
|
|
[TestPrototypes]
|
|
private const string Prototypes = $@"
|
|
- type: entity
|
|
name: {BuckleDummyId}
|
|
id: {BuckleDummyId}
|
|
components:
|
|
- type: Buckle
|
|
- type: Hands
|
|
- type: ComplexInteraction
|
|
- type: InputMover
|
|
- type: Physics
|
|
bodyType: KinematicController
|
|
- type: Body
|
|
prototype: Human
|
|
- type: StandingState
|
|
|
|
- type: entity
|
|
name: {StrapDummyId}
|
|
id: {StrapDummyId}
|
|
components:
|
|
- type: Strap
|
|
|
|
- type: entity
|
|
name: {ItemDummyId}
|
|
id: {ItemDummyId}
|
|
components:
|
|
- type: Item
|
|
";
|
|
|
|
[Test]
|
|
public async Task BuckleUnbuckleCooldownRangeTest()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
|
|
var testMap = await pair.CreateTestMap();
|
|
var coordinates = testMap.GridCoords;
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
var actionBlocker = entityManager.System<ActionBlockerSystem>();
|
|
var buckleSystem = entityManager.System<SharedBuckleSystem>();
|
|
var standingState = entityManager.System<StandingStateSystem>();
|
|
var xformSystem = entityManager.System<SharedTransformSystem>();
|
|
|
|
EntityUid human = default;
|
|
EntityUid chair = default;
|
|
BuckleComponent buckle = null;
|
|
StrapComponent strap = null;
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
human = entityManager.SpawnEntity(BuckleDummyId, coordinates);
|
|
chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
|
|
|
|
// Default state, unbuckled
|
|
Assert.That(entityManager.TryGetComponent(human, out buckle));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle, Is.Not.Null);
|
|
Assert.That(buckle.BuckledTo, Is.Null);
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
Assert.That(actionBlocker.CanMove(human));
|
|
Assert.That(actionBlocker.CanChangeDirection(human));
|
|
Assert.That(standingState.Down(human));
|
|
Assert.That(standingState.Stand(human));
|
|
});
|
|
|
|
// Default state, no buckled entities, strap
|
|
Assert.That(entityManager.TryGetComponent(chair, out strap));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(strap, Is.Not.Null);
|
|
Assert.That(strap.BuckledEntities, Is.Empty);
|
|
});
|
|
|
|
// Side effects of buckling
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.BuckledTo, Is.Not.Null);
|
|
Assert.That(buckle.Buckled);
|
|
|
|
Assert.That(actionBlocker.CanMove(human), Is.False);
|
|
Assert.That(actionBlocker.CanChangeDirection(human));
|
|
Assert.That(standingState.Down(human), Is.False);
|
|
Assert.That(
|
|
(xformSystem.GetWorldPosition(human) - xformSystem.GetWorldPosition(chair)).LengthSquared,
|
|
Is.LessThanOrEqualTo(0)
|
|
);
|
|
|
|
// Side effects of buckling for the strap
|
|
Assert.That(strap.BuckledEntities, Does.Contain(human));
|
|
});
|
|
|
|
#pragma warning disable NUnit2045 // Interdependent asserts.
|
|
// Trying to buckle while already buckled fails
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle), Is.False);
|
|
|
|
// Trying to unbuckle too quickly fails
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
|
|
Assert.That(buckle.Buckled);
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human), Is.False);
|
|
Assert.That(buckle.Buckled);
|
|
#pragma warning restore NUnit2045
|
|
});
|
|
|
|
// Wait enough ticks for the unbuckling cooldown to run out
|
|
await server.WaitRunTicks(60);
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
#pragma warning disable NUnit2045 // Interdependent asserts.
|
|
Assert.That(buckle.Buckled);
|
|
// Still buckled
|
|
#pragma warning restore NUnit2045
|
|
|
|
// Unbuckle
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.BuckledTo, Is.Null);
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
Assert.That(actionBlocker.CanMove(human));
|
|
Assert.That(actionBlocker.CanChangeDirection(human));
|
|
Assert.That(standingState.Down(human));
|
|
|
|
// Unbuckle, strap
|
|
Assert.That(strap.BuckledEntities, Is.Empty);
|
|
});
|
|
|
|
#pragma warning disable NUnit2045 // Interdependent asserts.
|
|
// Re-buckling has no cooldown
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
|
|
Assert.That(buckle.Buckled);
|
|
|
|
// On cooldown
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
|
|
Assert.That(buckle.Buckled);
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human), Is.False);
|
|
Assert.That(buckle.Buckled);
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human), Is.False);
|
|
Assert.That(buckle.Buckled);
|
|
#pragma warning restore NUnit2045
|
|
});
|
|
|
|
// Wait enough ticks for the unbuckling cooldown to run out
|
|
await server.WaitRunTicks(60);
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
#pragma warning disable NUnit2045 // Interdependent asserts.
|
|
// Still buckled
|
|
Assert.That(buckle.Buckled);
|
|
|
|
// Unbuckle
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
#pragma warning restore NUnit2045
|
|
|
|
// Move away from the chair
|
|
var oldWorldPosition = xformSystem.GetWorldPosition(chair);
|
|
xformSystem.SetWorldPosition(human, oldWorldPosition + new Vector2(1000, 1000));
|
|
|
|
// Out of range
|
|
#pragma warning disable NUnit2045 // Interdependent asserts.
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle), Is.False);
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
|
|
#pragma warning restore NUnit2045
|
|
|
|
// Move near the chair
|
|
oldWorldPosition = xformSystem.GetWorldPosition(chair);
|
|
xformSystem.SetWorldPosition(human, oldWorldPosition + new Vector2(0.5f, 0));
|
|
|
|
// In range
|
|
#pragma warning disable NUnit2045 // Interdependent asserts.
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
|
|
Assert.That(buckle.Buckled);
|
|
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
|
|
Assert.That(buckle.Buckled);
|
|
#pragma warning restore NUnit2045
|
|
|
|
// Force unbuckle
|
|
buckleSystem.Unbuckle(human, human);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
Assert.That(actionBlocker.CanMove(human));
|
|
Assert.That(actionBlocker.CanChangeDirection(human));
|
|
Assert.That(standingState.Down(human));
|
|
});
|
|
|
|
// Re-buckle
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
|
|
|
|
// Move away from the chair
|
|
oldWorldPosition = xformSystem.GetWorldPosition(chair);
|
|
xformSystem.SetWorldPosition(human, oldWorldPosition + new Vector2(1, 0));
|
|
});
|
|
|
|
await server.WaitRunTicks(1);
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
// No longer buckled
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
Assert.That(buckle.BuckledTo, Is.Null);
|
|
Assert.That(strap.BuckledEntities, Is.Empty);
|
|
});
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task BuckledDyingDropItemsTest()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
|
|
var testMap = await pair.CreateTestMap();
|
|
var coordinates = testMap.GridCoords;
|
|
|
|
EntityUid human = default;
|
|
BuckleComponent buckle = null;
|
|
HandsComponent hands = null;
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
var handsSys = entityManager.EntitySysManager.GetEntitySystem<SharedHandsSystem>();
|
|
var buckleSystem = entityManager.EntitySysManager.GetEntitySystem<SharedBuckleSystem>();
|
|
var xformSystem = entityManager.System<SharedTransformSystem>();
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
human = entityManager.SpawnEntity(BuckleDummyId, coordinates);
|
|
var chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
|
|
|
|
// Component sanity check
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(entityManager.TryGetComponent(human, out buckle));
|
|
Assert.That(entityManager.HasComponent<StrapComponent>(chair));
|
|
Assert.That(entityManager.TryGetComponent(human, out hands));
|
|
});
|
|
|
|
// Buckle
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.BuckledTo, Is.Not.Null);
|
|
Assert.That(buckle.Buckled);
|
|
});
|
|
|
|
// Put an item into every hand
|
|
for (var i = 0; i < hands.Count; i++)
|
|
{
|
|
var akms = entityManager.SpawnEntity(ItemDummyId, coordinates);
|
|
|
|
Assert.That(handsSys.TryPickupAnyHand(human, akms));
|
|
}
|
|
});
|
|
|
|
await server.WaitRunTicks(10);
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
// Still buckled
|
|
Assert.That(buckle.Buckled);
|
|
|
|
// Still with items in hand
|
|
foreach (var hand in hands.Hands.Keys)
|
|
{
|
|
Assert.That(handsSys.GetHeldItem((human, hands), hand), Is.Not.Null);
|
|
}
|
|
|
|
buckleSystem.Unbuckle(human, human);
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task ForceUnbuckleBuckleTest()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
|
|
var testMap = await pair.CreateTestMap();
|
|
var coordinates = testMap.GridCoords;
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
var buckleSystem = entityManager.System<SharedBuckleSystem>();
|
|
var xformSystem = entityManager.System<SharedTransformSystem>();
|
|
|
|
EntityUid human = default;
|
|
EntityUid chair = default;
|
|
BuckleComponent buckle = null;
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
human = entityManager.SpawnEntity(BuckleDummyId, coordinates);
|
|
chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
|
|
|
|
// Component sanity check
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(entityManager.TryGetComponent(human, out buckle));
|
|
Assert.That(entityManager.HasComponent<StrapComponent>(chair));
|
|
});
|
|
|
|
// Buckle
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.BuckledTo, Is.Not.Null);
|
|
Assert.That(buckle.Buckled);
|
|
});
|
|
|
|
// Move the buckled entity away
|
|
var oldWorldPosition = xformSystem.GetWorldPosition(chair);
|
|
xformSystem.SetWorldPosition(human, oldWorldPosition + new Vector2(100, 0));
|
|
});
|
|
|
|
await PoolManager.WaitUntil(server, () => !buckle.Buckled, 10);
|
|
|
|
Assert.That(buckle.Buckled, Is.False);
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
// Move the now unbuckled entity back onto the chair
|
|
var oldWorldPosition = xformSystem.GetWorldPosition(chair);
|
|
xformSystem.SetWorldPosition(human, oldWorldPosition);
|
|
|
|
// Buckle
|
|
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.BuckledTo, Is.Not.Null);
|
|
Assert.That(buckle.Buckled);
|
|
});
|
|
});
|
|
|
|
await server.WaitRunTicks(60);
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
// Still buckled
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(buckle.BuckledTo, Is.Not.Null);
|
|
Assert.That(buckle.Buckled);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|