예제 #1
0
 /// <summary>
 /// Get a summoner spell asynchronously.
 /// </summary>
 /// <param name="region">Region from which to retrieve the data.</param>
 /// <param name="summonerSpell">Summoner spell to retrieve.</param>
 /// <param name="summonerSpellData">Data to retrieve.</param>
 /// <param name="language">Language of the data to be retrieved.</param>
 /// <returns>A summoner spell.</returns>
 public async Task<SummonerSpellStatic> GetSummonerSpellAsync(Region region, SummonerSpell summonerSpell
     , SummonerSpellData summonerSpellData = SummonerSpellData.none, Language language = Language.en_US)
 {
     var wrapper = Cache.Get<SummonerSpellStaticWrapper>(SummonerSpellCacheKey + summonerSpell.ToCustomString());
     if (wrapper != null && wrapper.SummonerSpellData == summonerSpellData && wrapper.Language == language)
     {
         return wrapper.SummonerSpellStatic;
     }
     else
     {
         var listWrapper = Cache.Get<SummonerSpellListStaticWrapper>(SummonerSpellsCacheKey);
         if (listWrapper != null && listWrapper.SummonerSpellData == summonerSpellData
             && listWrapper.Language == language)
         {
             if (listWrapper.SummonerSpellListStatic.SummonerSpells.ContainsKey(summonerSpell.ToCustomString()))
             {
                 return listWrapper.SummonerSpellListStatic.SummonerSpells[summonerSpell.ToCustomString()];
             }
             else
             {
                 return null;
             }
         }
         else
         {
             var json = await requester.CreateRequestAsync(string.Format(SummonerSpellRootUrl, region.ToString())
                 + string.Format(IdUrl, (int)summonerSpell)
                 , new List<string>() { string.Format("locale={0}", language.ToString())
                     , summonerSpellData == SummonerSpellData.none ? string.Empty
                         : string.Format("spellData={0}", summonerSpellData.ToString()) });
             var spell = await JsonConvert.DeserializeObjectAsync<SummonerSpellStatic>(json);
             Cache.Add<SummonerSpellStaticWrapper>(SummonerSpellCacheKey + summonerSpell.ToCustomString()
                 , new SummonerSpellStaticWrapper(spell, language, summonerSpellData));
             return spell;
         }
     }
 }
예제 #2
0
        public static double GetSummonerSpellDamage(this Obj_AI_Hero source,
            Obj_AI_Base target,
            SummonerSpell summonerSpell)
        {
            if (summonerSpell == SummonerSpell.Ignite)
            {
                return 50 + 20 * source.Level - (target.HPRegenRate / 5 * 3);
            }

            if (summonerSpell == SummonerSpell.Smite)
            {
                if (target is Obj_AI_Hero)
                {
                    var chillingSmite =
                        source.Spellbook.Spells.FirstOrDefault(h => h.Name.Equals("s5_summonersmiteplayerganker"));
                    var challengingSmite =
                        source.Spellbook.Spells.FirstOrDefault(h => h.Name.Equals("s5_summonersmiteduel"));

                    if (chillingSmite != null)
                    {
                        return 20 + 8 * source.Level;
                    }

                    if (challengingSmite != null)

                    {
                        return 54 + 6 * source.Level;
                    }
                }

                return
                    new double[]
                    { 390, 410, 430, 450, 480, 510, 540, 570, 600, 640, 680, 720, 760, 800, 850, 900, 950, 1000 }[
                        source.Level - 1];
            }

            return 0d;
        }
