//----------------------------------------------------------------------------- // pickVehicle //----------------------------------------------------------------------------- static public Ship.Result pickVehicle(Character character) // unesesary copying... { Ship.Result shipInfo = new Ship.Result(); List <Ship.Result> vshipInfo = new List <Ship.Result>(); Console.WriteLine("Which vehicles do you want to use?"); for (int j = 0; j != character.vShips.Count; j++) { shipInfo = Ship.getShipDetails(character.vShips[j]); vshipInfo.Add(shipInfo); Console.WriteLine(j + " - " + vshipInfo[j].name); } int i = Convert.ToInt32(Console.ReadLine()); return(vshipInfo[i]); }
const int Parkinglotcapacity = 100; // Macro Substitude // 26 is the equvilant of 2 default ships (Char 0, Ship 0). used while debuging % for predictibility public static async Task InitiateDialogueAsync(RectangularPlatform parkingDeck) { parkingDeck.ShowCapacity(); Console.WriteLine("What's your name?"); var customerName = Console.ReadLine(); // Connect to DB here while api is loading :desktop: // establishDataBaseConnection(); Character customer = ApiUtils.LoadCharacter(customerName); //Task<Character> taskLoadChar = new Task<Character>(function: () => ApiUtils.LoadCharacter(customerName)); //Task<List<Ship.Result>> taskLoadShips = new Task<List<Ship.Result>>(function: () => loadAllVehiclesAsync(customer)); var taskLoadShips = Task.Factory.StartNew(() => loadAllVehiclesAsync(customer)); //Task<int> taskLoadShips = new Task<int>(function: ()=>loadAllVehiclesAsync(customer)); //taskLoadShips.Start(); //System.Console.WriteLine("FROM UI"); // should be called last but appear first. ✔ var currentPilot = new StarWarsPerson { Name = customer.Name }; if (DbUtils.IsDocked(currentPilot)) { Logger.systemLog("You already have a ship here, do you want to check it out or swap it for another one? ", ConsoleColor.DarkYellow); Logger.systemLog("S = swap, E = check out ", ConsoleColor.DarkYellow); string sAnswer = Console.ReadLine(); //char cAnswer = Console.ReadLine(); if (sAnswer[0] == 'e' || sAnswer[0] == 'E') { parkingDeck.CheckoutShip(currentPilot); return; } if (sAnswer[0] == 's' || sAnswer[0] == 'S') { parkingDeck.CheckoutShip(currentPilot); } // switch (sAnswer[0]) // { // case 'e': // case 'E': // parkingDeck.CheckoutShip(currentPilot); // break; // // case 's': // case 'S': // parkingDeck.CheckoutShip(currentPilot); // break; // // default: // break; // } } if (customer.Exists) { List <Ship.Result> vShip = await await taskLoadShips; //"await await" <-- intellisense WTF Console.WriteLine(); Logger.systemLog("Which ship?", ConsoleColor.DarkYellow); for (int i = 0; i != vShip.Count; i++) { Console.WriteLine(i + " - " + vShip[i].name); } int iAnswer = Convert.ToInt32(Console.ReadLine()); Ship.Result ship = new Ship.Result(); ship = vShip[iAnswer]; customer.CurrentShipName = ship.name; currentPilot.ShipName = ship.name; currentPilot.Length = ship.length; if (parkingDeck.ShipWillFit(ship.length)) { if (customer.Wealth > parkingDeck.CalculateDockingFee(ship.length)) { parkingDeck.DockShip(currentPilot); } else { Logger.systemLog("Sorry, you can't afford that"); } } else { Logger.systemLog("Your ship wont fit"); } } else { Logger.systemLog("You do not have access to this garage"); } }
//public static int delayed() //{ // Thread.Sleep(500); // systemLog("delay", ConsoleColor.Cyan); // return 0; //} //----------------------------------------------------------------------------- // intiiateDialouge //----------------------------------------------------------------------------- public static async Task intiiateDialouge(RectangularPlatform parkingDeck) { parkingDeck.showCapacity(); // Task<int> task = new Task<int>(delayed); // task.Start(); // systemLog("FROM intiiateDialouge2", ConsoleColor.DarkYellow); // TASK SPEED TEST, Remove! Character cCustomer = new Character(); Console.WriteLine("What's your name?"); string sCustomerName = Console.ReadLine(); //Task.Run(async () => await LoadCharacterAsync(sCustomerName)); Task <Character> taskLoadChar = new Task <Character>(function: () => loadCharacters(sCustomerName)); taskLoadChar.Start(); // Connect to DB here while api is loading 🖥 // establishDataBaseConnection(); cCustomer = await taskLoadChar; #region UNCOMMENT : Customer has parked a vehicle here but never check it out, thus its still here. Checkout now? : REQUIERES ENTITYFRAMEWORK INTERGRATION // select * from SpacePark where Name = [cCustomer.sName] && checkOut == NULL <<<<<<<<<<<<<<<<<<<<<<<<<<<<< // REQUIERES ENTITYFRAMEWORK INTERGRATION // if (sqlResults != null) // { // systemLog("you already have (a) ship(s) here, do you want to check one of them out? Y/N"); // char cAnswer = Console.ReadKey(); // switch (cAnswer) // { // case 'y': // case 'Y': // checkOutShip(); // return; // // default: // break; // } // } // Customer has parked a vehicle here but never check it out, thus its still here. Checkout now? #endregion if (cCustomer.bValid) { Ship.Result ship = pickVehicle(cCustomer); #region OLD CRAP // Pick a random person that wants to park //Random random = new Random(); //int iPersonAproaching = /*random.Next(0, vCharacters.Count);*/ 0; // ⚠ HardCoded while debuging, re-enable random later // GITHUB: "...be able to pay before they can leave the parking lot and get an invoice in the end." , No entry fee? Current wallet irrelevant? //if (! (parkingDeck.calculatePrice( Ship.getShipDetails(vCharacters[iPersonAproaching].vShips[iPersonAproaching]).length) > vCharacters[iPersonAproaching].iCoins) ) #endregion //if (isAuthorized(cCustomer)) if (cCustomer.bValid) { // replace 0 with iPersonAproaching if (parkingDeck.shipWillFit(ship.length)) { if (cCustomer.dWealth > parkingDeck.calculatePrice(Ship.getShipDetails(cCustomer.vShips[cCustomer.iDrivingShipNumber]).length)) { parkingDeck.dockShip(Ship.getShipDetails(cCustomer.vShips[cCustomer.iDrivingShipNumber]).length, cCustomer); } else { systemLog("Sorry, you can't afford that"); } } else { systemLog("Your ship wont fit"); } } } else { systemLog("You do not have acces to this garage"); } #region NOW TEMPORARYLY CACHES (using) SHIP FROM 'pickVehicle' WHILE DIALOUGE IS GOING ON //while (true) //{ // if(isAuthorized(vCharacters, sCustomerName)) // { // replace 0 with iPersonAproaching // if (parkingDeck.shipWillFit( Ship.getShipDetails( vCharacters[0].vShips[ vCharacters[0].iDrivingShipNumber ] ).length ) ) // { // if (vCharacters[0].dWealth > parkingDeck.calculatePrice(Ship.getShipDetails(vCharacters[0].vShips[vCharacters[0].iDrivingShipNumber]).length)) // { // parkingDeck.dockShip(Ship.getShipDetails(vCharacters[0].vShips[vCharacters[0].iDrivingShipNumber]).length, vCharacters[0] ); // } // else // { // systemLog("Sorry, you can't afford that"); // } // } // else // { // systemLog("Parkinglot is full, please come back later"); // } // } // else // { // systemLog("You do not have acces to this garage"); // } // //} #endregion }