Exemple #1
0
        public void TestTargetBack()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var skeleton = new Skeleton()
            {
                Position = new Position(0, 1)
            };

            skeleton.AggroBehaviuor = BehaviourPool.Get <TargetBack>();

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = skeleton,
                Position = skeleton.Position
            });

            var chunk = player.GetChunk();

            client.SendToServer(new EntityTargetPacket()
            {
                TargetUuid = skeleton.UID,
                WhoUuid    = player.UID
            });

            Assert.That(skeleton.Target == player);
        }
Exemple #2
0
        public void EntityPathfindingColiisionChecks()
        {
            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            var path = Server.Map.FindPath(new Position(0, 0), new Position(-2, 0));

            Assert.That(path.Count == 3);

            var monster = Server.Map.Monsters.Values.First();

            var newPosition = new Position(-1, 0); // in between player and goal

            Server.Events.Call(new EntityMoveEvent()
            {
                Entity = monster,
                To     = newPosition
            });

            var pathWithMonsterInBetween = Server.Map.FindPath(new Position(0, 0), new Position(-2, 0));

            Assert.That(pathWithMonsterInBetween.Count == 5,
                        "Player did not move around the monster that spawned between him and his goal");
        }
Exemple #3
0
        public void TestPlayerMovingOnVariousDiferentChunk()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var chunkPackets = new List <BasePacket>();

            client.RecievedPackets.Clear();

            player.MoveSpeed = int.MaxValue;

            for (int i = 1; i <= 30; i++)
            {
                var newPosition = new Position(player.Position.X + 1, player.Position.Y);

                client.SendToServer(new EntityMovePacket
                {
                    ClientId = client.ConnectionId,
                    UID      = player.UID,
                    To       = newPosition
                });

                chunkPackets = client.RecievedPackets
                               .Where(p => p.GetType() == typeof(ChunkPacket))
                               .ToList();
            }

            Assert.That(chunkPackets.Count == 3,
                        "Player did not recieve updates from chunk map");
        }
Exemple #4
0
        public void TestMonsterMovingUpdatingClients()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var skeleton = new Skeleton()
            {
                Position = new Position(0, 1)
            };
            var chunk = player.GetChunk();

            chunk.EntitiesInChunk[EntityType.MONSTER].Add(skeleton);

            client.RecievedPackets.Clear();

            skeleton.MovementTick();
            skeleton.MovementTick();
            skeleton.MovementTick();

            var monsterMovePackets = client.RecievedPackets
                                     .Where(p => p.GetType() == typeof(EntityMovePacket))
                                     .Select(p => (EntityMovePacket)p)
                                     .Where(p => p.UID == skeleton.UID)
                                     .ToList();

            Assert.That(monsterMovePackets.Count > 0,
                        "Player did not recieve updates from monster moving");
        }
        public void TestPlayerMoving()
        {
            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            client.SendToServer(new EntityMovePacket()
            {
                From = new Position(_player.X, _player.Y),
                To   = new Position(_player.X - 1, _player.Y),
                UID  = _player.UserId
            });

            var player = RedisHash <StoredPlayer> .Get(_player.UserId);

            Assert.That(player.X == _player.X - 1,
                        "Server did not store that the player moved");

            var onlinePlayer = Server.GetPlayer(_player.UserId);

            Assert.That(onlinePlayer.Position.X == _player.X - 1,
                        "Server did not update online player position");

            var chunk = onlinePlayer.GetChunk();

            Assert.That(chunk.x == -1,
                        "Player should have moved to other chunk");

            Assert.That(chunk.PlayersInChunk.Contains(onlinePlayer),
                        "New chunk did not contain the player reference");
        }
