/**********************************************************
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\shimering effusion\mobiles\ShimmeringEffusion.cs
Lines of code: 303
***********************************************************/


using System;
using System.Collections;
using Server;
using Server.Items;

namespace Server.Mobiles
{
	[CorpseName( "the remains of Shimmering Effusion" )]
	public class ShimmeringEffusion : BaseCreature
	{
	
		Random rand = new Random(); 
		private int amount; 
		private ArrayList spawns = new ArrayList();
		
		public override int SuperAI_DelayMax{ get{ return 0; } }
		public override int SuperAI_Intensity{ get{ return 150; } }			
	
		[Constructable]
		public ShimmeringEffusion() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "Shimmering Effusion";
			Body = 261;
			BaseSoundID = 1421;
			
			SetStr( 509, 540 );
			SetDex( 354, 381 );
			SetInt( 1513, 1578 );

			SetHits( 20000, 20000 );

			SetDamage( 24, 30 );
			
			SetDamageType( ResistanceType.Physical, 20 );
			SetDamageType( ResistanceType.Fire, 20 );
			SetDamageType( ResistanceType.Cold, 20 );
			SetDamageType( ResistanceType.Poison, 20 );
			SetDamageType( ResistanceType.Energy, 20 );

			SetResistance( ResistanceType.Physical, 75, 77 );
			SetResistance( ResistanceType.Fire, 60, 68 );
			SetResistance( ResistanceType.Cold, 60, 70 );
			SetResistance( ResistanceType.Poison, 76, 80 );
			SetResistance( ResistanceType.Energy, 75, 78 );

		    SetSkill( SkillName.EvalInt, 120.0, 140.0 );
			SetSkill( SkillName.Magery, 130.0, 150.0 );
			SetSkill( SkillName.Spellweaving, 130, 150.0 );			
			SetSkill( SkillName.Meditation, 100.0, 120.0 );
			SetSkill( SkillName.MagicResist, 120.0, 150.0);
			SetSkill( SkillName.Tactics, 100.5, 102.2 );
			SetSkill( SkillName.Wrestling, 100.2, 103.0 );

			Fame = 18000;
			Karma = -18000;

			VirtualArmor = 50;
		}
		
