/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jan-01-2012 10:09:15pm
Filepath: scripts\events and scenarios\Thanksgiving 2011\GrosseGiblets.cs
Lines of code: 264

Description: 

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


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

namespace Server.Mobiles
{
	[CorpseName( "a collosal turkey corpse" )]
	public class GrosseGiblets : BaseCreature
	{
		public override bool IgnoreYoungProtection { get { return Core.ML; } }

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

		public static void GiveReward(Mobile boss)
		{
			ArrayList toGive = new ArrayList();
			List<DamageStore> rights = BaseCreature.GetLootingRights( boss.DamageEntries, boss.HitsMax );

			for ( int i = rights.Count - 1; i >= 0; --i )
			{
				DamageStore ds = rights[i];
				if ( ds.m_HasRight )	toGive.Add( ds.m_Mobile );
			}
			if ( rights.Count == 0 )return;	
			
			for(int i=0;i<rights.Count;i++)
			{
				Mobile m = rights[i].m_Mobile;			
				PlayerMobile pm = m as PlayerMobile;	
	
				Item gift = new HornOfPlenty();	
						

				if(0.70 >= Utility.RandomDouble()) 
				{
					gift = new HornOfPlenty();	
					m.SendMessage(200,"You receive a gift: Horn Of Plenty");
				}
				else if (0.10 >= Utility.RandomDouble()) 
				{
					gift = new AbominableWishbone();
					m.SendMessage(200,"You receive a gift: Abominable Wishbone");
				}
				else if (0.10 >= Utility.RandomDouble()) 
				{
					gift = new TuftOfFeathers();
					m.SendMessage(200,"You receive a gift: Tuft Of Feathers");
				}
				else if (0.10 >= Utility.RandomDouble())
				{
					gift = new PlatinumToken();
					m.SendMessage(200,"You receive a gift: Platinum Roulette Token");
				}
				else
				{
					gift = new GravyBoat();	
					m.SendMessage(200,"You receive a gift: A Gravy Boat");
				}
				m.GiveItem(gift);			
			}
		}	

		public override void OnDeath( Container c )
		{
			base.OnDeath( c );
			GiveReward(this);	
		}

		private DateTime lastcacophony;
		private DateTime lastability;
		
		[Constructable]
		public GrosseGiblets() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "Grosse Giblets";
			Title = "the Huge";
			Body = 1026;
			BaseSoundID = 402;
			Hue = 1192;

			SetStr( 500 );
			SetDex( 100 );
			SetInt( 1000 );

			SetHits( 15000 );
			SetMana( 5000 );

			SetDamage( 17, 21 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 30 );
			SetResistance( ResistanceType.Fire, 30 );
			SetResistance( ResistanceType.Cold, 30 );
			SetResistance( ResistanceType.Poison, 30 );
			SetResistance( ResistanceType.Energy, 30 );

			SetSkill( SkillName.DetectHidden, 80.0 );
			SetSkill( SkillName.Meditation, 120.0 );
			SetSkill( SkillName.MagicResist, 150.0 );
			SetSkill( SkillName.Tactics, 100.0 );
			SetSkill( SkillName.Wrestling, 120.0 );

			Fame = 28000;
			Karma = -28000;

			VirtualArmor = 64;
			
			FollowersMax=20;			
			
			if(0.2>Utility.RandomDouble())	PackItem(new RandomTalisman());
		}

		public override void GenerateLoot()
		{		    
			AddLoot( LootPack.Rich, 5 );
			AddLoot( LootPack.SuperBoss, 7 );	
		}

