Ejemplo n.º 1
0
        public void Update()
        {
            if (_inQueue.DistinctBy(item => item.Login).Count() < 2)
            {
                return;
            }

            for (var i = 0; i < _inQueue.Count; i++)
            {
                if (_joinedQueueTime[_inQueue[i]] > _maxTimeInQueue)
                {
                    var hoomanBots = _inQueue.Where(usr => !usr.IsBot && usr != _inQueue[i]).ToArray();
                    if (hoomanBots.Any())
                    {
                        IServerUser bestHoomanBot;
                        if (hoomanBots.Length == 1)
                        {
                            bestHoomanBot = hoomanBots[0];
                        }
                        else
                        {
                            var bestMatch = Supervisor.GetBestChoice(_inQueue[i].Login, hoomanBots.Select(item => item.Login));
                            bestHoomanBot = hoomanBots.FirstOrDefault(bot => bot.Login == bestMatch);
                        }
                        if (bestHoomanBot == null)
                        {
                            _logger.LogError($"{GetType().Name}: {Supervisor.GetType()} gave me an invalid GUID as best choice!");
                            continue;
                        }

                        _logger.LogDebug($"{_inQueue[i]} found a match: {bestHoomanBot})");
                        OnSuggested?.Invoke(this, new MatchCreatedArgs(this, _gameMode, bestHoomanBot, _inQueue[i]));
                    }
                    else
                    {
                        var bestMatch  = Supervisor.GetBestChoice(_inQueue[i].Login, _inQueue.Where(item => item != _inQueue[i]).ToArray().Select(item => item.Login));
                        var bestBotBot = hoomanBots.FirstOrDefault(bot => bot.Login == bestMatch);

                        if (bestBotBot == null)
                        {
                            _logger.LogError($"{GetType().Name}: {Supervisor.GetType()} gave me an invalid GUID as best choice!");
                            continue;
                        }

                        _logger.LogDebug($"{_inQueue[i]} exceeded max queue time, matching with bot: {bestBotBot})");
                        OnSuggested?.Invoke(this, new MatchCreatedArgs(this, _gameMode, bestBotBot, _inQueue[i]));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void EnterQueue(IServerUser user)
        {
            var time = _time.Elapsed.TotalSeconds;

            if (time - _lastQueuerTime > _maxTimeInQueue && _inQueue.All(item => item.IsBot) && _inQueue.Any() && !user.IsBot)
            {
                AddUser(user);

                var bestMatch  = Supervisor.GetBestChoice(user.Login, _inQueue.Where(item => item != user).ToArray().Select(item => item.Login));
                var bestBotBot = _inQueue.FirstOrDefault(bot => bot.Login == bestMatch);

                if (bestBotBot == null)
                {
                    _logger.LogError($"{GetType().Name}: {Supervisor.GetType()} gave me an invalid GUID as best choice!");
                }
                else
                {
                    _logger.LogDebug($"Found a match (Queue very empty for a longer time, matching with bot: {bestBotBot})");
                    OnSuggested?.Invoke(this, new MatchCreatedArgs(this, _gameMode, user, bestBotBot));
                    return;
                }
            }


            if (!user.IsBot)
            {
                _lastQueuerTime = time;
            }

            AddUser(user);
            var autoBestMatch = _inQueue.FirstOrDefault(usr => usr != user && !usr.HasEverPlayedAgainst(user, Supervisor));

            if (autoBestMatch != null)
            {
                _logger.LogDebug($"Found a match (never played against {autoBestMatch})");
                OnSuggested?.Invoke(this, new MatchCreatedArgs(this, _gameMode, autoBestMatch, user));
            }
        }