Exemplo n.º 1
0
        public Runes(Summoner summoner, String region)
        {
            InitializeComponent();
            _summoner = summoner;

            DataTable table = new DataTable();

            table.Columns.Add("Rune Page ID");
            table.Columns.Add("Rune Page Name");
            table.Columns.Add("Is Current");

            for (int i = 1; i <= 30; i++)
            {
                table.Columns.Add("Rune Slot " + i.ToString());
            }

            pages = summoner.GetRunes();
            for (int i = 0; i < pages.Count<RunePage>(); i++)
            {
                DataRow row = table.NewRow();

                row["Rune Page ID"] = pages[i].id;
                row["Rune Page Name"] = pages[i].name;
                row["Is Current"] = pages[i].current.ToString();

                if (pages[i].slots != null)
                {
                    for (int j = 0; j < pages[i].slots.Count<RuneSlot>(); j++)
                    {
                        row["Rune Slot " + (j + 1).ToString()] = pages[i].slots[j].rune.description;
                    }
                }

                table.Rows.Add(row);
            }
            RuneDataGridView.DataSource = table;
        }
        private void searchButton_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Trim() == "" || regionComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please enter a name or select a region.");
                return;
            }
            summoner = info.LookupSummonerByName(nameTextBox.Text, regionComboBox.SelectedItem.ToString());
            MessageBox.Show(summoner.Name);//21014383
            summoner = info.LookupSummonerByID(regionComboBox.SelectedItem.ToString(), summoner.ID);
            gamesPlayed = summoner.GetRecentGames();
            champs = info.GetChampions();
            PlayerStatsSummaryList sum = summoner.GetStatSummary(Season.SEASON3);
            int i = 0;
            foreach(Game game in gamesPlayed)
            {
                DataRow row = table.NewRow();

                row["Game"] = string.Format("Game {0}", i + 1);
                i++;
                //row["Champion"] = champs.FindById(game.ChampionId).Name;

                row["Queue"] = game.subType;

                row["WinLoss"] = game.Statistics.Win.ToString();

                row["Type"] = game.GameType;

                row["Date"] = game.CreateDateTime.Date;
                string kda = "";
                kda += game.Statistics.ChampionsKilled.ToString() + "/" + game.Statistics.Deaths.ToString() +"/" + game.Statistics.Assists.ToString();

                row["K/D/A"] = kda;
                table.Rows.Add(row);
            }
            summonerInfoDataGrid.DataSource = table;
        }
        private void searchButton_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Trim() == "" || regionComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please enter a name or select a region.");
                return;
            }

            InfoGrabber g = new InfoGrabber("na", LolInfo.APIKEY);

            summoner = g.LookupSummonerByName(nameTextBox.Text, regionComboBox.SelectedItem.ToString());

            try
            {
                teams = summoner.GetTeams();
            }
            catch
            {

            }
            finally
            {
                for (int i = 0; i < teams.Count(); i++)
                {
                    DataRow row = table.NewRow();

                    row["Team Name"] = teams[i].Name;
                    row["Number of Members"] = teams[i].Roster.MemberList.Count().ToString();

                    int team3v3Wins = 0;
                    int team3v3Losses = 0;

                    int team5v5Wins = 0;
                    int team5v5Losses = 0;

                    if (teams[i].MatchHistory != null)
                    {
                        for (int j = 0; j < teams[i].MatchHistory.Count(); j++)
                        {
                            if (teams[i].MatchHistory[j].Win)
                            {
                                if (teams[i].MatchHistory[j].MapId == 41)
                                {
                                    team3v3Wins++;
                                }
                                else
                                {
                                    team5v5Wins++;
                                }
                            }
                            else
                            {
                                if (teams[i].MatchHistory[j].MapId == 41)
                                {
                                    team3v3Losses++;
                                }
                                else
                                {
                                    team5v5Losses++;
                                }
                            }
                        }
                        row["Total Win/Loss"] = (team3v3Wins + team5v5Wins).ToString() + "/" + (team3v3Losses + team5v5Losses).ToString();
                        row["3v3 Win/Loss"] = team3v3Wins.ToString() + "/" + team3v3Losses.ToString();
                        row["5v5 Win/Loss"] = team5v5Wins.ToString() + "/" + team5v5Losses.ToString();
                    }
                    else
                    {
                        row["Total Win/Loss"] = "No Games Played";
                        row["3v3 Win/Loss"] = "No Games Played";
                        row["5v5 Win/Loss"] = "No Games Played";
                    }
                    table.Rows.Add(row);
                }
            }
            teamsInfoDataGrid.DataSource = table;
        }
        /// <summary>
        /// Looks up the specified summoner in the specified region and returns that summoner
        /// </summary>
        /// <param name="summonerName">The summoner to search for</param>
        /// <param name="region">The server region to check</param>
        /// <returns></returns>
        public Dictionary<string, Summoner> LookupSummonersByName(string region, params string[] names)
        {
            DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings();
            settings.UseSimpleDictionaryFormat = true;

            DataContractJsonSerializer jSerializer = new DataContractJsonSerializer(typeof(Dictionary<string, Summoner>), settings);
            WebClient webClient = new WebClient();
            Summoner tempSummoner = new Summoner();

            string urlToCheck = string.Format("https://na.api.pvp.net/api/lol/{0}/v1.4/summoner/by-name/", region);

            for (int i = 0; i < names.Length; i++)
            {
                urlToCheck += names[i];

                if (i != names.Length - 1)
                {
                    urlToCheck += ",";
                }
            }

            Dictionary<string, Summoner> tempList;

            try
            {
                tempList = (Dictionary<string, Summoner>)jSerializer.ReadObject(webClient.OpenRead(string.Format(urlToCheck + "?api_key={0}", LolInfo.APIKEY)));
            }
            catch (WebException e)
            {
                throw new Exception(e.Message);
            }
            foreach (Summoner s in tempList.Values)
            {
                s.Region = region;
            }

            return tempList;
        }