예제 #1
0
        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;
            }
        }
예제 #2
0
        private static async Task HandleInGameCommands(string cmd, Player curPlayer)
        {
            var chatId = curPlayer.Id;

            //a separate part for performing dialogues
            if (GameCore.GetPlayerInDialogue(chatId) != null)
            {
                switch (cmd)
                {
                default:
                    break;

                case MarkerAskDirection:
                    CharacterAnswer(curPlayer, AnswerModes.DirectionAnswer);
                    break;

                case MarkerAskAround:
                    break;

                case MarkerTrade:
                    break;

                case MarkerBack:
                    GameCore.RemovePlayerInDialogue(chatId);
                    curPlayer.AskedDirection     = false;
                    curPlayer.AskedNeighbourhood = false;
                    AskForAction(chatId);
                    break;
                }
            }
            else
            {
                switch (cmd)
                {
                default:
                    break;

                case MarkerLoadGame:     //if the user wants to load his last saved game
                    GameCore.UpdatePlayerTimestamp(curPlayer);
                    AskForAction(chatId);
                    break;

                case MarkerUp:
                    curPlayer.DirectAction(0, -1);
                    break;

                case MarkerUpRight:
                    curPlayer.DirectAction(1, -1);
                    break;

                case MarkerRight:
                    curPlayer.DirectAction(1, 0);
                    break;

                case MarkerDownRight:
                    curPlayer.DirectAction(1, 1);
                    break;

                case MarkerDown:
                    curPlayer.DirectAction(0, 1);
                    break;

                case MarkerDownLeft:
                    curPlayer.DirectAction(-1, 1);
                    break;

                case MarkerLeft:
                    curPlayer.DirectAction(-1, 0);
                    break;

                case MarkerUpLeft:
                    curPlayer.DirectAction(-1, -1);
                    break;
                }
                if (cmd == MarkerChangeMode + curPlayer.Mode.ToString())
                {
                    curPlayer.Mode = (PlayerModes)Math.Abs((int)curPlayer.Mode - 1); //since there are only 2 modes
                                                                                     //available, we can change them
                                                                                     //with this magic
                    await CheckAndSendAsync(curPlayer.Id, $"I will {curPlayer.Mode} now");

                    AskForAction(curPlayer.Id, false);
                }
            }
        }