/**********************************************************
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\MirageDesert\BloodBeastMirage.cs
Lines of code: 206
***********************************************************/


using System;
using System.Collections;
using Server;
using Server.Items;
using Server.Engines.CannedEvil;
using System.Collections.Generic;


namespace Server.Mobiles
{
	[CorpseName( "the remains of a blood beast" )]
	public class BloodBeastMirage : basedemitel
	{
		public override bool DeleteCorpseOnDeath{ get{ return true; } }
		public override bool IgnoreYoungProtection { get { return Core.ML; } }
		public override bool AlwaysMurderer{ get{ return true; } }
		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 6 ) )
			{
				default:
				case 1: return WeaponAbility.WhirlwindAttack;
				case 2: return WeaponAbility.WhirlwindAttack;
				case 3: return WeaponAbility.BleedAttack;
				case 4: return WeaponAbility.BleedAttack;
				case 5: return WeaponAbility.InfectiousStrike;
				case 6: return WeaponAbility.WhirlwindAttack;
			}
		}
		
		[Constructable]
		public BloodBeastMirage() : base( AIType.AI_Melee, FightMode.Closest, 0.2, 0.4 )
		{
			Name = "The Blood Beast";
			Body = 318;
			Hue = 16385;
			BaseSoundID = 0x3E9;

			SetStr( 2000, 2000 );
			SetDex( 200, 200 );
			SetInt( 1000, 1000 );

			SetHits( 1000 );

			SetDamage( 25, 38 );

			SetDamageType( ResistanceType.Poison, 25 );
			SetDamageType( ResistanceType.Cold, 50 );
			SetDamageType( ResistanceType.Physical, 0 );
			SetDamageType( ResistanceType.Fire, 25 );

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

			SetSkill( SkillName.Poisoning, 200.0, 200.0 );
			SetSkill( SkillName.Meditation, 200.0, 200.0 );
			SetSkill( SkillName.MagicResist, 450.0, 450.0 );
			SetSkill( SkillName.Tactics, 120.0, 120.0 );
			SetSkill( SkillName.Wrestling, 100.0, 130.0 );

			
			VirtualArmor = 80;
		}
		
		public override bool OnBeforeDeath()
		{
			Gold gold = new Gold( Utility.RandomMinMax( 5400, 8750 ) );
			gold.MoveToWorld( Location, Map );

			if ( 0.8 > Utility.RandomDouble() ) {
				BloodBeastIdol item = new BloodBeastIdol();
				item.MoveToWorld( Location, Map );
			}

			Effects.SendLocationEffect( Location, Map, 0x376A, 10, 1 );
			return true;
		}		

		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if ( from != null && from != this)
			{
				if ( 0.025 > Utility.RandomDouble() )
				for(int i = 1+Utility.Random(5);i>0;i--)
				Timer.DelayCall( TimeSpan.FromSeconds( 0.5 ), new TimerStateCallback( CreateBlood_Callback ), from );
			}
			
			
		base.OnDamage(amount,from,willKill);
		}

		public virtual void CreateBlood_Callback( object state )
		{
			Mobile from = (Mobile)state;
			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 );

				BeastyBloodMirage bone = new BeastyBloodMirage();

				bone.Hue = 0;
				bone.Name = "Beasty Blood";
				switch (Utility.Random(3))
				{
				case 0: bone.ItemID = 4650; break;
				case 1: bone.ItemID = 4651; break;
				case 2: bone.ItemID = 4653; break;
				}
				

				bone.MoveToWorld( new Point3D( x, y, z ), map );
		
		}		


		public override void GenerateLoot()
		{
			AddLoot( LootPack.SuperBoss, 2 );
			AddLoot( LootPack.UltraRich, 3 );
			AddLoot( LootPack.MedScrolls, 2 );
		}

		

		public void DrainLife()
		{
			ArrayList list = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 8 ) )
			{
				if ( m == this || !CanBeHarmful( m ) )
					continue;

				if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team) )
					list.Add( m );
				else if ( m.Player )
					list.Add( m );
			}

			foreach ( Mobile m in list )
			{
				DoHarmful( m );

				m.FixedParticles( 0x374A, 10, 15, 5013, 0x496, 0, EffectLayer.Waist );
				m.PlaySound( 0x231 );

				m.SendMessage( "You feel the life drain out of you!" );

				int toDrain = Utility.RandomMinMax( 20, 60 );

				Hits += toDrain;
				m.Damage( toDrain, this );
			}
		}

		public override void OnGaveMeleeAttack( Mobile defender )
		{
			base.OnGaveMeleeAttack( defender );

			if ( 0.1 >= Utility.RandomDouble() )
				DrainLife();
		}

		public override void OnGotMeleeAttack( Mobile attacker )
		{
			base.OnGotMeleeAttack( attacker );

			if ( 0.1 >= Utility.RandomDouble() )
				DrainLife();
		}

		public override void AddNameProperties( ObjectPropertyList list )
		{
			base.AddNameProperties( list );

			list.Add("Mirage");
		}

		public BloodBeastMirage( 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();
		}
	}
	
	
	
	public class BeastyBloodMirage : Item
	{
		private SpawnTimer m_Timer;

		public override string DefaultName
		{
			get { return "Beasty Blood"; }
		}

		[Constructable]
		public BeastyBloodMirage() : base( 0xF7E )
		{
			Movable = false;
			Hue = 0x497;

			m_Timer = new SpawnTimer( this );
			m_Timer.Start();
		}

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

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

			writer.Write( (int) 0 ); // version
		}

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

			int version = reader.ReadInt();

			m_Timer = new SpawnTimer( this );
			m_Timer.Start();
		}

		private class SpawnTimer : Timer
		{
			private Item m_Item;

			public SpawnTimer( Item item ) : base( TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 20 ) ) )
			{
				Priority = TimerPriority.FiftyMS;

				m_Item = item;
			}

			protected override void OnTick()
			{
				if ( m_Item.Deleted )
					return;

				Mobile spawn = new BloodElemental(); 
				

				spawn.MoveToWorld( m_Item.Location, m_Item.Map );

				m_Item.Delete();
			}
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}