예제 #3
0
 /// <summary>
 /// Get a summoner spell asynchronously.
 /// </summary>
 /// <param name="region">Region from which to retrieve the data.</param>
 /// <param name="summonerSpell">Summoner spell to retrieve.</param>
 /// <param name="summonerSpellData">Data to retrieve.</param>
 /// <param name="language">Language of the data to be retrieved.</param>
 /// <returns>A summoner spell.</returns>
 public async Task<SummonerSpellStatic> GetSummonerSpellAsync(Region region, SummonerSpell summonerSpell,
     SummonerSpellData summonerSpellData = SummonerSpellData.none, Language language = Language.en_US)
 {
     var wrapper = cache.Get<string, SummonerSpellStaticWrapper>(
         SummonerSpellCacheKey + summonerSpell.ToCustomString());
     if (wrapper != null && wrapper.SummonerSpellData == summonerSpellData && wrapper.Language == language)
     {
         return wrapper.SummonerSpellStatic;
     }
     var listWrapper = cache.Get<string, SummonerSpellListStaticWrapper>(SummonerSpellsCacheKey);
     if (listWrapper != null && listWrapper.SummonerSpellData == summonerSpellData
         && listWrapper.Language == language)
     {
         return listWrapper.SummonerSpellListStatic.SummonerSpells.ContainsKey(summonerSpell.ToCustomString()) ?
             listWrapper.SummonerSpellListStatic.SummonerSpells[summonerSpell.ToCustomString()] : null;
     }
     var json = await requester.CreateGetRequestAsync(
         string.Format(SummonerSpellRootUrl, region.ToString()) +
         string.Format(IdUrl, (int)summonerSpell),
         RootDomain,
         new List<string>
         {
             string.Format("locale={0}", language.ToString()),
             summonerSpellData == SummonerSpellData.none ?
                 string.Empty :
                 string.Format("spellData={0}", summonerSpellData.ToString())
         });
     var spell = await Task.Factory.StartNew(() =>
         JsonConvert.DeserializeObject<SummonerSpellStatic>(json));
     cache.Add(SummonerSpellCacheKey + summonerSpell.ToCustomString(),
         new SummonerSpellStaticWrapper(spell, language, summonerSpellData), DefaultSlidingExpiry);
     return spell;
 }
예제 #4
0
        public static double GetSummonerSpellDamage(this Obj_AI_Hero source,
            Obj_AI_Base target,
            SummonerSpell summonerSpell)
        {
            if (summonerSpell == SummonerSpell.Ignite)
            {
                return 50 + 20 * source.Level - (target.HPRegenRate / 5 * 3);
            }

            if (summonerSpell == SummonerSpell.Smite)
            {
                return
                    new double[]
                    { 390, 410, 430, 450, 480, 510, 540, 570, 600, 640, 680, 720, 760, 800, 850, 900, 950, 1000 }[
                        source.Level - 1];
            }

            return 0d;
        }
예제 #5
0
        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;
            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 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 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 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 Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", skin.splashPath),
                            UriKind.Absolute);
                SkinImage.Source = new BitmapImage(skinSource);
            }
            catch (Exception)
            {
            }
        }
