/**********************************************************
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\Melisande\Mobiles\Lady Melisande.cs
Lines of code: 394
***********************************************************/


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

namespace Server.Mobiles
{
	[CorpseName( "the remains of Lady Melisande" )]
	public class LadyMelisande : BaseCreature
	{
	
		Random rand = new Random(); 
		private int amount; 
		bool minionssummoned=false;
		private bool spawnsatyr = true;
	
		[Constructable]
		public LadyMelisande() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "Lady Melisande";
			Body = 258;
			
			SetStr( 420, 976 );
			SetDex( 306, 327 );
			SetInt( 1549, 1676 );

			SetHits( 30000, 30000 );

			SetDamage( 14, 22 );
			
			SetDamageType( ResistanceType.Energy, 50 );
			SetDamageType( ResistanceType.Physical, 50 );

			SetResistance( ResistanceType.Physical, 47, 55 );
			SetResistance( ResistanceType.Fire, 41, 48 );
			SetResistance( ResistanceType.Cold, 57, 63 );
			SetResistance( ResistanceType.Poison, 70, 74 );
			SetResistance( ResistanceType.Energy, 74, 80 );

		    SetSkill( SkillName.EvalInt, 100.0, 120.0 );
			SetSkill( SkillName.Magery, 100.0, 120.0 );
			SetSkill( SkillName.SpiritSpeak, 100.0, 120.0 );
			SetSkill( SkillName.Necromancy, 100.0, 120.0 );
			SetSkill( SkillName.MagicResist, 120.0, 120.0);
			SetSkill( SkillName.Tactics, 100.1, 101.9 );
			SetSkill( SkillName.Wrestling, 100.7, 102.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

			amount = rand.Next( 4, 7 );
			for ( int m = 0; m < amount; m++ )
			{
				PackItem( new FermentedWine() ); 
			}

			switch ( Utility.Random( 75 ))
            {                                   
            	case 0: PackItem( new CrimsonCinture() ); break;        
			}
			
			switch ( Utility.Random( 5 ))
            {                                   
            	case 0: PackItem( new CorruptedTree() ); break;
            	case 1: PackItem( new CorruptedTree() ); break;    	
			}
			
			switch ( Utility.Random( 8 ))
            {                                   
            	case 4: PackItem( new CorruptedTree() ); break;
            	case 5: PackItem( new CorruptedTree() ); break; 	
			}
			
			switch ( Utility.Random( 10 ))
            {                                   
            	case 3: PackItem( new MelsHairDye () ); break;     	
			}
			
			switch ( Utility.Random( 18 ))
            {                                   
            	case 7: PackItem( new MelsHairDye () ); break;     	
			}
			
			switch ( Utility.Random( 30 ))
            {                               
				case 11: PackItem( new SquirrelSummoner () ); break;		      	
			}
			
			switch ( Utility.Random( 50 ))
            {                               
				case 10: PackItem( new MelisandesCorrodedHatchet () ); 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.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 (0.8 >= Utility.RandomDouble()) PackItem( new DiseasedBark(1) );	
			
			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 int GetAngerSound()
		{
			return 1405;
		}

		public override int GetIdleSound()
		{
			return 1404;
		}

		public override int GetAttackSound()
		{
			return 1403;
		}

		public override int GetHurtSound()
		{
			return 1406; 
		}

		public override int GetDeathSound()
		{
			return 1402; 
		}
	
		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.05; } }
		public override bool CanRummageCorpses{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override int TreasureMapLevel{ get{ return 4; } }
		public override bool IsMLCreature { get { return true;} }
		public override bool IsMLBoss { get { return true;} }
		public override int SuperAI_DelayMax{ get{ return 5; } }
		public override int SuperAI_Intensity{ get{ return 120; } }	
		public override bool NoFlee { get { return true; } }
		
		public override void OnDamage( int amount, Mobile attacker, bool willKill ) 
		{
			if ( 0.07 >= Utility.RandomDouble() ) {PutridNausea();} //Putrid Nausea Attack
		
			if ( 0.02 >= Utility.RandomDouble() ) //Smack talk ftw
			{
				this.PlaySound(Utility.RandomList(794, 811, 822, 803, 824, 794, 795, 796));
				this.Say(1075102 + Utility.Random(13));
			}
			
			base.OnDamage(amount, attacker, willKill );			
		}
		
		public void PutridNausea()
		{		
			ArrayList list = new ArrayList();
			
			this.PlaySound( 794 );
			this.Say( 1075115 );

			foreach ( Mobile m in this.GetMobilesInRange( 6 ) )
			{
				if ( m == this || !ShouldHarm( m ) || !this.InLOS( m ) )
					continue;

				list.Add( m );
			}
			
		
			for(int i=0;i<list.Count;i++)
			{
			Mobile m=null;
			if(list[i] is Mobile)m = list[i] as Mobile;
			else continue;
			
				m.FixedParticles( 0x374A, 1, 15, 9502, 668, 3, (EffectLayer)255 );
				m.SendLocalizedMessage(1075120);
				int toharm = Utility.RandomMinMax( 15, 25 );
				AOS.Damage(m, this, toharm, 0, 0, 0, 100, 0 );
				
				Server.Items.BaseWeapon.Mute(m,15,2.0);
				Server.Spells.Spell.Mute(m,15,2.0);
				
				if (m.Player) {
					m.PlaySound( m.Female ? 813 : 1087 );

					if ( !m.Mounted ) 
						m.Animate( 32, 5, 1, true, false, 0 ); 
              		
					Point3D p = new Point3D( m.Location ); 
					switch( m.Direction ) 
					{ 
						case Direction.North: 
							p.Y--; break;							 
						case Direction.South: 
							p.Y++; break;							 
						case Direction.East: 
							p.X++; break;							 
						case Direction.West: 
							p.X--; break; 							
						case Direction.Right: 
							p.X++; p.Y--; break;
						case Direction.Down: 
							p.X++; p.Y++; break;
						case Direction.Left: 
							p.X--; p.Y++; break;
						case Direction.Up: 
							p.X--; p.Y--; break;
						default: 
							break; 
					} 
					p.Z = m.Map.GetAverageZ( p.X, p.Y );
       				 	
					bool canFit = Server.Spells.SpellHelper.AdjustField( ref p, m.Map, 12, false );
       				 	
					if ( canFit ) 
					{
						Puke puke = new Puke(); 
						puke.Map = m.Map; 
						puke.Location = p;
					}
	            }
			}		
		}
		
		public class ItemRemovalTimer : Timer 
		{ 
			private Item i_item; 
			public ItemRemovalTimer( Item item ) : base( TimeSpan.FromSeconds( 1.0 ) ) 
			{ 
				Priority = TimerPriority.OneSecond; 
				i_item = item; 
			} 

			protected override void OnTick() 
			{ 
		        if (( i_item != null ) && ( !i_item.Deleted ))
		        { 
			        i_item.Delete();
			        Stop();
		        }
			} 
		} 

		public class Puke : Item 
		{
			private Timer m_Timer;
		 
			[Constructable] 
			public Puke() : base( Utility.RandomList( 0xf3b, 0xf3c ) ) 
			{ 
				Name = "A Pile of Puke"; 
				Hue = 0x557; 
				Movable = false; 

				m_Timer = new ItemRemovalTimer( this ); 
				m_Timer.Start(); 

			} 
		
			public override void OnAfterDelete()
			{
				base.OnAfterDelete();

				if ( m_Timer != null )
					m_Timer.Stop();
			}

			public override void OnSingleClick( Mobile from ) 
			{ 
				this.LabelTo( from, this.Name ); 
			} 
  
			public Puke( 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(); 

				this.Delete(); // none when the world starts 
			} 
		}
		
		public override void OnThink()
		{		
		
			Mobile spawn;
		
			if (minionssummoned == false)
			{
				minionssummoned = true;
				
				for(int i=0;i<4;i++)
				{
				spawn = new EnslavedSatyr();
				SetTempSummon(this,spawn);
				spawn.MoveToWorld( this.Location, this.Map );
				}

			}	
		
			if (this.Hits <= this.HitsMax * 0.5 && spawnsatyr == true)
			{
				spawnsatyr = false;
				this.Say( 1075119 );
				
				foreach ( Mobile m in this.GetMobilesInRange( 50 ) )
				{
					if ( m.Player && this.InLOS( m ) )
						m.SendLocalizedMessage(1075116); //Twisted satyr crawls on branch beside you
					else
						continue;
				}	
				
				for(int i=0;i<4;i++)
				{
				spawn = new EnslavedSatyr();
				SetTempSummon(this,spawn);
				spawn.MoveToWorld( this.Location, this.Map );
				}
			}	
		
		base.OnThink();	
		}

		public override void OnDeath( Container c )
		{
			base.OnDeath( c );
		}
		
		public LadyMelisande( Serial serial ) : base( serial )
		{
		}

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

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