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 void LoadTheGame() { // File.Exists(path); Console.WriteLine("Searching for existing save files..."); CMethods.SmartSleep(100); if (!Directory.Exists(base_dir)) { NoSaveFilesFound(); return; } Dictionary <string, List <string> > save_files = new Dictionary <string, List <string> >(); List <string> save_file_components = new List <string>() { sav_gems, sav_equipment, sav_inventory, sav_boss_flags, sav_game_info, sav_dialogue_flags, sav_chests, sav_player, sav_solou, sav_chili, sav_chyme, sav_parsto, sav_adorine, sav_storm, sav_kaltoh }; foreach (string path in Directory.GetDirectories(base_dir)) { if (save_file_components.All(x => File.Exists($"{path}/{x}"))) { // ...then set the dictionary key equal to the newly-formatted save file names string folder_name = path.Split('\\').Last(); save_files[folder_name] = save_file_components.Select(x => $"{base_dir}/{folder_name}/{x}").ToList(); } } if (save_files.Count == 0) { NoSaveFilesFound(); return; } CMethods.PrintDivider(); Console.WriteLine($"Found {save_files.Count} existing save files: "); // Print the list of save files int counter = 0; foreach (string folder in save_files.Keys) { Console.WriteLine($" [{counter + 1}] {folder}"); counter++; } while (true) { string chosen = CMethods.FlexibleInput("Input [#] (or type [c]reate new): ", save_files.Count); try { adventure_name = save_files.Keys.ToList()[int.Parse(chosen) - 1]; } catch (Exception ex) when(ex is FormatException || ex is ArgumentOutOfRangeException) { // Let the player create a new save file if (chosen.StartsWith("c")) { CMethods.PrintDivider(); UnitManager.CreatePlayer(); return; } continue; } CMethods.PrintDivider(); Console.WriteLine($"Loading Save File: '{adventure_name}'..."); CMethods.SmartSleep(100); JSONDeserializer.DeserializeEverything(); Console.WriteLine("Game loaded!"); return; } }
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; } } } }