public static List <Spell> GetSpellbook(CEnums.SpellCategory spell_category) { if (spell_category == CEnums.SpellCategory.attack) { return(attack_spellbook.Select(x => x as Spell).ToList()); } else if (spell_category == CEnums.SpellCategory.healing) { return(healing_spellbook.Select(x => x as Spell).ToList()); } else if (spell_category == CEnums.SpellCategory.buff) { return(buff_spellbook.Select(x => x as Spell).ToList()); } else { IEnumerable <Spell> attk_spls = attack_spellbook.Select(x => x as Spell); IEnumerable <Spell> heal_spls = healing_spellbook.Select(x => x as Spell); IEnumerable <Spell> buff_spls = buff_spellbook.Select(x => x as Spell); return(attk_spls.Concat(heal_spls).Concat(buff_spls).ToList()); } }
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; } } } }