sahisahi

Member
Today i was at Deceit dungeon and a Lizard shaman casted a lightning to a Energy Vortex and server crashed.

This is the crash log:


Exception:
System.InvalidCastException: Unable to cast object of type 'Server.Mobiles.EnergyVortex' to type 'Server.Mobiles.PlayerMobile'.
at Server.Spells.Fourth.LightningSpell.Target(Mobile m)
at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
at Server.Mobiles.SphereMageAI.ProcessTarget(Target targ)
at Server.Mobiles.SphereMageAI.Think()
at Server.Mobiles.BaseAI.AITimer.OnTick()
at Server.Timer.Slice()
at Server.Core.Main(String[] args)


Code:
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
using System;
using Server.Regions;
using Server.Guilds;


using System; //edited

namespace Server.Spells.Fourth
{
    public class LightningSpell : MagerySpell
    {
        public override SpellCircle Circle { get { return SpellCircle.Fourth; } }
        public override int Sound { get { return 0x29; } }
        public override int ManaCost { get { return 11; } } // edited

        private static readonly SpellInfo m_Info = new SpellInfo(
                "Lightning", "Por Ort Grav",
                263,
                9021,
                Reagent.MandrakeRoot,
                Reagent.SulfurousAsh
            );

        public LightningSpell( Mobile caster, Item scroll ) : base( caster, scroll, m_Info )
        {
        }

       // pvp changes
        public override TimeSpan GetCastDelay()
        {
            return TimeSpan.FromSeconds(1.6);
        }

        public override double GetResistPercent( Mobile target )
        {
            return 37.0;
        }
     
        public override void OnPlayerCast()
        {
            if (SphereSpellTarget is Mobile)
                Target((Mobile)SphereSpellTarget);
            else if (SphereSpellTarget is BaseWand)
            {
                BaseWand bw = SphereSpellTarget as BaseWand;
                bw.RechargeWand(Caster, this);
            }
            else
                DoFizzle();
        }

        public override void OnCast()
        {
            Caster.Target = new InternalTarget( this );
        }

        public override bool DelayedDamage{ get{ return false; } }

        public void Target( Mobile m )
        {
            if ( !Caster.CanSee( m ) )
            {
                Caster.SendLocalizedMessage( 500237 ); // Target can not be seen.
            }

            if ( CheckHSequence( m ) )
            {
                SpellHelper.CheckReflect( (int)Circle, Caster, ref m );
             
                         
                double damage = 12 + ((int)(GetDamageSkill(Caster) - GetResistSkill(m)) / 12);
                             
                             
                if ( CheckResisted( m ) )
             
                         {
                          
                          
                    Caster.SendAsciiMessage (28, "Your target resist the spell");
                    m.SendAsciiMessage(93,"You resist the spell");
                    damage = (int)(damage * 0.8);
                          

                     
                }
             
                 
             
                m.BoltEffect( 0 );
                Caster.RevealingAction();             
                //////////guild edit///////////////
                 if (m is PlayerMobile)  //  12/04/2017 not sure if this fix the Shaman lizardman crash
            {    // 12/04/2017 not sure if this fix the Shaman lizardman crash
Guild guild = Caster.Guild as Guild;
if (guild != null && Caster is PlayerMobile)
{
    switch (Caster.Guild.Type)
    {
        case GuildType.Chaos: damage += 2; break;
        case GuildType.Order: damage += 2; break;
    }
}
            ///////////end of guild edit////////////////
            Item weap = Caster.FindItemOnLayer(Layer.TwoHanded);
         if (weap != null && weap is bastonarchimago && Caster is PlayerMobile)
         damage += 3;
     ////////////////Key bonus//////////////////
       PlayerMobile mobile = (PlayerMobile)m;
       Container pack = m.Backpack;

        Item keyyflame = m.Backpack.FindItemByType(typeof(Keyyew));
        if (keyyflame != null)
        {
            damage -= 3;
     
                }
  
  
     ///////////////end of keybonus//////////////
                SpellHelper.Damage( this, m, damage, 0, 0, 0, 0, 100 );
                m.PlaySound(m.GetHurtSound());
                m.Animate(!m.Mounted ? 20 : 29, 5, 1, true, false, 0);
             
                FinishSequence();

             
                } 
        }
        }
     

        private class InternalTarget : Target
        {
            private readonly LightningSpell m_Owner;

            public InternalTarget( LightningSpell owner ) : base( 12, false, TargetFlags.Harmful )
            {
                m_Owner = owner;
            }

            protected override void OnTarget( Mobile from, object o )
            {
                if ( o is Mobile )
                    m_Owner.Target( (Mobile)o );
            }

            protected override void OnTargetFinish( Mobile from )
            {
                m_Owner.FinishSequence();
            }
        }
    }
        }

I added this, because i thought the crash issue was there, not sure thought.


