Ejemplo n.º 1
0
        private void MatchMakerEvent()
        {
            RemoveFinsihedMatches();

            var queuedUsers = _gameServerService.RegistredUsers.Where(user => user.UserState == UserState.Queued).ToList();

            if (queuedUsers.Count > 0)
            {
                Log.Info($"{queuedUsers.Count} users queued for matchmaking.");
            }

            for (int i = 0; i < _maxGamesPerCall && queuedUsers.Count > 1; i++)
            {
                var player1 = queuedUsers.ElementAt(0);
                var player2 = queuedUsers.ElementAt(1);
                queuedUsers.RemoveRange(0, 2);

                player1.UserState = UserState.Invited;
                player2.UserState = UserState.Invited;

                var gameId    = Index;
                var matchgame = new MatchGameService(_gameServerService, gameId, player1, player2);
                if (_matchGames.TryAdd(gameId, matchgame))
                {
                    matchgame.Initialize();
                }
                else
                {
                    Log.Error($"Couldn't add [GameId:{gameId}] match game with {player1.AccountName} and {player2.AccountName}.");
                }
            }
        }
Ejemplo n.º 2
0
        private void MatchMakerEvent()
        {
            var finishedMatches = _matchGames.Values.Where(matchGamesValue => matchGamesValue.IsFinished).ToList();

            finishedMatches.ForEach(p =>
            {
                if (_matchGames.TryRemove(p.GameId, out var finishedMatch))
                {
                    Log.Info($"[GameId:{finishedMatch.GameId}] finished, [{finishedMatch.Player1.AccountName}:{finishedMatch.Play1State}] vs [{finishedMatch.Player2.AccountName}:{finishedMatch.Play2State}].");
                }
            });

            var queuedUsers = _gameServerService.RegistredUsers.Where(user => user.UserState == UserState.Queued).ToList();

            if (queuedUsers.Count > 0)
            {
                Log.Info($"{queuedUsers.Count} users queued for matchmaking.");
            }

            for (int i = 0; i < _maxGamesPerCall && queuedUsers.Count > 1; i++)
            {
                var player1 = queuedUsers.ElementAt(0);
                var player2 = queuedUsers.ElementAt(1);
                queuedUsers.RemoveRange(0, 2);

                player1.UserState = UserState.Invited;
                player2.UserState = UserState.Invited;

                var gameId    = Index;
                var matchgame = new MatchGameService(_gameServerService, gameId, player1, player2);
                if (_matchGames.TryAdd(gameId, matchgame))
                {
                    matchgame.Initialize();
                }
                else
                {
                    Log.Error($"Couldn't add [GameId:{gameId}] match game with {player1.AccountName} and {player2.AccountName}.");
                }
            }
        }