private ExecutionResult SetMainMenu(Player player, params string[] messages)
        {
            ExecutionResult      executionResult = new ExecutionResult();
            List <MessageResult> resultMessages  = new List <MessageResult>();

            resultMessages.AddRange(messages.Select(a => new MessageResult {
                Message = a
            }));
            player.PlayerFlag = PlayerFlag.GAME_MENU.ToString();
            var result = MessageHandlerHelpers.ReturnToGameMenu(player, "");

            resultMessages.AddRange(result.MessagesToShow);
            executionResult.MessagesToShow = resultMessages;
            executionResult.OptionsToShow  = result.OptionsToShow;
            return(executionResult);
        }
Пример #2
0
        public ExecutionResult HandleMessage(string message, Player player)
        {
            if (player.PlayerFlag != PlayerFlag.LOAD_GAME.ToString())
            {
                player.PlayerMenuContext = player.PlayerFlag.ToString();
                player.PlayerFlag        = PlayerFlag.LOAD_GAME.ToString();
                return(ExecutionResultHelper.SingleMessage("Select a game save to load", GetOptions(player)));
            }
            else if (message == Messages.Return)
            {
                player.PlayerMenuContext2 = "0";
                if (player.PlayerMenuContext == PlayerFlag.GAME_MENU.ToString())
                {
                    return(MessageHandlerHelpers.ReturnToGameMenu(player, ""));
                }
                return(MessageHandlerHelpers.ReturnToMainMenu(player));
            }
            else if (message.StartsWith("<"))
            {
                if (int.TryParse(player.PlayerMenuContext2, out int pageNumber))
                {
                    if (pageNumber <= 0)
                    {
                        pageNumber = 1;
                    }
                    player.PlayerMenuContext2 = "" + (pageNumber - 1);
                }
                else
                {
                    player.PlayerMenuContext2 = "0";
                }
                return(ExecutionResultHelper.SingleMessage("Select a game save to load", GetOptions(player)));
            }
            else if (message.StartsWith(">"))
            {
                if (int.TryParse(player.PlayerMenuContext2, out int pageNumber))
                {
                    if (pageNumber < 0)
                    {
                        pageNumber = 0;
                    }
                    player.PlayerMenuContext2 = "" + (pageNumber + 1);
                }
                else
                {
                    player.PlayerMenuContext2 = "" + player.GameSaves.Count / PageSize;
                }
                return(ExecutionResultHelper.SingleMessage("Select a game save to load", GetOptions(player)));
            }
            else
            {
                var saveIdString = message.Split(' ')[0];
                if (!int.TryParse(saveIdString, out var saveId))
                {
                    return(ExecutionResultHelper.SingleMessage("Invalid save specified", GetOptions(player)));
                }
                var gameSave = _gameSaveService.GetGameSaveById(saveId, player.PlayerId)?.PlayerGameSave;
                if (gameSave == null)
                {
                    return(ExecutionResultHelper.SingleMessage($"Save with ID {saveId} is invalid. Either it doesn't exist, or it doesn't belong to you!", GetOptions(player)));
                }

                player.PlayerMenuContext2 = "0";

                player.ActiveGameSave.GameName     = gameSave.GameName;
                player.ActiveGameSave.GameSaveData = gameSave.GameSaveData.Select(a => new PlayerGameSaveData {
                    Name = a.Name, Value = a.Value
                }).ToList();
                player.ActiveGameSave.StateId    = gameSave.StateId;
                player.ActiveGameSave.FrameStack = gameSave.FrameStack.Select(a => new PlayerFrameStack
                {
                    CreatedDate   = a.CreatedDate,
                    FunctionName  = a.FunctionName,
                    ReturnStateId = a.ReturnStateId,
                    Save          = player.ActiveGameSave,
                    SaveId        = player.ActiveGameSave.SaveId
                }).ToList();

                player.PlayerFlag = PlayerFlag.IN_GAME.ToString();
                var games       = _gameStore.ListGames();
                var playerState = player.ActiveGameSave;
                var gameFound   = games.Where(a => a.GameName == playerState.GameName).FirstOrDefault();
                var state       = gameFound.FindStateById(playerState.StateId);
                var execResult  = new ExecutionResult
                {
                    MessagesToShow = new List <MessageResult> {
                        new MessageResult {
                            Message = _textParsing.ParseText(playerState, state.StateText)
                        }
                    },
                    OptionsToShow = _gameProcessor.GetCurrentOptions(playerState, gameFound, state)
                };

                execResult.OptionsToShow.Add("-Menu-");
                return(execResult);
            }
        }