Beispiel #1
0
        public void BComm(int playerId, Direction direction)
        {
            var s = BotService.BombCommand(playerId, direction);

            foreach (var item in s)
            {
                if (item.KeyBoardId != null)
                {
                    BotClient.SendTextMessageAsync(item.PlayerId, item.Answer, ParseMode.Markdown, false, false, 0, GetKeyboardMarkup(item.KeyBoardId));
                }
                else
                {
                    BotClient.SendTextMessageAsync(item.PlayerId, item.Answer, ParseMode.Markdown);
                }
            }
        }
Beispiel #2
0
        public void SComm(int playerid, Direction direction)
        {
            var s = BotService.ShootCommand(playerid, direction);

            //TODO: Вынести в метод SendResponse
            foreach (var item in s)
            {
                if (item.KeyBoardId != null)
                {
                    BotClient.SendTextMessageAsync(item.PlayerId, item.Answer, ParseMode.Markdown, false, false, 0, GetKeyboardMarkup(item.KeyBoardId));
                }
                else
                {
                    BotClient.SendTextMessageAsync(item.PlayerId, item.Answer, ParseMode.Markdown);
                }
            }
        }
Beispiel #3
0
        public List <MessageConfig> StateMachine(CharacterState state, string command, int playerId)
        {
            //TODO: Вынести сюда создание репозиториев
            switch (state)
            {
            case CharacterState.ChangeName:
                return(BotService.TryChangeName(command, playerId));

            case CharacterState.ChangeGameMode:
                switch (command)
                {
                case "/game":
                    return(BotService.FindGameCommand(playerId));

                case "/tutorial":
                    var              character        = _characterRepository.Read(playerId);
                    LobbyRepository  lobbyRepository  = new LobbyRepository();
                    MemberRepository memberRepository = new MemberRepository();
                    memberRepository.Create(0, playerId);
                    var lobby = lobbyRepository.Read(0);
                    lobby.Players.Add(new Player
                    {
                        Health         = 3,
                        HeroName       = character.CharacterName,
                        Rotate         = Direction.North,
                        TelegramUserId = playerId,
                        UserCoordinate = new Coordinate(3, 3)
                    });
                    lobbyRepository.Update(lobby);
                    character.State = CharacterState.Tutorial;
                    _characterRepository.Update(character);
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = "Обучение",
                            PlayerId = playerId
                        }
                    });

                default:
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = "неверная команда",
                            PlayerId = playerId
                        }
                    });
                }

            case CharacterState.Tutorial:
                switch (command)
                {
                case "Вверх":
                    return(TutorialService.MoveCommand(playerId, Direction.North));

                case "Вниз":
                    return(TutorialService.MoveCommand(playerId, Direction.South));

                case "Вправо":
                    return(TutorialService.MoveCommand(playerId, Direction.East));

                case "Влево":
                    return(TutorialService.MoveCommand(playerId, Direction.West));

                case "Взрыв стены":
                    var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard();
                    BotClient.SendTextMessageAsync(playerId, "Выбирай направление",
                                                   replyMarkup: inlineKeyboard);
                    BotClient.OnCallbackQuery += BotClient_OnCallbackQueryBomb;
                    return(null);

                case "/skip":
                    var              character        = _characterRepository.Read(playerId);
                    LobbyRepository  lobbyRepository  = new LobbyRepository();
                    MemberRepository memberRepository = new MemberRepository();
                    memberRepository.DeleteOne(playerId);
                    var lobby = lobbyRepository.Read(0);
                    lobby.Players.Remove(lobby.Players.Find(e => e.TelegramUserId == playerId));
                    lobbyRepository.Update(lobby);
                    character.State = CharacterState.ChangeGameMode;
                    _characterRepository.Update(character);
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = "Обучение пропущено",
                            PlayerId = playerId
                        }
                    });

                default:
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = "Неверная команда",
                            PlayerId = playerId
                        }
                    });
                }

            case CharacterState.FindGame:
                switch (command)
                {
                case "/help":
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = Answers.Help.RandomAnswer(),
                            PlayerId = playerId
                        }
                    });

                case "/stop":
                    _characterRepository.Read(playerId);
                    MemberRepository repo = new MemberRepository();
                    var character         = _characterRepository.Read(playerId);
                    character.State = CharacterState.ChangeGameMode;
                    _characterRepository.Update(character);
                    repo.DeleteOne(playerId);
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = "Вы удалены из очереди",
                            PlayerId = playerId
                        }
                    });

                default:
                    return(new List <MessageConfig>
                    {
                        new MessageConfig()
                        {
                            Answer = "Неверная команда",
                            PlayerId = playerId
                        }
                    });
                }

            case CharacterState.InGame:
                switch (command)
                {
                case "Вперед":
                    return(BotService.MoveCommand(playerId, Direction.North));

                case "Назад":
                    return(BotService.MoveCommand(playerId, Direction.South));

                case "Вправо":
                    return(BotService.MoveCommand(playerId, Direction.East));

                case "Влево":
                    return(BotService.MoveCommand(playerId, Direction.West));

                case "Удар кинжалом":
                    return(BotService.StabCommand(playerId));

                case "Пропуск хода":
                    return(BotService.SkipTurn(playerId));

                case "Выстрел":
                {
                    var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard();
                    BotClient.SendTextMessageAsync(playerId, "Выбирай направление",
                                                   replyMarkup: inlineKeyboard);
                    BotClient.OnCallbackQuery += BotClient_OnCallbackQueryShoot;
                    return(null);
                }

                case "Взрыв стены":
                {
                    var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard();
                    BotClient.SendTextMessageAsync(playerId, "Выбирай направление",
                                                   replyMarkup: inlineKeyboard);
                    BotClient.OnCallbackQuery += BotClient_OnCallbackQueryBomb;
                    return(null);
                }

                case "/afk":
                    return(BotService.AfkCommand(playerId));

                case "/leave":
                    return(BotService.TryLeaveCommand(playerId));
                }

                return(new List <MessageConfig>
                {
                    new MessageConfig()
                    {
                        Answer = Answers.UndefinedCommand.RandomAnswer(),
                        PlayerId = playerId
                    }
                });

            case CharacterState.NewCharacter:
                if (command == "/start")
                {
                    if (_characterRepository.Read(playerId) == null)
                    {
                        _characterRepository.Create(playerId);
                        return(new List <MessageConfig>
                        {
                            new MessageConfig()
                            {
                                Answer = "Напишите имя персонажа",
                                PlayerId = playerId
                            }
                        });
                    }
                }

                return(new List <MessageConfig>
                {
                    new MessageConfig()
                    {
                        Answer = "Неверная команда",
                        PlayerId = playerId
                    }
                });

            case CharacterState.AcceptLeave:
                if (command == "Подтверждаю")
                {
                    return(BotService.LeaveCommand(playerId));
                }
                else
                {
                    return(new List <MessageConfig>
                    {
                        new MessageConfig
                        {
                            Answer = "Не подтверждено",
                            PlayerId = playerId
                        }
                    });
                }

            case CharacterState.Ban:
                //TODO:REBAN
                return(new List <MessageConfig>
                {
                    new MessageConfig()
                    {
                        Answer = "В бане",
                        PlayerId = playerId
                    }
                });

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
            throw new ArgumentOutOfRangeException(nameof(state), state, null);
        }