/// <summary>
        /// Main logic behind Champion Select
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="message"></param>
        private void ChampSelect_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() == typeof(GameDTO))
            {
                #region In Champion Select

                GameDTO ChampDTO = message as GameDTO;
                LatestDto = ChampDTO;
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                {
                    //Allow all champions to be selected (reset our modifications)
                    ListViewItem[] ChampionArray = new ListViewItem[ChampionSelectListView.Items.Count];
                    ChampionSelectListView.Items.CopyTo(ChampionArray, 0);
                    foreach (ListViewItem y in ChampionArray)
                    {
                        y.IsHitTestVisible = true;
                        y.Opacity = 1;
                    }

                    //Push all teams into one array to save a foreach call (looks messy)
                    List<Participant> AllParticipants = new List<Participant>(ChampDTO.TeamOne.ToArray());
                    AllParticipants.AddRange(ChampDTO.TeamTwo);
                    foreach (Participant p in AllParticipants)
                    {
                        if (p is PlayerParticipant)
                        {
                            PlayerParticipant play = (PlayerParticipant)p;
                            //If it is our turn to pick
                            if (play.PickTurn == ChampDTO.PickTurn)
                            {
                                if (play.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId)
                                {
                                    ChampionSelectListView.IsHitTestVisible = true;
                                    ChampionSelectListView.Opacity = 1;
                                    GameStatusLabel.Content = "Your turn to pick!";
                                    break;
                                }
                            }
                        }
                        //Otherwise block selection of champions unless in dev mode
                        if (!DevMode)
                        {
                            ChampionSelectListView.IsHitTestVisible = false;
                            ChampionSelectListView.Opacity = 0.5;
                        }
                        GameStatusLabel.Content = "Waiting for others to pick...";
                    }

                    //Champion select was cancelled 
                    if (ChampDTO.GameState == "TEAM_SELECT")
                    {
                        if (CountdownTimer != null)
                        {
                            CountdownTimer.Stop();
                        }
                        Client.FixChampSelect();
                        FakePage fakePage = new FakePage();
                        fakePage.Content = Client.LastPageContent;
                        Client.SwitchPage(fakePage);
                        return;
                    }
                    else if (ChampDTO.GameState == "PRE_CHAMP_SELECT")
                    {
                        //Banning phase. Enable banning phase and this will render only champions for ban
                        BanningPhase = true;
                        PurpleBansLabel.Visibility = Visibility.Visible;
                        BlueBansLabel.Visibility = Visibility.Visible;
                        BlueBanListView.Visibility = Visibility.Visible;
                        PurpleBanListView.Visibility = Visibility.Visible;
                        GameStatusLabel.Content = "Bans are on-going";
                        counter = configType.BanTimerDuration - 3;

                        #region Render Bans
                        BlueBanListView.Items.Clear();
                        PurpleBanListView.Items.Clear();
                        foreach (var x in ChampDTO.BannedChampions)
                        {
                            Image champImage = new Image();
                            champImage.Height = 58;
                            champImage.Width = 58;
                            champImage.Source = champions.GetChampion(x.ChampionId).icon;
                            if (x.TeamId == 100)
                            {
                                BlueBanListView.Items.Add(champImage);
                            }
                            else
                            {
                                PurpleBanListView.Items.Add(champImage);
                            }

                            foreach (ListViewItem y in ChampionArray)
                            {
                                if ((int)y.Tag == x.ChampionId)
                                {
                                    ChampionSelectListView.Items.Remove(y);
                                    //Remove from arrays
                                    foreach (ChampionDTO PlayerChamps in ChampList.ToArray())
                                    {
                                        if (x.ChampionId == PlayerChamps.ChampionId)
                                        {
                                            ChampList.Remove(PlayerChamps);
                                            break;
                                        }
                                    }

                                    foreach (ChampionBanInfoDTO BanChamps in ChampionsForBan.ToArray())
                                    {
                                        if (x.ChampionId == BanChamps.ChampionId)
                                        {
                                            ChampionsForBan.Remove(BanChamps);
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        #endregion Render Bans
                    }
                    else if (ChampDTO.GameState == "CHAMP_SELECT")
                    {
                        //Picking has started. If pickturn has changed reset timer
                        LastPickTurn = ChampDTO.PickTurn;
                        BanningPhase = false;
                    }
                    else if (ChampDTO.GameState == "POST_CHAMP_SELECT")
                    {
                        //Post game has started. Allow trading
                        CanTradeWith = await Client.PVPNet.GetPotentialTraders();
                        HasLockedIn = true;
                        GameStatusLabel.Content = "All players have picked!";
                        if (configType != null)
                            counter = configType.PostPickTimerDuration - 2;
                        else
                            counter = 10;
                    }
                    else if (ChampDTO.GameState == "START_REQUESTED")
                    {
                        GameStatusLabel.Content = "The game is about to start!";
                        DodgeButton.IsEnabled = false; //Cannot dodge past this point!
                        counter = 1;
                    }

                    #region Display players

                    BlueListView.Items.Clear();
                    PurpleListView.Items.Clear();
                    int i = 0;
                    bool PurpleSide = false;

                    //Aram hack, view other players champions & names (thanks to Andrew)
                    List<PlayerChampionSelectionDTO> OtherPlayers = new List<PlayerChampionSelectionDTO>(ChampDTO.PlayerChampionSelections.ToArray());
                    bool AreWePurpleSide = false;

                    foreach (Participant participant in AllParticipants)
                    {
                        Participant tempParticipant = participant;
                        i++;
                        ChampSelectPlayer control = new ChampSelectPlayer();
                        //Cast AramPlayers as PlayerParticipants. This removes reroll data
                        if (tempParticipant is AramPlayerParticipant)
                        {
                            tempParticipant = new PlayerParticipant(tempParticipant.GetBaseTypedObject());
                        }

                        if (tempParticipant is PlayerParticipant)
                        {
                            PlayerParticipant player = tempParticipant as PlayerParticipant;
                            control.PlayerName.Content = player.SummonerName;

                            foreach (PlayerChampionSelectionDTO selection in ChampDTO.PlayerChampionSelections)
                            {
                                #region Disable picking selected champs

                                foreach (ListViewItem y in ChampionArray)
                                {
                                    if ((int)y.Tag == selection.ChampionId)
                                    {
                                        y.IsHitTestVisible = false;
                                        y.Opacity = 0.5;
                                        if (configType != null)
                                        {
                                            if (configType.DuplicatePick)
                                            {
                                                y.IsHitTestVisible = true;
                                                y.Opacity = 1;
                                            }
                                        }
                                    }
                                }

                                #endregion Disable picking selected champs

                                if (selection.SummonerInternalName == player.SummonerInternalName)
                                {
                                    //Clear our teams champion selection for aram hack
                                    OtherPlayers.Remove(selection);
                                    control = RenderPlayer(selection, player);
                                    //If we have locked in render skin select
                                    if (HasLockedIn && selection.SummonerInternalName == Client.LoginPacket.AllSummonerData.Summoner.InternalName && !DevMode)
                                    {
                                        if (PurpleSide)
                                            AreWePurpleSide = true;
                                        RenderLockInGrid(selection);
                                    }
                                }
                            }
                        }
                        else if (tempParticipant is ObfuscatedParticipant)
                        {
                            control.PlayerName.Content = "Summoner " + i;
                        }
                        else if (tempParticipant is BotParticipant)
                        {
                            BotParticipant bot = tempParticipant as BotParticipant;
                            string botChamp = bot.SummonerName.Split(' ')[0]; //Why is this internal name rito?
                            champions botSelectedChamp = champions.GetChampion(botChamp);
                            PlayerParticipant part = new PlayerParticipant();
                            PlayerChampionSelectionDTO selection = new PlayerChampionSelectionDTO();
                            selection.ChampionId = botSelectedChamp.id;
                            part.SummonerName = botSelectedChamp.displayName + " bot";
                            control = RenderPlayer(selection, part);
                        }
                        else
                        {
                            control.PlayerName.Content = "Unknown Summoner";
                        }
                        //Display purple side if we have gone through our team
                        if (i > ChampDTO.TeamOne.Count)
                        {
                            i = 0;
                            PurpleSide = true;
                        }

                        if (!PurpleSide)
                        {
                            BlueListView.Items.Add(control);
                        }
                        else
                        {
                            PurpleListView.Items.Add(control);
                        }
                    }

                    //Do aram hack!
                    if (OtherPlayers.Count > 0)
                    {
                        if (AreWePurpleSide)
                        {
                            BlueListView.Items.Clear();
                        }
                        else
                        {
                            PurpleListView.Items.Clear();
                        }

                        foreach (PlayerChampionSelectionDTO hackSelection in OtherPlayers)
                        {
                            ChampSelectPlayer control = new ChampSelectPlayer();
                            PlayerParticipant player = new PlayerParticipant();
                            player.SummonerName = hackSelection.SummonerInternalName;
                            control = RenderPlayer(hackSelection, player);

                            if (AreWePurpleSide)
                            {
                                BlueListView.Items.Add(control);
                            }
                            else
                            {
                                PurpleListView.Items.Add(control);
                            }
                        }
                    }

                    #endregion Display players
                }));

                #endregion In Champion Select
            }
            else if (message.GetType() == typeof(PlayerCredentialsDto))
            {
                #region Launching Game

                PlayerCredentialsDto dto = message as PlayerCredentialsDto;
                Client.CurrentGame = dto;

                if (!HasLaunchedGame)
                {
                    HasLaunchedGame = true;
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        if (CountdownTimer != null)
                        {
                            CountdownTimer.Stop();
                        }
                        Client.QuitCurrentGame();
                    }));
                    Client.LaunchGame();
                }

                #endregion Launching Game
            }
            else if (message.GetType() == typeof(TradeContractDTO))
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TradeContractDTO TradeDTO = message as TradeContractDTO;
                    if (TradeDTO.State == "PENDING")
                    {
                        PlayerTradeControl.Visibility = System.Windows.Visibility.Visible;
                        PlayerTradeControl.Tag = TradeDTO;
                        PlayerTradeControl.AcceptButton.Visibility = System.Windows.Visibility.Visible;
                        PlayerTradeControl.DeclineButton.Content = "Decline";

                        champions MyChampion = champions.GetChampion((int)TradeDTO.ResponderChampionId);
                        PlayerTradeControl.MyChampImage.Source = MyChampion.icon;
                        PlayerTradeControl.MyChampLabel.Content = MyChampion.displayName;
                        champions TheirChampion = champions.GetChampion((int)TradeDTO.RequesterChampionId);
                        PlayerTradeControl.TheirChampImage.Source = TheirChampion.icon;
                        PlayerTradeControl.TheirChampLabel.Content = TheirChampion.displayName;
                        PlayerTradeControl.RequestLabel.Content = string.Format("{0} wants to trade!", TradeDTO.RequesterInternalSummonerName);
                    }
                    else if (TradeDTO.State == "CANCELED" || TradeDTO.State == "DECLINED" || TradeDTO.State == "BUSY")
                    {
                        PlayerTradeControl.Visibility = System.Windows.Visibility.Hidden;
                        NotificationPopup pop = new NotificationPopup(ChatSubjects.INVITE_STATUS_CHANGED, 
                            string.Format("{0} has {1} this trade", TradeDTO.RequesterInternalSummonerName, TradeDTO.State));

                        if (TradeDTO.State == "BUSY")
                            pop.NotificationTextBox.Text = string.Format("{0} is currently busy", TradeDTO.RequesterInternalSummonerName);

                        pop.Height = 200;
                        pop.OkButton.Visibility = System.Windows.Visibility.Visible;
                        pop.HorizontalAlignment = HorizontalAlignment.Right;
                        pop.VerticalAlignment = VerticalAlignment.Bottom;
                        Client.NotificationGrid.Children.Add(pop);
                    }
                }));
            }
        }
        /// <summary>
        /// Render individual players
        /// </summary>
        /// <param name="selection">The champion the player has selected</param>
        /// <param name="player">The participant details of the player</param>
        /// <returns></returns>
        internal ChampSelectPlayer RenderPlayer(PlayerChampionSelectionDTO selection, PlayerParticipant player)
        {
            ChampSelectPlayer control = new ChampSelectPlayer();
            //Render champion
            if (selection.ChampionId != 0)
            {
                control.ChampionImage.Source = champions.GetChampion(selection.ChampionId).icon;
            }
            //Render summoner spells
            if (selection.Spell1Id != 0)
            {
                string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell1Id));
                control.SummonerSpell1.Source = Client.GetImage(uriSource);
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell2Id));
                control.SummonerSpell2.Source = Client.GetImage(uriSource);
            }
            //Set our summoner spells in client
            if (player.SummonerName == Client.LoginPacket.AllSummonerData.Summoner.Name)
            {
                string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell1Id));
                SummonerSpell1Image.Source = Client.GetImage(uriSource);
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell2Id));
                SummonerSpell2Image.Source = Client.GetImage(uriSource);
                MyChampId = selection.ChampionId;
            }
            //Has locked in
            if (player.PickMode == 2)
            {
                string uriSource = "/LegendaryClient;component/Locked.png";
                control.LockedInIcon.Source = Client.GetImage(uriSource);
            }
            //If trading with this player is possible
            if (CanTradeWith != null && (CanTradeWith.PotentialTraders.Contains(player.SummonerInternalName) || DevMode))
            {
                control.TradeButton.Visibility = System.Windows.Visibility.Visible;
            }
            //If this player is duo/trio/quadra queued with players
            if (player.TeamParticipantId != null)
            {
                //Byte hack to get individual hex colors
                byte[] values = BitConverter.GetBytes((double)player.TeamParticipantId);
                if (!BitConverter.IsLittleEndian) Array.Reverse(values);

                byte r = values[2];
                byte b = values[3];
                byte g = values[4];

                System.Drawing.Color myColor = System.Drawing.Color.FromArgb(r, b, g);

                var converter = new System.Windows.Media.BrushConverter();
                var brush = (Brush)converter.ConvertFromString("#" + myColor.Name);
                control.TeamRectangle.Fill = brush;
                control.TeamRectangle.Visibility = System.Windows.Visibility.Visible;
            }
            control.LockedInIcon.Visibility = System.Windows.Visibility.Visible;
            control.TradeButton.Tag = new KeyValuePair<PlayerChampionSelectionDTO, PlayerParticipant>(selection, player);
            control.TradeButton.Click += TradeButton_Click;
            control.PlayerName.Content = player.SummonerName;
            return control;
        }
        private async void ParseSpectatorGames()
        {
            if (gameList == null)
                return;
            if (gameList.Count <= 0)
                return;
            BlueBansLabel.Visibility = Visibility.Hidden;
            PurpleBansLabel.Visibility = Visibility.Hidden;
            BlueBanListView.Items.Clear();
            PurpleBanListView.Items.Clear();
            BlueListView.Items.Clear();
            PurpleListView.Items.Clear();
            int GameId = 0;
            var objectGame = gameList[SelectedGame];
            Dictionary<string, object> SpectatorGame = objectGame as Dictionary<string, object>;
            foreach (KeyValuePair<string, object> pair in SpectatorGame)
            {
                if (pair.Key == "participants")
                {
                    ArrayList players = pair.Value as ArrayList;
                    foreach (var objectPlayer in players)
                    {
                        Dictionary<string, object> playerInfo = objectPlayer as Dictionary<string, object>;
                        int teamId = 100;
                        int championId = 0;
                        int spell1Id = 0;
                        int spell2Id = 0;
                        string PlayerName = "";
                        foreach (KeyValuePair<string, object> playerPair in playerInfo)
                        {
                            if (playerPair.Key == "teamId")
                            {
                                teamId = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "championId")
                            {
                                championId = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "summonerName")
                            {
                                PlayerName = playerPair.Value as string;
                            }
                            if (playerPair.Key == "spell1Id")
                            {
                                spell1Id = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "spell2Id")
                            {
                                spell2Id = (int)playerPair.Value;
                            }
                        }
                        ChampSelectPlayer control = new ChampSelectPlayer();
                        control.ChampionImage.Source = champions.GetChampion(championId).icon;
                        string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(spell1Id));
                        control.SummonerSpell1.Source = Client.GetImage(uriSource);
                        uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(spell2Id));
                        control.SummonerSpell2.Source = Client.GetImage(uriSource);

                        control.PlayerName.Content = PlayerName;

                        if (teamId == 100)
                        {
                            BlueListView.Items.Add(control);
                        }
                        else
                        {
                            PurpleListView.Items.Add(control);
                        }
                    }
                }
                if (pair.Key == "gameId")
                {
                    GameId = (int)pair.Value;
                }
                if (pair.Key == "bannedChampions")
                {
                    ArrayList keyArray = pair.Value as ArrayList;
                    if (keyArray.Count > 0)
                    {
                        BlueBansLabel.Visibility = Visibility.Visible;
                        PurpleBansLabel.Visibility = Visibility.Visible;
                    }
                    foreach (Dictionary<string, object> keyArrayP in keyArray)
                    {
                        int cid = 0;
                        int teamId = 100;
                        foreach (KeyValuePair<string, object> keyArrayPair in keyArrayP)
                        {
                            if (keyArrayPair.Key == "championId")
                            {
                                cid = (int)keyArrayPair.Value;
                            }
                            if (keyArrayPair.Key == "teamId")
                            {
                                teamId = (int)keyArrayPair.Value;
                            }
                        }
                        ListViewItem item = new ListViewItem();
                        Image champImage = new Image();
                        champImage.Height = 58;
                        champImage.Width = 58;
                        champImage.Source = champions.GetChampion(cid).icon;
                        item.Content = champImage;
                        if (teamId == 100)
                        {
                            BlueBanListView.Items.Add(item);
                        }
                        else
                        {
                            PurpleBanListView.Items.Add(item);
                        }
                    }
                }
            }

            try
            {
                BaseRegion region = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
                string spectatorJSON = "";
                string url = region.SpectatorLink + "consumer/getGameMetaData/" + region.InternalName + "/" + GameId + "/token";
                using (WebClient client = new WebClient())
                {
                    spectatorJSON = await client.DownloadStringTaskAsync(url);
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(spectatorJSON);
                MMRLabel.Content = "≈" + deserializedJSON["interestScore"];
            }
            catch { MMRLabel.Content = "N/A"; }
        }