		public override bool OnBeforeDeath()
		{
			for ( int j = 0; j < 6; j++ )
			{
				PackItem(RandomMResources.Generate());	
			}
			
			for (int i = 0; i < Utility.RandomMinMax(1, 2); i++)
			{
				PackItem( new PetParrotStatue (Utility.RandomList(41, 495, 567, 48, 131, 75, 1001, 1169, 1155, 1164, 1160, 1162, 2210, 1324, 1157, 1364, 1156, 2101))); //Common hues/reward
			}
			
			if (0.15 >= Utility.RandomDouble())
				PackItem( new PetParrotStatue (Utility.RandomList(1281, 1158, 1266, 1150, 1167, 1109, 33, 1420, 1644, 1359))); //Uncommon 
			else if (0.05 >= Utility.RandomDouble())
				PackItem( new PetParrotStatue (Utility.RandomList(1166, 1165, 1172, 1168, 1175, 1152, 1161, 1151, 1154, 1153, 0, 1177)));//Rare reward hues


			switch ( Utility.Random( 75 ))
            {                                   
            	case 0: PackItem( new CrimsonCinture() ); break;        
			}
			
			switch ( Utility.Random( 5 ))
            {                                   
            	case 0: PackItem( new ShimmeringCrystal() ); break;
            	case 1: PackItem( new ShimmeringCrystal() ); break;    	
			}
			
			switch ( Utility.Random( 8 ))
            {                                   
            	case 4: PackItem( new ShimmeringCrystal() ); break;
            	case 5: PackItem( new ShimmeringCrystal() ); break; 	
			}
			
			switch ( Utility.Random( 30 ))
            {                               
				case 5: PackItem( new FetidEssenceStatue () ); break;
				case 15: PackItem( new CorporealBrumeStatue () ); break;
				case 20: PackItem( new MantraEffervescenceStatue () ); break;
				case 29: PackItem( new ShimmeringEffusionStatue () ); break;		      	
			}
			
			switch ( Utility.Random( 30 ))
            {                               
				case 11: PackItem( new ImprisonedFerret () ); break;	      	
			}
			
			switch ( Utility.Random( 80 ))
            {                               
				case 10: PackItem( new CrystalineRing () ); break;		      	
			}
			
			switch ( Utility.Random( 32 ))
            {                                   
            	case 0: PackItem( new PlateOfHonorArms() ); break;
            	case 1: PackItem( new PlateOfHonorChest() ); break;
				case 2: PackItem( new PlateOfHonorGloves () ); break;
            	case 3: PackItem( new PlateOfHonorGorget () ); break;       
				case 4: PackItem( new PlateOfHonorHelm () ); break;		
				case 5: PackItem( new PlateOfHonorLegs () ); break;		
				case 6: PackItem( new AcolyteArms() ); break;
            	case 7: PackItem( new AcolyteChest() ); break;
				case 8: PackItem( new AcolyteGloves () ); break;	
				case 9: PackItem( new AcolyteLegs () ); break;	
				case 10: PackItem( new EvocaricusSword() ); break;
            	case 11: PackItem( new MalekisHonor() ); break;
				case 12: PackItem( new GrizzleArms() ); break;
            	case 13: PackItem( new GrizzleChest() ); break;
				case 14: PackItem( new GrizzleGloves () ); break;       
				case 15: PackItem( new GrizzleHelm () ); break;		
				case 16: PackItem( new PlateOfHonorLegs () ); break;
				case 17: PackItem( new MageArmorArms() ); break;
            	case 18: PackItem( new MageArmorChest() ); break;
				case 19: PackItem( new MageArmorGloves () ); break;	
				case 20: PackItem( new MageArmorLegs () ); break;                    
				case 21: PackItem( new MyrmidonArms() ); break;
            	case 22: PackItem( new MyrmidonChest() ); break;
				case 23: PackItem( new MyrmidonGloves () ); break;
            	case 24: PackItem( new MyrmidonGorget () ); break;       
				case 25: PackItem( new MyrmidonHelm () ); break;		
				case 26: PackItem( new MyrmidonLegs () ); break;		
				case 27: PackItem( new DeathEssenceArms() ); break;
            	case 28: PackItem( new DeathEssenceChest() ); break;
				case 29: PackItem( new DeathEssenceGloves () ); break;      
				case 30: PackItem( new DeathEssenceHelm () ); break;		
				case 31: PackItem( new DeathEssenceLegs () ); break;		
			}
			
			for ( int k = 0; k < Utility.RandomMinMax( 1, 3 ); k++ )
			{
				PackItem(new RandomTalisman());
			}
			
				
			if (0.8 >= Utility.RandomDouble()) PackItem( new CapturedEssence(1) );	
			
			if (0.4 >= Utility.RandomDouble()) 
			{
				switch (Utility.RandomMinMax(0, 2 ))
				{
					case 0: PackItem(Loot.RandomMPWeapon(90,110, 0));break;
					case 1: PackItem(Loot.RandomMPWeapon(90,110, 1));break;
					case 2: PackItem(Loot.RandomMPWeapon(90,110, 2));break;      		
				}
			}
				
			if (0.10 >= Utility.RandomDouble()) 
			{
				switch (Utility.RandomMinMax(0, 2 ))
				{
					case 0: PackItem(Loot.RandomMPWeapon(110,130, 0));break;
					case 1: PackItem(Loot.RandomMPWeapon(110,130, 1));break;
					case 2: PackItem(Loot.RandomMPWeapon(110,130, 2));break;      		
				}
			}
			
			if (0.05 >= Utility.RandomDouble())
			{
				switch (Utility.RandomMinMax(0, 2 ))
				{
					case 0: PackItem(Loot.RandomMPWeapon(130,150, 0));break;
					case 1: PackItem(Loot.RandomMPWeapon(130,150, 1));break;
					case 2: PackItem(Loot.RandomMPWeapon(130,150, 2));break;      		
				}
			}
			
			if (Map == Map.Felucca)
				amount = 12;
			else
				amount = 8;

			for (int n = 0; n < amount; n++)
			{
				switch (Utility.RandomMinMax(0, 5 ))
				{
					case 0: PackItem( new Taint(1));break;
					case 1: PackItem( new Muculent(1));break;
					case 2: PackItem( new Corruption(1));break;      		
					case 3: PackItem( new Blight (1));break;
					case 4: PackItem( new Scourge(1));break;
					case 5: PackItem( new Putrefaction(1));break;
				}			
			}
			PackNecroReg( 50, 80 );
			
			
			 for(int i=Utility.Random(4);i>0;i--)PackItem(RandomRecipe.Peerless());				
		
		return base.OnBeforeDeath();
		}
		

