Example #1
0
        public static MatchReport GetMatchReport(string name, string region, bool platinumWinrates)
        {
            // Select which winrates to display.
            if (platinumWinrates)
            {
                Code.Leagueofgraphs.PlatinumWinrates = true;
            }
            else
            {
                Code.Leagueofgraphs.PlatinumWinrates = false;
            }

            try
            {
                _ = Code.Riot.GetCurrentGameWebsite(name, region);
            }
            catch (Exception)
            {
                throw;
            }

            Report = new MatchReport();

            var    BlueTeamChampions = new List <(string Name, double Winrate, string DamageDealt, string DamageReceived)>();
            var    RedTeamChampions  = new List <(string Name, double Winrate, string DamageDealt, string DamageReceived)>();
            double BlueAverageWinrate;
            double RedAverageWinrate;
            double BlueTotalChampionPoints;
            double RedTotalChampionPoints;

            var    BlueTeamTeamcomp        = new List <(string Amount, string GroupName, string Points)>();
            var    RedTeamTeamcomp         = new List <(string Amount, string GroupName, string Points)>();
            string PlayerTeam              = "";
            string PlayerChampion          = "";
            double BlueTotalTeamcompPoints = 0;
            double RedTotalTeamcompPoints  = 0;

            #region CHAMPIONS

            // BLUE TEAM
            foreach (var participant in Riot.CurrentGame.Participants)
            {
                // Get searched player's champion name (only here because it iterates through everyone anyway).
                if (participant.SummonerName.ToLower() == name.ToLower())
                {
                    PlayerChampion = Ddragon.GetChampionFullName(Ddragon.GetChampionName(participant.ChampionId));
                    name           = participant.SummonerName;
                }

                if (participant.TeamId == 100)
                {
                    string championName    = Ddragon.GetChampionName(participant.ChampionId);
                    double championWinrate = Leagueofgraphs.GetWinrate(championName);

                    (string, string)championBuffs = Wiki.GetChampionBuffsPair(championName);

                    string damageDealt    = championBuffs.Item1;
                    string damageReceived = championBuffs.Item2;

                    BlueTeamChampions.Add((championName, championWinrate, damageDealt, damageReceived));
                }
            }

            BlueTotalChampionPoints = (Math.Round(((Math.Round(BlueTeamChampions.Select(x => x.Winrate).Average(), 1) - 50) * 100)));
            BlueAverageWinrate      = Math.Round(BlueTeamChampions.Select(x => x.Winrate).Average(), 1);

            // RED TEAM
            foreach (var participant in Riot.CurrentGame.Participants)
            {
                if (participant.TeamId == 200)
                {
                    string championName    = Ddragon.GetChampionName(participant.ChampionId);
                    double championWinrate = Leagueofgraphs.GetWinrate(championName);

                    (string, string)championBuffs = Wiki.GetChampionBuffsPair(championName);

                    string damageDealt    = championBuffs.Item1;
                    string damageReceived = championBuffs.Item2;

                    RedTeamChampions.Add((championName, championWinrate, damageDealt, damageReceived));
                }
            }
            RedTotalChampionPoints = (Math.Round(((Math.Round(RedTeamChampions.Select(x => x.Winrate).Average(), 1) - 50) * 100)));
            RedAverageWinrate      = Math.Round(RedTeamChampions.Select(x => x.Winrate).Average(), 1);

            #endregion CHAMPIONS

            #region TEAMCOMPS

            // Load champion groups.
            Data.DataResearch.Research.LoadChampionGroups();

            // BLUE TEAM
            for (int i = 0; i < Data.DataResearch.Research.ChampionGroups.Count; i++)
            {
                var championGroupMembers = BlueTeamChampions.Select(x => x.Name).ToList().Intersect(Data.DataResearch.Research.ChampionGroups[i].Item1.ChampionNames);
                var points = Data.DataResearch.Research.ChampionGroups[i].Item1.Points[championGroupMembers.Count()];

                BlueTeamTeamcomp.Add((championGroupMembers.Count().ToString(), Data.DataResearch.Research.ChampionGroups[i].Item1.DisplayName, points.ToString()));

                BlueTotalTeamcompPoints += points;
            }

            // RED TEAM
            for (int i = 0; i < Data.DataResearch.Research.ChampionGroups.Count; i++)
            {
                var championGroupMembers = RedTeamChampions.Select(x => x.Name).ToList().Intersect(Data.DataResearch.Research.ChampionGroups[i].Item1.ChampionNames);
                var points = Data.DataResearch.Research.ChampionGroups[i].Item1.Points[championGroupMembers.Count()];

                RedTeamTeamcomp.Add((championGroupMembers.Count().ToString(), Data.DataResearch.Research.ChampionGroups[i].Item1.DisplayName, points.ToString()));

                RedTotalTeamcompPoints += points;
            }

            #endregion TEAMCOMPS

            #region SUMMARY

            if (Riot.IsPlayerBlueTeam)
            {
                PlayerTeam = "BLUE";
            }
            else
            {
                PlayerTeam = "RED";
            }

            #endregion SUMMARY

            // Fix champion names.
            for (int i = 0; i < BlueTeamChampions.Count; i++)
            {
                BlueTeamChampions[i] = (Ddragon.GetChampionFullName(BlueTeamChampions[i].Name), BlueTeamChampions[i].Winrate, BlueTeamChampions[i].DamageDealt, BlueTeamChampions[i].DamageReceived);
            }
            for (int i = 0; i < RedTeamChampions.Count; i++)
            {
                RedTeamChampions[i] = (Ddragon.GetChampionFullName(RedTeamChampions[i].Name), RedTeamChampions[i].Winrate, RedTeamChampions[i].DamageDealt, RedTeamChampions[i].DamageReceived);
            }

            Report.BlueTeamChampions       = BlueTeamChampions;
            Report.RedTeamChampions        = RedTeamChampions;
            Report.BlueTeamTeamcomp        = BlueTeamTeamcomp;
            Report.RedTeamTeamcomp         = RedTeamTeamcomp;
            Report.BlueAverageWinrate      = BlueAverageWinrate;
            Report.RedAverageWinrate       = RedAverageWinrate;
            Report.BlueTotalTeamcompPoints = BlueTotalTeamcompPoints;
            Report.RedTotalTeamcompPoints  = RedTotalTeamcompPoints;
            Report.BlueTotalChampionPoints = BlueTotalChampionPoints;
            Report.RedTotalChampionPoints  = RedTotalChampionPoints;
            Report.PlayerTeam       = PlayerTeam;
            Report.PlayerName       = name;
            Report.PlayerChampion   = PlayerChampion;
            Report.PlatinumWinrates = platinumWinrates;
            Report.PlayerRegion     = region;

            return(Report);
        }
