public void GotRecentGames(RecentGames result)
        {
            GameStats.Clear();
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            foreach (PlayerGameStats Game in result.GameStatistics)
            {
                Game.QueueType = Client.TitleCaseString(Game.QueueType.Replace("ODIN", "Dominion").Replace("UNRANKED", "").Replace("_5x5", "").Replace("_", " ")).Replace("Aram", "ARAM").Trim();
                MatchStats Match = new MatchStats();

                foreach (RawStat Stat in Game.Statistics)
                {
                    var type = typeof(MatchStats);
                    string fieldName = Client.TitleCaseString(Stat.StatType.Replace('_', ' ')).Replace(" ", "");
                    var f = type.GetField(fieldName);
                    f.SetValue(Match, Stat.Value);
                }

                Match.Game = Game;

                GameStats.Add(Match);
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                GamesListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();
                PurpleListView.Items.Clear();
                GameStatsListView.Items.Clear();
                foreach (MatchStats stats in GameStats)
                {
                    RecentGameOverview item = new RecentGameOverview();
                    champions GameChamp = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                    item.ChampionImage.Source = GameChamp.icon;
                    item.ChampionNameLabel.Content = GameChamp.displayName;
                    item.ScoreLabel.Content =
                        string.Format("{0}/{1}/{2} ({3})",
                        stats.ChampionsKilled,
                        stats.NumDeaths,
                        stats.Assists,
                        stats.Game.QueueType);

                    item.MapLabel.Content = BaseMap.GetMap(stats.Game.GameMapId).DisplayName;
                    item.DateLabel.Content = stats.Game.CreateDate;
                    item.IPEarnedLabel.Content = "+" + stats.Game.IpEarned + " IP";
                    item.PingLabel.Content = stats.Game.UserServerPing + "ms";

                    BrushConverter bc = new BrushConverter();
                    Brush brush = (Brush)bc.ConvertFrom("#FF609E74");

                    if (stats.Lose == 1)
                        brush = (Brush)bc.ConvertFrom("#FF9E6060");

                    item.GridView.Background = brush;
                    item.GridView.Width = 250;
                    GamesListView.Items.Add(item);
                }
            }));
        }