		public override void GenerateLoot()
		{
			AddLoot( LootPack.AosUltraRich, 2 );
			AddLoot( LootPack.AosSuperBoss, 2);
			AddLoot( LootPack.FilthyRich, 3 );
		}
	
		public override bool AutoDispel{ get{ return true; } }
		public override bool Unprovokable{ get{ return true; } }
		public override bool Uncalmable{ get{ return true; } }
		public override double AutoDispelChance{ get{ return 0.4; } }
		public override Poison PoisonImmune{ get{ return Poison.Deadly; } }
		public override bool IsMLCreature { get { return true;} }
		public override bool IsMLBoss { get { return true;} }
		public override bool NoFlee { get { return true; } }	
		public override int ArcaneLevel{ get{ return 2; } }		
		
		
		private int spawninc;
		private DateTime lastspawn;
		
		public override void OnDamage( int amount, Mobile attacker, bool willKill ) 
		{
		if(0.15>Utility.RandomDouble())spawninc++;
		
		
		Mobile spawn;
		
		
		//This is at a fixed amount right now. The way it will normally work is as follows:
		
		//For each player in the vicinity(Region) who is doing the peerless, effusion will spawn ONE
		//of this random list (Fetid Essence, Corporeal Brume, Mantra Effervescence) for EACH player.
		//Therefore if one person is doing the peerless, effusion will spawn 1. If there are 5 people
		//doing the peerless, effusion will spawn 5. 
		
		int tospawn = 1+ GetPlayersInRegion();
		int livespawns = GetLiveSpawns();
		if(tospawn<2)tospawn=2;
		//else if(tospawn>5)tospawn=5;
		
		if(livespawns>0)lastspawn=DateTime.Now;
		
			if ( attacker!=null && attacker != this && livespawns < tospawn && 0.02 > Utility.RandomDouble() && spawninc>=50 && (lastspawn+TimeSpan.FromMinutes(5))<DateTime.Now) //5% chance seems to be sufficient, but if not: 2%
			{
				for (int h = 0; h < tospawn - livespawns; h++)
				{
					switch (Utility.RandomMinMax(0, 2 ))
					{
						case 0: 
							spawn = new FetidEssence();
							SetTempSummon(this,spawn);
							spawn.MoveToWorld( this.Location, this.Map );
							spawns.Add(spawn);	
							break;
						case 1: 
							spawn = new CorporealBrume();
							SetTempSummon(this,spawn);
							spawn.MoveToWorld( this.Location, this.Map );
							spawns.Add(spawn);	
							break;
						case 2: 
							spawn = new MantraEffervescence();
							SetTempSummon(this,spawn);
							spawn.MoveToWorld( this.Location, this.Map );
							spawns.Add(spawn);	
							break;      		
					}
				}
			lastspawn=DateTime.Now;
			spawninc=0;
			}

			base.OnDamage(amount, attacker, willKill );			
		}
		
		DateTime lastdistancecheck;
		
		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;					
					
					
					if((lastdistancecheck+TimeSpan.FromMinutes(1))<DateTime.Now)
					{
						bool noonearound=true;
						lastdistancecheck=DateTime.Now;
						foreach ( Mobile p in m.GetMobilesInRange( 10 ) )
						{
						if(p is BaseCreature)continue;
						noonearound=false;
						break;
						}
					
						if(noonearound)
						{
						m.MoveToWorld(this.Location,this.Map);
						m.PlaySound( m.GetAngerSound() );						
						}
					}
				
				live++;							
                }
				
		return live;
		}
		

		public override void OnDeath( Container c )
		{
			base.OnDeath( c );
		}
		
		public override void OnThink()
		{
			if (this.Combatant != null && 0.015 >= Utility.RandomDouble())
				IntermittentDamage();
				
				
			base.OnThink();	
		}
		
		public void IntermittentDamage()
		{
			ArrayList list = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 15 ) )
			{
				if ( m == this || !CanBeHarmful( m ) || !this.InLOS( 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 )
			{
				m.PlaySound( 1427 );				
				AOS.Damage( m, this, Utility.RandomMinMax( 8, 12 ), true, 100, 0, 0, 0, 0 );
			}
		}
		
		public ShimmeringEffusion( 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();
		}
	}
}