Exemple #6
0
        public void TestPlayerTooFarAwayToRecieveUpdates()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var skeleton = new Skeleton()
            {
                Position = new Position(33, 0)
            };

            var monsterChunk = Server.Map.GetChunk(2, 0);
            var playerChunki = Server.Map.GetChunk(0, 0);

            var chunks = Server.Map.Chunks;

            monsterChunk.EntitiesInChunk[EntityType.MONSTER].Add(skeleton);

            client.RecievedPackets.Clear();

            skeleton.MovementTick();
            skeleton.MovementTick();
            skeleton.MovementTick();

            var monsterMovePackets = client.RecievedPackets
                                     .Where(p => p.GetType() == typeof(EntityMovePacket))
                                     .Select(p => (EntityMovePacket)p)
                                     .Where(p => p.UID == skeleton.UID)
                                     .ToList();

            Assert.That(monsterMovePackets.Count == 0,
                        "Player Recieved Updates from a too far away monster");
        }
Exemple #7
0
        public void TestPlayerPacketBeingRecieved()
        {
            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            Assert.That(client.RecievedPackets.Any(p => p.GetType() == typeof(PlayerPacket)),
                        "Player didnt got his own player packet with his info");
        }
Exemple #8
0
        public void TestChunksRecieved()
        {
            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            var chunksRecieved = client.RecievedPackets.Where(p => p.GetType() == typeof(ChunkPacket)).ToList();

            Assert.That(chunksRecieved.Count == 9,
                        "Player should have recieved 9 chunk packets (3x3)");
        }
Exemple #9
0
        public void TestMonsterDieCleansMonsterData()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var skeleton = new Skeleton()
            {
                Position = new Position(0, 1)
            };

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = skeleton,
                Position = skeleton.Position
            });
            skeleton.MovementBehaviour = null;
            skeleton.MovementTick();

            var skeletonMoveTask = GameScheduler.GetTask(skeleton.MovementTaskId);

            Assert.That(skeletonMoveTask != null,
                        "Monster movement task should be created upon spawning");

            player.Atk      = 5;
            player.AtkSpeed = 99999999;
            skeleton.Def    = 0;

            player.TryAttacking(skeleton, singleHit: true);

            Assert.That(skeleton.HP == skeleton.MAXHP - 5,
                        "5 atk on 0 def should deal 5 damage");

            player.Atk = 5000;

            player.TryAttacking(skeleton, singleHit: true);

            var moveTask   = GameScheduler.GetTask(skeleton.MovementTaskId);
            var attackTask = GameScheduler.GetTask(skeleton.AttackTaskId);

            Assert.That(skeleton.HP < 0,
                        "Skeleton should have < 0 hp as he took 5k damage");

            Assert.That(!Server.Map.Monsters.ContainsKey(skeleton.UID),
                        "Server should not contain the skeleton as its dead.");

            Assert.That(moveTask == null,
                        "Skeleton is dead and his move task should have been cancelled");

            Assert.That(attackTask == null,
                        "Skeleton is dead and his move task should have been cancelled");
        }
Exemple #10
0
        public void TestMovingPlayerCollision()
        {
            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            var tilePlayerIn = Server.Map.GetTile(_player.X, _player.Y);

            Assert.That(tilePlayerIn.Occupator.UID == _player.UserId,
                        "Player Did not occupy his tile when spawning");

            client.SendToServer(new EntityMovePacket()
            {
                To  = new Position(_player.X - 1, _player.Y),
                UID = _player.UserId,
            });

            var playerWasin   = Server.Map.GetTile(_player.X, _player.Y);
            var playerGoingTo = Server.Map.GetTile(_player.X - 1, _player.Y);

            Assert.That(Server.Map.IsPassable(_player.X - 1, _player.Y) == false,
                        "Player new occupation was not properly set after moving");
            Assert.That(Server.Map.IsPassable(_player.X, _player.Y) == true,
                        "Player new occupation was not properly set after moving");
            Assert.That(playerWasin.Occupator == null,
                        "Player new occupation was not properly set after moving");
            Assert.That(playerGoingTo.Occupator.UID == _player.UserId,
                        "Player new occupation was not properly set after moving");

            client.SendToServer(new EntityMovePacket()
            {
                To  = new Position(_player.X, _player.Y),
                UID = _player.UserId,
            });

            playerWasin   = Server.Map.GetTile(_player.X - 1, _player.Y);
            playerGoingTo = Server.Map.GetTile(_player.X, _player.Y);

            Assert.That(Server.Map.IsPassable(_player.X - 1, _player.Y) == true,
                        "Player new occupation was not properly set after moving");
            Assert.That(Server.Map.IsPassable(_player.X, _player.Y) == false,
                        "Player new occupation was not properly set after moving");
            Assert.That(playerWasin.Occupator == null,
                        "Player new occupation was not properly set after moving");
            Assert.That(playerGoingTo.Occupator.UID == _player.UserId,
                        "Player new occupation was not properly set after moving");
        }
