public List <string> GetOptions(Player player) { var activeGame = _gameStore.ListGames().FirstOrDefault(a => a.GameName == player.ActiveGameSave.GameName); var achievementList = AchievementService.HasPlayerDoneAchievements(activeGame, player); var achievementButtonText = $"{Messages.Achievements} ({achievementList.Count(a => a.hasAchieved)}/{achievementList.Count})"; var list = new List <string> { "Return to Game", Messages.SaveGame, Messages.LoadGame, achievementButtonText, "Main Menu", }; var testFeatures = _configService.GetConfigOrDefault("TestFeatures", "false", true); if (bool.TryParse(testFeatures, out var enableTestFeatures) && enableTestFeatures) { list.Add(Messages.ShowData); list.Add(Messages.RefreshGames); } return(list); }
public ExecutionResult HandleMessage(string message, Player player) { if (message == Messages.Return) { return(MessageHandlerHelpers.ReturnToMainMenu(player)); } var games = _gameStore.ListGames(); List <string> optionsToSend = new List <string>(); optionsToSend.Add(Messages.Return); var gameAchievementList = games.Select(a => (AchievementService.HasPlayerDoneAchievements(a, player), a.GameName)).ToList(); gameAchievementList.ForEach(a => { optionsToSend.Add($"{a.GameName} ({a.Item1.Count(b => b.hasAchieved)}/{a.Item1.Count()})"); }); var selectedGame = games.FirstOrDefault(a => message.StartsWith(a.GameName)); if (selectedGame != null) { var achievmentListString = AchievementService.HasPlayerDoneAchievements(selectedGame, player).OrderBy(a => a.hasAchieved).Select(a => $"{(a.hasAchieved ? "UNLOCKED! " : "")}{a.achievement.Name} - {a.achievement.Description}").ToList(); var responseMessage = string.Join("\n\n", achievmentListString); var result = ExecutionResultHelper.SingleMessage(responseMessage, optionsToSend); result.MessagesToShow.Insert(0, new MessageResult { Message = "Achievements for game: " + selectedGame.GameName }); return(result); } else { player.PlayerFlag = PlayerFlag.ACHIEVEMENTS.ToString(); var messageToSend = $"You have completed a total of: {gameAchievementList.Sum(a => a.Item1.Count(b => b.hasAchieved))} out of {gameAchievementList.Sum(a => a.Item1.Count())}"; return(new ExecutionResult { MessagesToShow = new List <MessageResult> { new MessageResult { Message = messageToSend } }, OptionsToShow = optionsToSend }); } }
public ExecutionResult HandleMessage(string message, Player player) { ExecutionResult executionResult = new ExecutionResult(); List <MessageResult> messages = new List <MessageResult>(); var activeGame = _gameStore.ListGames().FirstOrDefault(a => a.GameName == player.ActiveGameSave.GameName); var achievementList = new List <(bool hasAchieved, DrawAchievement achievement)>(); if (activeGame != null) { try { achievementList = AchievementService.HasPlayerDoneAchievements(activeGame, player); } catch (Exception) { _reporter.ReportError($"Error when finding achievements for player: {player?.Name}. Game was: {activeGame?.GameName}, player achievs: {player?.PermanentData?.Count}"); } } if (message == Messages.ShowData) { var execResult = new ExecutionResult(); execResult.MessagesToShow = new List <MessageResult> { new MessageResult { Message = "- Showing current game data -" }, new MessageResult { Message = string.Join("\n", player.ActiveGameSave.GameSaveData.Select(a => $"{a.Name}: [{a.Value}]")) } }; execResult.OptionsToShow = GetOptions(player); return(execResult); } else if (message == Messages.RefreshGames) { messages.Add(new MessageResult { Message = "Starting to look for new games at: " + DateTime.UtcNow.ToLongTimeString() }); _gameStore.ListGames(TimeSpan.FromSeconds(0)); messages.Add(new MessageResult { Message = "Finished refreshing at: " + DateTime.UtcNow.ToLongTimeString() }); } if (message == "Main Menu") { player.PlayerFlag = PlayerFlag.MAIN_MENU.ToString(); return(_mainMenuMessageHandler.HandleMessage(message, player)); } if (message == "Return to Game") { return(MessageHandlerHelpers.ReturnToGame(player, _gameStore, _textParsing, _gameProcessor)); } if (message.StartsWith(Messages.Achievements)) { var achievmentListString = achievementList.OrderBy(a => a.hasAchieved).Select(a => $"{(a.hasAchieved ? "UNLOCKED! " : "")}{a.achievement.Name} - {a.achievement.Description}").ToList(); var responseMessage = string.Join("\n\n", achievmentListString); messages.Add(new MessageResult { Message = "Achievements for game: " + activeGame.GameName }); messages.Add(new MessageResult { Message = responseMessage }); } messages.Add(new MessageResult { Message = "Returning to the main menu will reset your progress!" }); messages.Add(new MessageResult { Message = "*** MENU ***" }); executionResult.OptionsToShow = GetOptions(player); executionResult.MessagesToShow = messages; player.PlayerFlag = PlayerFlag.GAME_MENU.ToString(); return(executionResult); }