コード例 #1
0
ファイル: AGame.cs プロジェクト: Xwilarg/Sanara
        protected AGame(IMessageChannel textChan, IUser _, IPreload preload, IPostMode postMode, IMultiplayerMode versusMode, GameSettings settings)
        {
            _state    = GameState.Prepare;
            _textChan = textChan;
            if (_textChan is ITextChannel)
            {
                _guildId = ((ITextChannel)_textChan).GuildId;
            }
            else
            {
                throw new CommandFailed("Games are not yet available in private message."); // TODO!
            }
            _postMode     = postMode;
            _versusMode   = versusMode;
            _lobby        = settings.Lobby;
            _isCustomGame = settings.IsCustomGame;

            _gameName = preload.Name;
            _argument = null;// preload.GetNameArg();
            _messages = new List <ICommandContext>();
            _preload  = preload;

            _contributors = new List <ulong>();
            _score        = 0;

            _lobby.InitVersusRules(_versusMode.GetRules());
        }
コード例 #2
0
ファイル: AGame.cs プロジェクト: TheIndra55/Sanara
        protected AGame(IMessageChannel textChan, IUser _, IPreload preload, IPostMode postMode, IMultiplayerMode multiplayerMode, GameSettings settings)
        {
            _state    = GameState.PREPARE;
            _textChan = textChan;
            if (_textChan is ITextChannel)
            {
                _guildId = ((ITextChannel)_textChan).GuildId;
            }
            else
            {
                throw new CommandFailed("Games are not yet available in private message."); // TODO!
            }
            _postMode        = postMode;
            _multiplayerMode = multiplayerMode;
            _lobby           = settings.Lobby;

            _gameName = preload.GetGameNames()[0];
            _argument = preload.GetNameArg();

            textChan.SendMessageAsync(preload.GetRules() + $"\n\nYou will loose if you don't answer after {GetGameTime()} seconds\n\n" +
                                      "If the game break, you can use the 'Cancel' command to cancel it.\n" +
                                      "You can cooperate with other players to find the answers." +
                                      (_postMode is AudioMode ? "\nYou can listen again to the audio using the 'Replay' command." : "") +
                                      (_lobby != null ? "\n\n**You can join the lobby for the game by doing the 'Join' command**\nThe game will automatically start in " + _lobbyTimer + " seconds, you can start it right away using the 'Start' command" : "")).GetAwaiter().GetResult();

            _messages = new List <SocketUserMessage>();

            _contributors = new List <ulong>();
            _score        = 0;

            StaticObjects.Website?.AddGameAsync(_gameName, _argument);
        }
コード例 #3
0
ファイル: QuizzBooru.cs プロジェクト: TheIndra55/Sanara
        public QuizzBooru(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings) : base(textChan, user, preload, settings)
        {
            var info = new List <BooruQuizzPreloadResult>(preload.Load().Cast <BooruQuizzPreloadResult>())[0];

            _booru          = info.Booru;
            _allowedFormats = info.AllowedFormats;
        }
コード例 #4
0
        public PreloadMgr()
        {
            Preloads = new List <PreloadCtrl>();

            Type[] oTypes = ReflUtils.GetAllTypes((oType) =>
            {
                bool isSucess = false;
                if (oType.IsClass && oType.GetInterface(typeof(IPreload).Name) == typeof(IPreload))
                {
                    isSucess = true;
                }
                return(isSucess);
            });
            for (int i = 0; i < oTypes.Length; i++)
            {
                Type        oType        = oTypes[i];
                IPreload    oPreload     = Activator.CreateInstance(oType) as IPreload;
                object[]    oAttrs       = oType.GetCustomAttributes(typeof(PreloadSortAttribute), false);
                PreloadCtrl oPreloadCtrl = new PreloadCtrl();
                oPreloadCtrl.SortID   = 99;
                oPreloadCtrl.IPreload = oPreload;
                if (oAttrs.Length > 0)
                {
                    oPreloadCtrl.SortID = (oAttrs[0] as PreloadSortAttribute).SortID;
                }
                Preloads.Add(oPreloadCtrl);
            }

            Preloads.Sort((x, y) => x.SortID.CompareTo(y.SortID));

            IsDone = true;
        }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: Xwilarg/Sanara
        public ReplayLobby AddReplayLobby(IChannel chan, IPreload preload, Lobby lobby)
        {
            var rLobby = new ReplayLobby(preload, lobby.Host, lobby.GetUsers(), lobby.GetMultiplayerMode());

            _replayLobby.Add(chan.Id.ToString(), rLobby);
            return(rLobby);
        }