Beispiel #2
0
        public void GotRecentGames(RecentGames result)
        {
            if (result.GameStatistics == null)
            {
                return;
            }

            _gameStats.Clear();
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            foreach (var game in result.GameStatistics)
            {
                game.GameType =
                    Client.TitleCaseString(game.GameType.Replace("_GAME", string.Empty).Replace("MATCHED", "NORMAL"));
                var match = new MatchStats();

                foreach (var stat in game.Statistics)
                {
                    var type      = typeof(MatchStats);
                    var fieldName = Client.TitleCaseString(stat.StatType.Replace('_', ' ')).Replace(" ", string.Empty);
                    var f         = type.GetField(fieldName);
                    f.SetValue(match, stat.Value);
                }

                match.Game = game;

                _gameStats.Add(match);
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                GamesListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();
                PurpleListView.Items.Clear();
                GameStatsListView.Items.Clear();
                foreach (var stats in _gameStats)
                {
                    var item                       = new RecentGameOverview();
                    var gameChamp                  = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                    item.ChampionImage.Source      = gameChamp.icon;
                    item.ChampionNameLabel.Content = gameChamp.displayName;
                    item.ScoreLabel.Content        =
                        string.Format("{0}/{1}/{2} ",
                                      stats.ChampionsKilled,
                                      stats.NumDeaths,
                                      stats.Assists);

                    switch (stats.Game.QueueType)
                    {
                    case "NORMAL":
                        item.ScoreLabel.Content += "(Normal)";
                        break;

                    case "NORMAL_3x3":
                        item.ScoreLabel.Content += "(Normal 3v3)";
                        break;

                    case "ARAM_UNRANKED_5x5":
                        item.ScoreLabel.Content += "(ARAM)";
                        break;

                    case "NONE":
                        item.ScoreLabel.Content += "(Custom)";
                        break;

                    case "RANKED_SOLO_5x5":
                        item.ScoreLabel.Content += "(Ranked 5v5)";
                        break;

                    case "RANKED_TEAM_5x5":
                        item.ScoreLabel.Content += "(Ranked Team 5v5)";
                        break;

                    case "RANKED_TEAM_3x3":
                        item.ScoreLabel.Content += "(Ranked Team 3v3)";
                        break;

                    case "CAP_5x5":
                        item.ScoreLabel.Content += "(Team Builder)";
                        break;

                    case "BOT":
                        item.ScoreLabel.Content += "(Bots)";
                        break;

                    case "KING_PORO":
                        item.ScoreLabel.Content += "(King Poro)";
                        break;

                    case "COUNTER_PICK":
                        item.ScoreLabel.Content += "(Nemesis Draft)";
                        break;

                    default:
                        Client.Log(stats.Game.QueueType);
                        item.ScoreLabel.Content += "Please upload this log to github.";
                        break;
                    }

                    item.CreepScoreLabel.Content = stats.MinionsKilled + " minions";
                    item.DateLabel.Content       = stats.Game.CreateDate;
                    item.IPEarnedLabel.Content   = "+" + stats.Game.IpEarned + " IP";
                    item.PingLabel.Content       = stats.Game.UserServerPing + "ms";

                    var bc    = new BrushConverter();
                    var brush = (Brush)bc.ConvertFrom("#FF609E74");

                    if (Math.Abs(stats.Lose - 1) < .00001)
                    {
                        brush = (Brush)bc.ConvertFrom("#FF9E6060");
                    }
                    else if (Math.Abs(stats.Game.IpEarned) < .00001)
                    {
                        brush = (Brush)bc.ConvertFrom("#FFE27100");
                    }

                    item.GridView.Background = brush;
                    item.GridView.Width      = 280;
                    GamesListView.Items.Add(item);
                }
                if (GamesListView.Items.Count > 0)
                {
                    GamesListView.SelectedIndex = 0;
                }
            }));
        }
        public void GotRecentGames(RecentGames result)
        {
            GameStats.Clear();
            try
            {
                result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
                foreach (PlayerGameStats Game in result.GameStatistics)
                {
                    Game.GameType = Client.TitleCaseString(Game.GameType.Replace("_GAME", "").Replace("MATCHED", "NORMAL"));
                    var Match = new MatchStats();

                    foreach (RawStat Stat in Game.Statistics)
                    {
                        Type      type      = typeof(MatchStats);
                        string    fieldName = Client.TitleCaseString(Stat.StatType.Replace('_', ' ')).Replace(" ", "");
                        FieldInfo f         = type.GetField(fieldName);
                        f.SetValue(Match, Stat.Value);
                    }

                    Match.Game = Game;

                    GameStats.Add(Match);
                }
            }
            catch
            {
                Client.Log("Can't load player recent games", "ERROR");
            }
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                GamesListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();
                PurpleListView.Items.Clear();
                GameStatsListView.Items.Clear();
                foreach (MatchStats stats in GameStats)
                {
                    var item                       = new RecentGameOverview();
                    champions GameChamp            = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                    item.ChampionImage.Source      = GameChamp.icon;
                    item.ChampionNameLabel.Content = GameChamp.displayName;
                    item.ScoreLabel.Content        =
                        string.Format("{0}/{1}/{2} ",
                                      stats.ChampionsKilled,
                                      stats.NumDeaths,
                                      stats.Assists);

                    switch (stats.Game.QueueType)
                    {
                    case "NORMAL":
                        item.ScoreLabel.Content += "(Normal)";
                        break;

                    case "NORMAL_3x3":
                        item.ScoreLabel.Content += "(Normal 3v3)";
                        break;

                    case "ARAM_UNRANKED_5x5":
                        item.ScoreLabel.Content += "(ARAM)";
                        break;

                    case "NONE":
                        item.ScoreLabel.Content += "(Custom)";
                        break;

                    case "RANKED_SOLO_5x5":
                        item.ScoreLabel.Content += "(Ranked 5v5)";
                        break;

                    case "RANKED_TEAM_5x5":
                        item.ScoreLabel.Content += "(Ranked Team 5v5)";
                        break;

                    case "RANKED_TEAM_3x3":
                        item.ScoreLabel.Content += "(Ranked Team 3v3)";
                        break;

                    case "CAP_5x5":
                        item.ScoreLabel.Content += "(Team Builder)";
                        break;

                    case "BOT":
                        item.ScoreLabel.Content += "(Bots)";
                        break;

                    default:
                        Client.Log(stats.Game.QueueType);
                        item.ScoreLabel.Content += "Please upload this log to github.";
                        break;
                    }

                    item.CreepScoreLabel.Content = stats.MinionsKilled + " minions";
                    item.DateLabel.Content       = stats.Game.CreateDate;
                    item.IpEarnedLabel.Content   = "+" + stats.Game.IpEarned + " IP";
                    item.PingLabel.Content       = stats.Game.UserServerPing + "ms";

                    var bc    = new BrushConverter();
                    var brush = (Brush)bc.ConvertFrom("#FF609E74");

                    if (stats.Lose == 1)
                    {
                        brush = (Brush)bc.ConvertFrom("#FF9E6060");
                    }

                    else if (stats.Game.IpEarned == 0)
                    {
                        brush = (Brush)bc.ConvertFrom("#FFE27100");
                    }

                    item.GridView.Background = brush;
                    item.GridView.Width      = 250;
                    GamesListView.Items.Add(item);
                }
                if (GamesListView.Items.Count > 0)
                {
                    GamesListView.SelectedIndex = 0;
                }
            }));
        }
        private void GamesListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (GamesListView.SelectedIndex != -1)
            {
                MatchStats stats = GameStats[GamesListView.SelectedIndex];

                GameStatsListView.Items.Clear();
                PurpleListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();

                //Add self to game players
                var img = new Image();
                img.Width  = 58;
                img.Height = 58;
                img.Source = champions.GetChampion((int)Math.Round(stats.Game.ChampionId)).icon;
                BlueListView.Items.Add(img);

                foreach (FellowPlayerInfo info in stats.Game.FellowPlayers)
                {
                    img        = new Image();
                    img.Width  = 58;
                    img.Height = 58;
                    img.Source = champions.GetChampion((int)Math.Round(info.ChampionId)).icon;
                    if (info.TeamId == stats.Game.TeamId)
                    {
                        BlueListView.Items.Add(img);
                    }
                    else
                    {
                        PurpleListView.Items.Add(img);
                    }
                }

                Type classType = typeof(MatchStats);
                foreach (FieldInfo field in classType.GetFields(BindingFlags.Public | BindingFlags.Instance))
                {
                    if (field.GetValue(stats) is double)
                    {
                        if ((double)field.GetValue(stats) == 0)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    var item = new ProfilePage.KeyValueItem
                    {
                        Key =
                            Client.TitleCaseString(
                                string.Concat(field.Name.Select(fe => Char.IsUpper(fe) ? " " + fe : fe.ToString()))
                                .TrimStart(' ')),
                        Value = field.GetValue(stats)
                    };

                    if (((string)item.Key).StartsWith("Item"))
                    {
                        var uriSource =
                            new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "item", item.Value + ".png"),
                                    UriKind.Absolute);
                        if (File.Exists(uriSource.AbsolutePath))
                        {
                            img             = new Image();
                            img.Width       = 58;
                            img.Height      = 58;
                            img.Source      = new BitmapImage(uriSource);
                            img.Tag         = item;
                            img.MouseMove  += img_MouseMove;
                            img.MouseLeave += img_MouseLeave;
                            ItemsListView.Items.Add(img);
                        }
                    }
                    else
                    {
                        GameStatsListView.Items.Add(item);
                    }
                }
            }

            if (double.IsNaN(GameKeyHeader.Width))
            {
                GameKeyHeader.Width = GameKeyHeader.ActualWidth;
            }
            if (double.IsNaN(GameValueHeader.Width))
            {
                GameValueHeader.Width = GameValueHeader.ActualWidth;
            }
            GameKeyHeader.Width   = double.NaN;
            GameValueHeader.Width = double.NaN;
        }
        public void GotRecentGames(RecentGames result)
        {
            GameStats.Clear();
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            foreach (PlayerGameStats Game in result.GameStatistics)
            {
                Game.GameType = Client.TitleCaseString(Game.GameType.Replace("_GAME", "").Replace("MATCHED", "NORMAL"));
                MatchStats Match = new MatchStats();

                foreach (RawStat Stat in Game.Statistics)
                {
                    var    type      = typeof(MatchStats);
                    string fieldName = Client.TitleCaseString(Stat.StatType.Replace('_', ' ')).Replace(" ", "");
                    var    f         = type.GetField(fieldName);
                    f.SetValue(Match, Stat.Value);
                }

                Match.Game = Game;

                GameStats.Add(Match);
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                GamesListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();
                PurpleListView.Items.Clear();
                GameStatsListView.Items.Clear();
                foreach (MatchStats stats in GameStats)
                {
                    RecentGameOverview item        = new RecentGameOverview();
                    champions GameChamp            = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                    item.ChampionImage.Source      = GameChamp.icon;
                    item.ChampionNameLabel.Content = GameChamp.displayName;
                    item.ScoreLabel.Content        =
                        string.Format("{0}/{1}/{2} ({3})",
                                      stats.ChampionsKilled,
                                      stats.NumDeaths,
                                      stats.Assists,
                                      stats.Game.GameType);

                    item.CreepScoreLabel.Content = stats.MinionsKilled + " minions";
                    item.DateLabel.Content       = stats.Game.CreateDate;
                    item.IPEarnedLabel.Content   = "+" + stats.Game.IpEarned + " IP";
                    item.PingLabel.Content       = stats.Game.UserServerPing + "ms";

                    BrushConverter bc = new BrushConverter();
                    Brush brush       = (Brush)bc.ConvertFrom("#FF609E74");

                    if (stats.Lose == 1)
                    {
                        brush = (Brush)bc.ConvertFrom("#FF9E6060");
                    }

                    else if (stats.Game.IpEarned == 0)
                    {
                        brush = (Brush)bc.ConvertFrom("#FFE27100");
                    }

                    item.GridView.Background = brush;
                    item.GridView.Width      = 250;
                    GamesListView.Items.Add(item);
                }
            }));
        }
