public static bool SearchForTowns(bool enter = true) { if (TileManager.FindTileWithID(CInfo.CurrentTile).TownList.Count == 0) { return(false); } foreach (string town_id in TileManager.FindTileWithID(CInfo.CurrentTile).TownList) { Town town = FindTownWithID(town_id); CMethods.PrintDivider(); while (true) { string yes_no = CMethods.SingleCharInput($"The town of {town.TownName} is nearby. Enter? [Y]es or [N]o: "); if (CMethods.IsYesString(yes_no)) { CInfo.RespawnTile = CInfo.CurrentTile; town.EnterTown(); return(true); } else if (CMethods.IsNoString(yes_no)) { CMethods.PrintDivider(); break; } } } return(true); }
public static void WouldYouLikeToSave() { while (true) { string yes_no = CMethods.SingleCharInput("Do you wish to save your progress? | [Y]es or [N]o: ").ToLower(); if (CMethods.IsYesString(yes_no)) { Console.WriteLine("Saving..."); CMethods.SmartSleep(100); SaveTheGame(); Console.WriteLine("Game has been saved!"); CMethods.PressAnyKeyToContinue(); return; } else if (CMethods.IsNoString(yes_no)) { return; } } }
public static void AfterBattle(List <PlayableCharacter> active_pcus, List <Monster> monster_list, bool is_bossfight) { CMethods.PrintDivider(); foreach (PlayableCharacter pcu in active_pcus) { pcu.FixAllStats(); } foreach (Monster monster in monster_list) { monster.FixAllStats(); } if (active_pcus.Any(x => x.IsAlive())) { SoundManager.victory_music.PlayLooping(); if (is_bossfight) { Console.WriteLine($"The mighty {monster_list[0].Name} has been slain!"); CInfo.DefeatedBosses.Add(monster_list[0].UnitID); monster_list[0].UponDefeating(); } else { Console.WriteLine($"The {monster_list[0].Name} falls to the ground dead as a stone."); } int gold_drops = 0; foreach (Monster monster in monster_list) { gold_drops += Math.Max(Math.Max(1, monster.DroppedGold), (int)(2 * monster.Level)); } int expr_drops = 0; foreach (Monster monster in monster_list) { expr_drops += Math.Max(Math.Max(1, monster.DroppedXP), (int)Math.Pow(1.5, monster.Level)); } Dictionary <string, string> item_drops = new Dictionary <string, string>(); foreach (Monster monster in monster_list) { if (monster.DroppedItem != null || monster.SetDroppedItem()) { item_drops.Add(monster.Name, monster.DroppedItem); } } CInfo.GP += gold_drops; CMethods.PressAnyKeyToContinue(prompt: $"Your party got {gold_drops} GP"); foreach (PlayableCharacter pcu in active_pcus) { pcu.CurrentXP += expr_drops; CMethods.PressAnyKeyToContinue(prompt: $"{pcu.Name} gained {expr_drops} XP"); } foreach (KeyValuePair <string, string> drop in item_drops) { CMethods.PressAnyKeyToContinue(prompt: $"The {drop.Key} dropped a {ItemManager.FindItemWithID(drop.Value).ItemName}"); InventoryManager.AddItemToInventory(drop.Value); } foreach (PlayableCharacter pcu in active_pcus) { pcu.PlayerLevelUp(); } SoundManager.PlayCellMusic(); } else { SoundManager.gameover_music.PlayLooping(); Console.WriteLine($"Despite your best efforts, the {monster_list[0].Name} has killed your party."); CMethods.PrintDivider(); bool auto_yes = false; while (true) { string y_n; if (auto_yes) { y_n = "y"; } else { y_n = CMethods.SingleCharInput("Do you wish to continue playing? | [Y]es or [N]o: "); } if (CMethods.IsYesString(y_n)) { CInfo.CurrentTile = CInfo.RespawnTile; UnitManager.HealAllPCUs(true, true, true); SoundManager.PlayCellMusic(); return; } else if (CMethods.IsNoString(y_n)) { while (true) { string y_n2 = CMethods.SingleCharInput("Are you sure you want to quit? | [Y]es or [N]o: "); if (CMethods.IsYesString(y_n2)) { auto_yes = true; break; } else if (CMethods.IsNoString(y_n2)) { Environment.Exit(0); } } } } } }
public static void SetAdventureName() { // This function asks the player for an "adventure name". This is the // name of the directory in which his/her save files will be stored. while (true) { // Certain OSes don't allow certain characters, so this removes those characters // and replaces them with whitespace. The player is then asked if this is okay. string adventure = CMethods.MultiCharInput("Finally, what do you want to name this adventure? "); // This line removes all characters that are not alphanumeric, spaces, dashes, or underscores // We also remove repeated spaces like "Hello world" => "Hello world" // Finally we .Trim() to remove leading or ending whitespace like " Hello world " => "Hello world" adventure = Regex.Replace(Regex.Replace(adventure, @"[^\w\s\-]*", ""), @"\s+", " ").Trim(); // Make sure the adventure name isn't blank if (string.IsNullOrEmpty(adventure)) { continue; } // You also can't use "temp", because this is reserved for other features else if (adventure == "temp") { Console.WriteLine("Please choose a different name, that one definitely won't do!"); CMethods.PressAnyKeyToContinue(); continue; } // Make sure that the folder doesn't already exist else if (Directory.Exists(adventure)) { Console.WriteLine("I've already read about adventures with that name; be original!"); CMethods.PressAnyKeyToContinue(); continue; } // Max adventure name length is 35 else if (adventure.Length > 35) { Console.WriteLine("That adventure name is far too long, it would never catch on!"); CMethods.PressAnyKeyToContinue(); continue; } while (true) { string yes_no = CMethods.SingleCharInput($"You want your adventure to be remembered as '{adventure}'? | [Y]es or [N]o: ").ToLower(); if (CMethods.IsYesString(yes_no)) { adventure_name = adventure; return; } else if (CMethods.IsNoString(yes_no)) { CMethods.PrintDivider(); break; } } } }
public static bool PickSpellCategory(PlayableCharacter user, List <Monster> monster_list, bool is_battle) { while (true) { Console.WriteLine($"{user.Name}'s Spellbook:"); Console.WriteLine(" [1] Attack Spells"); Console.WriteLine(" [2] Healing Spells"); Console.WriteLine(" [3] Buff Spells"); if (user.CurrentSpell != null) { Console.WriteLine($" [4] Re-cast {user.CurrentSpell.SpellName}"); } while (true) { string category = CMethods.SingleCharInput("Input [#] (or type 'exit'): "); CEnums.SpellCategory true_category; if (CMethods.IsExitString(category)) { CMethods.PrintDivider(); return(false); } else if (category == "1") { true_category = CEnums.SpellCategory.attack; } else if (category == "2") { true_category = CEnums.SpellCategory.healing; } else if (category == "3") { true_category = CEnums.SpellCategory.buff; } else if (category == "4" && user.CurrentSpell != null) { if (user.CurrentSpell is HealingSpell || user.CurrentSpell is BuffSpell) { user.PlayerGetTarget(monster_list, $"Who should {user.Name} cast {user.CurrentSpell.SpellName} on?", true, false, false, false); } else { user.PlayerGetTarget(monster_list, $"Who should {user.Name} cast {user.CurrentSpell.SpellName} on?", false, true, false, false); } return(true); } else { continue; } if (PickSpell(true_category, user, monster_list, is_battle)) { return(true); } break; } } }
public static void PickInventoryAction(string item_id) { Item this_item = ItemManager.FindItemWithID(item_id); CMethods.PrintDivider(); // Loop while the item is in the inventory while (true) { string action; if (this_item is Equipment) { // You equip weapons/armor/accessories action = "Equip"; } else { // You use other items action = "Use"; } Console.WriteLine($"What should your party do with the {this_item.ItemName}? "); Console.WriteLine($" [1] {action}"); Console.WriteLine(" [2] Read Description"); Console.WriteLine(" [3] Drop"); while (true) { string chosen = CMethods.SingleCharInput("Input [#] (or type 'exit'): ").ToLower(); if (CMethods.IsExitString(chosen)) { return; } else if (chosen == "1") { // Items of these classes require a target to be used, so we have to acquire a target first if (this_item is Equipment || this_item is HealthManaPotion || this_item is StatusPotion) { if (UnitManager.player.PlayerGetTarget(new List <Monster>(), $"Who should {action} the {this_item.ItemName}?", true, false, true, false)) { CMethods.PrintDivider(); this_item.UseItem(UnitManager.player.CurrentTarget as PlayableCharacter); return; } break; } // Other items can just be used normally else { CMethods.PrintDivider(); this_item.UseItem(UnitManager.player); } return; } else if (chosen == "2") { // Display the item description CMethods.PrintDivider(); Console.WriteLine($"Description for '{this_item.ItemName}': \n"); Console.WriteLine(this_item.Description); CMethods.PressAnyKeyToContinue(); CMethods.PrintDivider(); break; } else if (chosen == "3") { CMethods.PrintDivider(); // You can't throw away important/essential items, such as tools and quest items. // This is to prevent the game from becoming unwinnable. if (this_item.IsImportant) { Console.WriteLine("Essential Items cannot be thrown away."); CMethods.PressAnyKeyToContinue(); } else { while (true) { string yes_or_no = CMethods.SingleCharInput($"Throw away the {this_item.ItemName}? | [Y]es or [N]o: ").ToLower(); if (CMethods.IsYesString(yes_or_no)) { RemoveItemFromInventory(this_item.ItemID); Console.WriteLine($"You toss the {this_item.ItemName} aside and continue on your journey."); CMethods.PressAnyKeyToContinue(); return; } else if (CMethods.IsNoString(yes_or_no)) { Console.WriteLine($"You decide to keep the {this_item.ItemName}."); CMethods.PressAnyKeyToContinue(); return; } } } } } } }
public static void PickInventoryCategory() { while (true) { Console.WriteLine("Your Inventory: "); Console.WriteLine(" [1] Armor"); Console.WriteLine(" [2] Weapons"); Console.WriteLine(" [3] Accessories"); Console.WriteLine(" [4] Consumables"); Console.WriteLine(" [5] Tools"); Console.WriteLine(" [6] Quest Items"); Console.WriteLine(" [7] Miscellaneous"); Console.WriteLine(" [8] View Equipment"); Console.WriteLine(" [9] View Quests"); while (true) { string chosen = CMethods.SingleCharInput("Input [#] (or type 'exit'): ").ToLower(); CEnums.InvCategory category; if (CMethods.IsExitString(chosen)) { return; } else if (chosen == "1") { category = CEnums.InvCategory.armor; } else if (chosen == "2") { category = CEnums.InvCategory.weapons; } else if (chosen == "3") { category = CEnums.InvCategory.accessories; } else if (chosen == "4") { category = CEnums.InvCategory.consumables; } else if (chosen == "5") { category = CEnums.InvCategory.tools; } else if (chosen == "6") { category = CEnums.InvCategory.quest; } else if (chosen == "7") { category = CEnums.InvCategory.misc; } else if (chosen == "8") { // Equipped items aren't actually stored in the inventory, so they need their own function to handle them PickEquipmentItem(); break; } else if (chosen == "9") { // Quests have their own function, because they aren't actually instances of the Item class ViewQuests(); break; } else { continue; } if (GetInventory()[category].Count > 0) { PickInventoryItem(category, false); break; } else { CMethods.PrintDivider(); Console.WriteLine($"Your part has no {category.EnumToString()}."); CMethods.PressAnyKeyToContinue(); CMethods.PrintDivider(); break; } } } }