I am trying to add a VirtualArmorMod to one of my spells with a timer with no luck any help will be greatful.


Code:
using System;
using System.Collections;
using Server.Targeting;
using Server.Network;
using Server.Mobiles;
using Server.Spells.Necromancy;

namespace Server.Spells.Cleric
{
    public class SheildofFaithSpell : ClericSpell
    {
        private static SpellInfo m_Info = new SpellInfo( "Purge", "Repurgo", 212, 9041 );
       
        public override TimeSpan CastDelayBase { get { return TimeSpan.FromSeconds( 1.5 ); } }
        public override int RequiredTithing{ get{ return 10; } }
        public override double RequiredSkill{ get{ return 45.0; } }
        public override int RequiredMana{ get{ return 10; } }
        public override bool BlocksMovement{ get{ return false; } }
       
        public SheildofFaithSpell( Mobile caster, Item scroll ) : base( caster, scroll, m_Info )
        {
        }
       
        public override void OnCast()
        {
            if ( CheckSequence() )
            {
                TimeSpan duration = TimeSpan.FromSeconds( Caster.Skills[SkillName.AnimalLore].Value * 0.1 );
                int amount = (int)( Caster.Skills[SkillName.AnimalLore].Value * .45 );
               
                Caster.SendMessage( "Your prayers have been answered and bleesed with the sheild of faith!" );
               
                ResistanceMod mod1 = new ResistanceMod( ResistanceType.Physical, + amount );
                ResistanceMod mod2 = new ResistanceMod( ResistanceType.Energy, + amount );
                VirtualArmorMod mod3 = new VirtualArmorMod( + 20 );
                               
                Caster.FixedParticles( 0x373A, 10, 15, 5012, 0x14, 3, EffectLayer.Waist );
               
                Caster.AddResistanceMod( mod1 );
                Caster.AddResistanceMod( mod2 );
                Caster.VirtualArmorMod( mod3 );
               
                new ExpireTimer( Caster, mod1, duration ).Start();
                new ExpireTimer( Caster, mod2, duration ).Start();
                new ExpireTimer( Caster, mod3, duration ).Start();
                               
                if ( Caster is GPlayerMobile )
                {
                    Misc.Levels.AwardExp( Caster, +5, true );
                }
                else
                {
                }
            }
           
            FinishSequence();
        }
       
        private class ExpireTimer : Timer
        {
            private Mobile m_Mobile;
            private ResistanceMod m_Mods;
            //private VirtualArmorMod m_VMods;
           
            public ExpireTimer( Mobile m, ResistanceMod mod, TimeSpan delay ) : base( delay )
            {
                m_Mobile = m;
                m_Mods = mod;
                //m_VMods = vmod;
            }
           
            public void DoExpire()
            {
                m_Mobile.RemoveResistanceMod( m_Mods );
                //m_Mobile.RemoveVirtualArmorMod( m_VMods );
                Stop();
            }
           
            protected override void OnTick()
            {
                if ( m_Mobile != null )
                {
                    //m_Mobile.VirtualArmorMod
                    m_Mobile.SendMessage( "The effect of sheild of faith wears off." );
                    DoExpire();
                }
            }
        }
    }
}
 
I would do it something like this:

Code:
                ResistanceMod mod1 = new ResistanceMod( ResistanceType.Physical, amount );
                ResistanceMod mod2 = new ResistanceMod( ResistanceType.Energy, amount );
                int mod3 = 20;
                              
                Caster.FixedParticles( 0x373A, 10, 15, 5012, 0x14, 3, EffectLayer.Waist );

                Caster.AddResistanceMod( mod1 );
                Caster.AddResistanceMod( mod2 );
                Caster.VirtualArmorMod += mod3;
               
                new ExpireTimer( Caster, mod1, mod2, mod3, duration ).Start();

And then, your timer would look like this:

Code:
        private class ExpireTimer : Timer
        {
            private Mobile m_Mobile;
            private ResistanceMod m_Mod1;
            private ResistanceMod m_Mod2;
            private int m_Mod3;
          
            public ExpireTimer( Mobile m, ResistanceMod mod1, ResistanceMod mod2, int mod3, TimeSpan delay ) : base( delay )
            {
                m_Mobile = m;
                m_Mod1 = mod1;
                m_Mod2 = mod2;
                m_Mod3 = mod3;
            }
          
            public void DoExpire()
            {
                m_Mobile.RemoveResistanceMod( m_Mod1 );
                m_Mobile.RemoveResistanceMod( m_Mod2 );
                m_Mobile.VirtualArmorMod -= m_Mod3;
                Stop();
            }
          
            protected override void OnTick()
            {
                if ( m_Mobile != null )
                {
                    m_Mobile.SendMessage( "The effect of the shield of faith wears off." );
                    DoExpire();
                }
            }
        }
 
Back