public IEnumerable <TournamentTeam> GetTeamsInTournament(string tournament)
        {
            var config            = ApiConfiguration.Load();
            var tournamentDetails = config.Tournaments.FirstOrDefault(k =>
                                                                      k.TournamentName.Equals(tournament, StringComparison.InvariantCultureIgnoreCase));

            return(tournamentDetails.TournamentType switch
            {
                ETournamentType.TeamFightTactics => (IEnumerable <TournamentTeam>)TeamRetrieval.Teams
                .Where(k => k.Tournament.TournamentName.Equals(tournament,
                                                               StringComparison.InvariantCultureIgnoreCase))
                .ToList()
                .ConvertAll(k => k as LeagueOfLegendsTeam),
                ETournamentType.League => TeamRetrieval.Teams
                .Where(k => k.Tournament.TournamentName.Equals(tournament,
                                                               StringComparison.InvariantCultureIgnoreCase))
                .ToList()
                .ConvertAll(k => k as LeagueOfLegendsTeam),
                ETournamentType.Rainbow6 => TeamRetrieval.Teams
                .Where(k => k.Tournament.TournamentName.Equals(tournament,
                                                               StringComparison.InvariantCultureIgnoreCase))
                .ToList()
                .ConvertAll(k => k as RainbowSixTeam),
                _ => new List <TournamentTeam>()
            });
 public List <Tournament> Get()
 {
     return(ApiConfiguration.Load().Tournaments);
 }
Exemple #3
0
        public static void GetTeams()
        {
            var config    = ApiConfiguration.Load();
            var newTeams  = new List <TournamentTeam>();
            var firstLoad = !Teams.Any();

            using (var web = new WebClient())
            {
                var profileIcons = JsonConvert.DeserializeObject <ProfileIcons>(
                    web.DownloadString("http://ddragon.leagueoflegends.com/cdn/9.20.1/data/en_US/profileicon.json"));

                foreach (var tournament in config.Tournaments)
                {
                    var participatingTeams = GetNuelTeams(config.NuelTournamentApi, config.NuelSignupPoolsApi,
                                                          tournament.TournamentName);

                    foreach (var team in participatingTeams)
                    {
                        var players = new List <TeamPlayer>();

                        foreach (var player in team.Members.ToList())
                        {
                            if (player.InGameName?.DisplayName == null)
                            {
                                var playerToAdd = tournament.TournamentType switch
                                {
                                    ETournamentType.Rainbow6 => (TeamPlayer) new RainbowSixPlayer
                                    {
                                        Name      = player.UserId,
                                        PlayerId  = "",
                                        IsCaptain = player.UserId == team.CaptainUserId
                                    },
                                    ETournamentType.TeamFightTactics => new LeagueOfLegendsPlayer
                                    {
                                        Name        = player.UserId,
                                        NumericRank = 5,
                                        IsCaptain   = player.UserId == team.CaptainUserId
                                    },
                                    ETournamentType.League => new LeagueOfLegendsPlayer
                                    {
                                        Name        = player.UserId,
                                        NumericRank = 5,
                                        IsCaptain   = player.UserId == team.CaptainUserId
                                    },
                                    _ => null
                                };

                                if (playerToAdd == null)
                                {
                                    continue;
                                }

                                players.Add(playerToAdd);
                            }
                            else
                            {
                                switch (tournament.TournamentType)
                                {
                                case ETournamentType.Rainbow6:
                                    var downloadStr = "{\"totalresults\":0}";
                                    try
                                    {
                                        downloadStr = web.DownloadString(
                                            $"https://r6tab.com/api/search.php?platform=uplay&search={player.InGameName.DisplayName}");
                                    }
                                    catch (WebException ex)
                                    {
                                        if (ex.Status != WebExceptionStatus.Timeout)
                                        {
                                            throw;
                                        }
                                    }

                                    var playerData = JsonConvert.DeserializeObject <PlayerData>(downloadStr);

                                    if ((playerData?.Results?.Length ?? 0) > 0)
                                    {
                                        var data = playerData.Results[0];
                                        players.Add(new RainbowSixPlayer
                                        {
                                            Name      = player.InGameName.DisplayName,
                                            Rank      = data.P_Currentrank,
                                            PlayerId  = data.P_User,
                                            Mmr       = data.P_Currentmmr,
                                            IsCaptain = player.UserId == team.CaptainUserId
                                        });
                                    }
                                    else
                                    {
                                        players.Add(new RainbowSixPlayer
                                        {
                                            Name      = player.InGameName.DisplayName,
                                            PlayerId  = "",
                                            IsCaptain = player.UserId == team.CaptainUserId
                                        });
                                    }

                                    break;

                                case ETournamentType.TeamFightTactics:
retryTft:
                                    try
                                    {
                                        var data = web.DownloadString(
                                            $"https://euw1.api.riotgames.com/tft/summoner/v1/summoners/by-name/{player.InGameName.DisplayName}?api_key={config.RiotApiKey}");
                                        var summonerDetails = JsonConvert.DeserializeObject <Summoner>(data);
                                        var data2           = web.DownloadString(
                                            $"https://euw1.api.riotgames.com/tft/league/v1/entries/by-summoner/{summonerDetails.Id}?api_key={config.RiotApiKey}");
                                        var playerStats = JsonConvert.DeserializeObject <SummonerLeague[]>(data2);
                                        Thread.Sleep(3000);

                                        if ((playerStats?.Length ?? 0) > 0)
                                        {
                                            var soloRankedData = playerStats.FirstOrDefault(k =>
                                                                                            k.QueueType.Equals("RANKED_TFT",
                                                                                                               StringComparison.InvariantCultureIgnoreCase));
                                            players.Add(new LeagueOfLegendsPlayer
                                            {
                                                Name = player.InGameName.DisplayName,
                                                Rank = soloRankedData == null
                                                        ? "bronze_1"
                                                        : soloRankedData.Tier.ToLower() + "_" +
                                                       LeagueUtils.FromRomanToInt(soloRankedData.Rank),
                                                NumericRank = soloRankedData == null
                                                        ? 5
                                                        : LeagueUtils.FromTierToInt(soloRankedData.Tier.ToLower()) +
                                                              LeagueUtils.FromRomanToInt(soloRankedData.Rank),
                                                PlayerId      = summonerDetails.Id,
                                                ProfileIconId =
                                                    int.TryParse(
                                                        profileIcons.Data.GetType()
                                                        .GetProperty("_" + summonerDetails.ProfileIconId)?.Name
                                                        ?.Substring(1) ?? "0", out var id)
                                                            ? id
                                                            : 0,
                                                IsCaptain = player.UserId == team.CaptainUserId
                                            });
                                        }