/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\Mobiles\Monsters\Ants\AntLion.cs
Lines of code: 307
***********************************************************/


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

namespace Server.Mobiles
{
	[CorpseName( "an ant lion corpse" )]
	public class AntLion : BaseCreature
	{
		[Constructable]
		public AntLion() : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "an ant lion";
			Body = 787;
			BaseSoundID = 1006;

			SetStr( 296, 320 );
			SetDex( 81, 105 );
			SetInt( 36, 60 );

			SetHits( 151, 162 );

			SetDamage( 7, 21 );

			SetDamageType( ResistanceType.Physical, 70 );
			SetDamageType( ResistanceType.Poison, 30 );

			SetResistance( ResistanceType.Physical, 45, 60 );
			SetResistance( ResistanceType.Fire, 25, 35 );
			SetResistance( ResistanceType.Cold, 30, 40 );
			SetResistance( ResistanceType.Poison, 40, 50 );
			SetResistance( ResistanceType.Energy, 30, 35 );

			SetSkill( SkillName.MagicResist, 70.0 );
			SetSkill( SkillName.Tactics, 90.0 );
			SetSkill( SkillName.Wrestling, 90.0 );

			Fame = 4500;
			Karma = -4500;

			VirtualArmor = 45;

			PackItem( new Bone( 3 ) );
			PackItem( new FertileDirt( Utility.RandomMinMax( 1, 5 ) ) );

			switch ( Utility.Random( 4 ) )
			{
				case 0: PackItem( new DullCopperOre( Utility.RandomMinMax( 1, 10 ) ) ); break;
				case 1: PackItem( new ShadowIronOre( Utility.RandomMinMax( 1, 10 ) ) ); break;
				case 2: PackItem( new CopperOre( Utility.RandomMinMax( 1, 10 ) ) ); break;
				case 3: PackItem( new BronzeOre( Utility.RandomMinMax( 1, 10 ) ) ); break;
			}
			