Exemple #11
0
        public void EntityEntityPassabilityCheck()
        {
            Assert.That(Server.Map.IsPassable(_player.X, _player.Y) == true,
                        "Tile is returning its not passable, but it should be");

            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            Assert.That(Server.Map.IsPassable(_player.X, _player.Y) == false,
                        "A tile that a player is in is returning passable");

            var skeleton = new Skeleton();

            skeleton.Position = new Position(0, 3);

            Assert.That(Server.Map.IsPassable(skeleton.Position.X, skeleton.Position.Y) == true,
                        "Tile should be flagged as passable as the skeleton is not there yet");

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = skeleton,
                Position = skeleton.Position
            });

            Assert.That(Server.Map.IsPassable(skeleton.Position.X, skeleton.Position.Y) == false,
                        "Tile should not be passable as there is a skeleton there now");

            var newPosition = new Position(skeleton.Position.X + 1, skeleton.Position.Y);

            Assert.That(Server.Map.IsPassable(newPosition.X, newPosition.Y) == true,
                        "Skeleton didnt move yet so it should be passable");

            Server.Events.Call(new EntityMoveEvent()
            {
                Entity = skeleton,
                From   = skeleton.Position,
                To     = newPosition
            });

            Assert.That(Server.Map.IsPassable(newPosition.X, newPosition.Y) == false,
                        "After skeleton moved his tile should be impassable");

            Assert.That(Server.Map.IsPassable(newPosition.X - 1, newPosition.Y) == true,
                        "Skeleton last position was not freed after he moved");
        }
Exemple #12
0
        public void TestDownloadAssetsSequence()
        {
            var client = ServerMocker.GetClient();

            AccountService.RegisterAccount(_player.Login, _player.Password, _player.Email, _player);
            client.Login(_player.Login, _player.Password);

            var assetsRequiredPackets = client.RecievedPackets.
                                        Where(p => p.GetType() == typeof(AssetPacket))
                                        .ToList();

            // sending to server that i dont own this assets client-side, please send me mister server
            client.RecievedPackets.Clear();
            foreach (var assetPacket in assetsRequiredPackets)
            {
                client.SendToServer(assetPacket);
            }

            Assert.That(client.RecievedPackets.Count == assetsRequiredPackets.Count,
                        "Client did not recieve all assets he asked for");
        }
Exemple #13
0
        public void TestMonsterAttackingPlayer()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var skeleton = new Skeleton()
            {
                Position = new Position(0, 1)
            };

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = skeleton,
                Position = skeleton.Position
            });

            var playerHpBefore = player.HP;

            client.RecievedPackets.Clear();

            Thread.Sleep(100);

            Server.Events.Call(new EntityTargetEvent()
            {
                Entity         = skeleton,
                TargetedEntity = player
            });

            var playerHpAfter = player.HP;

            var recievedDamagePackets = client.RecievedPackets
                                        .Where(p => p.GetType() == typeof(EntityAttackPacket))
                                        .Any();

            Assert.That(playerHpAfter < playerHpBefore,
                        "Player should have taken a hit from monster");

            Assert.True(recievedDamagePackets,
                        "Client did not recieved the skeleton attack packet");
        }
