public static void PickInventoryItem(CEnums.InvCategory category, bool selling) { // Select an object to interact with in your inventory // If "selling == True" that means that items are being sold, and not used. while (true) { CMethods.PrintDivider(); List <string> item_ids = DisplayInventory(category, selling); while (true) { string chosen = CMethods.FlexibleInput("Input [#] (or type 'exit'): ", item_ids.Count).ToLower(); try { chosen = item_ids[int.Parse(chosen) - 1]; } catch (Exception ex) when(ex is FormatException || ex is ArgumentOutOfRangeException) { if (CMethods.IsExitString(chosen)) { CMethods.PrintDivider(); return; } continue; } // If you're selling items at a general store, you have to call a different function if (selling) { SellItem(chosen); if (!GetInventory()[category].Any(x => x.IsImportant)) { return; } } else { PickInventoryAction(chosen); if (GetInventory()[category].Count == 0) { return; } } break; } } }
public static bool PickSpell(CEnums.SpellCategory category, PlayableCharacter user, List <Monster> monster_list, bool is_battle) { List <Spell> chosen_spellbook = GetSpellbook(category).Where(x => x.RequiredLevel <= user.Level).ToList(); int padding; CMethods.PrintDivider(); while (true) { padding = chosen_spellbook.Max(x => x.SpellName.Length); Console.WriteLine($"{user.Name}'s {category.EnumToString()} Spells | {user.MP}/{user.MaxMP} MP remaining"); int counter = 0; foreach (Spell spell in chosen_spellbook) { Console.WriteLine($" [{counter + 1}] {spell.SpellName} {new string('-', padding - spell.SpellName.Length)}-> {spell.ManaCost} MP"); counter++; } while (true) { string chosen_spell = CMethods.FlexibleInput("Input [#] (or type 'exit'): ", chosen_spellbook.Count); try { user.CurrentSpell = chosen_spellbook[int.Parse(chosen_spell) - 1]; } catch (Exception ex) when(ex is FormatException || ex is ArgumentOutOfRangeException) { if (CMethods.IsExitString(chosen_spell)) { CMethods.PrintDivider(); return(false); } continue; } // Of course, you can't cast spells without the required amount of MP if (user.CurrentSpell.ManaCost > user.MP) { CMethods.PrintDivider(); Console.WriteLine($"{user.Name} doesn't have enough MP to cast {user.CurrentSpell.SpellName}!"); CMethods.PressAnyKeyToContinue(); break; } if (is_battle) { if (user.CurrentSpell is HealingSpell || user.CurrentSpell is BuffSpell) { if (user.PlayerGetTarget(monster_list, $"Who should {user.Name} cast {user.CurrentSpell.SpellName} on?", true, false, false, false)) { return(true); } else { break; } } else { if (user.PlayerGetTarget(monster_list, $"Who should {user.Name} cast {user.CurrentSpell.SpellName} on?", false, true, false, false)) { return(true); } else { break; } } } else { user.PlayerGetTarget(monster_list, $"Who should {user.Name} cast {user.CurrentSpell.SpellName} on?", true, false, false, false); user.CurrentSpell.UseMagic(user, is_battle); 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; } } } }