예제 #1
0
        public static string DisplayHelp(IGuild guild, bool isChanNsfw)
        {
            if (guild != null && !Program.p.db.IsAvailable(guild.Id, Program.Module.Game))
            {
                return(Modules.Base.Sentences.NotAvailable(guild));
            }
            List <Tuple <APreload, string> > soloOnly  = new List <Tuple <APreload, string> >();
            List <Tuple <APreload, string> > multiOnly = new List <Tuple <APreload, string> >();
            List <Tuple <APreload, string> > both      = new List <Tuple <APreload, string> >();

            // Put all games on lists to know if they are multiplayer or not
            foreach (var game in Constants.allGames)
            {
                APreload preload = (APreload)Activator.CreateInstance(game.Item1);
                switch (preload.DoesAllowMultiplayer())
                {
                case APreload.Multiplayer.SoloOnly:
                    soloOnly.Add(new Tuple <APreload, string>(preload, game.Item3));
                    break;

                case APreload.Multiplayer.MultiOnly:
                    multiOnly.Add(new Tuple <APreload, string>(preload, game.Item3));
                    break;

                case APreload.Multiplayer.Both:
                    both.Add(new Tuple <APreload, string>(preload, game.Item3));
                    break;
                }
            }
            // Display help
            StringBuilder str = new StringBuilder();

            if (soloOnly.Count > 0)
            {
                str.AppendLine("**" + Translation.GetTranslation(guild, "gameModuleSoloOnly") + "**");
                AppendHelp(soloOnly, str, isChanNsfw, guild);
            }
            if (multiOnly.Count > 0)
            {
                str.AppendLine("**" + Translation.GetTranslation(guild, "gameModuleMultiOnly") + "**");
                AppendHelp(multiOnly, str, isChanNsfw, guild);
            }
            if (both.Count > 0)
            {
                str.AppendLine("**" + Translation.GetTranslation(guild, "gameModuleBoth") + "**");
                AppendHelp(both, str, isChanNsfw, guild);
            }
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleReset"));
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleScore"));

            /*str.AppendLine(Translation.GetTranslation(guild, "gameModuleJoin"));
             * str.AppendLine(Translation.GetTranslation(guild, "gameModuleLeave"));
             * str.AppendLine(Translation.GetTranslation(guild, "gameModuleStart"));*/
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleReplay"));
            str.Append("**Others multiplayer commands**: Join, Leave, Start");
            str.AppendLine(Environment.NewLine);
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleNote"));
            str.AppendLine(Environment.NewLine);
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleDifficulties"));
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleDifficulties2"));
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleDifficulties3"));
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleDifficulties4"));
            str.AppendLine(Environment.NewLine);
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleMultiHelp"));
            str.AppendLine(Translation.GetTranslation(guild, "gameModuleSoloHelp"));
            if (!isChanNsfw)
            {
                str.AppendLine(Environment.NewLine + Translation.GetTranslation(guild, "nsfwForFull"));
            }
            return(str.ToString());
        }