コード例 #6
0
ファイル: Lobby.cs プロジェクト: Xwilarg/Sanara
 public Lobby(IUser host, IPreload preload)
 {
     _users        = new() { host };
     _lobbyOwner   = host;
     _preload      = preload;
     _multiType    = MultiplayerType.VERSUS;
     _creationTime = DateTime.Now;
 }
コード例 #7
0
ファイル: Shiritori.cs プロジェクト: Xwilarg/Sanara
 public Shiritori(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings) : base(textChan, user, preload, StaticObjects.ModeText, new TurnByTurnMode(), settings)
 {
     _words          = new List <ShiritoriPreloadResult>(preload.Load().Cast <ShiritoriPreloadResult>());
     _isFirst        = true;
     _alreadySaid    = new List <string>();
     _lastUserChoice = null;
     _minWordLength  = 2;
 }
コード例 #8
0
 public ReplayLobby(IPreload preload, IUser lastHost, List <IUser> users, MultiplayerType versusType)
 {
     Preload       = preload;
     LastHost      = lastHost;
     _users        = users;
     _ready        = new();
     _versusType   = versusType;
     _creationTime = DateTime.Now;
 }
コード例 #9
0
        public IEnumerator Init()
        {
            if (!IsDone)
            {
                Notify(new EventArgs()
                {
                    ErrorStatus = PreloadError.Already
                });
                yield break;
            }

            IsDone = false;

            // 开始加载
            Notify(new EventArgs()
            {
                Status   = PreloadStatus.Start,
                Alreay   = 0,
                TotalNum = Preloads.Count
            });

            int       count          = 0;
            EventArgs oProgEventArgs = new EventArgs();

            // 加载中
            for (int i = 0; i < Preloads.Count; i++)
            {
                oProgEventArgs.Alreay = i;
                oProgEventArgs.Status = PreloadStatus.Loading;
                Notify(oProgEventArgs);

                IPreload oPreload = Preloads[i].IPreload;
                yield return(oPreload.Preloading());

                if (oPreload.IsSucess)
                {
                    count++;
                }
            }

            // 加载完成
            Notify(new EventArgs()
            {
                Alreay = count, Status = PreloadStatus.Finished
            });

            IsDone = true;
        }
コード例 #10
0
ファイル: QuizzAudio.cs プロジェクト: TheIndra55/Sanara
        public QuizzAudio(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings) : base(textChan, user, preload, settings, StaticObjects.ModeAudio)
        {
            var gUser = user as IGuildUser;

            if (gUser == null)
            {
                throw new CommandFailed("This game must be played in a server.");
            }
            _voiceChan = gUser.VoiceChannel;
            if (_voiceChan == null)
            {
                throw new CommandFailed("You must be in a vocal channel to play this game.");
            }
            _voiceSession = _voiceChan.ConnectAsync().GetAwaiter().GetResult();
            _process      = null;

            while (_voiceSession.ConnectionState != ConnectionState.Connected) // We wait to be connected before starting vocal stuffs
            {
            }
            _outStream = _voiceSession.CreatePCMStream(AudioApplication.Voice);
        }
コード例 #11
0
ファイル: QuizzBooruAnime.cs プロジェクト: TheIndra55/Sanara
 public QuizzBooruAnime(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings) : base(textChan, user, preload, settings)
 {
 }
