/**********************************************************
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\Interred Grizzle\Custom Mobiles\Monstrous Interred Grizzle.cs
Lines of code: 244
***********************************************************/


using System;
using Server;
using Server.Items;
using System.Text;
using System.Collections;
using Server.Network;
using Server.Targeting;
using Server.Mobiles;
using Server.Spells;
using Server.Spells.Necromancy;
using Server.Spells.Bushido;
using Server.Spells.Ninjitsu;
using Server.Factions;
using Server.Engines.Craft;
using System.Collections.Generic;
using Server.Spells.Spellweaving;

namespace Server.Mobiles
{
	[CorpseName( "the remains of a monstrous interred grizzle" )]
	public class MonstrousInterredGrizzle : BaseCreature
	{
	
		Random rand = new Random(); 
		private int amount;
		private DateTime lastcacophony;
		 
		[Constructable]
		public MonstrousInterredGrizzle() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "Monstrous Interred Grizzle";
			Body = 259;			
			BaseSoundID = 589;

			SetStr( 1198, 1207 );
			SetDex( 127, 135 );
			SetInt( 595, 646 );

			SetHits( 50000, 50000 );

			SetDamage( 24, 28 );

			SetDamageType( ResistanceType.Physical, 60 );
			SetDamageType( ResistanceType.Fire, 20 );
			SetDamageType( ResistanceType.Energy, 20 );

			SetResistance( ResistanceType.Physical, 48, 52 );
			SetResistance( ResistanceType.Fire, 77, 82 );
			SetResistance( ResistanceType.Cold, 56, 61 );
			SetResistance( ResistanceType.Poison, 32, 40 );
			SetResistance( ResistanceType.Energy, 69, 71 );

			SetSkill( SkillName.EvalInt, 100.0, 105.0 );
			SetSkill( SkillName.Magery, 100.0, 105.0 );
			SetSkill( SkillName.Meditation, 100.0, 105.0 );
			SetSkill( SkillName.Spellweaving, 120.0 );			
			SetSkill( SkillName.MagicResist, 120.0, 120.0);
			SetSkill( SkillName.Tactics, 118.5, 119.2);
			SetSkill( SkillName.Wrestling, 112.9, 116.9);
			SetSkill( SkillName.DetectHidden, 100.0);
			

			Fame = 24000;
			Karma = -24000;

			VirtualArmor = 80;
			
			
		}
		
		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;   
            	case 12: PackItem( new DreadsFlute() ); break;     
			}
			
			switch ( Utility.Random( 2 ))
            {                                   
            	case 1: PackItem( new GrizzleGob() ); break;	
			}
			
			switch ( Utility.Random( 5 ))
            {                                   
            	case 0: PackItem( new TombstoneOfTheDamned() ); break;
            	case 1: PackItem( new TombstoneOfTheDamned() ); break;
            	case 3: PackItem( new TombstoneOfTheDamned() ); break;   	
			}
			
			switch ( Utility.Random( 8 ))
            {                                   
				case 4: PackItem( new TombstoneOfTheDamned() ); break;
			}
			
			switch ( Utility.Random( 15 ))
            {                                   
				case 7: PackItem( new MaggotMound() ); break;
			}
			
			switch ( Utility.Random( 17 ))
            {                                   
				case 10: PackItem( new GrizzledSkullCollection() ); break;
			}
			
			switch ( Utility.Random( 35 ))
            {                                   
				case 11: PackItem( new GrizzleSummoner() ); break;
			}
			
			switch ( Utility.Random( 32 ))
            {                                   
				case 12: PackItem( new GrizzleArms() ); break;
            	case 13: PackItem( new GrizzleChest() ); break;
				case 14: PackItem( new GrizzleGloves () ); break;       
				case 15: PackItem( new GrizzleHelm () ); 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 GrizzledBones(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;
				}
			}
			
			
			 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 Meat{ get{ return 1; } }
		public override int TreasureMapLevel{ get{ return 5; } }
        public override bool BleedImmune{ get{ return true; } }
        public override bool AutoDispel{ get{ return true; } }
		public override bool Unprovokable{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override bool IsMLCreature { get { return true;} }
		public override bool IsMLBoss { get { return true;} }
		public override int SuperAI_DelayMax{ get{ return 2; } }
		public override int SuperAI_Intensity{ get{ return 100; } }	
		public override bool NoFlee { get { return true; } }				
		
		
		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if (from!=null && !willKill )
			{
				if ( from != null && from != this && 0.4 >= Utility.RandomDouble())
				{
					this.PlaySound( 1411 );
					SpillFluids(from);
					SpillFluids(from);
					SpillFluids(from);
				}
			}
			if (0.05 > Utility.RandomDouble() && (lastcacophony+TimeSpan.FromMinutes(2)) < DateTime.Now) {
				CacophonicBlast();
				lastcacophony=DateTime.Now;
			}
			
			base.OnDamage( amount, from, willKill );
		}
	
		public void CacophonicBlast()
		{		
			ArrayList list = new ArrayList();
			this.PlaySound( 1412 );

			foreach ( Mobile m in this.GetMobilesInRange( 20 ) )
			{
				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;
			
				int muteduration = 15;
				double mutepower = 2.0;
				
				muteduration = (int)(this.GetDistanceToSqrt(m) + 15);
				mutepower = (this.GetDistanceToSqrt(m)/4) + 2.0;
			
				m.FixedEffect( 0x3779, 10, 25 );
				m.SendLocalizedMessage(1072069);
				
				Server.Items.BaseWeapon.Mute(m,muteduration,mutepower);
				Server.Spells.Spell.Mute(m,muteduration,mutepower);
			}		
		}
		
		public void SpillFluids(Mobile from)
		{
		Map map = from.Map;

			if ( map == null )
				return;

				int x = (this.X-1) + Utility.Random( 3 );
				int y = (this.Y-1) + Utility.Random( 3 );
				int z = this.Z;

				Item item = new GrizzleAcid(); 

				

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

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