예제 #1
0
        public async Task<string[]> Load(double ID)
        {
            RecentGames result = await RiotCalls.GetRecentGames(ID);
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            GamesWithChamp = 0;
            foreach (PlayerGameStats game in result.GameStatistics)
            {
                game.GameType = Client.TitleCaseString(game.GameType.Replace("_GAME", "").Replace("MATCHED", "NORMAL"));
                var match = new MatchStats();

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

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

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

            }
            catch
            { ChampKDAString = "NO RECENT GAMES!!!"; }
            //GetKDA string
            OverallKDA = new KDA()
            {
                Kills = AKills,
                Deaths = ADeaths,
                Assists = AAssists,
                Games = AGamesPlayed
            };
            //Get champ KDA
            Champkda = new KDA()
            {
                Kills = ChampKills,
                Deaths = ChampDeaths,
                Assists = ChampAssists,
                Games = ChampGamesPlayed
            };
            return new List<string>() { ChampKDAString, KDAString }.ToArray();
        }
예제 #2
0
        public async Task <string[]> Load(double ID)
        {
            RecentGames result = await Client.PVPNet.GetRecentGames(ID);

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

                foreach (RawStat stat in game.Statistics)
                {
                    Type      type      = typeof(MatchStats);
                    string    fieldName = Client.TitleCaseString(stat.StatType.Replace('_', ' ')).Replace(" ", "");
                    FieldInfo f         = type.GetField(fieldName);
                    f.SetValue(match, stat.Value);
                }
                match.Game = game;
                GameStats.Add(match);
            }
            int AKills, ChampKills;
            int ADeaths, ChampDeaths;
            int AAssists, ChampAssists;
            int AGamesPlayed, ChampGamesPlayed;
            int Wins, ChampWins;

            AKills      = 0; ADeaths = 0; AAssists = 0; AGamesPlayed = 0; ChampKills = 0;
            ChampDeaths = 0; ChampAssists = 0; ChampGamesPlayed = 0; Wins = 0; ChampWins = 0;
            //Load average KDA for past 20 games if possible
            foreach (MatchStats stats in GameStats)
            {
                if (stats.Win == 1)
                {
                    Wins++;
                }
                champions gameChamp = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                AKills   = AKills + (Int32)stats.ChampionsKilled;
                ADeaths  = ADeaths + (Int32)stats.NumDeaths;
                AAssists = AAssists + (Int32)stats.Assists;
                AGamesPlayed++;

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

            string KDAString = string.Format("{0}/{1}/{2}",
                                             (AKills / AGamesPlayed),
                                             (ADeaths / AGamesPlayed),
                                             (AAssists / AGamesPlayed));
            string ChampKDAString = "";

            try
            {
                ChampKDAString = string.Format("{0}/{1}/{2}",
                                               (ChampKills / ChampGamesPlayed),
                                               (ChampDeaths / ChampGamesPlayed),
                                               (ChampAssists / ChampGamesPlayed));
            }
            catch
            { ChampKDAString = "NO RECENT GAMES!!!"; }
            //GetKDA String
            OverallKDA = new KDA()
            {
                Kills   = AKills,
                Deaths  = ADeaths,
                Assists = AAssists,
                Games   = AGamesPlayed
            };
            //Get champ KDA
            Champkda = new KDA()
            {
                Kills   = ChampKills,
                Deaths  = ChampDeaths,
                Assists = ChampAssists,
                Games   = ChampGamesPlayed
            };
            return(new List <string>()
            {
                ChampKDAString, KDAString
            }.ToArray());
        }
예제 #3
0
 public string KDAToString(KDA kda)
 {
     return((kda.Kills / kda.Games) + "/" + (kda.Deaths / kda.Games) + "/" + (kda.Assists / kda.Games));
 }