public EndOfGamePage(EndOfGameStats statistics)
 {
     InitializeComponent();
     RenderStats(statistics);
     Client.SwitchPage(Client.MainPage);
     Client.runonce = false;
     Client.ChampId = -1;
     RoomJid = Client.GetChatroomJid(statistics.RoomName, statistics.RoomPassword, false);
     
     newRoom = new MucManager(Client.XmppConnection);
     Client.XmppConnection.OnMessage += XmppConnection_OnMessage;
     Client.XmppConnection.OnPresence += XmppConnection_OnPresence;
     Client.RiotConnection.MessageReceived += RiotConnection_MessageReceived;
     newRoom.AcceptDefaultConfiguration(new Jid(RoomJid));
     newRoom.JoinRoom(new Jid(RoomJid), Client.LoginPacket.AllSummonerData.Summoner.Name);
 }
        private void RenderStats(EndOfGameStats Statistics)
        {
            TimeSpan t = TimeSpan.FromSeconds(Statistics.GameLength);
            TimeLabel.Content = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
            ModeLabel.Content = Statistics.GameMode;
            TypeLabel.Content = Statistics.GameType;

            List<PlayerParticipantStatsSummary> AllParticipants = new List<PlayerParticipantStatsSummary>(Statistics.TeamPlayerParticipantStats.ToArray());
            AllParticipants.AddRange(Statistics.OtherTeamPlayerParticipantStats);

            foreach (PlayerParticipantStatsSummary summary in AllParticipants)
            {
                EndOfGamePlayer playerStats = new EndOfGamePlayer();
                champions Champ = champions.GetChampion(summary.SkinName); //Misleading variable name
                playerStats.ChampImage.Source = Champ.icon;
                playerStats.ChampLabel.Content = Champ.name;
                playerStats.PlayerLabel.Content = summary.SummonerName;
                var uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell1Id));
                playerStats.Spell1Image.Source = Client.GetImage(uriSource);
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell2Id));
                playerStats.Spell2Image.Source = Client.GetImage(uriSource);

                double ChampionsKilled = 0;
                double Assists = 0;
                double Deaths = 0;

                foreach (RawStatDTO stat in summary.Statistics)
                {
                    if (stat.StatTypeName.StartsWith("ITEM") && stat.Value != 0)
                    {
                        Image item = new Image();
                        uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png");
                        item.Source = Client.GetImage(uriSource);
                        playerStats.ItemsListView.Items.Add(item);
                    }

                    switch (stat.StatTypeName)
                    {
                        case "GOLD_EARNED":
                            if (stat.Value > 0)
                            {
                                playerStats.GoldLabel.Content = string.Format("{0:N1}k", stat.Value / 1000);
                            }
                            break;

                        case "MINIONS_KILLED":
                            playerStats.CSLabel.Content = stat.Value;
                            break;

                        case "LEVEL":
                            playerStats.LevelLabel.Content = stat.Value;
                            break;

                        case "CHAMPIONS_KILLED":
                            ChampionsKilled = stat.Value;
                            break;

                        case "ASSISTS":
                            Assists = stat.Value;
                            break;

                        case "NUM_DEATHS":
                            Deaths = stat.Value;
                            break;

                        default:
                            break;
                    }
                }

                playerStats.ScoreLabel.Content = ChampionsKilled + "/" + Deaths + "/" + Assists;

                PlayersListView.Items.Add(playerStats);
            }

            PlayersListView.Items.Insert(AllParticipants.Count / 2, new Separator());

            /*championSkins Skin = championSkins.GetSkin(Statistics.SkinIndex);
            var skinSource = Path.Combine(Client.ExecutingDirectory, "Assets", "champions", Skin.splashPath);
            SkinImage.Source = Client.GetImage(skinSource);*/
        }
        private void RenderStats(EndOfGameStats statistics)
        {
            TimeSpan t = TimeSpan.FromSeconds(statistics.GameLength);
            TimeLabel.Content = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
            ModeLabel.Content = statistics.GameMode;
            TypeLabel.Content = statistics.GameType;
            // Add Garena TW match history
            if (Client.Garena && !string.IsNullOrEmpty(Settings.Default.DefaultGarenaRegion) && Settings.Default.DefaultGarenaRegion == "TW")
                MatchStatsOnline = string.Format("http://lol.moa.tw/summoner/show/{0}#tabs-recentgame2", statistics.SummonerName.Replace(" ", "_"));
            else
                MatchStatsOnline = "http://matchhistory.na.leagueoflegends.com/en/#match-details/" + Client.Region.InternalName + "/" + statistics.ReportGameId + "/" + statistics.UserId;

            GainedIP.Content = "+" + statistics.IpEarned + " IP";
            TotalIP.Content = statistics.IpTotal.ToString(CultureInfo.InvariantCulture).Replace(".0", "") + " IP Total";
            string game = " XP";
            var allParticipants =
                new List<PlayerParticipantStatsSummary>(statistics.TeamPlayerParticipantStats.ToArray());
            allParticipants.AddRange(statistics.OtherTeamPlayerParticipantStats);
            foreach (PlayerParticipantStatsSummary summary in allParticipants)
            {
                var playerStats = new EndOfGamePlayer(summary.UserId, summary.GameId, summary.SummonerName, statistics.TeamPlayerParticipantStats.Contains(summary));
                champions champ = champions.GetChampion(summary.SkinName); //Misleading variable name
                playerStats.ChampImage.Source = champ.icon;
                playerStats.ChampLabel.Content = champ.name;
                playerStats.PlayerLabel.Content = summary.SummonerName;
                if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell1Id))))
                {
                    var UriSource = new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell1Id)), UriKind.Absolute);
                    playerStats.Spell1Image.Source = new BitmapImage(UriSource);
                }
                else
                    Client.Log(SummonerSpell.GetSpellImageName((int)summary.Spell1Id) + " is missing");
                if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell2Id))))
                {
                    var UriSource = new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell2Id)), UriKind.Absolute);
                    playerStats.Spell2Image.Source = new BitmapImage(UriSource);
                }
                else
                    Client.Log(SummonerSpell.GetSpellImageName((int)summary.Spell2Id) + " is missing");
                double championsKilled = 0;
                double assists = 0;
                double deaths = 0;
                bool victory = false;
                foreach (RawStatDTO stat in summary.Statistics.Where(stat => stat.StatTypeName.ToLower() == "win"))
                {
                    if (summary.SummonerName == Client.LoginPacket.AllSummonerData.Summoner.Name)
                    {
                        victory = true;
                        GameResultLabel.Content = "Victory";
                    }
                        
                }

                if (statistics.Ranked)
                {
                    game = " LP";
                    GainedXP.Content = (victory ? "+" : "-") + statistics.ExperienceEarned + game;
                    TotalXP.Content = statistics.ExperienceTotal + game;
                }
                else
                {
                    if (Client.LoginPacket.AllSummonerData.SummonerLevel.Level < 30)
                    {
                        GainedXP.Content = "+" + statistics.ExperienceEarned + game;
                        TotalXP.Content = statistics.ExperienceTotal + game;
                    }
                    else
                    {
                        GainedXP.Visibility = Visibility.Hidden;
                        TotalXP.Visibility = Visibility.Hidden;
                    }
                }

                foreach (RawStatDTO stat in summary.Statistics)
                {
                    if (stat.StatTypeName.StartsWith("ITEM") && Math.Abs(stat.Value) > 0)
                    {
                        var item = new Image();
                        if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")))
                        {
                            var UriSource = new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png"), UriKind.Absolute);
                            item.Source = new BitmapImage(UriSource);
                        }
                        else
                            Client.Log(stat.Value + ".png is missing");
                        playerStats.ItemsListView.Items.Add(item);
                    }
                    switch (stat.StatTypeName)
                    {
                        case "GOLD_EARNED":
                            if (stat.Value > 0)
                            {
                                playerStats.GoldLabel.Content = string.Format("{0:N1}k", stat.Value/1000);
                            }
                            break;

                        case "MINIONS_KILLED":
                            playerStats.CsLabel.Content = stat.Value;
                            break;

                        case "LEVEL":
                            playerStats.LevelLabel.Content = stat.Value;
                            break;

                        case "CHAMPIONS_KILLED":
                            championsKilled = stat.Value;
                            break;

                        case "ASSISTS":
                            assists = stat.Value;
                            break;

                        case "NUM_DEATHS":
                            deaths = stat.Value;
                            break;
                    }
                }
                playerStats.ScoreLabel.Content = championsKilled + "/" + deaths + "/" + assists;
                PlayersListView.Items.Add(playerStats);                
            }
            PlayersListView.Items.Insert(allParticipants.Count/2, new Separator());
            championSkins skin = championSkins.GetSkin(statistics.SkinIndex);
            try
            {
                if (skin == null)
                    return;

                var skinSource =
                    new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", skin.splashPath),
                        UriKind.Absolute);
                SkinImage.Source = new BitmapImage(skinSource);
            }
            catch (Exception)
            {
            }
        }
 public EndOfGamePage(EndOfGameStats Statistics)
 {
     InitializeComponent();
     RenderStats(Statistics);
 }