Example #1
0
        public async Task MM(CommandContext ctx)
        {
            using (SqliteContext lite = new SqliteContext())
            {
                var allProfiles = lite.Profiles;
                var queue       = lite.playerQueue;
                int queueCount  = 12;

                if (queue.Count() < 12)
                {
                    await ctx.Channel.SendMessageAsync($"Not enough players queued. Need {12 - queue.Count()} players.");

                    return;
                }

                while (queueCount != 0)
                {
                    //Adding player to role team
                    foreach (var player in queue)
                    {
                        if (player.role == "dps")
                        {
                            dpsTeamList.Add(player);
                            queueCount--;
                        }
                        else if (player.role == "tank")
                        {
                            tankTeamList.Add(player);
                            queueCount--;
                        }
                        else //player.role == support
                        {
                            supportTeamList.Add(player);
                            queueCount--;
                        }
                    }
                }

                //For each role team, find the highest and lowest value, pair them, then the remaining two are the last

                string[] maps = { "Blizzard World",      "Busan",     "Dorado", "Eichenwalde", "Hanamura",
                                  "Havana",              "Hollywood", "Ilios",  "Junkertown",  "Kings Row","Lijiang Tower",
                                  "Nepal",               "Numbani",   "Oasis",  "Rialto",      "Route 66", "Temple of Anubis",
                                  "Volskaya Industries", "Watchpoint: Gibraltar" };

                var Team1Average = Math.Round(Team1.Average(i => i.queueSr));
                var Team2Average = Math.Round(Team2.Average(i => i.queueSr));

                Random rnd = new Random();
                int    i   = rnd.Next(0, maps.Length + 1);

                string map = maps[i];

                string Team1Message = "```" + $"Team 1: ";
                string Team2Message = "Team 2: ";

                foreach (var player in Team1)
                {
                    Team1Message = Team1Message + "\n" + $"{player.userName,-25} : {player.role,10} : {player.queueSr}";
                    player.Team  = 1;
                    await lite.SaveChangesAsync();
                }

                foreach (var player in Team2)
                {
                    Team2Message = Team2Message + "\n" + $"{player.userName,-25} : {player.role,10} : {player.queueSr}";
                    player.Team  = 2;
                    await lite.SaveChangesAsync();
                }

                await ctx.Channel.SendMessageAsync(Team1Message + "\n" + "\n" + Team2Message
                                                   + "\n" + "\n" + $"Team 1 Average : {Team1Average, 10}"
                                                   + "\n" + $"Team 2 Average: { Team2Average, 10}"
                                                   + "\n" + "\n" + $"{map}" +
                                                   "```");

                game = true;
            }
            return;
        }