public override void OnHit(Mobile attacker, Mobile defender, ref int damage)
        {
            if (!Validate(attacker))
            {
                return;
            }
            try
            {
                switch (SpellRegistry.Create <T>(attacker))
                {
                case ITargetableAsyncSpell <Mobile> targetableAsyncSpell:
                    targetableAsyncSpell.OnTargetAsync(new TargetResponse <Mobile>
                    {
                        Target = defender,
                        Type   = TargetResponseType.Success
                    });
                    break;

                case IAsyncSpell asyncSpell:
                    asyncSpell.CastAsync();
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(
                    $"Failed to invoke {GetType().Name}<{typeof(T).Name}> for Mobile: {attacker.GetType().Name}, Serial: {attacker.Serial}");
            }
        }
Esempio n. 2
0
        private static void EventSink_CastSpellRequest(Mobile from, int id, Item item)
        {
            var spellId = (SpellEntry)id;

            if (!(item is Spellbook book) || !book.HasSpell(spellId))
            {
                book = Find(from, spellId);
            }

            if (book != null && book.HasSpell(spellId))
            {
                var spell = SpellRegistry.Create(spellId, from, null);

                if (spell != null)
                {
                    spell.Cast();
                }
                else
                {
                    from.SendLocalizedMessage(502345); // This spell has been temporarily disabled.
                }
            }
            else
            {
                from.SendLocalizedMessage(500015); // You do not have that spell!
            }
        }
Esempio n. 3
0
        public override void OnHit(Mobile attacker, Mobile defender, ref int damage)
        {
            if (!Validate(attacker))
            {
                return;
            }

            try
            {
                var spell = SpellRegistry.Create <DispelSpell>(attacker);

                spell.OnTargetAsync(new TargetResponse <Mobile>
                {
                    Target = defender,
                }).ConfigureAwait(false);

                if (SpellHelper.TryResist(attacker, defender, spell.Circle))
                {
                    defender.Mana = 0;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(
                    $"Failed to invoke {GetType().Name} for Mobile: {attacker.GetType().Name}, Serial: {attacker.Serial}");
            }
        }
Esempio n. 4
0
        public virtual Spell GetRandomDamageSpellMage()
        {
            int maxCircle = (int)((m_Mobile.Skills[SkillName.Magery].Value + 20.0) / (100.0 / 7.0));

            if (maxCircle < 1)
            {
                maxCircle = 1;
            }
            else if (maxCircle > 8)
            {
                maxCircle = 8;
            }

            if (m_Mobile.PreferredSpells != null && m_Mobile.PreferredSpells.Count > 0 && Utility.RandomDouble() < 0.75)
            {
                var spellType = m_Mobile.PreferredSpells[Utility.Random(m_Mobile.PreferredSpells.Count)];
                var spell     = SpellRegistry.Create(spellType, m_Mobile, null);
                return(spell);
            }

            switch (Utility.Random(maxCircle * 2))
            {
            case 0:
            case 1: return(new MagicArrowSpell(m_Mobile, null));

            case 2:
            case 3: return(new HarmSpell(m_Mobile, null));

            case 4:
            case 5: return(new FireballSpell(m_Mobile, null));

            case 6:
            case 7: return(new LightningSpell(m_Mobile, null));

            case 8:
            case 9: return(new MindBlastSpell(m_Mobile, null));

            case 10: return(new EnergyBoltSpell(m_Mobile, null));

            case 11: return(new ExplosionSpell(m_Mobile, null));

            default: return(new FlameStrikeSpell(m_Mobile, null));
            }
        }
Esempio n. 5
0
        public override void OnDoubleClick(Mobile from)
        {
            if (!IsChildOf(from.Backpack))
            {
                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
                return;
            }

            var spell = SpellRegistry.Create(SpellEntry, from, this);

            if (spell != null)
            {
                spell.Cast();
            }
            else
            {
                from.SendLocalizedMessage(502345); // This spell has been temporarily disabled.
            }
        }