/// <summary> /// Choose PC from player's list of characters and add to party /// </summary> /// <param name="playerID">Player_ID primary key</param> public void ChoosePC(int playerID) { bool isGood = false; while (!isGood) { Console.Clear(); PrintHeader("Choose Your Character"); Console.WriteLine(); Player player = _playerDAL.GetPlayerByID(playerID); List <PlayerCharacter> pcs = _pcDAL.GetAllPlayersPCs(playerID); List <int> pcIds = new List <int>(); if (pcs.Count > 0) { Console.WriteLine("{0,-5}{1,-20}{2,-35}", "ID", "Name", "Class"); Console.WriteLine("------------------------------------------------------------"); foreach (PlayerCharacter pc in pcs) { Console.WriteLine("{0,-5}{1,-20}{2,-35}", pc.PcId, pc.Name, $"lvl {pc.Level} {pc.Race} {pc.TypeClass}"); pcIds.Add(pc.PcId); } Console.WriteLine(); string input = CLIHelper.GetIntInListOrQ("Select Character or Press Q to Quit", pcIds, "q", false); if (input == "Q" || input == "q") { isGood = true; } else { int pcIndex = Convert.ToInt32(input) - 1; _activeParty.Add(pcs[pcIndex]); isGood = true; } } else { Console.WriteLine(); CLIHelper.CenteredWriteline($"Sorry, {player.Name.ToUpper()} has not added a CHARACTER to the database"); CLIHelper.CenteredWriteline("Go to the DATABASE EDITOR to create a character and start your adventure!"); Console.WriteLine(); CLIHelper.CenteredWriteline("(press any key to return to the PARTY EDITOR)"); Console.ReadKey(); isGood = true; } } }
public ActionResult <Response> LeaveGame([FromHeader] int playerID) { try { Player player = new Player(playerID); //Get the player who is leaving the game PlayerDAL playerDAL = new PlayerDAL(); Response <Player> getPlayerResponse = playerDAL.GetPlayerByID(playerID); if (!getPlayerResponse.IsSuccessful()) { return(new Response(getPlayerResponse.ErrorMessage, getPlayerResponse.ErrorCode)); } player = getPlayerResponse.Data; //Create the hub interface which will be used to send live updates to clients HubInterface hubInterface = new HubInterface(_hubContext); //If the player leaving the game is the host and the game is currently in the lobby kick all other players from the game //because only the host player can begin the game if (player.IsHost && player.Game.IsInLobby()) { Response endLobbyResponse = new GameDAL().EndLobby(player.Game); //If successfully kicked all players from the game send live updates to clients that they have been removed from the lobby if (endLobbyResponse.IsSuccessful()) { hubInterface.UpdateLobbyEnded(player.Game); } //Return and leave the method because there is nothing else to process at this point return(endLobbyResponse); } //Call the data access layer to remove the player from the game. bool isGameComplete = false; bool isPhotosComplete = false; Response <List <Photo> > leaveGameResponse = playerDAL.LeaveGame(player, ref isGameComplete, ref isPhotosComplete); //Return the error response if an error occurred if (!leaveGameResponse.IsSuccessful()) { return(new Response(leaveGameResponse.ErrorMessage, leaveGameResponse.ErrorCode)); } //Call the hub method to send out notifications to players that the game is now complete if (isGameComplete) { hubInterface.UpdateGameCompleted(player.Game, true); } //Otherwise, if the photo list is not empty then photos have been completed and need to send out updates else if (isPhotosComplete) { foreach (var photo in leaveGameResponse.Data) { hubInterface.UpdatePhotoVotingCompleted(photo); } } //If the game is not completed send out the player left notification if (!isGameComplete) { hubInterface.UpdatePlayerLeftGame(player); } return(new Response(leaveGameResponse.ErrorMessage, leaveGameResponse.ErrorCode)); } //Catch any error associated with invalid model data catch (InvalidModelException e) { return(new Response(e.Msg, e.Code)); } //Catch any unhandled / unexpected server errrors catch { return(StatusCode(500)); } }