private void Tick(object sender, ElapsedEventArgs e) { if (CoolDownTick > 2) { CoolDownTick = 0; CoolDown = null; } else if (CoolDown != null) { CoolDownTick++; } TickOnNewGames++; if (TickOnNewGames > MaxTickOnNewGames) { TickOnNewGames = 0; MaxTickOnNewGames = Rand.Next(10, 30); lock (GamesToPlay) _DiscordClient.SetGame(GamesToPlay[Rand.Next(0, GamesToPlay.Count() - 1)]); } foreach (Server s in _DiscordClient.Servers) { if (Radios.ContainsKey(s.Id)) { Radios[s.Id].VoiceSocket?.SendHeartbeat(); } } _DiscordClient.Servers.Where(x => !_ServerSettings.ContainsKey(x.Id)).ToList().ForEach(x => _ServerSettings.Add(x.Id, new ServerSettings(x))); //_ServerSettings.Keys.Except(_DiscordClient.Servers.) UpdateConsole(); }
public void SetGameScore(int firstPlayerScore, int secondPlayerScore) { GamesToPlay[PlayedOnCurrentStage].Play(firstPlayerScore, secondPlayerScore); if (_tournament is DoubleEliminationTournament && GamesToPlay.Count > 1 && PlayedOnCurrentStage < _gamesNeedToPlay) { var lastGame = GamesToPlay[GamesToPlay.Count - 1]; if (lastGame.SecondPlayer == null) { GamesToPlay[GamesToPlay.Count - 1] = new Game(lastGame.FirstPlayer, GamesToPlay[PlayedOnCurrentStage].Loser); } else { if (PlayedOnCurrentStage == _gamesNeedToPlay - 1 && PlayedOnCurrentStage % 2 == 0) { PlayedOnCurrentStage++; return; } else { GamesToPlay.Add(new Game(GamesToPlay[PlayedOnCurrentStage].Loser, null)); } } } PlayedOnCurrentStage++; }
public void GetGamesToPlay(Tournament tournament) { _tournament = tournament; GamesToPlay.Clear(); var lastStage = tournament.WinnersGrid.Count - 1; foreach (var game in tournament.WinnersGrid[lastStage]) { if (game.SecondPlayer != null) { GamesToPlay.Add(new Game(game.FirstPlayer, game.SecondPlayer)); } } if (tournament is DoubleEliminationTournament) { var doubleEliminationTournament = (DoubleEliminationTournament)tournament; lastStage = doubleEliminationTournament.LosersGrid.Count - 1; foreach (var game in doubleEliminationTournament.LosersGrid[lastStage]) { if (GamesToPlay[GamesToPlay.Count - 1].SecondPlayer == null) { GamesToPlay[GamesToPlay.Count - 1] = new Game(GamesToPlay[GamesToPlay.Count - 1].FirstPlayer, game.Winner); } else { GamesToPlay.Add(new Game(game.Winner, null)); } } if (GamesToPlay[GamesToPlay.Count - 1].SecondPlayer == null) { GamesToPlay.Remove(GamesToPlay[GamesToPlay.Count - 1]); } } PlayedOnCurrentStage = 0; _gamesNeedToPlay = GamesToPlay.Count; }
public DiscordBotWorker(Form1 ControlPannel, string[] _GamesToPlay, SoundBoardList _SoundBoardBinding) { _ControlPannel = ControlPannel; #if DEBUG ConsoleWrite("is Debug build\n"); #else ConsoleWrite("is Chidori build\n"); #endif ConsoleWrite("Building Client......"); _DiscordClient = new DiscordClient() .UsingAudio(x => { x.Mode = AudioMode.Both; x.EnableEncryption = true; x.Bitrate = AudioServiceConfig.MaxBitrate; x.BufferLength = 10000; }); //configsfor things #if DEBUG //the sound cloud client config SCClient = new SoundCloudClient("9789f855276cf2c76bf4c6b62a09155e"); track.ToStringOverRide = x => { return(x != null ? "```Title: " + x.title + "\nID : " + x.id + "\nstreamable : " + x.streamable + "\nstream_url:" + x.stream_url + "```" : null); }; #endif //the anime client config _MyAnimeListClient = new MyAnimeListClient("The_True_Trooper", "Jim456852,.,"); Manga.ToStringOverRide = x => { return(x != null ? "```Title: " + x.title + "\nEnglish: " + x.english + "\nSynonyms: " + x.synonyms + "\nChapters: " + x.chapters + "\nVolumes: " + x.volumes + "\nScore: " + x.score + "\nType: " + x.type + "\nStatus: " + x.status + "\nStart Date: " + x.start_date + "\nEnd Date: " + x.end_date + "\nSynopsis: " + x.synopsis.Replace("<br />", "").Replace("[i]", "").Replace("[/i]", "").HtmlDecode() + "```" + "\nhttp://myanimelist.net/manga/" + x.id : null); }; Anime.ToStringOverRide = x => { return(x != null ? "```Title: " + x.title + "\nEnglish: " + x.english + "\nSynonyms: " + x.synonyms + "\nEpisodes: " + x.episodes + "\nScore: " + x.score + "\nType: " + x.type + "\nStatus: " + x.status + "\nStart Date: " + x.start_date + "\nEnd Date: " + x.end_date + "\nSynopsis: " + x.synopsis.Replace("<br />", "").Replace("[i]", "").Replace("[/i]", "").HtmlDecode() + "```" + "\nhttp://myanimelist.net/anime/" + x.id : null); }; //bot callbacks and event bindings MasterAndCommander = new ControlPannelCommand(_MasterAndCommander); SoundBoardListUpDate = new VoidVoid(_SoundBoardListUpDate); _DiscordClient.Ready += Ready; _DiscordClient.MessageReceived += MessRec; //_DiscordClient.MessageUpdated += MessRec; _DiscordClient.UserJoined += JoinHello; _DiscordClient.JoinedServer += JoinServer; _DiscordClient.UserUpdated += UserUpHello; _DiscordClient.RoleCreated += RoleCreate; _DiscordClient.RoleDeleted += RoleDelete; _DiscordClient.RoleUpdated += RoleUpdate; _DiscordClient.UserBanned += UserBanned; _DiscordClient.UserUnbanned += UserUnbanned; _DiscordClient.ChannelCreated += ChannelCreated; _DiscordClient.ChannelDestroyed += ChannelDeleted; _DiscordClient.ChannelUpdated += ChannelUpdated; ConsoleWrite("Building support classes......"); //ticks info Ticker.Elapsed += Tick; MaxTickOnNewGames = Rand.Next(30); //list populating ConsoleWrite("Populating lists......"); GamesToPlay = null; lock (GamesToPlay) GamesToPlay = GamesToPlay.Concat(_GamesToPlay).ToArray(); SoundBoardBinding = null; lock (SoundBoardBinding) SoundBoardBinding = _SoundBoardBinding; Connect(); }