Пример #1
0
        public void Update(PlatformGameLifecycleDTO CurrentGame)
        {
            Game = 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"; }
        }
Пример #2
0
        /// <summary>
        /// Loads the particiapants for the game
        /// </summary>
        /// <param name="allParticipants"></param>
        /// <param name="n"></param>
        /// <param name="list"></param>
        private async void LoadPar(List<Participant> allParticipants,PlatformGameLifecycleDTO n, ListView list)
        {
            bool isYourTeam = false;
            list.Items.Clear();
            list.Items.Refresh();
            try
            {
                string mmrJson;
                string url = Client.Region.SpectatorLink + "consumer/getGameMetaData/" + Client.Region.InternalName +
                             "/" + n.Game.Id + "/token";
                using (var client = new WebClient())
                    mmrJson = client.DownloadString(url);

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

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

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

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

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