示例#1
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);
        }