Exemple #14
0
        public void Start()
        {
            Redis redis = new Redis();

            redis.Start();
            TestDb.Create();
            _server = new Server(new Server.ServerStartConfig()
            {
                Port = 123, DisableSpawners = true
            });
            // _server.StartGameThread();
            GameThread.TIME_MS_NOW = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            _player = new StoredPlayer()
            {
                UserId    = "wololo",
                Login     = "******",
                Password  = "******",
                MoveSpeed = 1,
                X         = 0,
                Y         = 0
            };
            _client = ServerMocker.GetClient();
            _client.FullLoginSequence(_player);
            _monster = new Skeleton()
            {
                HP       = 10,
                Position = new Position(1, 0)
            };

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = _monster,
                Position = _monster.Position
            });

            // So we can send move events w/o worryng about cooldown check
            Server.GetPlayer(_player.UserId).MoveSpeed = int.MaxValue;
        }
Exemple #15
0
        public void TestDownloadAssetSequenceTwice()
        {
            var client = ServerMocker.GetClient();

            AccountService.RegisterAccount(_player.Login, _player.Password, _player.Email, _player);

            client.Login(_player.Login, _player.Password);
            var assetsRequiredPackets = client.RecievedPackets.
                                        Where(p => p.GetType() == typeof(AssetPacket))
                                        .ToList();

            client.RecievedPackets.Clear();
            foreach (var assetPacket in assetsRequiredPackets)
            {
                client.SendToServer(assetPacket);
            }

            var assetsRecieved = client.RecievedPackets.
                                 Where(p => p.GetType() == typeof(AssetPacket))
                                 .ToList();

            // Now logging out and logging in again and recieveing the assets again

            client.Logout();
            client.Login(_player.Login, _player.Password);

            var assetsRequiredPacketsAgain = client.RecievedPackets.
                                             Where(p => p.GetType() == typeof(AssetPacket))
                                             .ToList();

            // sending to server that i dont own this assets client-side, please send me mister server
            client.RecievedPackets.Clear();
            foreach (var assetPacket in assetsRequiredPacketsAgain)
            {
                client.SendToServer(assetPacket);
            }
        }
Exemple #16
0
        public void TestMonsterMovingCollision()
        {
            var client = ServerMocker.GetClient();

            client.FullLoginSequence(_player);

            var skeleton = new Skeleton();

            skeleton.Position          = new Position(1, 1);
            skeleton.MovementBehaviour = BehaviourPool.Get <LeftRightWalk>();

            Server.Map.GetTile(2, 1).TileId = 2; // block

            var originalX = skeleton.Position.X;

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = skeleton,
                Position = skeleton.Position
            });

            client.SendToServer(new EntityMovePacket()
            {
                To  = new Position(_player.X, _player.Y + 1),
                UID = _player.UserId,
            });

            client.RecievedPackets.Clear();

            skeleton.MovementTick();

            Assert.That(skeleton.Position.X == originalX,
                        "Skeleton couldnt have moved as he was in between 2 obstacles");

            Assert.That(client.RecievedPackets.Count == 0,
                        "Player should not recieve monster move packets if the monster didnt moved");
        }
Exemple #17
0
        public void TestPlayerTooFarAwayToRecieveUpdates()
        {
            var client = ServerMocker.GetClient();
            var player = client.FullLoginSequence(_player);

            var skeleton = new Skeleton()
            {
                Position = new Position(45, 0)
            };

            Server.Events.Call(new EntitySpawnEvent()
            {
                Entity   = skeleton,
                Position = skeleton.Position
            });

            var monsterChunk = Server.Map.GetChunkByChunkPosition(2, 0);
            var playerChunki = Server.Map.GetChunkByChunkPosition(0, 0);

            var chunks = Server.Map.Chunks;

            client.RecievedPackets.Clear();

            skeleton.MovementTick();
            skeleton.MovementTick();
            skeleton.MovementTick();

            var monsterMovePackets = client.RecievedPackets
                                     .Where(p => p.GetType() == typeof(EntityMovePacket))
                                     .Select(p => (EntityMovePacket)p)
                                     .Where(p => p.UID == skeleton.UID)
                                     .ToList();

            Assert.That(monsterMovePackets.Count == 0,
                        "Player Recieved Updates from a too far away monster");
        }