예제 #6
0
        private static void CheckSummoner(SummonerSpell spell)
        {
            bool healperzent;
            bool healhealth;

            switch (spell.Summoner)
            {
            case Summoner.Ignite:
            {
                if (ChampSupported)
                {
                    break;
                }
                if (!PUC.Menu.Item("act_ignite_ks").GetValue <bool>())
                {
                    break;
                }
                const int igniterange = 600;
                foreach (var enemy in PUC.AllHerosEnemy.Where(hero => hero.IsValidTarget(igniterange) && PUC.Player.GetSummonerSpellDamage(hero, Damage.SummonerSpell.Ignite) > hero.Health))
                {
                    if (spell.IsReady())
                    {
                        spell.CastSpell(enemy);
                    }
                    break;
                }
            }
            break;

            case Summoner.Smite:                     // Supported by Tarzan
                break;

            case Summoner.Heal:
                if (!PUC.Menu.Item("act_heal_use").GetValue <bool>() || Utility.InFountain())
                {
                    break;
                }
                const int healrange = 700;
                foreach (var friend in PUC.AllHerosFriend.Where(hero => hero.IsValid && !hero.IsDead && hero.Distance(PUC.Player) < healrange))
                {
                    if (friend.IsMe || PUC.Menu.Item("useHealFriend").GetValue <bool>())
                    {
                        healperzent = false;
                        healhealth  = false;
                        if (friend.Health / friend.MaxHealth * 100 <= PUC.Menu.Item("act_heal_Percent").GetValue <Slider>().Value)
                        {
                            healperzent = true;
                        }
                        if (friend.Health < PUC.Menu.Item("act_heal_Health").GetValue <Slider>().Value)
                        {
                            healhealth = true;
                        }
                        if (healperzent)
                        {
                            if (PUC.Menu.Item("act_heal_ifEnemy1").GetValue <bool>())
                            {
                                if (Utility.CountEnemysInRange(1000, friend) > 0)
                                {
                                    if (spell.IsReady())
                                    {
                                        spell.CastSpell();
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                if (spell.IsReady())
                                {
                                    spell.CastSpell();
                                }
                                break;
                            }
                        }
                        if (healhealth)
                        {
                            if (PUC.Menu.Item("act_heal_ifEnemy2").GetValue <bool>())
                            {
                                if (Utility.CountEnemysInRange(1000, friend) > 0)
                                {
                                    if (spell.IsReady())
                                    {
                                        spell.CastSpell();
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                if (spell.IsReady())
                                {
                                    spell.CastSpell();
                                }
                                break;
                            }
                        }
                    }
                }
                break;

            case Summoner.Barrier:
                if (!PUC.Menu.Item("act_barrier_use").GetValue <bool>() || Utility.InFountain())
                {
                    break;
                }
                healperzent = false;
                healhealth  = false;
                if (PUC.Player.Health / PUC.Player.MaxHealth * 100 <= PUC.Menu.Item("act_barrier_Percent").GetValue <Slider>().Value)
                {
                    healperzent = true;
                }
                if (PUC.Player.Health < PUC.Menu.Item("act_barrier_Health").GetValue <Slider>().Value)
                {
                    healhealth = true;
                }
                if (healperzent)
                {
                    if (PUC.Menu.Item("act_barrier_ifEnemy1").GetValue <bool>())
                    {
                        if (Utility.CountEnemysInRange(1000, PUC.Player) > 0)
                        {
                            if (spell.IsReady())
                            {
                                spell.CastSpell();
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (spell.IsReady())
                        {
                            spell.CastSpell();
                        }
                        break;
                    }
                }
                if (healhealth)
                {
                    if (PUC.Menu.Item("act_barrier_ifEnemy2").GetValue <bool>())
                    {
                        if (Utility.CountEnemysInRange(1000, PUC.Player) > 0)
                        {
                            if (spell.IsReady())
                            {
                                spell.CastSpell();
                            }
                        }
                    }
                    else
                    if (spell.IsReady())
                    {
                        spell.CastSpell();
                    }
                }
                break;

            case Summoner.Exhaust:
                if (!PUC.Menu.Item("act_exhoust_use").GetValue <bool>())
                {
                    break;
                }
                const int range      = 550;
                var       maxDpsHero = PUC.AllHerosEnemy.Where(hero => hero.IsValidTarget(range + 200)).OrderByDescending(x => x.BaseAttackDamage * x.AttackSpeedMod).FirstOrDefault();
                if (maxDpsHero == null)
                {
                    return;
                }
                var maxDps = maxDpsHero.BaseAttackDamage * maxDpsHero.AttackSpeedMod;
                if (PUC.AllHerosFriend.Where(hero => hero.IsAlly && hero.Distance(ObjectManager.Player) <= range).Any(friend => friend.Health <= maxDps * PUC.Menu.Item("act_exhoust_killfriend").GetValue <Slider>().Value))
                {
                    if (spell.IsReady())
                    {
                        spell.CastSpell(maxDpsHero);
                    }
                }
                if (PUC.Player.Health <= maxDps * PUC.Menu.Item("act_exhoust_killme").GetValue <Slider>().Value)
                {
                    if (spell.IsReady())
                    {
                        spell.CastSpell(maxDpsHero);
                    }
                }
                break;

            case Summoner.Cleanse:
                if (BuffnamesCC.Any(bufftype => PUC.Player.HasBuffOfType(bufftype) && PUC.Menu.Item("act_cleanse_" + bufftype).GetValue <bool>()))
                {
                    if (spell.IsReady())
                    {
                        spell.CastSpell();
                    }
                }
                break;
            }
        }
예제 #7
0
        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 }
                                        };
                                        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;

                                        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);
                }
            }));
        }
