/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-24-2011 10:26:35pm
Filepath: scripts\Mobiles\Special\Meraktus.cs
Lines of code: 209

Description: 

***********************************************************/


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

namespace Server.Mobiles
{
	public class Meraktus : BaseChampion
	{
		public override ChampionSkullType SkullType{ get{ return ChampionSkullType.Power; } }
		private DateTime lastability;
		private bool m_SpawnedMinions;
		
		private ArrayList spawns = new ArrayList();

		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 2 ) )
			{
			default:				
			case 0: return WeaponAbility.CrushingBlow;
			case 1: return WeaponAbility.ConcussionBlow;
			}
		}	

		[Constructable]
		public Meraktus() : base( AIType.AI_Super )
		{
			Name = "Meraktus";
			Title = "the Tormented";
			Hue = 2101;
			Body = 262;

			SetStr( 1419, 1438 );
			SetDex( 309, 413 );
			SetInt( 129, 131 );

			SetHits( 10000 );
			SetStam( 309, 413 );

			SetDamage( 16, 30 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 67, 90 );
			SetResistance( ResistanceType.Fire, 65, 70 );
			SetResistance( ResistanceType.Cold, 54, 57 );
			SetResistance( ResistanceType.Poison, 41, 58 );
			SetResistance( ResistanceType.Energy, 50, 52 );

			SetSkill( SkillName.MagicResist, 107.0, 111.3 );
			SetSkill( SkillName.Tactics, 107.5, 117.3 );
			SetSkill( SkillName.Wrestling, 101.2, 104.1 );
			SetSkill( SkillName.DetectHidden, 140.0, 160.0 );

			Fame = 25000;
			Karma = -25000;

			VirtualArmor = 20;
			if(0.5>Utility.RandomDouble())	PackItem(new RandomTalisman());
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.UltraRich, 6 );
			AddLoot( LootPack.FilthyRich );
			
			if(0.05>Utility.RandomDouble())
			{
				switch(Utility.Random(1))
				{
					case 0:PackItem(new SashOfTheTormentedMinotaur());break;			
				}
			}		
		}
		
		public override int GetAngerSound()
		{
			return 0x599;
		}

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

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

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

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

		public override bool Unprovokable{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Greater; } }

		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if (this.InLOS( from ) && !from.InRange( this, 3 ) && from.Alive && !from.Blessed && 0.05 >= Utility.RandomDouble()) {
				this.Location = from.Location; 
				this.PlaySound( 0x59B );
				this.Combatant = from;
				from.SendMessage( "Meraktus charges towards you!" );
			}
			
			if(GetLiveSpawns()!=0 && this.Hits <= 0) {
				from.SendMessage( "Meraktus will not fall until her tormented minotaur are killed!" );
			}
			
			base.OnDamage( amount, from, willKill );
		}
		
		public override bool OnBeforeDeath()
		{
			if (GetLiveSpawns()==0) {
				base.OnBeforeDeath();
				return true;
			}
			else {
				return false;
			}
		}
		
		public override void OnThink ()
		{
			if ( !m_SpawnedMinions )
			{
				Mobile spawn;

				for(int i=0;i<3;i++)
				{
					spawn = new TormentedMinotaur();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
				}
				
				m_SpawnedMinions = true;
			}
			else if (m_SpawnedMinions == true && 0.01 >= Utility.RandomDouble())
			{
				CheckMinions();
			}	
		
			if (lastability < DateTime.Now)
					GroundStomp();
					
			base.OnThink();	
		}
		
		private int GetLiveSpawns()
		{
			int live=0;
				for( int i = 0; i < spawns.Count; ++i )
                {
                Mobile m = spawns[i] as Mobile;

                if( m == null || m.Deleted || !m.Alive)continue;
				live++;							
                }
				
			return live;
		}
		
		public void CheckMinions()
		{
			ArrayList summonBack = new ArrayList();
  
			foreach ( Mobile m in this.GetMobilesInRange( 200 ) )
			{
				if ( m is TormentedMinotaur && (int)this.GetDistanceToSqrt(m) > 25 || m is TormentedMinotaur && !this.InLOS( m )) {
					summonBack.Add( m );
				}
			}

			if ( summonBack.Count > 0 )
			{	
				foreach ( Mobile m in summonBack )
				{
					Effects.SendLocationParticles( EffectItem.Create( m.Location, m.Map, EffectItem.DefaultDuration ), 0x3728, 10, 10, 2023 );
					m.Location = this.Location;
					Effects.SendLocationParticles( EffectItem.Create( this.Location, m.Map, EffectItem.DefaultDuration ), 0x3728, 10, 10, 5023 );
					m.PlaySound( 0x1FE );
				}
			}
		}
	
		public static readonly TimeSpan DefenderRemountDelay = TimeSpan.FromSeconds( 10.0 );
		
		public void GroundStomp()
		{
			ArrayList list = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 10 ) )
			{
				if ( m == this || !CanBeHarmful( m ) || !ShouldHarm( 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.SendMessage( "Meraktus slams the ground with tremendous force" );
				
				if (m.Mounted)	
				{					
					m.Dismount();
					
					m.SendLocalizedMessage( 1060083 ); // You fall off of your mount and take damage!

					m.PlaySound( 0x59C );
					m.FixedParticles( 0x3728, 10, 15, 9955, EffectLayer.Waist );

					AOS.Damage( m, this, 30 * (12 - (int)this.GetDistanceToSqrt(m)), 100, 0, 0, 0, 0 );
					BaseMount.SetMountPrevention( m, BlockMountType.Dazed, DefenderRemountDelay );
				}
				else {
					m.PlaySound( 0x59C );
					m.FixedParticles( 0x3728, 10, 15, 9955, EffectLayer.Waist );

					AOS.Damage( m, this, 30 * (12 - (int)this.GetDistanceToSqrt(m)), 100, 0, 0, 0, 0 );
				}
			}
			lastability=DateTime.Now + TimeSpan.FromSeconds(Utility.RandomMinMax( 10, 35 ));
		}

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 );
			writer.Write(m_SpawnedMinions);
			//SERIALIZE private ArrayList spawns = new ArrayList();
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			m_SpawnedMinions = reader.ReadBool();
			//DESERIALIZE private ArrayList spawns = new ArrayList();
		}
	}
}