예제 #2
0
        private async Task <Func <ulong, string> > PlayInternal(string[] args, ITextChannel chan, ulong playerId)
        {
            if (args.Length == 0)
            {
                return(Sentences.InvalidGameName);
            }
            string     gameName   = args[0].ToLower();
            Difficulty difficulty = Difficulty.Normal;
            bool       isFull     = false;
            bool       sendImage  = false;
            bool       isCropped  = false;

            APreload.Shadow      isShaded      = APreload.Shadow.None;
            APreload.Multiplayer isMultiplayer = APreload.Multiplayer.SoloOnly;
            if (args.Length > 1)
            {
                foreach (string s in args.Skip(1).Select(x => x.ToLower()))
                {
                    switch (s)
                    {
                    case "full":
                        isFull = true;
                        break;

                    case "multi":
                    case "multiplayer":
                        isMultiplayer = APreload.Multiplayer.MultiOnly;
                        break;

                    case "easy":
                        difficulty = Difficulty.Easy;
                        break;

                    case "normal":
                    case "solo":
                        break;     // These case exist so the user can precise them, but they do nothing

                    case "crop":
                    case "cropped":
                        isCropped = true;
                        break;

                    case "shade":
                    case "shadow":
                    case "shaded":
                        isShaded = APreload.Shadow.Transparency;
                        break;

                    case "image":
                        sendImage = true;
                        break;

                    default:
                        return(Sentences.InvalidGameArgument);
                    }
                }
            }
            foreach (var game in Constants.allGames)
            {
                APreload preload = (APreload)Activator.CreateInstance(game.Item1);
                if (preload.ContainsName(gameName))
                {
                    if (!chan.IsNsfw && preload.IsNsfw())
                    {
                        return(Modules.Base.Sentences.ChanIsNotNsfw);
                    }
                    if (isMultiplayer == APreload.Multiplayer.MultiOnly && preload.DoesAllowMultiplayer() == APreload.Multiplayer.SoloOnly)
                    {
                        return(Sentences.MultiNotAvailable);
                    }
                    if (isMultiplayer == APreload.Multiplayer.SoloOnly && preload.DoesAllowMultiplayer() == APreload.Multiplayer.MultiOnly)
                    {
                        return(Sentences.SoloNotAvailable);
                    }
                    if (isFull && !preload.DoesAllowFull())
                    {
                        return(Sentences.FullNotAvailable);
                    }
                    if (sendImage && !preload.DoesAllowSendImage())
                    {
                        return(Sentences.SendImageNotAvailable);
                    }
                    if (isCropped && !preload.DoesAllowCropped())
                    {
                        return(Sentences.CropNotAvailable);
                    }
                    if (isCropped && preload.DoesAllowShadow() == APreload.Shadow.None)
                    {
                        return(Sentences.ShadowNotAvailable);
                    }
                    if (isShaded != APreload.Shadow.None)
                    {
                        isShaded = preload.DoesAllowShadow();
                    }
                    try
                    {
                        string introMsg = "";
                        if (isMultiplayer == APreload.Multiplayer.MultiOnly)
                        {
                            introMsg += Sentences.LobbyCreation(chan.GuildId, MultiplayerLobby.lobbyTime.ToString()) + Environment.NewLine + Environment.NewLine;
                        }
                        introMsg += "**" + Sentences.Rules(chan.GuildId) + ":**" + Environment.NewLine +
                                    preload.GetRules(chan.GuildId, isMultiplayer == APreload.Multiplayer.MultiOnly) + Environment.NewLine;
                        if (isMultiplayer == APreload.Multiplayer.MultiOnly)
                        {
                            if (preload.GetMultiplayerType() == APreload.MultiplayerType.Elimination)
                            {
                                introMsg += Sentences.RulesMultiElimination(chan.GuildId) + Environment.NewLine;
                            }
                            else
                            {
                                introMsg += Sentences.RulesMultiBestOf(chan.GuildId, AGame.nbMaxTry, AGame.nbQuestions) + Environment.NewLine;
                            }
                        }
                        introMsg += Sentences.RulesTimer(chan.GuildId, preload.GetTimer() * (int)difficulty) + Environment.NewLine + Environment.NewLine +
                                    Sentences.RulesReset(chan.GuildId);
                        await chan.SendMessageAsync(introMsg);

                        AGame newGame = (AGame)Activator.CreateInstance(game.Item2, chan, new Config(preload.GetTimer(), difficulty, preload.GetGameName(), isFull, sendImage, isCropped, isShaded, isMultiplayer, preload.GetMultiplayerType()), playerId);
                        _games.Add(newGame);
                        if (Program.p.sendStats)
                        {
                            await Program.p.UpdateElement(new Tuple <string, string>[] { new Tuple <string, string>("games", preload.GetGameName()) });
                        }
                        return(null);
                    }
                    catch (NoDictionnaryException)
                    {
                        return(Sentences.NoDictionnary);
                    }
                }
            }
            return(Sentences.InvalidGameName);
        }
예제 #3
0
        public async Task Score(params string[] _)
        {
            if (Context.Guild == null)
            {
                await ReplyAsync(Modules.Base.Sentences.CommandDontPm(Context.Guild));

                return;
            }
            Utilities.CheckAvailability(Context.Guild, Program.Module.Game);
            await Program.p.DoAction(Context.User, Program.Module.Game);

            var scores = await Program.p.db.GetAllScores();

            if (!scores.Any(x => x.Key == Context.Guild.Id.ToString()))
            {
                await ReplyAsync(Sentences.NoScore(Context.Guild));

                return;
            }
            var           me         = scores[Context.Guild.Id.ToString()];
            StringBuilder finalStr   = new StringBuilder();
            float         finalScore = 0;
            bool          ranked     = false;
            int           nbGuilds   = scores.Count(x => x.Value.Count > 0);

            foreach (var game in Constants.allRankedGames)
            {
                APreload preload  = (APreload)Activator.CreateInstance(game.Item1);
                string   gameName = preload.GetGameName();
                if (!me.ContainsKey(preload.GetGameName()))
                {
                    finalStr.Append("**" + preload.GetGameSentence(Context.Guild) + "**:" + Environment.NewLine +
                                    Sentences.NotRanked(Context.Guild) + Environment.NewLine + Environment.NewLine);
                    continue;
                }
                ranked = true;
                string[] myElems = me[gameName].Split('|');
                var      users   = await Context.Guild.GetUsersAsync();

                int      myScore      = int.Parse(myElems[0]);
                string[] contributors = myElems.Skip(1).Select(x => users.Where(y => y.Id.ToString() == x).FirstOrDefault()?.ToString() ?? "(Unknown)").ToArray();
                int      rankedNumber = scores.Where(x => Program.p.client.GetGuild(ulong.Parse(x.Key)) != null && x.Value.ContainsKey(gameName)).Count();
                int      myRanking    = scores.Where(x => Program.p.client.GetGuild(ulong.Parse(x.Key)) != null && x.Value.ContainsKey(gameName) && int.Parse(x.Value[gameName].Split('|')[0]) > myScore).Count() + 1;
                int      bestScore    = scores.Where(x => x.Value.ContainsKey(gameName)).Max(x => int.Parse(x.Value[gameName].Split('|')[0]));
                finalStr.Append("**" + preload.GetGameSentence(Context.Guild) + "**:" + Environment.NewLine +
                                Sentences.ScoreText(Context.Guild, myRanking, rankedNumber, myScore, bestScore) + Environment.NewLine +
                                Sentences.ScoreContributors(Context.Guild) + " " + string.Join(", ", contributors) + Environment.NewLine + Environment.NewLine);
                finalScore += myScore * 100f / bestScore;
            }
            int myGlobalRanking = 1;

            if (ranked)
            {
                foreach (var s in scores)
                {
                    int sScore = 0;
                    foreach (var elem in s.Value)
                    {
                        int best = scores.Where(x => x.Value.ContainsKey(elem.Key)).Max(x => int.Parse(x.Value[elem.Key].Split('|')[0]));
                        sScore += int.Parse(elem.Value.Split('|')[0]) * 100 / best;
                    }
                    if (sScore > finalScore)
                    {
                        myGlobalRanking++;
                    }
                }
            }
            await ReplyAsync((ranked ? Sentences.GlobalRanking(Context.Guild, myGlobalRanking, nbGuilds, finalScore / Constants.allRankedGames.Length)
                : Sentences.NoGlobalRanking(Context.Guild)) + Environment.NewLine + Environment.NewLine +
                             finalStr.ToString());
        }