Beispiel #6
0
        public async Task<string[]> Load(double ID)
        {
            RecentGames result = await RiotCalls.GetRecentGames(ID);
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            GamesWithChamp = 0;
            foreach (PlayerGameStats game in result.GameStatistics)
            {
                game.GameType = Client.TitleCaseString(game.GameType.Replace("_GAME", "").Replace("MATCHED", "NORMAL"));
                var match = new MatchStats();

                foreach (RawStat stat in game.Statistics)
                {
                    Type type = typeof(MatchStats);
                    string fieldName = Client.TitleCaseString(stat.StatType.Replace('_', ' ')).Replace(" ", "");
                    FieldInfo f = type.GetField(fieldName);
                    f.SetValue(match, stat.Value);
                }
                match.Game = game;
                GameStats.Add(match);
            }
            int AKills, ChampKills;
            int ADeaths, ChampDeaths;
            int AAssists, ChampAssists;
            int AGamesPlayed, ChampGamesPlayed;
            int Wins, ChampWins;
            AKills = 0; ADeaths = 0; AAssists = 0; AGamesPlayed = 0; ChampKills = 0;
            ChampDeaths = 0; ChampAssists = 0; ChampGamesPlayed = 0; Wins = 0; ChampWins = 0;
            //Load average KDA for past 20 games if possible
            foreach (MatchStats stats in GameStats)
            {
                if (stats.Win == 1)
                    Wins++;
                champions gameChamp = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                AKills = AKills + (int)stats.ChampionsKilled;
                ADeaths = ADeaths + (int)stats.NumDeaths;
                AAssists = AAssists + (int)stats.Assists;
                AGamesPlayed++;

                if (ChampID == (int)Math.Round(stats.Game.ChampionId))
                {
                    if (stats.Win == 1)
                        ChampWins++;
                    ChampKills = ChampKills + (int)stats.ChampionsKilled;
                    ChampDeaths = ChampDeaths + (int)stats.NumDeaths;
                    ChampAssists = ChampAssists + (int)stats.Assists;
                    ChampGamesPlayed++;
                    GamesWithChamp++;
                }
            }
            WinLossRatio = (Wins / AGamesPlayed) * 100;
            try
            {
                WinLossChampRatio = (ChampGamesPlayed != 0 && ChampGamesPlayed != 0 ? ChampWins / ChampGamesPlayed : 1) * 100;
            }
            catch { }

            string KDAString = string.Format("{0}/{1}/{2}",
                                (AKills / AGamesPlayed),
                                (ADeaths / AGamesPlayed),
                                (AAssists / AGamesPlayed));
            string ChampKDAString = "";
            try
            {
                ChampKDAString = string.Format("{0}/{1}/{2}",
                    (ChampKills != 0 && ChampGamesPlayed != 0 ? ChampKills / ChampGamesPlayed : 0),
                    (ChampDeaths != 0 && ChampGamesPlayed != 0 ? ChampDeaths / ChampGamesPlayed : 0),
                    (ChampAssists != 0 && ChampGamesPlayed != 0 ? ChampAssists / ChampGamesPlayed : 0));

            }
            catch
            { ChampKDAString = "NO RECENT GAMES!!!"; }
            //GetKDA string
            OverallKDA = new KDA()
            {
                Kills = AKills,
                Deaths = ADeaths,
                Assists = AAssists,
                Games = AGamesPlayed
            };
            //Get champ KDA
            Champkda = new KDA()
            {
                Kills = ChampKills,
                Deaths = ChampDeaths,
                Assists = ChampAssists,
                Games = ChampGamesPlayed
            };
            return new List<string>() { ChampKDAString, KDAString }.ToArray();
        }
        /// <summary>
        /// Loads the particiapants for the game
        /// </summary>
        /// <param name="allParticipants"></param>
        /// <param name="n"></param>
        /// <param name="list"></param>
        private async void LoadPar(List<Participant> allParticipants,PlatformGameLifecycleDTO n, ListView list)
        {
            bool isYourTeam = false;
            list.Items.Clear();
            list.Items.Refresh();
            try
            {
                string mmrJson;
                string url = Client.Region.SpectatorLink + "consumer/getGameMetaData/" + Client.Region.InternalName +
                             "/" + n.Game.Id + "/token";
                using (var client = new WebClient())
                    mmrJson = client.DownloadString(url);

                var serializer = new JavaScriptSerializer();
                var deserializedJson = serializer.Deserialize<Dictionary<string, object>>(mmrJson);
                MMRLabel.Content = "Game MMR ≈ " + deserializedJson["interestScore"];
            }
            catch
            {
                MMRLabel.Content = "Unable to calculate Game MMR";
            }

            foreach (Participant par in allParticipants)
            {
                if (par is PlayerParticipant)
                {
                    PublicSummoner scoutersum = await RiotCalls.GetSummonerByName(GSUsername);
                    if ((par as PlayerParticipant).AccountId == scoutersum.AcctId)
                        isYourTeam = true;
                }
            }
            foreach (Participant par in allParticipants)
            {
                if (par is PlayerParticipant)
                {
                    var participant = par as PlayerParticipant;
                    foreach (PlayerChampionSelectionDTO championSelect in n.Game.PlayerChampionSelections.Where(championSelect =>
                        championSelect.SummonerInternalName == participant.SummonerInternalName))
                    {
                        GameScouterPlayer control = new GameScouterPlayer();
                        control.Tag = championSelect;
                        GameStats = new List<MatchStats>();
                        control.Username.Content = championSelect.SummonerInternalName;
                        //Make it so you can see yourself
                        if (championSelect.SummonerInternalName == GSUsername)
                            control.Username.Foreground = (Brush)(new BrushConverter().ConvertFrom("#FF007A53"));
                        control.ChampIcon.Source = champions.GetChampion(championSelect.ChampionId).icon;
                        if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell1Id)))))
                        {
                            var UriSource = new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell1Id))), UriKind.Absolute);
                            control.SumIcon1.Source = new BitmapImage(UriSource);
                        }
                        if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell2Id)))))
                        {
                            var UriSource = new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell2Id))), UriKind.Absolute);
                            control.SumIcon2.Source = new BitmapImage(UriSource);
                        }
                        GameStats.Clear();
                        try
                        {
                            PublicSummoner summoner = await RiotCalls.GetSummonerByName(championSelect.SummonerInternalName.Replace("summoner", string.Empty));
                            if(File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", summoner.ProfileIconId.ToString() + ".png")))
                                control.ProfileIcon.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", summoner.ProfileIconId.ToString() + ".png"));
                            RecentGames result = await RiotCalls.GetRecentGames(summoner.AcctId);
                            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
                            foreach (PlayerGameStats game in result.GameStatistics)
                            {
                                game.GameType = Client.TitleCaseString(game.GameType.Replace("_GAME", "").Replace("MATCHED", "NORMAL"));
                                var match = new MatchStats();

                                foreach (RawStat stat in game.Statistics)
                                {
                                    Type type = typeof (MatchStats);
                                    string fieldName = Client.TitleCaseString(stat.StatType.Replace('_', ' ')).Replace(" ", "");
                                    FieldInfo f = type.GetField(fieldName);
                                    f.SetValue(match, stat.Value);
                                }
                                match.Game = game;
                                GameStats.Add(match);
                            }
                            int Kills, ChampKills;
                            int Deaths, ChampDeaths;
                            int Assists, ChampAssists;
                            int GamesPlayed, ChampGamesPlayed;
                            Kills = 0; Deaths = 0; Assists = 0; GamesPlayed = 0; ChampKills = 0; ChampDeaths = 0; ChampAssists = 0; ChampGamesPlayed = 0;
                            //Load average KDA for past 20 games if possible
                            foreach (MatchStats stats in GameStats)
                            {
                                champions gameChamp = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                                Kills = Kills + (int)stats.ChampionsKilled;
                                Deaths = Deaths + (int)stats.NumDeaths;
                                Assists = Assists + (int)stats.Assists;
                                GamesPlayed++;
                                if (championSelect.ChampionId == (int)Math.Round(stats.Game.ChampionId))
                                {
                                    ChampKills = ChampKills + (int)stats.ChampionsKilled;
                                    ChampDeaths = ChampDeaths + (int)stats.NumDeaths;
                                    ChampAssists = ChampAssists + (int)stats.Assists;
                                    ChampGamesPlayed++;
                                }
                            }
                            //GetKDA string
                            string KDAString = string.Format("{0}/{1}/{2}",
                                (Kills / GamesPlayed),
                                (Deaths / GamesPlayed),
                                (Assists / GamesPlayed));
                            string ChampKDAString = "";
                            try
                            {
                                ChampKDAString = string.Format("{0}/{1}/{2}",
                                (ChampKills / ChampGamesPlayed),
                                (ChampDeaths / ChampGamesPlayed),
                                (ChampAssists / ChampGamesPlayed));
                                
                            }
                            catch { }
                            
                            if (ChampGamesPlayed == 0)
                                ChampKDAString = "No Games lately";
                            control.AverageKDA.Content = KDAString;
                            control.ChampAverageKDA.Content = ChampKDAString;
                            BrushConverter bc = new BrushConverter();
                            if (isYourTeam)
                            {
                                bc = new BrushConverter();
                                if (ChampKills < ChampDeaths)
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FFC51C1C");
                                else if (ChampKills == ChampDeaths)
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FF8D8D8D");
                                else
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FF1EBF1E");

                                bc = new BrushConverter();
                                if (Kills < Deaths)
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FFC51C1C");
                                else if (Kills == Deaths)
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FF8D8D8D");
                                else
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FF1EBF1E");
                            }
                            else
                            {
                                bc = new BrushConverter();
                                if (ChampKills > ChampDeaths)
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FFC51C1C");
                                else if (ChampKills == ChampDeaths)
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FF8D8D8D");
                                else
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FF1EBF1E");

                                bc = new BrushConverter();
                                if (Kills > Deaths)
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FFC51C1C");
                                else if (Kills == Deaths)
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FF8D8D8D");
                                else
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FF1EBF1E");
                            }
                        }
                        catch
                        {
                            Client.Log("Failed to get stats about player", "GAME_SCOUTER_ERROR");
                        }
                        if (participant.TeamParticipantId != null)
                        {
                            try
                            {
                                Brush myColor = color[(double)participant.TeamParticipantId];
                                control.QueueTeamColor.Fill = myColor;
                                control.QueueTeamColor.Visibility = Visibility.Visible;
                            }
                            catch
                            {
                                BrushConverter bc = new BrushConverter();
                                Brush brush = Brushes.White;
                                //I know that there is a better way in the InGamePage
                                //I find that sometimes the colors (colours) are very hard to distinguish from eachother
                                //This makes sure that each color is easy to see
                                //because of hexa hill I put 12 in just in case
                                switch (ColorId)
                                {
                                    case 0:
                                        //blue
                                        brush = (Brush)bc.ConvertFrom("#FF00E8FF");
                                        break;
                                    case 2:
                                        //Lime Green
                                        brush = (Brush)bc.ConvertFrom("#FF00FF00");
                                        break;
                                    case 3:
                                        //Yellow
                                        brush = (Brush)bc.ConvertFrom("#FFFFFF00");
                                        break;
                                    case 4:
                                        //Blue Green
                                        brush = (Brush)bc.ConvertFrom("#FF007A53");
                                        break;
                                    case 5:
                                        //Purple
                                        brush = (Brush)bc.ConvertFrom("#FF5100FF");
                                        break;
                                    case 6:
                                        //Pink
                                        brush = (Brush)bc.ConvertFrom("#FFCB46C5");
                                        break;
                                    case 7:
                                        //Dark Green
                                        brush = (Brush)bc.ConvertFrom("#FF006409");
                                        break;
                                    case 8:
                                        //Brown
                                        brush = (Brush)bc.ConvertFrom("#FF643200");
                                        break;
                                    case 9: 
                                        //White
                                        brush = (Brush)bc.ConvertFrom("#FFFFFFFF");
                                        break;
                                    case 10:
                                        //Grey
                                        brush = (Brush)bc.ConvertFrom("#FF363636");
                                        break;
                                    case 11:
                                        //Red Pink
                                        brush = (Brush)bc.ConvertFrom("#FF8F4242");
                                        break;
                                    case 12:
                                        //Grey Blue
                                        brush = (Brush)bc.ConvertFrom("#FFFF0000");
                                        break;
                                }
                                color.Add((double)participant.TeamParticipantId, brush);
                                ColorId++;
                                control.QueueTeamColor.Fill = brush;
                                control.QueueTeamColor.Visibility = Visibility.Visible;
                            }
                        }
                        //control.MouseMove += controlMouseEnter;
                        control.MouseEnter += controlMouseEnter;
                        control.MouseLeave += control_MouseLeave;
                        control.MouseDown += control_MouseDown;
                        TinyRuneMasteryData smallData = new TinyRuneMasteryData();
                        //Now store data in the tags so that all of the event handlers work
                        Dictionary<string, object> data = new Dictionary<string, object>();
                        data.Add("MasteryDataControl", smallData);
                        data.Add("RuneData", await GetUserRunesPage(GSUsername));
                        data.Add("MasteryData", await GetUserRunesPage(GSUsername));
                        control.Tag = data;
                        list.Items.Add(control);
                    }
                }
            }
        }
        public void GotRecentGames(RecentGames result)
        {
            if (result.GameStatistics == null)
            {
                return;
            }

            gameStats.Clear();
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            foreach (var game in result.GameStatistics)
            {
                game.GameType =
                    Client.TitleCaseString(game.GameType.Replace("_GAME", string.Empty).Replace("MATCHED", "NORMAL"));
                var match = new MatchStats();

                foreach (var stat in game.Statistics)
                {
                    var type = typeof (MatchStats);
                    var fieldName = Client.TitleCaseString(stat.StatType.Replace('_', ' ')).Replace(" ", string.Empty);
                    var f = type.GetField(fieldName);
                    f.SetValue(match, stat.Value);
                }

                match.Game = game;

                gameStats.Add(match);
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                GamesListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();
                PurpleListView.Items.Clear();
                GameStatsListView.Items.Clear();
                foreach (var stats in gameStats)
                {
                    var item = new RecentGameOverview();
                    var gameChamp = champions.GetChampion((int) Math.Round(stats.Game.ChampionId));
                    item.ChampionImage.Source = gameChamp.icon;
                    item.ChampionNameLabel.Content = gameChamp.displayName;
                    item.ScoreLabel.Content =
                        string.Format("{0}/{1}/{2} ",
                            stats.ChampionsKilled,
                            stats.NumDeaths,
                            stats.Assists);

                    switch (stats.Game.QueueType)
                    {
                        case "NORMAL":
                            item.ScoreLabel.Content += "(Normal)";
                            break;
                        case "NORMAL_3x3":
                            item.ScoreLabel.Content += "(Normal 3v3)";
                            break;
                        case "ODIN_UNRANKED":
                            item.ScoreLabel.Content += "(Dominion)";
                            break;
                        case "ARAM_UNRANKED_5x5":
                            item.ScoreLabel.Content += "(ARAM)";
                            break;
                        case "NONE":
                            item.ScoreLabel.Content += "(Custom)";
                            break;
                        case "RANKED_SOLO_5x5":
                            item.ScoreLabel.Content += "(Ranked 5v5)";
                            break;
                        case "RANKED_TEAM_5x5":
                            item.ScoreLabel.Content += "(Ranked Team 5v5)";
                            break;
                        case "RANKED_TEAM_3x3":
                            item.ScoreLabel.Content += "(Ranked Team 3v3)";
                            break;
                        case "CAP_5x5":
                            item.ScoreLabel.Content += "(Team Builder)";
                            break;
                        case "BOT":
                            item.ScoreLabel.Content += "(Bots)";
                            break;
                        case "KING_PORO":
                            item.ScoreLabel.Content += "(King Poro)";
                            break;
                        case "COUNTER_PICK":
                            item.ScoreLabel.Content += "(Nemesis Draft)";
                            break;
                        case "URF":
                            item.ScoreLabel.Content += "(URF)";
                            break;
                        default:
                            Client.Log(stats.Game.QueueType);
                            item.ScoreLabel.Content += "Please upload this log to github.";
                            break;
                    }

                    item.CreepScoreLabel.Content = stats.MinionsKilled + " minions";
                    item.DateLabel.Content = stats.Game.CreateDate;
                    item.IPEarnedLabel.Content = "+" + stats.Game.IpEarned + " IP";
                    item.PingLabel.Content = stats.Game.UserServerPing + "ms";

                    var bc = new BrushConverter();
                    var brush = (Brush) bc.ConvertFrom("#FF609E74");

                    if (Math.Abs(stats.Lose - 1) < .00001)
                    {
                        brush = (Brush) bc.ConvertFrom("#FF9E6060");
                    }
                    else if (Math.Abs(stats.Game.IpEarned) < .00001)
                    {
                        brush = (Brush) bc.ConvertFrom("#FFE27100");
                    }

                    item.GridView.Background = brush;
                    item.GridView.Width = 280;
                    GamesListView.Items.Add(item);
                }
                if (GamesListView.Items.Count > 0)
                {
                    GamesListView.SelectedIndex = 0;
                }
            }));
        }