/// <summary> /// If the player isn't being held by entities asks him where would he like to go. /// </summary> /// <param name="chatId">The player's id</param> /// <returns></returns> public static async void AskForAction(long chatId, bool sendField = true) { Player curPlayer = GameCore.GetActivePlayer(chatId); if (curPlayer != null) { List <KeyboardButton[]> buttons; if (sendField) { await SendCurrentFieldPicture(curPlayer); } if (GameCore.GetPlayerInDialogue(chatId) == null) // if the player didn't start a conversation { buttons = new List <KeyboardButton[]>() { new KeyboardButton[] { MarkerUpLeft, MarkerUp, MarkerUpRight }, new KeyboardButton[] { MarkerLeft, MarkerChangeMode + curPlayer.Mode.ToString(), MarkerRight }, new KeyboardButton[] { MarkerDownLeft, MarkerDown, MarkerDownRight } }; } else { buttons = new List <KeyboardButton[]>() { new KeyboardButton[] { MarkerAskDirection, MarkerAskAround }, new KeyboardButton[] { MarkerTrade, MarkerBack } }; } ReplyKeyboardMarkup replyKeyboard = new ReplyKeyboardMarkup(buttons); await CheckAndSendAsync(chatId, "Choose the next action: ", replyKeyboard); } }
internal static async void BotClient_HandleMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) { Telegram.Bot.Types.Message msg = e.Message; string cmd; if (msg.Type == MessageType.Text) { cmd = msg.Text; } else { cmd = msg.Type.ToString(); } var chatId = msg.Chat.Id; await Logger.Log(msg.Chat.Username + " : " + cmd); if (cmd[0].CompareTo('/') == 0) //if it is a command { await HandleCommand(msg, cmd, chatId); } else //if it is something different from a command { Player curPlayer = GameCore.GetActivePlayer(chatId); if (curPlayer != null) //if the user started a game { await HandleGameStartupMessage(cmd, curPlayer); } else //if the user didn't start a game (entered settings) { switch (msg.Type) //if the user sent a modifications pack { case MessageType.Document when GameCore.GetPlayerInDialogue(chatId) != null: await HandleModPack(msg, chatId); break; default: await HandleSettingsCommand(cmd, chatId); break; } } } }
private static async Task HandleCommand(Telegram.Bot.Types.Message msg, string cmd, long chatId) { Player curActivePlayer; switch (CheckForCommands(cmd)) { default: break; case "hello": //quick test await CheckAndSendAsync(chatId, "Hello, " + msg.From.FirstName + " " + msg.From.LastName); break; case "start": //when the bot has been just started await CheckAndSendAsync(chatId, "Hello! I am the bot for " + "the Black Path game! Type \"/help\" to learn about commands!"); break; case "help": //find out how to work with the bot string res = ""; foreach (var c in commands) { res += "/" + c.Key + $" - {c.Value}\n"; } await CheckAndSendAsync(chatId, res); break; case "id": //find out what ID does the user have await CheckAndSendAsync(chatId, chatId.ToString()); break; case "pos": //get your position, format: X Y curActivePlayer = GameCore.GetActivePlayer(chatId); await CheckAndSendAsync(chatId, curActivePlayer.X.ToString() + " " + curActivePlayer.Y.ToString()); break; case "game": //starts the game itself if (GameCore.GetActivePlayer(chatId) != null) { await CheckAndSendAsync(chatId, "You can't have two active games " + "at one time! Type /stop to end the current session."); break; } if (await GameCore.AddActivePlayer(chatId) == 0) { await CheckAndSendAsync(chatId, "Looks like you've already got " + "a saved game. What'd you like to do?", new ReplyKeyboardMarkup(new List <KeyboardButton> { new KeyboardButton(MarkerNewGame), new KeyboardButton(MarkerLoadGame) }, oneTimeKeyboard : true)); } else { await AskForGameFieldSize(chatId); } break; case "map": curActivePlayer = GameCore.GetActivePlayer(chatId); if (curActivePlayer != null) { await SendCurrentFieldPicture(curActivePlayer); } else { await CheckAndSendAsync(chatId, "You are not in game!"); } break; case "changeopen": if (chatId != 458715080) { break; //maybe I would be ought to leave this for the whole society } curActivePlayer = GameCore.GetActivePlayer(chatId); if (curActivePlayer != null) { foreach (var c in curActivePlayer.Field) { c.Opened = !c.Opened; } } break; case "stop": //stops the current game curActivePlayer = GameCore.GetActivePlayer(chatId); if (curActivePlayer == null) { await CheckAndSendAsync(chatId, "You have no active session.", new ReplyKeyboardRemove()); break; } await CheckAndSendAsync(chatId, "Your session will be ended in few seconds...\n" + "Don't type anything else!", new ReplyKeyboardRemove()); curActivePlayer = GameCore.GetActivePlayer(chatId); await GameCore.SerializePlayer(curActivePlayer); GameCore.RemoveActivePlayer(chatId); await CheckAndSendAsync(chatId, "Your session has been saved and ended! Type " + "/game to start a game or load it."); break; case "settings": //change the settings of the game, especially the modpacks if (GameCore.GetActivePlayer(chatId) != null) { await CheckAndSendAsync(chatId, "You can only change settings " + "when not in the game! Type /stop to end the current session."); break; } await CheckAndSendAsync(chatId, $"{MarkerModpack}: change the modpack you are using or set a new one.\n" + $"{MarkerStandardModpack}: get the modpack the game uses by default.\n" + $"{MarkerSetStandardModpack}: set the used modpack to default. Warning! This operation will delete all your mods from the server!\n" + $"{MarkerBack}: exit Settings menu"); var markup = new ReplyKeyboardMarkup(new KeyboardButton[] { new KeyboardButton(MarkerModpack), new KeyboardButton(MarkerStandardModpack), new KeyboardButton(MarkerSetStandardModpack), new KeyboardButton(MarkerBack) }); await CheckAndSendAsync(chatId, "What do you want to do?", markup); break; } }