Example #2
0
        public static void AnalyzeWinrates()
        {
            // For each champion show its winrate in console.

            // BLUE TEAM

            Console.WriteLine();
            Console.WriteLine("------------------------------------------------------------------------------------------------");
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.WriteLine(" BLUE TEAM \t\t WINRATE \t DAMAGE DEALT \t DAMAGE RECEIVED ");
            Console.ResetColor();
            foreach (var participant in Riot.CurrentGame.Participants)
            {
                if (participant.TeamId == 100)
                {
                    string championName    = Ddragon.GetChampionName(participant.ChampionId);
                    double championWinrate = Leagueofgraphs.GetWinrate(championName);

                    Console.Write($"{championName}{(championName.Length > 7 ? "\t" : "\t\t")}\t");

                    // Select winrate text color.

                    if (championWinrate >= 52)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else if (championWinrate >= 50)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                    }
                    else if (championWinrate >= 48)
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }

                    Console.Write($"{championWinrate}");
                    Console.ResetColor();

                    string championBuffs = Wiki.GetChampionBuffs(championName);

                    if (championBuffs[2] == '+')
                    {
                        // Champion is buffed.
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else if (championBuffs[2] == '-')
                    {
                        // Champion is nerfed.
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    else if (championBuffs[4] == '-')
                    {
                        // Champion is buffed (only damage received).
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else
                    {
                        // Either no changes, or only damage received nerf.
                        Console.ForegroundColor = ConsoleColor.Red;
                    }

                    Console.WriteLine(championBuffs);
                    Console.ResetColor();

                    // Add champion with winrate to BlueTeam dictionary.
                    BlueTeamChampions.Add(championName, championWinrate);
                }
            }
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.WriteLine($" AVERAGE WINRATE: \t{Math.Round(BlueTeamChampions.Values.Average(), 1)}");
            Console.ResetColor();
            Console.WriteLine();

            BlueChampionPoints = (int)(Math.Round(((Math.Round(BlueTeamChampions.Values.Average(), 1) - 50) * 100)));

            // RED TEAM

            Console.BackgroundColor = ConsoleColor.Red;
            Console.WriteLine(" RED TEAM \t\t WINRATE \t DAMAGE DEALT \t DAMAGE RECEIVED ");
            Console.ResetColor();
            foreach (var participant in Riot.CurrentGame.Participants)
            {
                if (participant.TeamId == 200)
                {
                    string championName    = Ddragon.GetChampionName(participant.ChampionId);
                    double championWinrate = Leagueofgraphs.GetWinrate(championName);

                    Console.Write($"{championName}{(championName.Length > 7 ? "\t" : "\t\t")}\t");

                    // Select winrate text color.

                    if (championWinrate >= 52)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else if (championWinrate >= 50)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                    }
                    else if (championWinrate >= 48)
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }

                    Console.Write($"{championWinrate}");
                    Console.ResetColor();

                    string championBuffs = Wiki.GetChampionBuffs(championName);

                    if (championBuffs[2] == '+')
                    {
                        // Champion is buffed.
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else if (championBuffs[2] == '-')
                    {
                        // Champion is nerfed.
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    else if (championBuffs[4] == '-')
                    {
                        // Champion is buffed (only damage received).
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else
                    {
                        // Either no changes, or only damage received nerf.
                        Console.ForegroundColor = ConsoleColor.Red;
                    }

                    Console.WriteLine(championBuffs);
                    Console.ResetColor();

                    // Add champion with winrate to RedTeam dictionary.
                    RedTeamChampions.Add(championName, championWinrate);
                }
            }
            Console.BackgroundColor = ConsoleColor.Red;
            Console.WriteLine($" AVERAGE WINRATE: \t{Math.Round(RedTeamChampions.Values.Average(), 1)}");
            Console.ResetColor();

            RedChampionPoints = (int)(Math.Round(((Math.Round(RedTeamChampions.Values.Average(), 1) - 50) * 100)));

            Console.WriteLine("------------------------------------------------------------------------------------------------");
            Console.WriteLine();
        }