public void OnePlayerMatchMakingTest()
        {
            //one player two bots
            var player = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.GameMode, 1 }
            });

            _playersManager.Add(player, new List <Guid> {
                _group.Id
            });
            emptyTask.Wait(1500);
            var rooms = _roomManager.GetRooms(_group.Id);

            Assert.AreEqual(0, rooms.Count());
            rooms = _roomManager.GetRooms(_group.Id, false);
            Assert.AreEqual(1, rooms.Count());
            _roomManager.UpdateRoomState(rooms.First().Id, 1, RoomState.Open, 1);
            rooms = _roomManager.GetRooms(_group.Id);
            Assert.AreEqual(1, rooms.Count());
            var room = rooms.FirstOrDefault();

            Assert.AreEqual(1, room.CurrentWeight);
            Assert.AreEqual(true, room.IsOpen());
            Assert.AreEqual(true, room.CanJoin(2, 1));
        }
        public void AddRemoveTest()
        {
            var player   = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object>());
            var playerId = player.Id;

            _playersManager.Add(player, groupList1);
            var newPlayer = _playersManager.GetPlayer(playerId);

            Assert.AreEqual(player, newPlayer);
            Assert.AreEqual(1, _playersManager.Count());
            _playersManager.Remove(playerId);
            Assert.AreEqual(0, _playersManager.Count());
            Assert.IsNull(_playersManager.GetPlayer(Guid.NewGuid()));
        }
Exemplo n.º 3
0
        public void AddPlayerToMatchMaking(MatchMakingPlayer player)
        {
            lock (_mutex)
            {
                var groups = GetMatchmakingGroupIds(player.Properties);
                if (groups == null || groups.Count == 0)
                {
                    _logger.Info($"AddPlayerToMatchMaking error: no groups for player");
                    groups = new List <Guid>();
                    groups.Add(AddMatchMakingGroup(player.Properties));
                }

                _playersManager.Add(player, groups);
            }
        }
Exemplo n.º 4
0
        public void WeightJoinTest()
        {
            //first player
            var player1 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.GameMode, 1 }
            }, 1);
            //second player with weight > 1 (team probably)
            var player2 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.GameMode, 1 }
            }, 6);

            _playersManager.Add(player1, new List <Guid> {
                _group.Id
            });
            _playersManager.Add(player2, new List <Guid> {
                _group.Id
            });
            emptyTask.Wait(1500);
            var rooms = _roomManager.GetRooms(_group.Id);

            Assert.AreEqual(0, rooms.Count());
            rooms = _roomManager.GetRooms(_group.Id, false);
            Assert.AreEqual(1, rooms.Count());
            var room = rooms.First();

            Assert.AreEqual(RoomState.Closed, room.State);
            Assert.AreEqual(0, room.MaxWeightToJoin);
            Assert.AreEqual(2, room.CurrentWeight);
            Assert.AreEqual(12, room.TotalWeightNeeded);
            //update state
            _roomManager.UpdateRoomState(rooms.First().Id, 2, RoomState.Open, 5);
            rooms = _roomManager.GetRooms(_group.Id);
            Assert.AreEqual(1, rooms.Count());
            room = rooms.FirstOrDefault();
            Assert.AreEqual(2, room.CurrentWeight);
            Assert.AreEqual(true, room.IsOpen());
            Assert.AreEqual(true, room.CanJoin(5, 5));
            //third player
            var player3 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.GameMode, 1 }
            }, 1);

            _playersManager.Add(player3, new List <Guid> {
                _group.Id
            });
            emptyTask.Wait(1500);
            rooms = _roomManager.GetRooms(_group.Id, false);
            _roomManager.UpdateRoomState(rooms.First().Id, 2, RoomState.Open, 5);
            //forth player
            var player4 = new MatchMakingPlayer(new FakePeer(), new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.GameMode, 1 }
            }, 4);

            _playersManager.Add(player4, new List <Guid> {
                _group.Id
            });
            emptyTask.Wait(1500);
            rooms = _roomManager.GetRooms(_group.Id, false);
            //player 4 has weight > 1 - so he will go to new room
            Assert.AreEqual(2, rooms.Count());
        }