Example #1
0
        public async Task BuckledDyingDropItemsTest()
        {
            await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes });

            var server = pairTracker.Pair.Server;

            var testMap = await PoolManager.CreateTestMap(pairTracker);

            var coordinates = testMap.GridCoords;

            EntityUid           human  = default;
            BuckleComponent     buckle = null;
            HandsComponent      hands  = null;
            SharedBodyComponent body   = null;

            await server.WaitIdleAsync();

            await server.WaitAssertion(() =>
            {
                var entityManager = IoCManager.Resolve <IEntityManager>();

                human     = entityManager.SpawnEntity(BuckleDummyId, coordinates);
                var chair = entityManager.SpawnEntity(StrapDummyId, coordinates);

                // Component sanity check
                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);

                    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
                foreach (var hand in hands.Hands.Values)
                {
                    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
                foreach (var hand in hands.Hands.Values)
                {
                    Assert.Null(hands.ActiveHandEntity);
                }

                buckle.TryUnbuckle(human, true);
            });

            await pairTracker.CleanReturnAsync();
        }
        public async Task BuckledDyingDropItemsTest()
        {
            var options = new ServerContentIntegrationOption {
                ExtraPrototypes = Prototypes
            };
            var server = StartServer(options);

            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>();

                var grid        = GetMainGrid(mapManager);
                var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0);

                human     = entityManager.SpawnEntity(BuckleDummyId, coordinates);
                var chair = entityManager.SpawnEntity(StrapDummyId, coordinates);

                // Component sanity check
                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);

                    // Equip items
                    Assert.True(entityManager.TryGetComponent(akms, out SharedItemComponent item));
                    Assert.True(hands.PutInHand(item));
                }
            });

            await server.WaitRunTicks(10);

            await server.WaitAssertion(() =>
            {
                // Still buckled
                Assert.True(buckle.Buckled);

                // With items in all hands
                foreach (var slot in hands.HandNames)
                {
                    Assert.NotNull(hands.GetItem(slot));
                }

                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
                foreach (var slot in hands.HandNames)
                {
                    Assert.Null(hands.GetItem(slot));
                }

                buckle.TryUnbuckle(human, true);
            });
        }