Code:
    //////////guild edit///////////////
                 if (m is PlayerMobile)  //  12/04/2017 not sure if this fix the Shaman lizardman crash
            {    // 12/04/2017 not sure if this fix the Shaman lizardman crash

            ///////////end of guild edit////////////////


Thanks!
 
Change your part:
Code:
if (m is PlayerMobile) // 12/04/2017 not sure if this fix the Shaman lizardman crash
{ // 12/04/2017 not sure if this fix the Shaman lizardman crash
    Guild guild = Caster.Guild as Guild;
    if (guild != null && Caster is PlayerMobile)

to this part, the Lizardmen Shaman would be the Caster. Give it a try and see if it still crashes

Code:
if (Caster is PlayerMobile && m is PlayerMobile)
{
    Guild guild = Caster.Guild as Guild;
    if (guild != null)
 
Thank you so much!! i had similar crashes with other spells, like MindBlast and Teleport. The cast happens when a basecreature cast it:


Crash mindblast:

Exception:
System.InvalidCastException: Unable to cast object of type 'Server.Factions.FactionPaladinyew' to type 'Server.Mobiles.PlayerMobile'.
at Server.Spells.Fifth.MindBlastSpell.CheckCast()
at Server.Spells.Spell.DirectCast()
at Server.Factions.FactionGuardAI.Think()
at Server.Mobiles.BaseAI.AITimer.OnTick()
at Server.Timer.Slice()
at Server.Core.Main(String[] args)


Code:
using System;
using Server.Targeting;
using Server.Network;
using Server.Mobiles;
//using System.Collections;
using Server;
//using Server.Prompts;
//using Server.Mobiles;
//using Server.Network;
//using Server.Gumps;
//using Server.Items;

namespace Server.Spells.Fifth
{
    public class MindBlastSpell : MagerySpell
    {
        private static SpellInfo m_Info = new SpellInfo(
                "Mind Blast", "Por Corp Wis",
                218,
                Core.AOS ? 9002 : 9032,
                Reagent.BlackPearl,
                Reagent.MandrakeRoot,
                Reagent.Nightshade,
                Reagent.SulfurousAsh
            );
//private int intel;
        public override SpellCircle Circle { get { return SpellCircle.Fifth; } }
        public override int Sound { get { return 0x213; } }

        public override int ManaCost { get { return 17; } } //Loki edit

        public MindBlastSpell( Mobile caster, Item scroll ) : base( caster, scroll, m_Info )
        {
            if ( Core.AOS )
                m_Info.LeftHandEffect = m_Info.RightHandEffect = 9002;
        }

        public override double GetResistPercent( Mobile target )
        {
            return 59.0;
        }
         public override TimeSpan GetCastDelay()
        {
            return TimeSpan.FromSeconds(2.8);
        }
         public override void OnPlayerCast()
        {
            if (SphereSpellTarget is Mobile)
                Target((Mobile)SphereSpellTarget);
        }
       
        public override void OnCast()
        {
            Caster.Target = new InternalTarget( this );
        }

        public override bool CheckCast( )
        {
           
       PlayerMobile mobile = (PlayerMobile)Caster;
       if(Caster.RawInt < 80 )
       {
           Caster.SendAsciiMessage("You need at least 80 int to cast this spell!");
       return false;
          }
          else    
                return true;
        }
   
   
       
        private void AosDelay_Callback( object state )
        {
            object[] states = (object[])state;
            Mobile caster = (Mobile)states[0];
            Mobile target = (Mobile)states[1];
            Mobile defender = (Mobile)states[2];
            int damage = (int)states[3];

            if ( caster.HarmfulCheck( defender ) )
            {
                SpellHelper.Damage( this, target, Utility.RandomMinMax( damage, damage + 3 ), 0, 0, 100, 0, 0 );

                target.FixedParticles( 0x374A, 10, 15, 5038, 1181, 2, EffectLayer.Head );
                target.PlaySound( 0x213 );
            }
        }

        public override bool DelayedDamage{ get{ return !Core.AOS; } }

        public void Target( Mobile m )
        {
            if ( !Caster.CanSee( m ) )
            {
                Caster.SendLocalizedMessage( 500237 ); // Target can not be seen.
            }
            else if ( Core.AOS )
            {
                if ( Caster.CanBeHarmful( m ) && CheckSequence() )
                {
                    Mobile from = Caster, target = m;

                    SpellHelper.Turn( from, target );

                    SpellHelper.CheckReflect( (int)this.Circle, ref from, ref target );

                    int damage = (int)((Caster.Skills[SkillName.Magery].Value + Caster.Int) / 6);
                   
                   
                    /*        if ( CheckResisted( m ) )
                {
                    
                    damage = (int)(damage * 0.7);
                                     // You feel yourself resisting magical energy.
                }*/

                    if ( damage > 25 )
                        damage = 25;

                    Timer.DelayCall( TimeSpan.FromSeconds( 2.7 ),
                        new TimerStateCallback( AosDelay_Callback ),
                        new object[]{ Caster, target, m, damage } );
                }
            }
            else if ( CheckHSequence( m ) )
            {
                Mobile from = Caster, target = m;

                SpellHelper.Turn( from, target );

                SpellHelper.CheckReflect( (int)this.Circle, ref from, ref target );

                // Algorithm: (highestStat - lowestStat) / 2 [- 50% if resisted]

                int highestStat = target.Str, lowestStat = target.Str;

                if ( target.Dex > highestStat )
                    highestStat = target.Dex;

                if ( target.Dex < lowestStat )
                    lowestStat = target.Dex;

                if ( target.Int > highestStat )
                    highestStat = target.Int;

                if ( target.Int < lowestStat )
                    lowestStat = target.Int;

                if ( highestStat > 100 )
                    highestStat = 100;

                if ( lowestStat > 100 )
                    lowestStat = 100;

                double damage = GetDamageScalar(m)*(highestStat - lowestStat) / 2;
                if ( damage > 25 )
                    damage = 25;

                if ( CheckResisted( target ) )
                {
                    damage /= 2;
                    Caster.SendAsciiMessage (28, "Tu objetivo resiste la magia");
                    m.SendAsciiMessage(93,"Sientes como resistes la magia");
                }

                from.FixedParticles( 0x374A, 10, 15, 2038, EffectLayer.Head );

                target.FixedParticles( 0x374A, 10, 15, 5038, EffectLayer.Head );
                target.PlaySound( 0x213 );

                SpellHelper.Damage( this, target, damage, 0, 0, 100, 0, 0 );
            }

            FinishSequence();
        }

        public override double GetSlayerDamageScalar( Mobile target )
        {
            return 1.0; //This spell isn't affected by slayer spellbooks
        }

        private class InternalTarget : Target
        {
            private MindBlastSpell m_Owner;

            public InternalTarget( MindBlastSpell owner ) : base( Core.ML ? 10 : 12, false, TargetFlags.Harmful )
            {
                m_Owner = owner;
            }

            protected override void OnTarget( Mobile from, object o )
            {
                if ( o is Mobile )
                    m_Owner.Target( (Mobile)o );
            }

            protected override void OnTargetFinish( Mobile from )
            {
                m_Owner.FinishSequence();
            }
        }
    }
}




Crash Teleport;

Exception:
System.InvalidCastException: Unable to cast object of type 'Server.Mobiles.ChaosDragoonEliteyew' to type 'Server.Mobiles.PlayerMobile'.
at Server.Spells.Third.TeleportSpell.CheckCast()
at Server.Spells.Spell.DirectCast()
at Server.Mobiles.MageAI.OnFailedMove()
at Server.Mobiles.MageAI.DoActionCombat()
at Server.Mobiles.BaseAI.AITimer.OnTick()
at Server.Timer.Slice()
at Server.Core.Main(String[] args)



Code:
using Server.Items;
using Server.Regions;
using Server.Network;
using Server.Mobiles;
using Server.Targeting;
using Server.Engines.XmlSpawner2;

namespace Server.Spells.Third
{
    public class TeleportSpell : MagerySpell
    {
        public override SpellCircle Circle { get { return SpellCircle.Third; } }
        public override int Sound { get { return 0x1FE; } }
       
        public override bool CanTargetGround { get { return true; } }

        private static readonly SpellInfo m_Info = new SpellInfo(
                "Teleport", "Rel Por",
                263,
                9031,
                Reagent.Bloodmoss,
                Reagent.MandrakeRoot
            );

        public TeleportSpell( Mobile caster, Item scroll ) : base( caster, scroll, m_Info )
        {
        }

        public override bool CheckCast()
        {
            if (Caster.Region is HouseRegion)
            {
                Caster.SendAsciiMessage("You cannot cast that spell here!");
                return false;
            }
            //ArrayList list = XmlAttach.FindAttachments(m,typeof(Xmlmorph));
             XmlMorph morph = (XmlMorph)XmlAttach.FindAttachment(this, typeof(XmlMorph));

                if (morph != null)
                {
            Caster.LocalOverheadMessage(MessageType.Regular, 906, true, "You cant not cast that spell");
            DoFizzle();
            return false;
                }
    PlayerMobile mobile = (PlayerMobile)Caster;
       Container pack = Caster.Backpack;

        Item am = Caster.Backpack.FindItemByType(typeof(cargamento));
        if (am != null)
        {
          ;
            DoFizzle();
            return false;
        }

            return SpellHelper.CheckTravel( Caster, TravelCheckType.TeleportFrom );
        }

        public override void OnPlayerCast()
        {
            Target(SphereSpellTarget);
        }

        public override void OnCast()
        {
            Caster.Target = new InternalTarget( this );
        }

        public void Target( object op )
        {
            IPoint3D p = op as IPoint3D;
            Mobile mobileTarget = op as Mobile;

            IPoint3D orig = p;
            Map map = Caster.Map;

            SpellHelper.GetSurfaceTop( ref p );
            if( Caster.HasTrade )
            {
          //      Caster.SendMessage( " );
                DoFizzle();
                return;
            }
             XmlMorph morph = (XmlMorph)XmlAttach.FindAttachment(this, typeof(XmlMorph));

                if (morph != null)
                {
       //    
            DoFizzle();
            return;
                }

            PlayerMobile mobile = (PlayerMobile)Caster;
       Container pack = Caster.Backpack;

        Item am = Caster.Backpack.FindItemByType(typeof(cargamento));
        if (am != null)
        {
           //
            DoFizzle();
            return;
        }
           
            if ( !SpellHelper.CheckTravel( Caster, TravelCheckType.TeleportFrom ) )
            {
            }
            else if ( !SpellHelper.CheckTravel( Caster, map, new Point3D( p ), TravelCheckType.TeleportTo ) )
            {
            }
            else if (mobileTarget == null && ( map == null || !map.CanSpawnMobile(p.X, p.Y, p.Z)))
            {
                Caster.SendLocalizedMessage( 501942 ); // That location is blocked.
            }
            else if (Region.Find(new Point3D(p),map) is HouseRegion)
            {
                Caster.SendLocalizedMessage( 501942 ); // That location is blocked.
            }
            else if ( SpellHelper.CheckMulti( new Point3D( p ), map ) )
            {
                Caster.SendLocalizedMessage( 501942 ); // That location is blocked.
            }
            else if (SphereSpellTarget is BaseWand)
            {
                BaseWand bw = SphereSpellTarget as BaseWand;
                bw.RechargeWand(Caster, this);
            }
            else if ( CheckSequence() )
            {
                if (op != null && Caster.InLOS(p) && Caster.InRange(new Point2D(p.X,p.Y),14))
                {
                    Mobile m = Caster;

                    Point3D from = m.Location;
                    Point3D to = new Point3D(p);

                    m.Location = to;
                    m.RevealingAction();
                    m.ProcessDelta();

                    Effects.SendLocationParticles(EffectItem.Create(from, m.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
                    Effects.SendLocationParticles(EffectItem.Create(to, m.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 5023);

                    m.PlaySound(Sound);

                    IPooledEnumerable eable = m.GetItemsInRange(0);

                    foreach (Item item in eable)
                    {
                        if (item is Server.Spells.Sixth.ParalyzeFieldSpell.InternalItem || item is Server.Spells.Fifth.PoisonFieldSpell.InternalItem || item is Server.Spells.Fourth.FireFieldSpell.InternalItem)
                            item.OnMoveOver(m);
                    }

                    eable.Free();
                }
                else
                    Caster.SendAsciiMessage("You can't see that target!");
            }

            FinishSequence();
        }

        public class InternalTarget : Target
        {
            private readonly TeleportSpell m_Owner;

            public InternalTarget( TeleportSpell owner ) : base( 12, true, TargetFlags.None )
            {
                m_Owner = owner;
            }

            protected override void OnTarget( Mobile from, object o )
            {
                IPoint3D p = o as IPoint3D;

                if ( p != null )
                    m_Owner.Target( o );
            }

            protected override void OnTargetFinish( Mobile from )
            {
                m_Owner.FinishSequence();
            }
        }
    }
}
 
For Mindblast remove the line in CheckCast()
Code:
PlayerMobile mobile = (PlayerMobile)Caster;

and for Teleport I guess you want it to be like this
Code:
public override bool CheckCast()
{
    if (Caster.Region is HouseRegion)
    {
        Caster.SendAsciiMessage("You cannot cast that spell here!");
        return false;
    }
    //ArrayList list = XmlAttach.FindAttachments(m,typeof(Xmlmorph));
    XmlMorph morph = (XmlMorph)XmlAttach.FindAttachment(this, typeof(XmlMorph));

    if (morph != null)
    {
        Caster.LocalOverheadMessage(MessageType.Regular, 906, true, "You can not cast that spell");
        DoFizzle();
        return false;
    }
   
    if(Caster is PlayerMobile)
    {
        Item am = Caster.Backpack.FindItemByType(typeof(cargamento));
        if (am != null)
        {
            DoFizzle();
            return false;
        }
    }

    return SpellHelper.CheckTravel(Caster, TravelCheckType.TeleportFrom);
}

And one general hint. If it crashes in one spell, after you changed / added something, try to understand why it crashes. It will save you from more crashes in the long run.
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back