/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\mobiles\ml\InterredGrizzle.cs
Lines of code: 241
***********************************************************/


using System;
using System.Collections;
using Server.Items;
using Server.Network;
using Server.Mobiles;

namespace Server.Mobiles
{
	[CorpseName( "an interred grizzle corpse" )]
	public class InterredGrizzle : BaseCreature
	{

		[Constructable]
		public InterredGrizzle() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "An Interred Grizzle";
			Body = 259;			
			BaseSoundID = 589;

			SetStr( 288, 320 );
			SetDex( 121, 170 );
			SetInt( 300, 400 );

			SetHits( 432, 550 );

			SetDamage( 16, 19 );

			SetDamageType( ResistanceType.Physical, 50 );
			SetDamageType( ResistanceType.Energy, 50 );

			SetResistance( ResistanceType.Physical, 60, 70 );
			SetResistance( ResistanceType.Fire, 50, 60 );
			SetResistance( ResistanceType.Cold, 20, 30 );
			SetResistance( ResistanceType.Poison, 30, 40 );
			SetResistance( ResistanceType.Energy, 30, 40 );

			SetSkill( SkillName.EvalInt, 85.0, 100.0 );
			SetSkill( SkillName.Magery, 100.0, 115.0 );
			SetSkill( SkillName.SpiritSpeak, 110.0 );
			SetSkill( SkillName.Necromancy, 100.0 );
			SetSkill( SkillName.MagicResist, 90.0, 110.0);
			SetSkill( SkillName.Tactics, 80.1, 90.0 );
			SetSkill( SkillName.Wrestling, 90.1, 110.0 );

			Fame = 12000;
			Karma = -12000;

			VirtualArmor = 60;
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.FilthyRich, 1 );
			AddLoot( LootPack.UltraRich, 1 );
		}
		
		public override int GetAngerSound()
		{
			return 1410;
		}

		public override int GetIdleSound()
		{
			return 1409;
		}

		public override int GetAttackSound()
		{
			return 1408;
		}

		public override int GetHurtSound()
		{
			return 1411; 
		}

		public override int GetDeathSound()
		{
			return 1407; 
		}

		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if (from!=null && !willKill )
			{
				if ( from != this && 0.2 >= Utility.RandomDouble())
				{
					this.PlaySound( 1411 );
					SpillFluids(from);
					SpillFluids(from);
					SpillFluids(from);
				}
			}

			base.OnDamage( amount, from, willKill );
		}

		public void SpillFluids(Mobile from)
		{
		if(from==null)return;
		
			Map map = from.Map;

			if ( map == null )
				return;

				int x = this.X + Utility.RandomMinMax( -1, 1 );
				int y = this.Y + Utility.RandomMinMax( -1, 1 );
				int z = this.Z;

				z = map.GetAverageZ( x, y );

				Item item = new GrizzleAcid();

				item.MoveToWorld( new Point3D( x, y, z ), map );
		}
		
		public override int Meat{ get{ return 4; } }
		public override int TreasureMapLevel{ get{ return 4; } }
        public override bool BleedImmune{ get{ return true; } }
        public override bool AutoDispel{ get{ return true; } }
		public override bool Unprovokable{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override bool IsMLCreature { get { return true;} }
		public override bool NoFlee { get { return true; } }		

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

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

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
		}
	}
}





namespace Server.Items
{

public class GrizzleAcid : Item
	{
		private TimeSpan m_Duration;
		private int m_MinDamage;
		private int m_MaxDamage;

		private DateTime m_Created;

		private bool m_Drying;

		private Timer m_Timer;

		[CommandProperty( AccessLevel.GameMaster )]
		public bool Drying
		{
			get
			{
				return m_Drying;
			}
			set
			{
				m_Drying = value;

				if( m_Drying )
					Hue = 152;		
			}
		}


		[CommandProperty( AccessLevel.GameMaster )]
		public TimeSpan Duration{ get{ return m_Duration; } set{ m_Duration = value; } }

		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				m_MinDamage = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxDamage
		{
			get
			{
				return m_MaxDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				if ( value < MinDamage )
					value = MinDamage;

				m_MaxDamage = value;
			}
		}

		[Constructable]
		public GrizzleAcid() : this( TimeSpan.FromSeconds( 10.0 ), 5, 20 )
		{
		}

		public override string DefaultName { get { return "infernal ooze"; } }

		[Constructable]
		public GrizzleAcid( TimeSpan duration, int minDamage, int maxDamage )
			: base( 0x122A )
		{
			Hue = 253;
			ItemID = Utility.RandomList(4650, 4651);
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
			m_Created = DateTime.Now;
			m_Duration = duration;


			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), new TimerCallback( OnTick ) );
		}

		public override void OnAfterDelete()
		{
			if( m_Timer != null )
				m_Timer.Stop();
		}

		int corrode=0;
		
		private void OnTick()
		{
			DateTime now = DateTime.Now;
			TimeSpan age = now - m_Created;
			

			if( age > m_Duration )
				Delete();
			else
			{
				if( !Drying && age > (m_Duration - age) )
					Drying = true;

				ArrayList toDamage = new ArrayList();

				corrode++;
				
				foreach( Mobile m in GetMobilesInRange( 0 ) )
				{
					BaseCreature bc = m as BaseCreature;

					if( m.Alive && !m.IsDeadBondedPet && m.AccessLevel==AccessLevel.Player &&(bc == null || bc.Controlled || bc.Summoned) )
					{
						toDamage.Add( m );

						if(corrode>5)	BaseArmor.Corrode(m,1+Utility.Random(5),1,"The acid corrodes your armor!");
									
					}
				}
				
				if(corrode>5)corrode=0;

				for( int i = 0; i < toDamage.Count; i++ )
					Damage( (Mobile)toDamage[i] );
			}
		
		}


		public override bool OnMoveOver( Mobile m )
		{
			Damage( m );
			return true;
		}

		public void Damage( Mobile m )
		{
			if(HarmItem.ShouldHarm(m))m.Damage( Utility.RandomMinMax( MinDamage, MaxDamage ) );	
		}
		
		//public override double HitArmorCorruptChance{ get{ return 0.1; } }	

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

		public override void Serialize( GenericWriter writer )
		{
			//Don't serialize these
		}

		public override void Deserialize( GenericReader reader )
		{
		this.Delete();
		}
	}

}