/// <summary> /// Opens the shop /// </summary> /// <param name="player">The player data</param> public static void Open(ref Human human) { string input; ShopMenu menu = new ShopMenu(); do { // Show the shop and get a choice input = menu.Show(); // Get the item ID that was selected and // if the human has enough money to buy it, // try to buy the item. try { int itemId = int.Parse(input); if (human.Money >= shopCosts[itemId]) human.PurchaseItem(itemId, shopCosts[itemId]); else { ConsoleTools.DrawDesign(ConsoleTools.notEnoughMoney); ConsoleTools.DrawDesign(ConsoleTools.shop); } } catch (Exception) { // Pressed escape to exit } } while (!input.Equals("")); }
/// <summary> /// Moves to the map with the given ID /// </summary> /// <param name="id">map ID</param> /// <param name="human">human reference</param> /// <returns>the new map</returns> public static Map CreateMap(int id, Human human) { if (id > 0) id = 1; // Create the map and return it Type type = Type.GetType(mapPrefix + mapNames[id]); return (Map)Activator.CreateInstance(type, new object[] { human.Seed, human }); }
/// <summary> /// Starts a new adventure /// </summary> public static void Action() { int file = FileSelect.Open(true); if (file < 1) return; Human human = new Human(file); Map map = new Area(human.Seed, ref human); Adventure.Begin(human, map); }
/// <summary> /// Smokebomb effect /// </summary> /// <param name="human">player using the item</param> /// <returns></returns> public override Boolean Use(Human human) { // The human must be in a battle to use it if (human.battling != 1 || quantity == 0) return false; human.battling = 0; quantity--; return true; }
/// <summary> /// Use the masking dew /// </summary> /// <param name="human">Player using the item</param> /// <returns>true if the item was successfully used</returns> public override Boolean Use(Human human) { // Cannot use if its effect is already active or there is none to use if (human.dewSteps > 0 || quantity == 0 || human.battling > 0) return false; human.dewSteps = Constants.IntValue("maskingDewDuration"); quantity--; return true; }
/// <summary> /// Uses the item to warp to another location /// </summary> /// <returns>true if the potion was consumed</returns> public override Boolean Use(Human human) { // Cannot use a crystal when the player is already in the destination map or when there is no item to use if (human.battling == 0 && human.area != destination[0] && quantity > 0) { human.MoveToWorld(destination); if (this is WarpCrystal) quantity--; return true; } else return false; }
/// <summary> /// Loads the file pointed to and stores the data in the supplied human and map /// </summary> /// <param name="human">human object</param> /// <param name="map">map object</param> /// <param name="saveFile">save file id</param> /// <returns>true if the load was successful</returns> public static Boolean LoadGame(out Human human, out Map map, int saveFile) { StreamReader load = null; //try { // Opens the file load = new StreamReader(directory + saveFile); string json = load.ReadLine(); human = new Human(saveFile); human.JsonEncoding = json; load.Close(); // Load the world if (human.area == 0) map = new Town(human.Seed, ref human); else map = new Area(human.Seed, ref human); return true; /* } catch (Exception e) { Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight); Console.Clear(); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.ReadKey(); load.Close(); if (saveFile == -1) { // Was no save file int file = FileSelect.Open(true); human = new Human(file); map = new Area(human.Seed, ref human); return false; } else { // Corrupt save file human = new Human(saveFile); map = new Area(human.Seed, ref human); return false; } }*/ }
/// <summary> /// Uses the potion to heal the player /// </summary> /// <returns>true if the potion was consumed</returns> public override Boolean Use(Human human) { // The human must be damaged in order to use a potion if (human.IsDamaged && quantity > 0) { if (human.battling > 0) human.Damage(-battleHealAmount); else human.Damage(-fieldHealAmount); human.LimitHp(); quantity--; return true; } else return false; }
/// <summary> /// Saves the data to the designated file /// </summary> /// <param name="human">human data</param> /// <param name="map">map data</param> /// <param name="saveFile">save file id</param> /// <returns>true if the save was successful</returns> public static Boolean SaveGame(Human human, int saveFile) { try { Directory.CreateDirectory(directory.Replace("/Save", "")); // Open the file StreamWriter save = new StreamWriter(directory + saveFile); save.WriteLine(human.JsonEncoding); save.Close(); return true; } catch (Exception) { return false; } }
/// <summary> /// Uses the item /// </summary> /// <param name="world">The world using it from</param> /// <param name="battling">Whether or not it is being used in battle</param> /// <returns>true if the item was consumed</returns> public virtual Boolean Use(Human human) { return false; }
/// <summary> /// Begins a practice battle /// </summary> public static void Action() { Human practiceHuman = new Human(999, 999); Enemy practiceEnemy = new Minion(-1); Battle.Fight(practiceHuman, practiceEnemy); }
/// <summary> /// Executes a fight between the given combatants /// </summary> /// <param name="humanPtr">The human</param> /// <param name="enemyPtr">The enemy</param> /// <returns></returns> public static int Fight(Human humanPtr, Enemy enemyPtr) { // Initialize a battlefield and the battle data battlefield = new Battlefield(); ap = new int[2]; human = humanPtr; enemy = enemyPtr; horizontalPosition = 0; verticalPosition = 0; action = 0; Draw(); ConsoleKey key; do { int[] direction; System.Threading.Thread.Sleep(25); key = KeyInput.Key; if (key == ConsoleKey.UpArrow) direction = up; else if (key == ConsoleKey.RightArrow) direction = right; else if (key == ConsoleKey.LeftArrow) direction = left; else if (key == ConsoleKey.DownArrow) direction = down; else { if (key == ConsoleKey.H) { Help(); Draw(); } else if (key == ConsoleKey.I && enemy.Level != 999) { bool? usedItem = Inventory(); Draw(); if (usedItem == null) return -1; else if (usedItem == true) AiTurn(); } else if (key == ConsoleKey.Escape && enemy.Level == 999) return 1; else if (key == ConsoleKey.Tab && extraTurns == 0) { action = GetAction(action + 1); RefreshBattleStats(); } else if (key == ConsoleKey.Spacebar) { Act(); if (battlefield.CountTokens(1) == 0) return 0; else if (battlefield.CountTokens(2) == 0) return human.Health; } else CheckForShortcut(key.ToString().Replace("D", "")); continue; } // Move the player if a // directional key was pressed MoveCursor(direction); } while (human.Health > 0 && enemy.Health > 0); if (human.Health <= 0) return 0; return human.Health; }
/// <summary> /// Town constructor /// </summary> /// <param name="seed">the seed</param> /// <param name="human">the human reference</param> public Town(int seed, ref Human human) { this.seed = seed; this.human = human; }
/// <summary> /// Begins the adventure /// </summary> /// <param name="human">human pbject</param> /// <param name="map">map object</param> public static void Begin(Human human, Map map) { humanRef = human; ConsoleKey key; int[] direction; // Initializes the map and then draws it Console.Clear(); Console.WriteLine("Generating map..."); map.Generate(); map.Draw(); int cycles = 0; do { Thread.Sleep(25); cycles = (cycles + 1) % 15; key = KeyInput.Key; if (key == ConsoleKey.UpArrow) direction = up; else if (key == ConsoleKey.RightArrow) direction = right; else if (key == ConsoleKey.LeftArrow) direction = left; else if (key == ConsoleKey.DownArrow) direction = down; else if (key == ConsoleKey.E && KeyInput.Modifier == ConsoleModifiers.Control) { Constants.Edit(); map.Draw(); continue; } else { if (key == ConsoleKey.M) { if (MastermindRPG.Actions.Action.Execute("Menu").ToString().Equals("Save")) break; } else if (key == ConsoleKey.H) MastermindRPG.Actions.Action.Execute("AdventureHelp"); else if (key == ConsoleKey.I) { MastermindRPG.Actions.Action.Execute("Inventory"); if (map.Id != human.area) { map = WorldTransition.CreateMap(human.area, human); map.Generate(); } } else { if (cycles == 0) map.Tick(); continue; } map.Draw(); continue; } if (cycles == 0) map.Tick(); // Move the player try { bool? check = map.WalkableTile(human.Position[0] + direction[0], human.Position[1] + direction[1]); if (check == null) map.ChangeRoom(direction); else if (check == true) { human.Move(direction); map.MoveAction(); } } // If the player went out of the bounds of the room, // change to the next room catch (Exception e) { Console.SetBufferSize(Console.LargestWindowWidth, 300); Console.Clear(); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.ReadKey(); map.ChangeRoom(direction); } // If the map was ever changed, load the new map if (map.Id != human.area) { map = WorldTransition.CreateMap(human.area, human); map.Generate(); map.Draw(); } // Refresh the display map.Refresh(); } while (key != ConsoleKey.Escape); // Save the game upon exiting (Quicksave) Save.SaveGame(human, human.SaveFile); }
/// <summary> /// Constructor /// </summary> /// <param name="seed">Seed of the area</param> /// <param name="human">Human reference</param> public Area(int seed, ref Human human) { this.seed = seed; this.human = human; currentRoom = new int[] { 0, 0 }; random = new Random(); enemyList = new SimpleList<Minion>(); pathing = new Pathfinder(); backup = new int[2]; }
/// <summary> /// Encounter a minion while exploring /// </summary> private void Encounter(params Minion[] minion) { human.battling = 1; Enemy enemy; if (minion.Length == 0) enemy = new Minion(human.area); else enemy = minion[0]; int result = Battle.Fight(human, enemy); human.battling = 0; if (result > 0) human += enemy.Reward; else if (result == 0) { try { File.Delete(directory + human.SaveFile); } catch (Exception) { } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; ConsoleTools.CenterConsole(25, 2); Console.WriteLine(" You Lost!"); ConsoleTools.Pause(); Environment.Exit(0); } ConsoleTools.DrawDesign(ConsoleTools.mapGui); Draw(); ConsoleTools.Draw(25, 9, Constants.CharValue("playerToken")); }
/// <summary> /// Changes between rooms in the area /// </summary> /// <param name="direction">The direction to move in {horizontal change, vertical change}</param> public void ChangeRoom(int[] direction) { // Clear the old room for (int y = 3; y < 16; ++y) ConsoleTools.Draw(9, y, " "); ConsoleTools.Draw(25, 9, Constants.CharValue("playerToken")); // If the room moving to is outside the bounds of the area, it is a boss room if (currentRoom[0] + direction[0] < 0 || currentRoom[0] + direction[0] == length || currentRoom[1] + direction[1] < 0 || currentRoom[1] + direction[1] == width) // If the human has not beat the boss already, fight it if (human.progress < human.area) { human.Heal(); human.battling = 2; Enemy enemy = new Boss(human.area); int result = Battle.Fight(human, enemy); human.battling = 0; if (result > 0) { human += enemy.Reward; human.progress++; human.MoveToWorld(new int[] { 0, 16, 6 }); } else if (result == 0) { try { File.Delete(directory + human.SaveFile); } catch (Exception) { } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; ConsoleTools.CenterConsole(25, 2); Console.WriteLine(" You Lost!"); ConsoleTools.Pause(); Environment.Exit(0); } } // Otherwise move to town else human.MoveToWorld(new int[] { 0, 16, 6 }); // If the room is within the area's bounds, move into it and position the player appropriately else { // Change rooms currentRoom[0] += direction[0]; currentRoom[1] += direction[1]; // Set the new player position if (direction[0] == 1) human.Position = new int[] { 0, human.Position[1] }; if (direction[0] == -1) human.Position = new int[] { CurrentRoom.HorizontalSize - 1, human.Position[1] }; if (direction[1] == 1) human.Position = new int[] { human.Position[0], 0 }; if (direction[1] == -1) human.Position = new int[] { human.Position[0], CurrentRoom.VerticalSize - 1 }; DisplayStats(); } }