示例#4
0
        public void Update(PlatformGameLifecycleDTO CurrentGame)
        {
            BlueBansLabel.Visibility = System.Windows.Visibility.Hidden;
            PurpleBansLabel.Visibility = System.Windows.Visibility.Hidden;
            PurpleBanListView.Items.Clear();
            BlueBanListView.Items.Clear();

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

            ImageGrid.Children.Clear();

            List<Participant> AllParticipants = new List<Participant>(CurrentGame.Game.TeamOne.ToArray());
            AllParticipants.AddRange(CurrentGame.Game.TeamTwo);

            int i = 0;
            int y = 0;
            foreach (Participant part in AllParticipants)
            {
                ChampSelectPlayer control = new ChampSelectPlayer();
                if (part is PlayerParticipant)
                {
                    PlayerParticipant participant = part as PlayerParticipant;
                    foreach (PlayerChampionSelectionDTO championSelect in CurrentGame.Game.PlayerChampionSelections)
                    {
                        if (championSelect.SummonerInternalName == participant.SummonerInternalName)
                        {
                            control.ChampionImage.Source = champions.GetChampion(championSelect.ChampionId).icon;
                            var uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell1Id)));
                            control.SummonerSpell1.Source = Client.GetImage(uriSource);
                            uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell2Id)));
                            control.SummonerSpell2.Source = Client.GetImage(uriSource);

                            #region Generate Background

                            Image m = new Image();
                            Canvas.SetZIndex(m, -2);
                            m.Stretch = Stretch.None;
                            m.Width = 100;
                            m.Opacity = 0.50;
                            m.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                            m.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                            m.Margin = new System.Windows.Thickness(y++ * 100, 0, 0, 0);
                            System.Drawing.Rectangle cropRect = new System.Drawing.Rectangle(new System.Drawing.Point(100, 0), new System.Drawing.Size(100, 560));
                            System.Drawing.Bitmap src = System.Drawing.Image.FromFile(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", champions.GetChampion(championSelect.ChampionId).portraitPath)) as System.Drawing.Bitmap;
                            System.Drawing.Bitmap target = new System.Drawing.Bitmap(cropRect.Width, cropRect.Height);

                            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target))
                            {
                                g.DrawImage(src, new System.Drawing.Rectangle(0, 0, target.Width, target.Height),
                                                cropRect,
                                                System.Drawing.GraphicsUnit.Pixel);
                            }

                            m.Source = Client.ToWpfBitmap(target);
                            ImageGrid.Children.Add(m);

                            #endregion Generate Background
                        }
                    }

                    control.PlayerName.Content = participant.SummonerName;

                    if (participant.TeamParticipantId != null)
                    {
                        byte[] values = BitConverter.GetBytes((double)participant.TeamParticipantId);
                        if (!BitConverter.IsLittleEndian) Array.Reverse(values);

                        byte r = values[2];
                        byte b = values[3];
                        byte g = values[4];

                        System.Drawing.Color myColor = System.Drawing.Color.FromArgb(r, b, g);

                        var converter = new System.Windows.Media.BrushConverter();
                        var brush = (Brush)converter.ConvertFromString("#" + myColor.Name);
                        control.TeamRectangle.Fill = brush;
                        control.TeamRectangle.Visibility = System.Windows.Visibility.Visible;
                    }
                }

                i++;
                if (i <= 5)
                {
                    BlueListView.Items.Add(control);
                }
                else
                {
                    PurpleListView.Items.Add(control);
                }
            }

            if (CurrentGame.Game.BannedChampions.Count > 0)
            {
                BlueBansLabel.Visibility = System.Windows.Visibility.Visible;
                PurpleBansLabel.Visibility = System.Windows.Visibility.Visible;
            }

            foreach (var x in CurrentGame.Game.BannedChampions)
            {
                Image champImage = new Image();
                champImage.Height = 58;
                champImage.Width = 58;
                champImage.Source = champions.GetChampion(x.ChampionId).icon;
                if (x.TeamId == 100)
                {
                    BlueBanListView.Items.Add(champImage);
                }
                else
                {
                    PurpleBanListView.Items.Add(champImage);
                }
            }

            try
            {
                string mmrJSON = "";
                string url = Client.Region.SpectatorLink + "consumer/getGameMetaData/" + Client.Region.InternalName + "/" + CurrentGame.Game.Id + "/token";
                using (WebClient client = new WebClient())
                {
                    mmrJSON = client.DownloadString(url);
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(mmrJSON);
                MMRLabel.Content = "≈" + deserializedJSON["interestScore"];
            }
            catch { MMRLabel.Content = "N/A"; }
        }
        /// <summary>
        ///     Render individual players
        /// </summary>
        /// <param name="selection">The champion the player has selected</param>
        /// <param name="player">The participant details of the player</param>
        /// <returns></returns>
        internal ChampSelectPlayer RenderPlayer(PlayerChampionSelectionDTO selection, PlayerParticipant player)
        {
            var control = new ChampSelectPlayer(selection.SummonerInternalName, selection.ChampionId, true);
            //Render champion
            if (selection.ChampionId != 0)
            {
                control.ChampionImage.Source = champions.GetChampion(selection.ChampionId).icon;
                control.Tag = selection.ChampionId;
            }

            //Render summoner spells
            if (selection.Spell1Id != 0)
            {
                string UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                    SummonerSpell.GetSpellImageName((int)selection.Spell1Id));
                control.SummonerSpell1.Source = Client.GetImage(UriSource);
                UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                    SummonerSpell.GetSpellImageName((int)selection.Spell2Id));
                control.SummonerSpell2.Source = Client.GetImage(UriSource);
            }
            //Set our summoner spells in client
            if (player.SummonerName == Client.LoginPacket.AllSummonerData.Summoner.Name)
            {
                string UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                    SummonerSpell.GetSpellImageName((int)selection.Spell1Id));
                SummonerSpell1Image.Source = Client.GetImage(UriSource);
                UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                    SummonerSpell.GetSpellImageName((int)selection.Spell2Id));
                SummonerSpell2Image.Source = Client.GetImage(UriSource);
                MyChampId = selection.ChampionId;
            }
            //Has locked in
            if (player.PickMode == 2)
            {
                const string UriSource = "/LegendaryClient;component/Locked.png";
                control.LockedInIcon.Source = Client.GetImage(UriSource);
            }
            //Make obvious whos pick turn it is
            if (player.PickTurn != LatestDto.PickTurn &&
                (LatestDto.GameState == "CHAMP_SELECT" || LatestDto.GameState == "PRE_CHAMP_SELECT"))
                control.Opacity = 0.5;
            else
                //Full opacity when not picking or banning
                control.Opacity = 1;

            //If trading with this player is possible
            if (CanTradeWith != null && (CanTradeWith.PotentialTraders.Contains(player.SummonerInternalName) || Client.Dev))
                control.TradeButton.Visibility = Visibility.Visible;

            //If this player is duo/trio/quadra queued with players
            if (player.TeamParticipantId != null && (double)player.TeamParticipantId != 0)
            {
                //byte hack to get individual hex colors
                byte[] values = BitConverter.GetBytes((double)player.TeamParticipantId);
                if (!BitConverter.IsLittleEndian) Array.Reverse(values);

                byte r = values[2];
                byte b = values[3];
                byte g = values[4];

                Color myColor = Color.FromArgb(r, b, g);

                var converter = new BrushConverter();
                var brush = (Brush)converter.ConvertFromString("#" + myColor.Name);
                control.TeamRectangle.Fill = brush;
                control.TeamRectangle.Visibility = Visibility.Visible;
            }
            control.LockedInIcon.Visibility = Visibility.Visible;
            control.TradeButton.Tag = new KeyValuePair<PlayerChampionSelectionDTO, PlayerParticipant>(selection, player);
            control.TradeButton.Click += TradeButton_Click;
            control.PlayerName.Content = player.SummonerName;

            return control;
        }
        /// <summary>
        ///     Main logic behind Champion Select
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="message"></param>
        private void Select_OnMessageReceived(object sender, object message)
        {
            if (message is GameDTO)
            {
                #region In Champion Select

                var champDto = message as GameDTO;
                //Sometimes chat doesn't work so spam this until it does
                LatestDto = champDto;
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                {
                    //Allow all champions to be selected (reset our modifications)
                    var championArray = new ListViewItem[ChampionSelectListView.Items.Count];
                    ChampionSelectListView.Items.CopyTo(championArray, 0);
                    foreach (ListViewItem y in championArray)
                    {
                        y.IsHitTestVisible = true;
                        y.Opacity = 1;
                    }

                    //Push all teams into one array to save a foreach call (looks messy)
                    if (champDto == null)
                        return;

                    var allParticipants = new List<Participant>(champDto.TeamOne.ToArray());
                    allParticipants.AddRange(champDto.TeamTwo);

                    int t = 1;

                    if (LatestDto.QueueTypeName == "COUNTER_PICK") //fix for nemesis draft, get your champ from GameDTO
                    {
                        var selectedChamp = champDto.PlayerChampionSelections.Find(item => item.SummonerInternalName == Client.LoginPacket.AllSummonerData.Summoner.InternalName);
                        ChangeSelectedChampionSkins(selectedChamp.ChampionId);
                    }
                    foreach (PlayerParticipant participant in allParticipants.Select(p => p as PlayerParticipant))
                    {
                        if (participant != null)
                        {
                            PlayerParticipant play = participant;
                            //If it is our turn to pick
                            if (play.PickTurn == champDto.PickTurn)
                            {
                                if (play.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId)
                                {
                                    if (Settings.Default.PickBanFocus)
                                        Client.MainWin.Focus();
                                    if (Settings.Default.PickBanFlash)
                                        Client.MainWin.FlashWindow();
                                    //Allows us to instapick any champ we own. 
                                    if (Client.usingInstaPick)
                                    {
                                        bool champbanned = false;
                                        //disallow picking banned champs
                                        try
                                        {
                                            foreach (
                                                BannedChampion x in
                                                    champDto.BannedChampions.Where(
                                                        x => x.ChampionId == Client.SelectChamp))
                                                champbanned = true;

                                            //disallow picking picked champs
                                            foreach (
                                                PlayerChampionSelectionDTO selection in
                                                    champDto.PlayerChampionSelections.Where(
                                                        selection => selection.ChampionId == Client.SelectChamp))
                                                champbanned = true;

                                            var temp = new ListViewItem
                                            {
                                                Tag = Client.SelectChamp
                                            };
                                            if (!champbanned)
                                                ListViewItem_PreviewMouseDown(temp, null);

                                            Client.usingInstaPick = false;
                                        }
                                        catch
                                        {
                                            Client.Log("Something went weird insta-picking a champ", "Error");
                                        }
                                    }

                                    ChampionSelectListView.IsHitTestVisible = true;

                                    ChampionSelectListView.Opacity = 1;
                                    GameStatusLabel.Content = "Your turn to pick!";
                                    break;
                                }
                            }
                            if (string.IsNullOrEmpty(participant.SummonerName))
                            {
                                participant.SummonerName = "Summoner " + t;
                                t++;
                            }
                        }
                        //Otherwise block selection of champions unless in dev mode
                        if (!Client.Dev)
                        {
                            ChampionSelectListView.IsHitTestVisible = false;
                            ChampionSelectListView.Opacity = 0.5;
                        }
                        GameStatusLabel.Content = "Waiting for others to pick...";
                    }

                    allParticipants = allParticipants.Distinct().ToList();

                    //Champion select was cancelled 
                    if (champDto.GameState == "TEAM_SELECT")
                    {
                        if (CountdownTimer != null)
                            CountdownTimer.Stop();

                        Client.FixChampSelect();

                        return;
                    }
                    if (champDto.GameState == "PRE_CHAMP_SELECT")
                    {
                        //Banning phase. Enable banning phase and this will render only champions for ban
                        BanningPhase = true;
                        PurpleBansLabel.Visibility = Visibility.Visible;
                        BlueBansLabel.Visibility = Visibility.Visible;
                        BlueBanListView.Visibility = Visibility.Visible;
                        PurpleBanListView.Visibility = Visibility.Visible;
                        GameStatusLabel.Content = "Bans are on-going";
                        counter = configType.BanTimerDuration - 3;

                        #region Render Bans

                        BlueBanListView.Items.Clear();
                        PurpleBanListView.Items.Clear();
                        foreach (BannedChampion x in champDto.BannedChampions)
                        {
                            var champImage = new Image
                            {
                                Height = 58,
                                Width = 58,
                                Source = champions.GetChampion(x.ChampionId).icon
                            };
                            if (x.TeamId == 100)
                                BlueBanListView.Items.Add(champImage);
                            else
                                PurpleBanListView.Items.Add(champImage);

                            foreach (var y in championArray.Where(y => (int)y.Tag == x.ChampionId))
                            {
                                ChampionSelectListView.Items.Remove(y);
                                //Remove from arrays
                                foreach (
                                    ChampionDTO playerChamps in
                                        ChampList.ToArray()
                                            .Where(playerChamps => x.ChampionId == playerChamps.ChampionId))
                                {
                                    ChampList.Remove(playerChamps);

                                    break;
                                }

                                foreach (
                                    ChampionBanInfoDTO banChamps in
                                        ChampionsForBan.ToArray()
                                            .Where(banChamps => x.ChampionId == banChamps.ChampionId))
                                {
                                    ChampionsForBan.Remove(banChamps);

                                    break;
                                }
                            }
                        }

                        #endregion Render Bans
                    }
                    else if (champDto.GameState == "CHAMP_SELECT")
                    {
                        //Picking has started. If pickturn has changed reset timer
                        LastPickTurn = champDto.PickTurn;
                        BanningPhase = false;
                    }
                    else if (champDto.GameState == "POST_CHAMP_SELECT")
                    {
                        //Post game has started. Allow trading
                        CanTradeWith = await RiotCalls.GetPotentialTraders();
                        HasLockedIn = true;
                        GameStatusLabel.Content = "All players have picked!";
                        if (configType != null)
                            counter = configType.PostPickTimerDuration - 2;
                        else
                            counter = 10;
                    }
                    else if (champDto.GameState == "START_REQUESTED")
                    {
                        GameStatusLabel.Content = "The game is about to start!";
                        DodgeButton.IsEnabled = false; //Cannot dodge past this point!
                        counter = 1;
                    }
                    else if (champDto.GameState == "TERMINATED")
                    {
                        var pop = new NotifyPlayerPopup("Player Dodged", "Player has Dodged Queue.")
                        {
                            HorizontalAlignment = HorizontalAlignment.Right,
                            VerticalAlignment = VerticalAlignment.Bottom
                        };
                        Client.CurrentPage = previousPage;
                        Client.HasPopped = false;
                        Client.ReturnButton.Content = "Return to Lobby Page";
                        Client.ReturnButton.Visibility = Visibility.Visible;
                        Client.inQueueTimer.Visibility = Visibility.Visible;
                        Client.NotificationGrid.Children.Add(pop);
                        Client.RiotConnection.MessageReceived -= ChampSelect_OnMessageReceived;
                        //Client.OnFixChampSelect -= ChampSelect_OnMessageReceived;
                        Client.GameStatus = "inQueue";
                        Client.SetChatHover();
                        Client.SwitchPage(previousPage);
                        Client.ClearPage(typeof(ChampSelectPage));

                    }

                    #region Display players

                    BlueListView.Items.Clear();
                    PurpleListView.Items.Clear();
                    BlueListView.Items.Refresh();
                    PurpleListView.Items.Refresh();
                    int i = 0;
                    bool purpleSide = false;

                    //Aram hack, view other players champions & names (thanks to Andrew)
                    var otherPlayers = new List<PlayerChampionSelectionDTO>(champDto.PlayerChampionSelections.ToArray());
                    AreWePurpleSide = false;

                    foreach (Participant participant in allParticipants)
                    {
                        Participant tempParticipant = participant;
                        i++;
                        var control = new ChampSelectPlayer();
                        //Cast AramPlayers as PlayerParticipants. This removes reroll data
                        if (tempParticipant is AramPlayerParticipant)
                        {
                            tempParticipant = (PlayerParticipant)tempParticipant;
                        }

                        if (tempParticipant is PlayerParticipant)
                        {
                            var player = tempParticipant as PlayerParticipant;
                            if (!string.IsNullOrEmpty(player.SummonerName))
                            {
                                control.PlayerName.Content = player.SummonerName;
                                control.sumName = player.SummonerName;
                            }
                            else
                            {
                                try
                                {
                                    AllPublicSummonerDataDTO summoner =
                                        await RiotCalls.GetAllPublicSummonerDataByAccount(player.SummonerId);
                                    if (summoner.Summoner != null && !string.IsNullOrEmpty(summoner.Summoner.Name))
                                        control.PlayerName.Content = summoner.Summoner.Name;
                                    else
                                        control.PlayerName.Content = "Unknown Player";
                                }
                                catch
                                {
                                    control.PlayerName.Content = "Unknown Player";
                                }
                            }

                            foreach (PlayerChampionSelectionDTO selection in champDto.PlayerChampionSelections)
                            {
                                #region Disable picking selected champs

                                PlayerChampionSelectionDTO selection1 = selection;
                                foreach (ListViewItem y in championArray.Where(y => (int)y.Tag == selection1.ChampionId))
                                {
                                    y.IsHitTestVisible = true;
                                    y.Opacity = 0.5;
                                    if (configType == null)
                                        continue;

                                    if (!configType.DuplicatePick)
                                        continue;

                                    y.IsHitTestVisible = false;
                                    y.Opacity = 1;
                                }

                                foreach (ListViewItem y in championArray.Where(y => disabledCharacters.Contains((int)y.Tag)))
                                {
                                    y.Opacity = .7;
                                    y.IsHitTestVisible = false;
                                }

                                #endregion Disable picking selected champs

                                if (selection.SummonerInternalName != player.SummonerInternalName)
                                    continue;

                                //Clear our teams champion selection for aram hack
                                otherPlayers.Remove(selection);
                                control = RenderPlayer(selection, player);
                                //If we have locked in render skin select
                                if (!HasLockedIn ||
                                    selection.SummonerInternalName !=
                                    Client.LoginPacket.AllSummonerData.Summoner.InternalName || (Client.Dev && champDto.MapId != 12))
                                    continue;

                                if (purpleSide)
                                    AreWePurpleSide = true;

                                RenderLockInGrid(selection);
                                if (player.PointSummary == null)
                                    continue;

                                LockInButton.Content = string.Format("Reroll ({0}/{1})",
                                    player.PointSummary.CurrentPoints, player.PointSummary.PointsCostToRoll);
                                LockInButton.IsEnabled = player.PointSummary.NumberOfRolls > 0;
                            }
                        }
                        else if (tempParticipant is ObfuscatedParticipant)
                        {
                            control.PlayerName.Content = "Summoner " +
                                                         ((tempParticipant as ObfuscatedParticipant).GameUniqueId -
                                                          ((tempParticipant as ObfuscatedParticipant).GameUniqueId > 5
                                                              ? 5
                                                              : 0));
                        }
                        else if (tempParticipant is BotParticipant)
                        {
                            var bot = tempParticipant as BotParticipant;
                            if (bot.SummonerInternalName.Contains('_'))
                            {
                                string botChamp = bot.SummonerInternalName.Split('_')[1]; //Why is this internal name rito?
                                champions botSelectedChamp = champions.GetChampion(botChamp);
                                var part = new PlayerParticipant();
                                var selection = new PlayerChampionSelectionDTO
                                {
                                    ChampionId = botSelectedChamp.id
                                };
                                part.SummonerName = botSelectedChamp.displayName + " bot";
                                control = RenderPlayer(selection, part);
                            }
                            else
                            {
                                control.PlayerName.Content = "Bot";
                                control.sumName = "Bot";
                            }
                        }
                        else
                            control.PlayerName.Content = "Unknown Summoner";

                        //Display purple side if we have gone through our team
                        if (i > champDto.TeamOne.Count)
                        {
                            i = 0;
                            purpleSide = true;
                        }

                        if (!purpleSide)
                            BlueListView.Items.Add(control);
                        else
                            PurpleListView.Items.Add(control);
                    }

                    //Do aram hack!
                    if (otherPlayers.Count <= 0)
                        return;

                    if (AreWePurpleSide)
                        BlueListView.Items.Clear();
                    else
                        PurpleListView.Items.Clear();

                    foreach (PlayerChampionSelectionDTO hackSelection in otherPlayers)
                    {
                        var player = new PlayerParticipant
                        {
                            SummonerName = hackSelection.SummonerInternalName
                        };
                        ChampSelectPlayer control = RenderPlayer(hackSelection, player);
                        if (AreWePurpleSide)
                            BlueListView.Items.Add(control);
                        else
                            PurpleListView.Items.Add(control);
                    }

                    #endregion Display players
                }));

                #endregion In Champion Select
            }
            else if (message is PlayerCredentialsDto)
            {
                Client.RiotConnection.MessageReceived -= ChampSelect_OnMessageReceived;

                #region Launching Game

                var dto = message as PlayerCredentialsDto;
                Client.CurrentGame = dto;

                if (HasLaunchedGame)
                    return;

                HasLaunchedGame = true;


                if (Settings.Default.AutoRecordGames)
                {
                    Dispatcher.InvokeAsync(async () =>
                    {
                        PlatformGameLifecycleDTO n =
                            await
                                RiotCalls.RetrieveInProgressSpectatorGameInfo(
                                    Client.LoginPacket.AllSummonerData.Summoner.Name);
                        if (n.GameName != null)
                        {
                            string ip = n.PlayerCredentials.ObserverServerIp + ":" +
                                        n.PlayerCredentials.ObserverServerPort;
                            string key = n.PlayerCredentials.ObserverEncryptionKey;
                            var gameId = (int)n.PlayerCredentials.GameId;
                            new ReplayRecorder(ip, gameId, Client.Region.InternalName, key);
                        }
                    });
                }
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    if (CountdownTimer != null)
                        CountdownTimer.Stop();

                    InGame();
                    Client.ReturnButton.Visibility = Visibility.Hidden;
                    if (!Settings.Default.DisableClientSound)
                    {
                        Client.AmbientSoundPlayer.Stop();
                    }
                }));

                #endregion Launching Game
            }
            else if (message is TradeContractDTO)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    var tradeDto = message as TradeContractDTO;
                    if (tradeDto == null)
                        return;

                    switch (tradeDto.State)
                    {
                        case "PENDING":
                            {
                                PlayerTradeControl.Visibility = Visibility.Visible;
                                PlayerTradeControl.Tag = tradeDto;
                                PlayerTradeControl.AcceptButton.Visibility = Visibility.Visible;
                                PlayerTradeControl.DeclineButton.Content = "Decline";

                                champions myChampion = champions.GetChampion((int)tradeDto.ResponderChampionId);
                                PlayerTradeControl.MyChampImage.Source = myChampion.icon;
                                PlayerTradeControl.MyChampLabel.Content = myChampion.displayName;
                                champions theirChampion = champions.GetChampion((int)tradeDto.RequesterChampionId);
                                PlayerTradeControl.TheirChampImage.Source = theirChampion.icon;
                                PlayerTradeControl.TheirChampLabel.Content = theirChampion.displayName;
                                PlayerTradeControl.RequestLabel.Content = string.Format("{0} wants to trade!",
                                    tradeDto.RequesterInternalSummonerName);
                            }
                            break;
                        case "BUSY":
                        case "DECLINED":
                        case "CANCELED":
                            {
                                PlayerTradeControl.Visibility = Visibility.Hidden;

                                TextInfo text = new CultureInfo("en-US", false).TextInfo;
                                var pop = new NotificationPopup(ChatSubjects.INVITE_STATUS_CHANGED,
                                    string.Format("{0} has {1} this trade", tradeDto.RequesterInternalSummonerName,
                                        text.ToTitleCase(tradeDto.State)));

                                if (tradeDto.State == "BUSY")
                                    pop.NotificationTextBox.Text = string.Format("{0} is currently busy",
                                        tradeDto.RequesterInternalSummonerName);

                                pop.Height = 200;
                                pop.OkButton.Visibility = Visibility.Visible;
                                pop.HorizontalAlignment = HorizontalAlignment.Right;
                                pop.VerticalAlignment = VerticalAlignment.Bottom;
                                Client.NotificationGrid.Children.Add(pop); //*/
                            }
                            break;
                    }
                }));
            }
        }
        private void ParseSpectatorGames()
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                try
                {
                    if (GameList == null)
                        return;

                    if (GameList.Count <= 0)
                        return;

                    BlueBansLabel.Visibility = Visibility.Hidden;
                    PurpleBansLabel.Visibility = Visibility.Hidden;
                    BlueBanListView.Items.Clear();
                    PurpleBanListView.Items.Clear();
                    BlueListView.Items.Clear();
                    PurpleListView.Items.Clear();
                    int gameId = 0;
                    object objectGame = GameList[SelectedGame];
                    var spectatorGame = objectGame as Dictionary<string, object>;
                    ImageGrid.Children.Clear();
                    if (spectatorGame != null)
                        foreach (var pair in spectatorGame)
                        {
                            switch (pair.Key)
                            {
                                case "participants":
                                    {
                                        var players = pair.Value as ArrayList;

                                        int i = 0;
                                        foreach (object objectPlayer in players)
                                        {
                                            var playerInfo = objectPlayer as Dictionary<string, object>;
                                            int teamId = 100;
                                            int championId = 0;
                                            int spell1Id = 0;
                                            int spell2Id = 0;
                                            string playerName = "";
                                            foreach (var playerPair in playerInfo)
                                            {
                                                switch (playerPair.Key)
                                                {
                                                    case "teamId":
                                                        teamId = (int)playerPair.Value;
                                                        break;
                                                    case "championId":
                                                        championId = (int)playerPair.Value;
                                                        break;
                                                    case "summonerName":
                                                        playerName = playerPair.Value as string;
                                                        break;
                                                    case "spell1Id":
                                                        spell1Id = (int)playerPair.Value;
                                                        break;
                                                    case "spell2Id":
                                                        spell2Id = (int)playerPair.Value;
                                                        break;
                                                }
                                            }
                                            var control = new ChampSelectPlayer
                                            {
                                                ChampionImage = { Source = champions.GetChampion(championId).icon },
                                                champID = championId,
                                                sumName = playerName,
                                                KnownPar = true
                                            };
                                            var UriSource =
                                                new System.Uri(
                                                    Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                                                        SummonerSpell.GetSpellImageName(spell1Id)), UriKind.Absolute);
                                            control.SummonerSpell1.Source = new BitmapImage(UriSource);
                                            UriSource =
                                                new System.Uri(
                                                    Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                                                        SummonerSpell.GetSpellImageName(spell2Id)), UriKind.Absolute);
                                            control.SummonerSpell2.Source = new BitmapImage(UriSource);
                                            control.PlayerName.Content = playerName;
                                            control.Tag = new List<object> { playerName, championId };

                                            var m = new Image();
                                            Panel.SetZIndex(m, -2); //Put background behind everything
                                            m.Stretch = Stretch.None;
                                            m.Width = 100;
                                            m.Opacity = 0.30;
                                            m.HorizontalAlignment = HorizontalAlignment.Left;
                                            m.VerticalAlignment = VerticalAlignment.Stretch;
                                            m.Margin = new Thickness(i++ * 100, 0, 0, 0);
                                            var cropRect = new Rectangle(new Point(100, 0), new Size(100, 560));
                                            var src =
                                                System.Drawing.Image.FromFile(Path.Combine(Client.ExecutingDirectory,
                                                    "Assets",
                                                    "champions", champions.GetChampion(championId).portraitPath)) as Bitmap;
                                            var target = new Bitmap(cropRect.Width, cropRect.Height);

                                            using (Graphics g = Graphics.FromImage(target))
                                                g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
                                                    cropRect,
                                                    GraphicsUnit.Pixel);

                                            m.Source = Client.ToWpfBitmap(target);
                                            ImageGrid.Children.Add(m);
                                            if (teamId == 100)
                                                BlueListView.Items.Add(control);
                                            else
                                                PurpleListView.Items.Add(control);
                                        }
                                    }
                                    break;
                                case "gameId":
                                    gameId = (int)pair.Value;
                                    break;
                                case "mapId":
                                    try
                                    {
                                        MapLabel.Content = BaseMap.GetMap((int)pair.Value).DisplayName;
                                    }
                                    catch (Exception e)
                                    {
                                        Client.Log(e.Source, "Error");
                                        Client.Log(e.Message, "Error");
                                    }
                                    break;
                                case "gameLength":
                                    {
                                        var seconds = (int)pair.Value;
                                        Client.spectatorTimer.Stop();
                                        Client.spectatorTimer = new Timer(1000);
                                        Client.spectatorTimer.Elapsed += (s, e) => // Sincerely Idk when to stop it
                                        {
                                            seconds++;
                                            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                                            {
                                                TimeSpan ts = TimeSpan.FromSeconds(seconds);
                                                GameTimeLabel.Content = string.Format("{0:D2}:{1:D2} min", ts.Minutes,
                                                    ts.Seconds);
                                            }));
                                        };
                                        Client.spectatorTimer.Start();
                                    }
                                    break;
                                case "bannedChampions":
                                    {
                                        //ArrayList players = pair.Value as ArrayList;
                                        //Dictionary<string, object> playerInfo = objectPlayer as Dictionary<string, object>;
                                        //foreach (KeyValuePair<string, object> playerPair in playerInfo)
                                        var keyArray = pair.Value as ArrayList;
                                        if (keyArray.Count > 0)
                                        {
                                            BlueBansLabel.Visibility = Visibility.Visible;
                                            PurpleBansLabel.Visibility = Visibility.Visible;
                                        }
                                        foreach (Dictionary<string, object> keyArrayP in keyArray)
                                        //Dictionary<string, object> keyArrayP = keyArray as Dictionary<string, object>;
                                        {
                                            int cid = 0;
                                            int teamId = 100;
                                            foreach (var keyArrayPair in keyArrayP)
                                            {
                                                switch (keyArrayPair.Key)
                                                {
                                                    case "championId":
                                                        cid = (int)keyArrayPair.Value;
                                                        break;
                                                    case "teamId":
                                                        teamId = (int)keyArrayPair.Value;
                                                        break;
                                                }
                                            }
                                            var item = new ListViewItem();
                                            var champImage = new Image
                                            {
                                                Height = 58,
                                                Width = 58
                                            };
                                            //temp
                                            try
                                            {
                                                champImage.Source = champions.GetChampion(cid).icon;
                                            }
                                            catch
                                            {
                                            }

                                            item.Content = champImage;
                                            if (teamId == 100)
                                                BlueBanListView.Items.Add(item);
                                            else
                                                PurpleBanListView.Items.Add(item);
                                        }
                                    }
                                    break;
                            }
                        }

                    try
                    {
                        BaseRegion region = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
                        string spectatorJson;
                        string url = region.SpectatorLink + "consumer/getGameMetaData/" + region.InternalName + "/" +
                                     gameId + "/token";
                        using (var client = new WebClient())
                            spectatorJson = client.DownloadString(url);

                        var serializer = new JavaScriptSerializer();
                        var deserializedJson = serializer.Deserialize<Dictionary<string, object>>(spectatorJson);
                        MMRLabel.Content = "≈" + deserializedJson["interestScore"];
                    }
                    catch
                    {
                        MMRLabel.Content = "N/A";
                    }

                    if (Client.curentlyRecording.Contains(gameId))
                    {
                        RecordButton.IsEnabled = false;
                        RecordButton.Content = "Recording...";
                    }
                    else
                    {
                        RecordButton.IsEnabled = true;
                        RecordButton.Content = "Record";
                    }
                }
                catch (Exception e)
                {
                    Client.Log(e.Message);
                }
            }));
        }
        private void ParseSpectatorGames()
        {
            if (gameList == null)
                return;
            if (gameList.Count <= 0)
                return;
            BlueBansLabel.Visibility = Visibility.Hidden;
            PurpleBansLabel.Visibility = Visibility.Hidden;
            BlueBanListView.Items.Clear();
            PurpleBanListView.Items.Clear();
            BlueListView.Items.Clear();
            PurpleListView.Items.Clear();
            int GameId = 0;
            var objectGame = gameList[SelectedGame];
            Dictionary<string, object> SpectatorGame = objectGame as Dictionary<string, object>;
            ImageGrid.Children.Clear();
            foreach (KeyValuePair<string, object> pair in SpectatorGame)
            {
                if (pair.Key == "participants")
                {
                    ArrayList players = pair.Value as ArrayList;

                    int i = 0;
                    foreach (var objectPlayer in players)
                    {
                        Dictionary<string, object> playerInfo = objectPlayer as Dictionary<string, object>;
                        int teamId = 100;
                        int championId = 0;
                        int spell1Id = 0;
                        int spell2Id = 0;
                        string PlayerName = "";
                        foreach (KeyValuePair<string, object> playerPair in playerInfo)
                        {
                            if (playerPair.Key == "teamId")
                            {
                                teamId = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "championId")
                            {
                                championId = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "summonerName")
                            {
                                PlayerName = playerPair.Value as string;
                            }
                            if (playerPair.Key == "spell1Id")
                            {
                                spell1Id = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "spell2Id")
                            {
                                spell2Id = (int)playerPair.Value;
                            }
                        }
                        ChampSelectPlayer control = new ChampSelectPlayer();
                        control.ChampionImage.Source = champions.GetChampion(championId).icon;
                        var uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(spell1Id)), UriKind.Absolute);
                        control.SummonerSpell1.Source = new BitmapImage(uriSource);
                        uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(spell2Id)), UriKind.Absolute);
                        control.SummonerSpell2.Source = new BitmapImage(uriSource);
                        control.PlayerName.Content = PlayerName;

                        Image m = new Image();
                        Canvas.SetZIndex(m, -2); //Put background behind everything
                        m.Stretch = Stretch.None;
                        m.Width = 100;
                        m.Opacity = 0.30;
                        m.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        m.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                        m.Margin = new System.Windows.Thickness(i++ * 100, 0, 0, 0);
                        System.Drawing.Rectangle cropRect = new System.Drawing.Rectangle(new System.Drawing.Point(100, 0), new System.Drawing.Size(100, 560));
                        System.Drawing.Bitmap src = System.Drawing.Image.FromFile(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", champions.GetChampion(championId).portraitPath)) as System.Drawing.Bitmap;
                        System.Drawing.Bitmap target = new System.Drawing.Bitmap(cropRect.Width, cropRect.Height);

                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target))
                        {
                            g.DrawImage(src, new System.Drawing.Rectangle(0, 0, target.Width, target.Height),
                                            cropRect,
                                            System.Drawing.GraphicsUnit.Pixel);
                        }

                        m.Source = Client.ToWpfBitmap(target);
                        ImageGrid.Children.Add(m);

                        if (teamId == 100)
                        {
                            BlueListView.Items.Add(control);
                        }
                        else
                        {
                            PurpleListView.Items.Add(control);
                        }
                    }
                }
                if (pair.Key == "gameId")
                {
                    GameId = (int)pair.Value;
                }
                if (pair.Key == "mapId")
                {
                    MapLabel.Content = BaseMap.GetMap((int)pair.Value).DisplayName;
                }
                if (pair.Key == "bannedChampions")
                {
                    ArrayList keyArray = pair.Value as ArrayList;
                    if (keyArray.Count > 0)
                    {
                        BlueBansLabel.Visibility = Visibility.Visible;
                        PurpleBansLabel.Visibility = Visibility.Visible;
                    }
                    foreach (Dictionary<string, object> keyArrayP in keyArray)
                    {
                        int cid = 0;
                        int teamId = 100;
                        foreach (KeyValuePair<string, object> keyArrayPair in keyArrayP)
                        {
                            if (keyArrayPair.Key == "championId")
                            {
                                cid = (int)keyArrayPair.Value;
                            }
                            if (keyArrayPair.Key == "teamId")
                            {
                                teamId = (int)keyArrayPair.Value;
                            }
                        }
                        ListViewItem item = new ListViewItem();
                        Image champImage = new Image();
                        champImage.Height = 58;
                        champImage.Width = 58;
                        champImage.Source = champions.GetChampion(cid).icon;
                        item.Content = champImage;
                        if (teamId == 100)
                        {
                            BlueBanListView.Items.Add(item);
                        }
                        else
                        {
                            PurpleBanListView.Items.Add(item);
                        }
                    }
                }
            }

            try
            {
                BaseRegion region = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
                string spectatorJSON = "";
                string url = region.SpectatorLink + "consumer/getGameMetaData/" + region.InternalName + "/" + GameId + "/token";
                using (WebClient client = new WebClient())
                {
                    spectatorJSON = client.DownloadString(url);
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(spectatorJSON);
                MMRLabel.Content = "≈" + deserializedJSON["interestScore"];
            }
            catch { MMRLabel.Content = "N/A"; }
        }
 internal ChampSelectPlayer RenderPlayer(PlayerChampionSelectionDTO selection, PlayerParticipant player)
 {
     ChampSelectPlayer control = new ChampSelectPlayer();
     if (selection.ChampionId != 0)
     {
         control.ChampionImage.Source = champions.GetChampion(selection.ChampionId).icon;
     }
     if (selection.Spell1Id != 0)
     {
         var uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell1Id)), UriKind.Absolute);
         control.SummonerSpell1.Source = new BitmapImage(uriSource);
         uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell2Id)), UriKind.Absolute);
         control.SummonerSpell2.Source = new BitmapImage(uriSource);
     }
     if (player.SummonerName == Client.LoginPacket.AllSummonerData.Summoner.Name)
     {
         var uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell1Id)), UriKind.Absolute);
         SummonerSpell1Image.Source = new BitmapImage(uriSource);
         uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell2Id)), UriKind.Absolute);
         SummonerSpell2Image.Source = new BitmapImage(uriSource);
     }
     control.PlayerName.Content = player.SummonerName;
     return control;
 }
        private void ChampSelect_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() == typeof(GameDTO))
            {
                #region In Champion Select

                GameDTO ChampDTO = message as GameDTO;
                LatestDto = ChampDTO;
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                {
                    ListViewItem[] ChampionArray = new ListViewItem[ChampionSelectListView.Items.Count];
                    ChampionSelectListView.Items.CopyTo(ChampionArray, 0);
                    foreach (ListViewItem y in ChampionArray)
                    {
                        y.IsHitTestVisible = true;
                        y.Opacity = 1;
                    }

                    List<Participant> AllParticipants = new List<Participant>(ChampDTO.TeamOne.ToArray());
                    AllParticipants.AddRange(ChampDTO.TeamTwo);
                    foreach (Participant p in AllParticipants)
                    {
                        if (p is PlayerParticipant)
                        {
                            PlayerParticipant play = (PlayerParticipant)p;
                            if (play.PickTurn == ChampDTO.PickTurn)
                            {
                                if (play.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId)
                                {
                                    ChampionSelectListView.IsHitTestVisible = true;
                                    ChampionSelectListView.Opacity = 1;
                                    GameStatusLabel.Content = "Your turn to pick!";
                                    break;
                                }
                            }
                        }
                        if (!DevMode)
                        {
                            ChampionSelectListView.IsHitTestVisible = false;
                            ChampionSelectListView.Opacity = 0.5;
                        }
                        GameStatusLabel.Content = "Waiting for others to pick...";
                    }

                    if (ChampDTO.GameState == "TEAM_SELECT")
                    {
                        if (CountdownTimer != null)
                        {
                            CountdownTimer.Stop();
                        }
                        Client.PVPNet.OnMessageReceived -= ChampSelect_OnMessageReceived;
                        Client.ClearPage(this);
                        FakePage fakePage = new FakePage();
                        fakePage.Content = Client.LastPageContent;
                        Client.SwitchPage(fakePage);
                        return;
                    }
                    else if (ChampDTO.GameState == "PRE_CHAMP_SELECT")
                    {
                        BanningPhase = true;
                        PurpleBansLabel.Visibility = Visibility.Visible;
                        BlueBansLabel.Visibility = Visibility.Visible;
                        BlueBanListView.Visibility = Visibility.Visible;
                        PurpleBanListView.Visibility = Visibility.Visible;
                        GameStatusLabel.Content = "Bans are on-going";
                        counter = configType.BanTimerDuration;

                        ChampionBanInfoDTO[] BannedChamps = await Client.PVPNet.GetChampionsForBan();

                        #region Render Bans

                        BlueBanListView.Items.Clear();
                        PurpleBanListView.Items.Clear();
                        foreach (var x in ChampDTO.BannedChampions)
                        {
                            Image champImage = new Image();
                            champImage.Height = 58;
                            champImage.Width = 58;
                            champImage.Source = champions.GetChampion(x.ChampionId).icon;
                            if (x.TeamId == 100)
                            {
                                BlueBanListView.Items.Add(champImage);
                            }
                            else
                            {
                                PurpleBanListView.Items.Add(champImage);
                            }

                            foreach (ListViewItem y in ChampionArray)
                            {
                                if ((int)y.Tag == x.ChampionId)
                                {
                                    ChampionSelectListView.Items.Remove(y);
                                }
                            }
                        }

                        #endregion Render Bans
                    }
                    else if (ChampDTO.GameState == "CHAMP_SELECT")
                    {
                        BanningPhase = false;
                    }
                    else if (ChampDTO.GameState == "POST_CHAMP_SELECT")
                    {
                        HasLockedIn = true;
                        GameStatusLabel.Content = "All players have picked!";
                        if (configType != null)
                            counter = configType.PostPickTimerDuration - 5;
                        else
                            counter = 10;
                    }
                    else if (ChampDTO.GameState == "START_REQUESTED")
                    {
                        GameStatusLabel.Content = "The game is about to start!";
                        DodgeButton.IsEnabled = false; //Cannot dodge past this point!
                    }

                    #region Display players

                    BlueListView.Items.Clear();
                    PurpleListView.Items.Clear();
                    int i = 0;
                    bool PurpleSide = false;

                    //Aram hack, view other players champions & names (thanks to Andrew)
                    List<PlayerChampionSelectionDTO> OtherPlayers = new List<PlayerChampionSelectionDTO>(ChampDTO.PlayerChampionSelections.ToArray());
                    bool AreWePurpleSide = false;

                    foreach (Participant participant in AllParticipants)
                    {
                        Participant tempParticipant = participant;
                        i++;
                        ChampSelectPlayer control = new ChampSelectPlayer();
                        if (tempParticipant is AramPlayerParticipant)
                        {
                            tempParticipant = new PlayerParticipant(tempParticipant.GetBaseTypedObject());
                        }

                        if (tempParticipant is PlayerParticipant)
                        {
                            PlayerParticipant player = tempParticipant as PlayerParticipant;
                            control.PlayerName.Content = player.SummonerName;

                            foreach (PlayerChampionSelectionDTO selection in ChampDTO.PlayerChampionSelections)
                            {
                                #region Disable picking selected champs

                                foreach (ListViewItem y in ChampionArray)
                                {
                                    if ((int)y.Tag == selection.ChampionId)
                                    {
                                        y.IsHitTestVisible = false;
                                        y.Opacity = 0.5;
                                        if (configType != null)
                                        {
                                            if (configType.DuplicatePick)
                                            {
                                                y.IsHitTestVisible = true;
                                                y.Opacity = 1;
                                            }
                                        }
                                    }
                                }

                                #endregion Disable picking selected champs

                                if (selection.SummonerInternalName == player.SummonerInternalName)
                                {
                                    OtherPlayers.Remove(selection);
                                    control = RenderPlayer(selection, player);
                                    if (HasLockedIn && selection.SummonerInternalName == Client.LoginPacket.AllSummonerData.Summoner.InternalName)
                                    {
                                        if (PurpleSide)
                                            AreWePurpleSide = true;
                                        RenderLockInGrid(selection);
                                    }
                                }
                            }
                        }
                        else if (tempParticipant is ObfuscatedParticipant)
                        {
                            control.PlayerName.Content = "Summoner " + i;
                        }
                        else if (tempParticipant is BotParticipant)
                        {
                            BotParticipant bot = tempParticipant as BotParticipant;
                            string botChamp = bot.SummonerName.Split(' ')[0]; //Why is this internal name rito?
                            champions botSelectedChamp = champions.GetChampion(botChamp);
                            PlayerParticipant part = new PlayerParticipant();
                            PlayerChampionSelectionDTO selection = new PlayerChampionSelectionDTO();
                            selection.ChampionId = botSelectedChamp.id;
                            part.SummonerName = botSelectedChamp.displayName + " bot";
                            control = RenderPlayer(selection, part);
                        }
                        else
                        {
                            control.PlayerName.Content = "Unknown Summoner";
                        }
                        if (i > ChampDTO.TeamOne.Count)
                        {
                            i = 0;
                            PurpleSide = true;
                        }

                        if (!PurpleSide)
                        {
                            BlueListView.Items.Add(control);
                        }
                        else
                        {
                            PurpleListView.Items.Add(control);
                        }
                    }

                    //Do aram hack!
                    if (OtherPlayers.Count > 0)
                    {
                        if (AreWePurpleSide)
                        {
                            BlueListView.Items.Clear();
                        }
                        else
                        {
                            PurpleListView.Items.Clear();
                        }

                        foreach (PlayerChampionSelectionDTO hackSelection in OtherPlayers)
                        {
                            ChampSelectPlayer control = new ChampSelectPlayer();
                            PlayerParticipant player = new PlayerParticipant();
                            player.SummonerName = hackSelection.SummonerInternalName;
                            control = RenderPlayer(hackSelection, player);

                            if (AreWePurpleSide)
                            {
                                BlueListView.Items.Add(control);
                            }
                            else
                            {
                                PurpleListView.Items.Add(control);
                            }
                        }
                    }

                    #endregion Display players
                }));

                #endregion In Champion Select
            }
            else if (message.GetType() == typeof(PlayerCredentialsDto))
            {
                #region Launching Game

                PlayerCredentialsDto dto = message as PlayerCredentialsDto;
                Client.CurrentGame = dto;
                Client.PVPNet.OnMessageReceived -= ChampSelect_OnMessageReceived;

                if (!HasLaunchedGame)
                {
                    HasLaunchedGame = true;
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        Client.SwitchPage(new InGame());
                        if (CountdownTimer != null)
                        {
                            CountdownTimer.Stop();
                        }
                        Client.PVPNet.OnMessageReceived -= ChampSelect_OnMessageReceived;
                        Client.ClearPage(this);
                    }));
                    Client.LaunchGame();
                }

                #endregion Launching Game
            }
        }
