コード例 #1
0
        public async Task TestDeleteVisiting()
        {
            await using var pairTracker = await PoolManager.GetServerClient();

            var server = pairTracker.Pair.Server;

            var       entMan    = server.ResolveDependency <IServerEntityManager>();
            EntityUid playerEnt = default;
            EntityUid visitEnt  = default;
            Mind      mind      = null;
            await server.WaitAssertion(() =>
            {
                var player = IoCManager.Resolve <IPlayerManager>().ServerSessions.Single();

                var mapMan = IoCManager.Resolve <IMapManager>();

                var mapId = mapMan.GetAllMapIds().Last();
                var pos   = new MapCoordinates(Vector2.Zero, mapId);

                playerEnt = entMan.SpawnEntity(null, pos);
                visitEnt  = entMan.SpawnEntity(null, pos);

                mind = new Mind(player.UserId);
                mind.ChangeOwningPlayer(player.UserId);

                mind.TransferTo(playerEnt);
                mind.Visit(visitEnt);

                Assert.That(player.AttachedEntity, Is.EqualTo(visitEnt));
                Assert.That(mind.VisitingEntity, Is.EqualTo(visitEnt));
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await server.WaitAssertion(() =>
            {
                entMan.DeleteEntity(visitEnt);
                if (mind == null)
                {
                    Assert.Fail("Mind was null");
                    return;
                }

                if (mind.VisitingEntity != null)
                {
                    Assert.Fail("Mind VisitingEntity was not null");
                    return;
                }

                // This used to throw so make sure it doesn't.
                entMan.DeleteEntity(playerEnt);
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await pairTracker.CleanReturnAsync();
        }
コード例 #2
0
        public async Task TestGhostOnDeleteMap()
        {
            await using var pairTracker = await PoolManager.GetServerClient();

            var server = pairTracker.Pair.Server;

            EntityUid playerEnt = default;
            Mind      mind      = null;
            MapId     map       = default;
            await server.WaitAssertion(() =>
            {
                var player = IoCManager.Resolve <IPlayerManager>().ServerSessions.Single();

                var mapMan = IoCManager.Resolve <IMapManager>();

                map      = mapMan.CreateMap();
                var grid = mapMan.CreateGrid(map);

                var entMgr = IoCManager.Resolve <IServerEntityManager>();

                mapMan.CreateNewMapEntity(MapId.Nullspace);

                playerEnt = entMgr.SpawnEntity(null, grid.ToCoordinates());

                mind = new Mind(player.UserId);
                mind.ChangeOwningPlayer(player.UserId);

                mind.TransferTo(playerEnt);

                Assert.That(mind.CurrentEntity, Is.EqualTo(playerEnt));
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await server.WaitPost(() =>
            {
                var mapMan = IoCManager.Resolve <IMapManager>();

                mapMan.DeleteMap(map);
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await server.WaitAssertion(() =>
            {
                Assert.That(IoCManager.Resolve <IEntityManager>().EntityExists(mind.CurrentEntity !.Value), Is.True);
                Assert.That(mind.CurrentEntity, Is.Not.EqualTo(playerEnt));
            });

            await pairTracker.CleanReturnAsync();
        }
コード例 #3
0
        public async Task TestGhostOnDelete()
        {
            // Has to be a non-dummy ticker so we have a proper map.

            await using var pairTracker = await PoolManager.GetServerClient();

            var server = pairTracker.Pair.Server;

            var       entMan    = server.ResolveDependency <IServerEntityManager>();
            EntityUid playerEnt = default;
            Mind      mind      = null;
            await server.WaitAssertion(() =>
            {
                var player = IoCManager.Resolve <IPlayerManager>().ServerSessions.Single();

                var mapMan = IoCManager.Resolve <IMapManager>();

                var mapId = mapMan.GetAllMapIds().Last();
                var pos   = new MapCoordinates(Vector2.Zero, mapId);

                playerEnt = entMan.SpawnEntity(null, pos);

                mind = new Mind(player.UserId);
                mind.ChangeOwningPlayer(player.UserId);

                mind.TransferTo(playerEnt);

                Assert.That(mind.CurrentEntity, Is.EqualTo(playerEnt));
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await server.WaitPost(() =>
            {
                entMan.DeleteEntity(playerEnt);
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await server.WaitAssertion(() =>
            {
                Assert.That(entMan.EntityExists(mind.CurrentEntity !.Value), Is.True);
            });

            await pairTracker.CleanReturnAsync();
        }
コード例 #4
0
        public async Task TestDeleteVisiting()
        {
            var(_, server) = await StartConnectedServerDummyTickerClientPair();

            var       entMan    = server.ResolveDependency <IServerEntityManager>();
            EntityUid playerEnt = default;
            EntityUid visitEnt  = default;
            Mind      mind      = null;

            server.Assert(() =>
            {
                var player = IoCManager.Resolve <IPlayerManager>().ServerSessions.Single();

                var mapMan = IoCManager.Resolve <IMapManager>();

                mapMan.CreateNewMapEntity(MapId.Nullspace);

                playerEnt = entMan.SpawnEntity(null, MapCoordinates.Nullspace);
                visitEnt  = entMan.SpawnEntity(null, MapCoordinates.Nullspace);

                mind = new Mind(player.UserId);
                mind.ChangeOwningPlayer(player.UserId);

                mind.TransferTo(playerEnt);
                mind.Visit(visitEnt);

                Assert.That(player.AttachedEntity, Is.EqualTo(visitEnt));
                Assert.That(mind.VisitingEntity, Is.EqualTo(visitEnt));
            });

            server.RunTicks(1);

            server.Assert(() =>
            {
                entMan.DeleteEntity(visitEnt);

                Assert.That(mind.VisitingEntity, Is.EqualTo(default));
コード例 #5
0
 public void WipeMind()
 {
     Mind?.ChangeOwningPlayer(null);
     Mind = null;
 }
コード例 #6
0
 public void WipeMind()
 {
     Mind?.TransferTo(null);
     // This will ensure Mind == null
     Mind?.ChangeOwningPlayer(null);
 }