コード例 #12
0
        public static async Task InitializeAsync(Credentials credentials)
        {
            await Db.InitAsync("Sanara");

            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", AppDomain.CurrentDomain.BaseDirectory + "/Keys/GoogleAPI.json");

            if (credentials.RavenKey != null)
            {
                RavenClient = new RavenClient(credentials.RavenKey);
            }

            HttpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 Sanara");

            Safebooru.HttpClient = HttpClient;
            Gelbooru.HttpClient  = HttpClient;
            E621.HttpClient      = HttpClient;
            E926.HttpClient      = HttpClient;
            Rule34.HttpClient    = HttpClient;
            Konachan.HttpClient  = HttpClient;

            RomajiToHiragana = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText("LanguageResource/Hiragana.json"));
            foreach (var elem in RomajiToHiragana)
            {
                HiraganaToRomaji.Add(elem.Value, elem.Key);
            }
            RomajiToKatakana = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText("LanguageResource/Katakana.json"));
            foreach (var elem in RomajiToKatakana)
            {
                KatakanaToRomaji.Add(elem.Value, elem.Key);
            }
            foreach (var elem in ISO639)
            {
                ISO639Reverse.Add(elem.Value, elem.Key);
            }

            await Utils.Log(new LogMessage(LogSeverity.Info, "Static Preload", "Loading game preload (might take several minutes if this is the first time)"));

            Preloads = new IPreload[]
            {
                new ShiritoriPreload(),
                new ArknightsPreload(),
                new ArknightsAudioPreload(),
                new KancollePreload(),
                new KancolleAudioPreload(),
                new GirlsFrontlinePreload(),
                new AzurLanePreload(),
                new FateGOPreload(),
                new PokemonPreload(),
                new AnimePreload(),
                new BooruQuizzPreload(),
                new BooruFillPreload()
            };
            await Utils.Log(new LogMessage(LogSeverity.Info, "Static Preload", "Game preload done"));

            await SM.InitAsync();

            GM.Init();

            if (File.Exists("Saves/Premium.txt"))
            {
                AllowedPremium = File.ReadAllLines("Saves/Premium.txt");
            }

            if (credentials.YouTubeKey != null)
            {
                YouTube = new YouTubeService(new BaseClientService.Initializer
                {
                    ApiKey = credentials.YouTubeKey
                });
            }

            if (credentials.KitsuEmail != null)
            {
                KitsuAuth = new HttpRequestMessage(HttpMethod.Post, "https://kitsu.io/api/oauth/token")
                {
                    Content = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "grant_type", "password" },
                        { "username", credentials.KitsuEmail },
                        { "password", credentials.KitsuPassword }
                    })
                };
            }

            if (credentials.UploadWebsiteLocation != null)
            {
                UploadWebsiteLocation = credentials.UploadWebsiteLocation;
                if (!UploadWebsiteLocation.EndsWith("/"))
                {
                    UploadWebsiteLocation += "/";
                }

                UploadWebsiteUrl = credentials.UploadWebsiteUrl;
                if (!UploadWebsiteUrl.EndsWith("/"))
                {
                    UploadWebsiteUrl += "/";                                  // Makes sure the URL end with a /
                }
            }

            if (credentials.TopGgToken != null)
            {
                DblToken = credentials.TopGgToken;
            }

            if (credentials.GithubKey != null)
            {
                GithubKey = credentials.GithubKey;
            }

            if (File.Exists("Keys/GoogleAPI.json"))
            {
                GoogleCredential googleCredentials = GoogleCredential.FromFile("Keys/GoogleAPI.json");
                TranslationClient = TranslationClient.Create();
                VisionClient      = ImageAnnotatorClient.Create();
            }

            if (credentials.StatsWebsiteUrl != null)
            {
                Website = new UploadManager(credentials.StatsWebsiteUrl, credentials.StatsWebsiteToken);
            }

            if (credentials.MyDramaListApiKey != null)
            {
                MyDramaListApiKey = credentials.MyDramaListApiKey;
            }
        }
コード例 #13
0
 public Quizz(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings) : base(textChan, user, preload, StaticObjects.ModeUrl, new SpeedMode(), settings)
 {
     _words         = new List <QuizzPreloadResult>(preload.Load().Cast <QuizzPreloadResult>());
     _allValidNames = _words.SelectMany(x => x.Answers).ToArray();
 }
コード例 #14
0
 /// <summary>
 /// Called by QuizzAudio
 /// </summary>
 public Quizz(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings, IPostMode mode, bool doesCongratulate) : base(textChan, user, preload, mode, new SpeedMode(), settings)
 {
     _words            = new List <QuizzPreloadResult>(preload.Load().Cast <QuizzPreloadResult>());
     _allValidNames    = _words.SelectMany(x => x.Answers).ToArray();
     _doesCongratulate = doesCongratulate;
 }
コード例 #15
0
ファイル: FillAllBooru.cs プロジェクト: Xwilarg/Sanara
 public FillAllBooru(IMessageChannel textChan, IUser user, IPreload preload, GameSettings settings) : base(textChan, user, preload, StaticObjects.ModeUrl, new SpeedFillAllBooruMode(), settings)
 {
 }