예제 #4
0
        public static async Task <string> GetBestScores()
        {
            var scores = await Program.p.db.GetAllScores();

            string globalRankingStr = "";
            Dictionary <string, Tuple <int, bool> > globalRanking = new Dictionary <string, Tuple <int, bool> >();

            foreach (var s in scores)
            {
                int sScore = 0;
                foreach (var elem in s.Value)
                {
                    int best = scores.Where(x => x.Value.ContainsKey(elem.Key)).Max(x => int.Parse(x.Value[elem.Key].Split('|')[0]));
                    sScore += int.Parse(elem.Value.Split('|')[0]) * 100 / best;
                }
                if (sScore > 0)
                {
                    globalRanking.Add(s.Key, new Tuple <int, bool>(sScore, Program.p.db.IsAnonymized(ulong.Parse(s.Key))));
                }
            }
            int i = 0;

            while (i < 5 && globalRanking.Count > 0)
            {
                var    elem  = globalRanking.First(x => x.Value.Equals(globalRanking.Values.Max()));
                IGuild guild = Program.p.client.GetGuild(ulong.Parse(elem.Key));
                if (guild != null && guild.Name != null)
                {
                    if (globalRankingStr != "")
                    {
                        globalRankingStr += "|";
                    }
                    try
                    {
                        globalRankingStr += (elem.Value.Item2 ? "Anonymous" : Program.p.GetName(guild.Name)) + "|" + (elem.Value.Item1 / Constants.allRankedGames.Length);
                    } catch (NullReferenceException)
                    { } // No idea why this goes here
                    i++;
                }
                globalRanking.Remove(elem.Key);
            }
            StringBuilder finalStr = new StringBuilder();

            // Output format: Game1Place1Server | Game1Place1Score | Game1Place2Server..... Game1Place3Score $ Game2Place1Server | Game2Place1Score
            foreach (var game in Constants.allRankedGames)
            {
                APreload preload  = (APreload)Activator.CreateInstance(game.Item1);
                string   gameName = preload.GetGameName();

                // Prepare array containing all games serverId/score
                List <Tuple <string, string> > allScores = new List <Tuple <string, string> >();
                foreach (var elem in scores)
                {
                    if (elem.Value.ContainsKey(gameName))
                    {
                        allScores.Add(new Tuple <string, string>(elem.Key, elem.Value[gameName].Split('|')[0]));
                    }
                }
                List <Tuple <string, int> > best = new List <Tuple <string, int> >();
                string        bestServer;
                int           bestScore;
                List <string> alreadySaid = new List <string>();
                while (best.Count < 5 && allScores.Count > alreadySaid.Count)
                {
                    bestServer = null;
                    bestScore  = -1;
                    foreach (var elem in allScores)
                    {
                        int score = int.Parse(elem.Item2);
                        if (!alreadySaid.Contains(elem.Item1) && (bestServer == null || score > bestScore))
                        {
                            bestServer = elem.Item1;
                            bestScore  = score;
                        }
                    }
                    alreadySaid.Add(bestServer);
                    IGuild guild = Program.p.client.GetGuild(ulong.Parse(bestServer));
                    if (guild != null)
                    {
                        var name = (Program.p.db.IsAnonymized(guild.Id) ? "Anonymous" : Program.p.client.GetGuild(ulong.Parse(bestServer)).Name);
                        if (name != null)
                        {
                            best.Add(new Tuple <string, int>(Program.p.GetName(name), bestScore));
                        }
                    }
                }
                finalStr.Append(string.Join("|", best.Select(x => x.Item1 + "|" + x.Item2)) + "$");
            }
            return(globalRankingStr + "$" + finalStr);
        }