/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\ML Peerless + misc areas\demitel\dragon den\Dracolich.cs
Lines of code: 149
***********************************************************/


using System;
using Server;
using Server.Items;

namespace Server.Mobiles
{
	[CorpseName( "a dracolich corpse" )]
	public class Dracolich : BaseCreature
	{
		public int x, y, z; 
		public int maxspawns = 0;
		
		[Constructable]
		public Dracolich () : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "a dracolich";
			Body = 104;
			Hue = 1175;
			BaseSoundID = 0x488;

			SetStr( 898, 1030 );
			SetDex( 68, 200 );
			SetInt( 2488, 2620 );

			SetHits( 2005, 2599 );

			SetDamage( 29, 35 );

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

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

			SetSkill( SkillName.EvalInt, 120.0 );
			SetSkill( SkillName.Magery, 120.0 );
			SetSkill( SkillName.MagicResist, 100.3, 130.0 );
			SetSkill( SkillName.Tactics, 97.6, 100.0 );
			SetSkill( SkillName.Wrestling, 120.0 );
			SetSkill( SkillName.Necromancy, 120.0 );
			SetSkill( SkillName.SpiritSpeak, 120.0 );

			Fame = 22500;
			Karma = -22500;

			VirtualArmor = 80;

			PackItem( new Bone( 12 ) );
			PackItem( new Gold( Utility.RandomMinMax( 6510, 8000 ) ) );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.FilthyRich, 4 );
			AddLoot( LootPack.Gems, 15 );
		}

		public override bool ReacquireOnMovement{ get{ return true; } }
		public override bool HasBreath{ get{ return true; } } // fire breath enabled
		public override int BreathFireDamage{ get{ return 0; } }
		public override int BreathColdDamage{ get{ return 100; } }
		public override bool Unprovokable{ get{ return Core.SE; } }
		public override bool Uncalmable{ get{ return Core.SE; } }
		public override int BreathEffectHue{ get{ return 0x480; } }
		public override double BonusPetDamageScalar{ get{ return (Core.SE)? 2.5 : 1.0; } }

		public override bool AutoDispel{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override bool BleedImmune{ get{ return true; } }
		
		public override void OnDamagedBySpell( Mobile attacker )
		{
			if ( 0.2 >= Utility.RandomDouble() && !attacker.InRange( this, 3 ) ) //Prevents extra bones on meleers with hit spell weps
				BeginBoneDrop( attacker );
		}
		
		public override void OnGotMeleeAttack( Mobile attacker )
		{
			if ( 0.2 >= Utility.RandomDouble() )
				BeginBoneDrop( attacker );
		}
		
		public virtual void BeginBoneDrop( Mobile defender )
		{
			if ( Deleted )
				return;
				
			if ( maxspawns < 15)
			{
				defender.SendMessage("A bone falls from the dracolich!");
				new DracolichBone().MoveToWorld( Location, Map );
				x = this.X;
				y = this.Y;
				z = this.Z;
					
				PlaySound( 0x48E );

				Timer.DelayCall( TimeSpan.FromSeconds( 5.0 ), new TimerStateCallback( Appear_Callback ), defender );
			}
		}	
		
		private void Appear_Callback( object state )
		{
			Mobile defender = state as Mobile;
			if ( defender != null )
			{
				defender.Frozen = false;
	
				Mobile spawn;
				
				switch ( Utility.Random( 6 ) )
				{
					default:
					case 0: 
						spawn = new LichLord(); 
						break;
					case 1: 
						spawn = new Lich(); 
						break;
					case 3: 
						if ( 0.4 >= Utility.RandomDouble() )
							spawn = new Wight(); 
						else
							spawn = new Wraith();
						break;
				}
					
				spawn.MoveToWorld( new Point3D( x, y, z), Map );
				maxspawns += 1; 
			}
		}
		
		public class DracolichBone : Item
		{
			public DracolichBone() : base( 3966 )
			{
				Movable = false;
				Hue = 1175;
				Name = "a bone piece";

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

			public DracolichBone( 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 Dracolich( 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();
		}
	}
}