			if ( 0.08 >= Utility.RandomDouble() )
			{
			Container pack = new AdventurerSkeleton();
			
			switch ( Utility.Random( 9 ) )
			{
				case 0: //Archer 
				pack.DropItem( new Arrow( Utility.RandomMinMax( 25, 35 ) ) );
				pack.DropItem( new Bolt( Utility.RandomMinMax( 25, 35 ) ) );
				pack.DropItem( new Bow());
				pack.DropItem( new Crossbow());
				break;
				
				case 1: //Warrior
				pack.DropItem( new Bandage( Utility.RandomMinMax( 35, 60 ) ) );
				
				for (int l = 0; l < 2; l++)
				{
					switch ( Utility.Random( 8 ))
					{
						case 0: pack.DropItem( new RingmailArms() ); break;
						case 1: pack.DropItem( new RingmailChest() ); break;
						case 2: pack.DropItem( new RingmailGloves() ); break;
						case 3: pack.DropItem( new RingmailLegs() ); break;
						case 4: pack.DropItem( new PlateGorget() ); break;
						case 5: pack.DropItem( new PlateGloves() ); break;
						case 6: pack.DropItem( new StuddedArms() ); break;
						case 7: pack.DropItem( new StuddedChest() ); break;
					}
				}
				
				for (int k = 0; k < 4; k++)
				{
					switch ( Utility.Random( 12 ))
					{
						case 0: pack.DropItem( new Mace() ); break;
						case 1: pack.DropItem( new ExecutionersAxe() ); break;
						case 2: pack.DropItem( new Scimitar() ); break;
						case 3: pack.DropItem( new Dagger() ); break;
						case 4: pack.DropItem( new Bardiche() ); break;
						case 5: pack.DropItem( new WarMace() ); break;
						case 6: pack.DropItem( new Maul() ); break;
						case 7: pack.DropItem( new BattleAxe() ); break;
						case 8: pack.DropItem( new Pike() ); break;
						case 9: pack.DropItem( new Spear() ); break;
						case 10: pack.DropItem( new DoubleBladedStaff() ); break;
						case 11: pack.DropItem( new Halberd()); break;
					}
				}
				break;
				
				case 2: //Mage
				pack.DropItem( new BlackPearl( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new Bloodmoss( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new Nightshade( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new SulfurousAsh( Utility.Random( 10, 30 ) ) ); 
				pack.DropItem( new MandrakeRoot( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new Ginseng( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new Spellbook());
				pack.DropItem( new WizardsHat());
				break;
				
				case 3: //Necromancer
				pack.DropItem( new NoxCrystal( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new PigIron( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new DaemonBlood( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new GraveDust( Utility.Random( 10, 30 ) ) ); 
				pack.DropItem( new BatWing( Utility.Random( 10, 30 ) ) );
				pack.DropItem( new NecromancerSpellbook());
				pack.DropItem( new BoneHelm());
				pack.DropItem( new Scythe());
				break;
				
				case 4: //Paladin
				pack.DropItem( new BookOfChivalry());
				pack.DropItem( new Longsword());
				pack.DropItem( new PlateHelm());
				pack.DropItem( new PlateGloves());
				pack.DropItem( new PlateChest());
				pack.DropItem( new OrderShield());
				pack.DropItem( new Gold( Utility.Random( 200, 375 ) ) );
				break;
				
				case 5: //Tamer
				pack.DropItem( new ShepherdsCrook());
				pack.DropItem( new Bandage( Utility.RandomMinMax( 15, 35 ) ) );
				pack.DropItem( new RawRibs( Utility.RandomMinMax( 2, 6 ) ) );
				pack.DropItem( new BallOfSummoning());
				break;
				
				case 6: //Samurai
				pack.DropItem( new BookOfBushido());
			
				for (int i = 0; i < 3; i++)
				{
					switch ( Utility.Random( 8 ))
					{
						case 0: pack.DropItem( new Tessen() ); break;
						case 1: pack.DropItem( new Wakizashi() ); break;
						case 2: pack.DropItem( new Nunchaku() ); break;
						case 3: pack.DropItem( new Daisho() ); break;
						case 4: pack.DropItem( new Sai() ); break;
						case 5: pack.DropItem( new Tekagi() ); break;
						case 6: pack.DropItem( new Kama() ); break;
						case 7: pack.DropItem( new Katana() ); break;
					}
				}
				break;
				
				case 7: //Ninja
				pack.DropItem( new BookOfNinjitsu());
				pack.DropItem( new SmokeBomb());
				
				for (int j = 0; j < 3; j++)
				{
					switch ( Utility.Random( 8 ))
					{
						case 0: pack.DropItem( new Tessen() ); break;
						case 1: pack.DropItem( new Wakizashi() ); break;
						case 2: pack.DropItem( new Nunchaku() ); break;
						case 3: pack.DropItem( new Daisho() ); break;
						case 4: pack.DropItem( new Sai() ); break;
						case 5: pack.DropItem( new Tekagi() ); break;
						case 6: pack.DropItem( new Kama() ); break;
						case 7: pack.DropItem( new Katana() ); break;
					}
				}
				break;
				
				case 8: //Arcanist
				pack.DropItem( new SpellweavingBook());
				pack.DropItem( new RuneBlade() ); 
				pack.DropItem( new MaleElvenRobe() ); 
			
				for (int i = 0; i < 3; i++)
				{
					switch ( Utility.Random( 8 ))
					{
						case 0: pack.DropItem( new WoodlandChest() ); break;
						case 1: pack.DropItem( new WoodlandArms() ); break;
						case 2: pack.DropItem( new WoodlandGloves() ); break;
						case 3: pack.DropItem( new WoodlandGorget() ); break;
						case 4: pack.DropItem( new WoodlandLegs() ); break;
						case 5: pack.DropItem( new LeafGloves() ); break;
						case 6: pack.DropItem( new LeafLegs() ); break;
						case 7: pack.DropItem( new LeafChest() ); break;
						case 8: pack.DropItem( new LeafGorget() ); break;
						case 9: pack.DropItem( new LeafArms() ); break;
					}
				}
				break;
			}

			PackItem( pack );
			}

		}

		public override int GetAngerSound()
		{
			return 0x5A;
		}

		public override int GetIdleSound()
		{
			return 0x5A;
		}

		public override int GetAttackSound()
		{
			return 0x164;
		}

		public override int GetHurtSound()
		{
			return 0x187;
		}

		public override int GetDeathSound()
		{
			return 0x1BA;
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Average, 2 );
		}

		public override void OnDamage( int amount, Mobile defender, bool willKill )
		{
			if (defender!=null && 0.1 >= Utility.RandomDouble() )
				BeginTunnel( defender );
			else if (defender!=null && 0.4 >= Utility.RandomDouble() && !defender.InRange( this, 2 ))
				SpitPoison( defender );
				
		base.OnDamage( amount, defender, willKill );
		}
		
		public virtual void SpitPoison( Mobile defender )
		{
			if(defender==null)return;
			defender.SendMessage( "The antlion spits poison at you");
			defender.ApplyPoison( this, Poison.Greater );
			Effects.SendPacket( defender, defender.Map, new HuedEffect( EffectType.Moving, Serial.Zero, Serial.Zero, 540, this.Location, defender.Location, 10, 0, false, false, 68, 0 ) );
			AOS.Damage( defender, this, Utility.RandomMinMax( 5, 20 ), 0, 0, 0, 100, 0 );
		}	
		
		
		public virtual void BeginTunnel( Mobile defender )
		{
			if ( Deleted || defender==null)
				return;
				
			defender.SendMessage("The antlion digs deep into the ground");
			new DugTunnel().MoveToWorld( Location, Map );

			this.Hits += 25;
			this.Hidden = true;
			this.Frozen = true;
			this.Blessed = true;
			
				int x = this.X;
				int y = this.Y;
				int z = this.Z - 100;
				this.MoveToWorld( new Point3D( x, y, z ), Map );
					
			PlaySound( 0x247 );

			Timer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerStateCallback( Appear_Callback ), defender );
		}	
		
		private void Appear_Callback( object state )
		{
			Mobile defender = state as Mobile;

			if ( defender != null )
			{
				defender.Frozen = false;
				defender.Combatant = null;
				
				if (!defender.InRange( this, 12 ))
				{
					this.MoveToWorld( new Point3D( this.X, this.Y, 0 ), Map );
				}
				else
				{
					this.Location = defender.Location;
					int BurstAttack = Utility.RandomMinMax( 20, 50 );
					AOS.Damage(defender, this, BurstAttack, 100, 0, 0, 0, 0 );
				}
				new DugTunnel().MoveToWorld( Location, Map );
				this.Frozen = false;
				this.Hidden = false;
				this.Blessed = false;
				defender.SendMessage("The antlion bursts out of the ground");
				PlaySound ( 0x164 );
			}
		}
		
		public class DugTunnel : Item
		{
		public override bool DisplayWeight { get { return ( false ); } }			
		
			public DugTunnel() : base( 4216 )
			{
				Movable = false;
				Hue = 1;
				Name = "a deep tunnel";

				Timer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerCallback( Delete ) );
			}

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

			public override void Serialize( GenericWriter writer )
			{
				base.Serialize(writer);

				writer.Write( (int) 0 );
			}

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

				int version = reader.ReadInt();

				Delete();
			}
			
		}

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

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

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