public void SetCurrentChamp(Int64 champId) { if (InvokeRequired) { Invoke(new Action <Int64>(SetCurrentChamp), champId); return; } Console.WriteLine("champ" + champId); if (champId == 0) { return; } currChampIcon.Image = ChampIcons.Get(Convert.ToInt32(champId)); int champKills = 0; int champAssists = 0; int champDeaths = 0; bool playedChamp = false; if (PlayerStats != null) { foreach (var stat in PlayerStats.LifetimeStatistics) { if (stat.ChampionID == champId) { playedChamp = true; if (stat.StatType.Contains("TOTAL_CHAMPION_KILLS")) { champKills = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_ASSISTS")) { champAssists = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_DEATHS_PER_SESSION")) { champDeaths = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_SESSIONS_PLAYED")) { champGames.Text = Convert.ToInt32(stat.Value).ToString(); } if (stat.StatType.Contains("TOTAL_SESSIONS_WON")) { champPercentWon.Text = Convert.ToInt32(stat.Value).ToString(); } } } } if (playedChamp) { champPercentWon.Text = ((100.0f * (Convert.ToInt32(champPercentWon.Text)) / Convert.ToDouble(champGames.Text)) + 0.0001).ToString().Substring(0, 4) + "%"; if (Convert.ToDouble(champPercentWon.Text.Substring(0, 4)) > 50.0f) { champPercentWon.ForeColor = Color.DarkGreen; } else { champPercentWon.ForeColor = Color.DarkRed; } float champKdaCalc = (champKills + champAssists) / (float)champDeaths; champKda.Text = (champKdaCalc + 0.0001).ToString().Substring(0, 4); if (champKdaCalc < 2.25) { champKda.ForeColor = Color.DarkRed; } else if (champKdaCalc < 3) { champKda.ForeColor = Color.DarkOrange; } else { champKda.ForeColor = Color.DarkGreen; } } else { champKda.Text = "?.??"; champPercentWon.Text = "??.?%"; champGames.Text = "0"; } }
public void SetGames(RecentGames games) { if (games == null || games.GameStatistics.Count < 1) { return; } if (InvokeRequired) { Invoke(new Action <RecentGames>(SetGames), games); return; } RemoveAll(p => (p.Tag as string) == "Recent"); var layout = new TableLayoutPanel { Dock = DockStyle.Fill, Margin = Padding.Empty, }; const int rows = 5; const int cols = 2; var list = games.GameStatistics.OrderByDescending(p => p.GameId).ToList(); for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { int idx = y + (x * rows); if (idx >= list.Count) { break; } var game = list[idx]; if (game.ChampionId == 0) { continue; } var won = game.Statistics.GetInt(RawStat.WIN) != 0; var kills = game.Statistics.GetInt(RawStat.CHAMPION_KILLS); var deaths = game.Statistics.GetInt(RawStat.DEATHS); var assists = game.Statistics.GetInt(RawStat.ASSISTS); var left = game.Leaver; var botgame = game.QueueType == "BOT"; var wonlabel = CreateLabel(string.Format("{0}{1}", left ? "[L] " : "", won ? "Won" : "Lost")); wonlabel.ForeColor = won ? Color.Green : Color.Red; var kdrlbl = CreateLabel(string.Format("({0}/{1}/{2})", kills, deaths, assists)); kdrlbl.ForeColor = GetKdrColor(kills, deaths); var champicon = new PictureBox { Image = ChampIcons.Get(game.ChampionId), Margin = Padding.Empty, SizeMode = PictureBoxSizeMode.StretchImage, Size = new Size(20, 20) }; if (botgame) { wonlabel.ForeColor = kdrlbl.ForeColor = Color.Black; } var controls = new List <Control> { champicon, wonlabel, kdrlbl, CreateSpellPicture(game.Spell1), CreateSpellPicture(game.Spell2) }; //Add a space between the last column in each set. controls[controls.Count - 1].Margin = new Padding(0, 0, 5, 0); for (int i = 0; i < controls.Count; i++) { layout.AddControl(controls[i], i + x * controls.Count, y); } } } var tab = new TabPage("Recent") { BackColor = this.BackColor, Tag = "Recent" }; tab.Controls.Add(layout); AddTab(tab); }
public void SetRankedStats(PublicSummoner summoner, AggregatedStats stats) { if (summoner == null || stats == null) { return; } if (InvokeRequired) { Invoke(new Action <PublicSummoner, AggregatedStats>(SetRankedStats), summoner, stats); return; } PlayerStats = stats; int kills = 0; int assists = 0; int deaths = 0; Dictionary <int, int> favChamps = new Dictionary <int, int>(); foreach (var stat in stats.LifetimeStatistics) { if (stat.ChampionID == 0) { if (stat.StatType.Contains("TOTAL_CHAMPION_KILLS")) { kills = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_ASSISTS")) { assists = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_DEATHS_PER_SESSION")) { deaths = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_SESSIONS_PLAYED")) { totalGames.Text = Convert.ToInt32(stat.Value).ToString(); } if (stat.StatType.Contains("TOTAL_SESSIONS_WON")) { totalPercentWon.Text = Convert.ToInt32(stat.Value).ToString(); } } else { if (stat.StatType.Contains("TOTAL_SESSIONS_PLAYED")) { if (favChamps.Count() <= 5) { favChamps.Add(stat.ChampionID, Convert.ToInt32(stat.Value)); } else { var min = favChamps.OrderBy(kvp => kvp.Value).First(); var minKey = min.Key; var minValue = min.Value; if (Convert.ToInt32(stat.Value) > minValue) { favChamps.Remove(minKey); favChamps.Add(stat.ChampionID, Convert.ToInt32(stat.Value)); } } } } } totalPercentWon.Text = ((100.0f * (Convert.ToInt32(totalPercentWon.Text)) / Convert.ToDouble(totalGames.Text)) + 0.0001).ToString().Substring(0, 4) + "%"; if (Convert.ToDouble(totalPercentWon.Text.Substring(0, 4)) > 50.0f) { totalPercentWon.ForeColor = Color.DarkGreen; } else { totalPercentWon.ForeColor = Color.DarkRed; } float totalKdaCalc = (kills + assists) / (float)deaths; totalKda.Text = totalKdaCalc.ToString().Substring(0, 4); if (totalKdaCalc < 2.25) { totalKda.ForeColor = Color.DarkRed; } else if (totalKdaCalc < 3) { totalKda.ForeColor = Color.DarkOrange; } else { totalKda.ForeColor = Color.DarkGreen; } for (int i = 0; i < 5; i++) { var favChamp = favChamps.OrderBy(kvp => kvp.Value).Last(); var name = ChampNames.GetOrDefault(favChamp.Key); favChampIcons[i].Image = ChampIcons.Get(favChamp.Key); favChamps.Remove(favChamp.Key); foreach (var stat in stats.LifetimeStatistics) { if (favChamp.Key == stat.ChampionID) { if (stat.StatType.Contains("TOTAL_CHAMPION_KILLS")) { kills = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_ASSISTS")) { assists = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_DEATHS_PER_SESSION")) { deaths = Convert.ToInt32(stat.Value); } } } float tempChampKda = (kills + assists) / (float)deaths; favChampKdas[i].SetToolTip(favChampIcons[i], tempChampKda.ToString()); } }