		public override bool BardImmune{ get{ return !Core.SE; } }
		public override bool Unprovokable{ get{ return Core.SE; } }
		public override bool Uncalmable{ get{ return Core.SE; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override int SuperAI_DelayMax{ get{ return 0; } }	
		public override double TargetTamerChance { get { return 0.02; }}	
		public override int Meat{ get{ return 40; } }
		public override MeatType MeatType{ get{ return MeatType.Bird; } }
		public override int Feathers{ get{ return 500; } }
		public override bool CantbeSupreme { get { return true;} }
		public override bool CantbeParagon { get { return true;} }			

		public override int TreasureMapLevel{ get{ return 6; } }

		private static bool m_InHere;

		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if ( from != null && from != this && !m_InHere )
			{
				m_InHere = true;
				AOS.Damage( from, this, Utility.RandomMinMax( 8, 20 ), 100, 0, 0, 0, 0 );

				MovingEffect( from, 16831, 10, 0, false, false, 0, 0 ); //0xECA
				PlaySound( 0x491 );

				if ( 0.05 > Utility.RandomDouble() )
					Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerStateCallback( CreateEggs_Callback ), from );

				m_InHere = false;
			}
			
			if (this.InLOS( from ) && !from.InRange( this, 3 ) && from.Alive && !from.Blessed && 0.05 >= Utility.RandomDouble()) {
				this.Location = from.Location; 
				this.PlaySound( 0x63E );
				this.Combatant = from;
				from.SendMessage( "Grosse Giblets angrily flies to your location!" );
			}
			
			base.OnDamage(amount, from, willKill );	
		}
		
		public override void OnThink()
		{
			if (0.05 > Utility.RandomDouble() && (lastcacophony+TimeSpan.FromMinutes(1)) < DateTime.Now) {
				CacophonousLambaste();
				lastcacophony=DateTime.Now;
			}
			
			if (0.2 > Utility.RandomDouble() && lastability < DateTime.Now) {
				this.Say("*Slams the ground with great force!*");
				GroundStomp();
			}

			base.OnThink();		
		}
	
		public static readonly TimeSpan DefenderRemountDelay = TimeSpan.FromSeconds( 10.0 );
		
		public void GroundStomp()
		{
			ArrayList ilist = new ArrayList();
			ArrayList list = new ArrayList();
			
			foreach ( Item i in this.GetItemsInRange( 12 ) )
			{
				if ( i.Movable == false || i == null)
					continue;
				else
					ilist.Add( i );
			}
			
			foreach ( Item i in ilist )
			{
				Effects.SendLocationParticles( EffectItem.Create( i.Location, i.Map, EffectItem.DefaultDuration ), 0x3728, 8, 20, 5042 );
				Effects.PlaySound( i, i.Map, 0x59C );
				i.Delete();
			}

			foreach ( Mobile m in this.GetMobilesInRange( 12 ) )
			{
				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 );
				
				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, 60, 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, 60, 100, 0, 0, 0, 0 );
				}
			}
			lastability=DateTime.Now + TimeSpan.FromSeconds(Utility.RandomMinMax( 80, 120 ));
		}
		
		public void CacophonousLambaste()
		{		
			ArrayList list = new ArrayList();
			this.PlaySound( 1412 );

			foreach ( Mobile m in this.GetMobilesInRange( 12 ) )
			{
				if ( m == this || !ShouldHarm( m ) || !this.InLOS( m ) || !m.Alive || m.Blessed )
					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 virtual void CreateEggs_Callback( object state )
		{
			Mobile from = (Mobile)state;
			Map map = from.Map;

			if ( map == null || !this.InLOS( from ) )
				return;

			int count = 1; //Utility.RandomMinMax( 1, 3 );

			for ( int i = 0; i < count; ++i )
			{
				int x = from.X + Utility.RandomMinMax( -1, 1 );
				int y = from.Y + Utility.RandomMinMax( -1, 1 );
				int z = from.Z;

				if ( !map.CanFit( x, y, z, 16, false, true ) )
				{
					z = map.GetAverageZ( x, y );

					if ( z == from.Z || !map.CanFit( x, y, z, 16, false, true ) )
						continue;
				}

				UnholyEgg egg = new UnholyEgg();

				egg.Hue = 1150;
				egg.Name = "unholy egg";
				egg.ItemID = 16831;

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

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