示例#11
0
        public void Update(PlatformGameLifecycleDTO currentGame, string username)
        {
            user = username;
            game = currentGame;
            BlueBansLabel.Visibility = Visibility.Hidden;
            PurpleBansLabel.Visibility = Visibility.Hidden;
            PurpleBanListView.Items.Clear();
            BlueBanListView.Items.Clear();

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

            ImageGrid.Children.Clear();

            var allParticipants = new List<Participant>(currentGame.Game.TeamOne.ToArray());
            allParticipants.AddRange(currentGame.Game.TeamTwo);

            var i = 0;
            var y = 0;
            foreach (var part in allParticipants)
            {
                var control = new ChampSelectPlayer();
                if (part is PlayerParticipant)
                {
                    var participant = part as PlayerParticipant;
                    foreach (
                        var championSelect in
                            currentGame.Game.PlayerChampionSelections.Where(
                                championSelect =>
                                    championSelect.SummonerInternalName == participant.SummonerInternalName))
                    {
                        control.KnownPar = true;
                        control.sumName = participant.SummonerInternalName;
                        control.champID = championSelect.ChampionId;
                        control.ChampionImage.Source = champions.GetChampion(championSelect.ChampionId).icon;
                        var UriSource =
                            new System.Uri(
                                Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                                    SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell1Id))),
                                UriKind.Absolute);
                        control.SummonerSpell1.Source = new BitmapImage(UriSource);
                        UriSource =
                            new System.Uri(
                                Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                                    SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell2Id))),
                                UriKind.Absolute);
                        control.SummonerSpell2.Source = new BitmapImage(UriSource);

                        var m = new Image();
                        Panel.SetZIndex(m, -2);
                        m.Stretch = Stretch.None;
                        m.Width = 100;
                        m.Opacity = 0.50;
                        m.HorizontalAlignment = HorizontalAlignment.Left;
                        m.VerticalAlignment = VerticalAlignment.Stretch;
                        m.Margin = new Thickness(y++*100, 0, 0, 0);
                        var cropRect = new Rectangle(new Point(100, 0), new Size(100, 560));
                        var src =
                            System.Drawing.Image.FromFile(Path.Combine(Client.ExecutingDirectory, "Assets",
                                "champions", champions.GetChampion(championSelect.ChampionId).portraitPath)) as
                                Bitmap;
                        var target = new Bitmap(cropRect.Width, cropRect.Height);

                        using (var g = Graphics.FromImage(target))
                        {
                            if (src != null)
                            {
                                g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
                                    cropRect,
                                    GraphicsUnit.Pixel);
                            }
                        }

                        m.Source = Client.ToWpfBitmap(target);
                        ImageGrid.Children.Add(m);
                    }

                    control.PlayerName.Content = participant.SummonerName;

                    if (participant.TeamParticipantId != null)
                    {
                        var values = BitConverter.GetBytes((double) participant.TeamParticipantId);
                        if (!BitConverter.IsLittleEndian) Array.Reverse(values);

                        var r = values[2];
                        var b = values[3];
                        var g = values[4];

                        var myColor = Color.FromArgb(r, b, g);

                        var converter = new BrushConverter();
                        var brush = (Brush) converter.ConvertFromString("#" + myColor.Name);
                        control.TeamRectangle.Fill = brush;
                        control.TeamRectangle.Visibility = Visibility.Visible;
                    }
                }

                i++;
                if (i <= 5)
                {
                    BlueListView.Items.Add(control);
                }
                else
                {
                    PurpleListView.Items.Add(control);
                }
            }

            if (currentGame.Game.BannedChampions.Count > 0)
            {
                BlueBansLabel.Visibility = Visibility.Visible;
                PurpleBansLabel.Visibility = Visibility.Visible;
            }

            foreach (var x in currentGame.Game.BannedChampions)
            {
                var champImage = new Image
                {
                    Height = 58,
                    Width = 58,
                    Source = champions.GetChampion(x.ChampionId).icon
                };
                if (x.TeamId == 100)
                {
                    BlueBanListView.Items.Add(champImage);
                }
                else
                {
                    PurpleBanListView.Items.Add(champImage);
                }
            }

            try
            {
                string mmrJson;
                var url = Client.Region.SpectatorLink + "consumer/getGameMetaData/" + Client.Region.InternalName +
                          "/" + currentGame.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 = "≈" + deserializedJson["interestScore"];
            }
            catch
            {
                MMRLabel.Content = "N/A";
            }
        }