public string JoinGame(ulong guildId, ulong chanId, ulong playerId) { AGame game = _games.Find(x => x.IsSelf(chanId)); if (game == null) { return(Sentences.LobbyNoWaiting(guildId)); } if (!game.IsWaitingForPlayers()) { return(Sentences.LobbyNoWaiting(guildId)); } if (!game.HaveMultiplayerLobby()) { return(Sentences.LobbySoloJoin(guildId)); } if (game.IsFull()) { return(Sentences.LobbyFull(guildId)); } if (game.IsPlayerInLobby(playerId)) { return(Sentences.LobbyAlreadyInThis(guildId)); } if (_games.Any(x => x.IsPlayerInLobby(playerId))) { return(Sentences.LobbyAlreadyIn(guildId)); } game.AddPlayerToLobby(playerId); return(Sentences.LobbyJoined(guildId, game.GetName())); }
public async Task ReceiveMessageAsync(string message, SocketUser user, ulong chanId) // Called everytimes a message is sent somewhere { AGame game = _games.Find(x => x.IsSelf(chanId)); if (game != null) { await game.CheckCorrectAsync(user, message); } }
// Cancel the current game public bool Cancel(ulong chanId) { AGame game = _games.Find(x => x.IsSelf(chanId)); if (game == null) { return(false); } game.Cancel(); return(true); }
public async Task <bool> Replay(ulong chanId) { AGame game = _games.Find(x => x.IsSelf(chanId)); if (game == null) { return(false); } await game.ReplayAudio(); return(true); }
public async Task ReceiveMessageAsync(string message, SocketUser user, ulong chanId, SocketUserMessage msg) // Called everytimes a message is sent somewhere { if (message.ToLower().EndsWith("replay") || message.ToLower().EndsWith("cancel")) // replay and cancel are commands that can be used in the middle of a game { return; } AGame game = _games.Find(x => x.IsSelf(chanId)); if (game != null) { await game.CheckCorrectAsync(user, message, msg); } }
public string LeaveGame(ulong guildId, ulong chanId, ulong playerId) { AGame game = _games.Find(x => x.IsSelf(chanId)); if (game == null) { return(Sentences.LobbyNoWaiting(guildId)); } if (!game.IsWaitingForPlayers()) { return(Sentences.LobbyAlreadyStarted(guildId)); } if (!game.HaveMultiplayerLobby()) { return(Sentences.LobbySoloLeave(guildId)); } if (!game.IsPlayerInLobby(playerId)) { return(Sentences.LobbyAlreadyOut(guildId)); } game.RemovePlayerFromLobby(playerId); return(Sentences.LobbyLeaved(guildId) + (game.IsLobbyEmpty() ? Environment.NewLine + Sentences.LobbyEmpty(guildId) : "")); }
private void GameLoop() { while (Thread.CurrentThread.IsAlive) { for (int i = _games.Count - 1; i >= 0; i--) { try { AGame g = _games[i]; if (g.IsWaitingForPlayers()) { if (g.IsReady()) { if (g.HaveEnoughPlayer()) { g.Start().GetAwaiter().GetResult(); } else { g.DisplayCantStart().GetAwaiter().GetResult(); } } } else { _games[i].LooseTimerAsync().GetAwaiter().GetResult(); } } catch (Exception e) { Program.p.LogError(new LogMessage(LogSeverity.Error, e.Source, e.Message, e)); } _games.RemoveAll(x => x.DidLost()); Thread.Sleep(250); } } }
public async Task <string> StartGame(ulong guildId, ulong chanId, ulong playerId) { AGame game = _games.Find(x => x.IsSelf(chanId)); if (game == null) { return(Sentences.LobbyNoWaiting(guildId)); } if (!game.IsWaitingForPlayers()) { return(Sentences.LobbyNoWaiting(guildId)); } if (!game.IsPlayerInLobby(playerId)) { return(Sentences.LobbyAlreadyOut(guildId)); } if (!game.HaveEnoughPlayer()) { return(Sentences.LobbyNotEnoughPlayer(guildId)); } await game.Start(); return(null); }
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); }