// Subscribe to the CastSpell event spellbook.CastSpell += OnCastSpell; // Cast spell function public void OnCastSpell(object sender, SpellbookCastSpellEventArgs e) { // Check if the caster has enough mana to cast the spell if (e.Caster.Mana >= e.Spell.ManaCost) { // Deduct mana from the caster e.Caster.Mana -= e.Spell.ManaCost; // Cast the spell e.Spell.Cast(); } }
// Subscribe to the CastSpell event spellbook.CastSpell += (sender, e) => { // Print the name of the spell being cast Console.WriteLine($"Casting spell: {e.Spell.Name}"); };In this example, we subscribe to the CastSpell event using a lambda expression. When the event is triggered, it simply prints the name of the spell being cast to the console. Package library: This class is likely part of a custom library that was created specifically for the Spellbook class and its related functionality. It is not part of the standard .NET Framework library.