Exemple #1
0
        public LeagueEntry GetLeaguePosition(string summonerId, string server)
        {
            List <LeagueEntry> leagues = _client.GetLeagueEntriesBySummonerIdAsync(summonerId, server).Result;

            foreach (LeagueEntry league in leagues)
            {
                if (league.QueueType == "RANKED_SOLO_5x5")
                {
                    return(league);
                }
            }
            return(null);
        }
Exemple #2
0
        async Task <SummonerData> GetSummoner(string name, string server)
        {
            SummonerData summonerData = new SummonerData();
            int          elo;
            string       info = "";

            DateTime start = DateTime.Now;

            var summoner = await client.GetSummonerBySummonerNameAsync(name, server);

            if (summoner == null)
            {
                return(null);
            }
            var leagueEntries = await client.GetLeagueEntriesBySummonerIdAsync(summoner.Id, server);

            var leagueEntry = leagueEntries.Where(l => l.QueueType == "RANKED_SOLO_5x5").FirstOrDefault();

            if (leagueEntry == null)
            {
                var matchList = await client.GetMatchListByAccountIdAsync(summoner.AccountId, platformId : server);

                if (matchList == null)
                {
                    elo  = StaticValues.DefaultElo;
                    info = "No match list. Default value.";
                }
                else
                {
                    var match = await client.GetMatchAsync(matchList.Matches[0].GameId, server);

                    if (match == null)
                    {
                        elo  = StaticValues.DefaultElo;
                        info = "Can't get last match. Default value.";
                    }
                    else
                    {
                        info = "Based on last match.";
                        var participant = match.Participants.Where(p => p.ParticipantId == match.ParticipantIdentities.Where(i => i.Player.SummonerName == summoner.Name).FirstOrDefault().ParticipantId).FirstOrDefault();
                        var tier        = participant.HighestAchievedSeasonTier;
                        if (tier == null || tier == "UNRANKED")
                        {
                            elo   = StaticValues.DefaultElo;
                            info += " (Unranked)";
                        }
                        else
                        {
                            elo   = RankToPoints($"{tier} 2");
                            info += $" ({tier})";
                        }
                    }
                }
            }
            else
            {
                elo  = RankToPoints($"{leagueEntry.Tier} {RomanToArabic(leagueEntry.Rank)}") + leagueEntry.LeaguePoints;
                info = $"{leagueEntry.Tier} {leagueEntry.Rank}";
            }
            var timeout = 3000 - (DateTime.Now - start).TotalMilliseconds;

            if (timeout > 0)
            {
                Thread.Sleep((int)timeout);
            }

            summonerData.Name = summoner.Name;
            summonerData.Info = info;
            summonerData.Elo  = elo;
            return(summonerData);
        }