
//////////////////////////
//Created by LostSinner//
////////////////////////
using System;
using Server;

namespace Server.Items
{
    public class ISTile3 : Item
    {
        private int m_Damage;

        [CommandProperty(AccessLevel.GameMaster)]
        public int Damage
        {
            get { return m_Damage; }
            set
            {
                m_Damage = value;
                if ( m_Damage < 1 ) m_Damage = 1;
                Name = String.Format( "explosion trap [{0}% dmg]", m_Damage );
            }
        }

        [Constructable]
        public ISTile3() : this( 35 )
        {
        }

        [Constructable]
        public ISTile3( int damage ) : base( 1313 )
        {
            Weight = 1.0;
            Visible = false;
            Movable = false;
            Hue = 1;
            m_Damage = damage;
            Name = String.Format( "explosion trap [{0}% dmg]", m_Damage );
        }

        public ISTile3(Serial serial) : base(serial)
        {
        }

        public override bool OnMoveOver(Mobile m)
        {
            if (!m.Player || !m.Alive || m.Blessed || m.AccessLevel > AccessLevel.Player)
                return true; 
            
            if ( !BaseTrap.CheckResisted( m ) )
            {
               m.RevealingAction();
               m.FixedParticles(0x36BD, 20, 10, 5044, EffectLayer.Head);
               m.PlaySound(0x307);
               int dmg = Engines.XmlSpawner2.XmlSpecial.PercentualDamage( ISTile5.GetDamage( m_Damage, m ), m );
               m.Hits -= dmg;
               ISTile5.SendDmgPacket( m, dmg );
               if (m.Hits < 2)
                  m.Kill();
            }
            
            return true;
        }

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 1 ); // version
			
			writer.Write( m_Damage );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			switch( version )
			{
				case 1:
				{
					m_Damage = reader.ReadInt();
					goto case 0;
				}
            case 0:
				{
					if ( version < 1 )
					{
                  m_Damage = 35;
               }
               Name = String.Format( "explosion trap [{0}% dmg]", m_Damage );
					break;
				}
			}
		}
    }
}