예제 #8
0
        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);
                        }
                    }
                }
                else if (pair.Key == "gameId")
                {
                    GameId = (int)pair.Value;
                }
                else if (pair.Key == "mapId")
                {
                    MapLabel.Content = BaseMap.GetMap((int)pair.Value).DisplayName;
                }
                else if (pair.Key == "gameLength")
                {
                    var seconds = (int)pair.Value;
                    GameTimeLabel.Content = string.Format("{0:D}:{1:00} min", seconds / 60, seconds % 60);
                }
                else if (pair.Key == "bannedChampions")
                {
                    //ArrayList players = pair.Value as ArrayList;
                    //Dictionary<string, object> playerInfo = objectPlayer as Dictionary<string, object>;
                    //foreach (KeyValuePair<string, object> playerPair in playerInfo)
                    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)
                    //Dictionary<string, object> keyArrayP = keyArray as Dictionary<string, object>;
                    {
                        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;
                        //temp
                        try
                        {
                            champImage.Source = champions.GetChampion(cid).icon;
                        }
                        catch { }

                        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"; }
        }
        //This is something you don't know exists
        private void RenderLegenadryClientPlayerSumSpellIcons()
        {
            if (ChampionId != 0)
            {
                TeamPlayer.Champion.Source = champions.GetChampion(ChampionId).icon;
            }
            string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)spell1));

            TeamPlayer.SummonerSpell1Image.Source = Client.GetImage(uriSource);
            uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)spell2));
            TeamPlayer.SummonerSpell2Image.Source = Client.GetImage(uriSource);
        }
예제 #10
0
        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 = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell1Id)), UriKind.Absolute);
                playerStats.Spell1Image.Source = new BitmapImage(uriSource);
                uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)summary.Spell2Id)), UriKind.Absolute);
                playerStats.Spell2Image.Source = new BitmapImage(uriSource);

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

                foreach (RawStatDTO stat in summary.Statistics)
                {
                    if (stat.StatTypeName.StartsWith("ITEM") && stat.Value != 0)
                    {
                        System.Windows.Controls.Image item = new System.Windows.Controls.Image();
                        uriSource   = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png"), UriKind.Absolute);
                        item.Source = new BitmapImage(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);

            try
            {
                var skinSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", Skin.splashPath), UriKind.Absolute);
                SkinImage.Source = new BitmapImage(skinSource);
            }
            catch
            {
            }
        }
예제 #11
0
 public IHateWpf(SummonerSpell spell, bool selected)
 {
     this.Spell    = spell;
     this.Selected = selected;
 }
예제 #12
0
        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;

            if (gameList.Count > SelectedGame)
            {
                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"; }
            }
        }
        /// <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 || LatestDto.GameState == "POST_CHAMP_SELECT" || LatestDto.GameState == "START_REQUESTED")
            {
                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) || DevMode))
            {
                control.TradeButton.Visibility = System.Windows.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];

                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);
        }
예제 #14
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 = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell1Id))), UriKind.Absolute);
                            control.SummonerSpell1.Source = new BitmapImage(uriSource);
                            uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell2Id))), UriKind.Absolute);
                            control.SummonerSpell2.Source = new BitmapImage(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"; }
        }
예제 #15
0
        private async void Load(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 Client.PVPNet.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;
                        var uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(Convert.ToInt32(championSelect.Spell1Id))),
                                                UriKind.Absolute);
                        control.SumIcon1.Source = new BitmapImage(uriSource);
                        uriSource =
                            new 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 Client.PVPNet.GetSummonerByName(championSelect.SummonerInternalName);

                            control.ProfileIcon.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", summoner.ProfileIconId.ToString() + ".png"));
                            RecentGames result = await Client.PVPNet.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 + (Int32)stats.ChampionsKilled;
                                Deaths  = Deaths + (Int32)stats.NumDeaths;
                                Assists = Assists + (Int32)stats.Assists;
                                GamesPlayed++;
                                if (championSelect.ChampionId == (int)Math.Round(stats.Game.ChampionId))
                                {
                                    ChampKills   = ChampKills + (Int32)stats.ChampionsKilled;
                                    ChampDeaths  = ChampDeaths + (Int32)stats.NumDeaths;
                                    ChampAssists = ChampAssists + (Int32)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("#FFFF0000");
                                }
                                else if (ChampKills == ChampDeaths)
                                {
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FF67FF67");
                                }
                                else
                                {
                                    control.ChampKDAColor.Fill = (Brush)bc.ConvertFrom("#FF00FF3A");
                                }

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

                                bc = new BrushConverter();
                                if (Kills > Deaths)
                                {
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FFFF0000");
                                }
                                else if (Kills == Deaths)
                                {
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FF67FF67");
                                }
                                else
                                {
                                    control.GameKDAColor.Fill = (Brush)bc.ConvertFrom("#FF00FF3A");
                                }
                            }
                        }
                        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;
                            }
                        }
                        list.Items.Add(control);
                    }
                }
            }
        }