/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\Mobiles\Monsters\Ants\BlackSolenQueen.cs
Lines of code: 188
***********************************************************/


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

namespace Server.Mobiles
{
	[CorpseName( "a solen queen corpse" )]
	public class BlackSolenQueen : BaseCreature
	{
		private bool m_BurstSac;
		public bool BurstSac{ get{ return m_BurstSac; } }
		public int x, y, z; 
		public int maxspawns = 0;

		[Constructable]
		public BlackSolenQueen() : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "a black solen queen";
			Body = 807;
			BaseSoundID = 959;
			Hue = 0x453;

			SetStr( 296, 320 );
			SetDex( 121, 145 );
			SetInt( 76, 100 );

			SetHits( 151, 162 );

			SetDamage( 10, 15 );

			SetDamageType( ResistanceType.Physical, 70 );
			SetDamageType( ResistanceType.Poison, 30 );

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

			SetSkill( SkillName.MagicResist, 70.0 );
			SetSkill( SkillName.Tactics, 90.0 );
			SetSkill( SkillName.Wrestling, 90.0 );

			Fame = 4500;
			Karma = -4500;

			VirtualArmor = 45;

			SolenHelper.PackPicnicBasket( this );

			PackItem( new ZoogiFungus( ( Utility.RandomDouble() > 0.05 )? 11 : 25 ) );

			if ( Utility.RandomDouble() < 0.05 )
				PackItem( new BallOfSummoning() );
		}

		public override int GetAngerSound()
		{
			return 0x259;
		}

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

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

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

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

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich );
		}

		public override bool IsEnemy( Mobile m )
		{
			if ( SolenHelper.CheckBlackFriendship( m ) )
				return false;
			else
				return base.IsEnemy( m );
		}

		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if(from!=null)SolenHelper.OnBlackDamage( from );

			if ( !willKill )
			{
				if ( !BurstSac )
				{
					if ( 0.2 >= Utility.RandomDouble() && !this.Controlled && !this.Summoned)
						BeginCocoonDrop( from );
					if ( from != null && from != this && !InRange( from, 1 ) && 0.4 >= Utility.RandomDouble()) 
					{
						PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "* The solen spits an acidic substance at you! *" );
						AOS.Damage( from, this, Utility.RandomMinMax( 3, 6 ), true, 100, 0, 0, 0, 0 );
						SpillAcid( TimeSpan.FromSeconds( 10 ), 30, 30, from );
					}
					if ( Hits < 50 )
					{
						PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "* The solen's acid sac is burst open! *" );
						m_BurstSac = true;
					}
				}
				else if ( from != null && from != this && InRange( from, 1 ) )
				{
					SpillAcid( TimeSpan.FromSeconds( 10 ), 30, 30, from );
				}
			}

			base.OnDamage( amount, from, willKill );
		}
		
		public virtual void BeginCocoonDrop( Mobile defender )
		{
			if ( Deleted )
				return;
				
			if ( maxspawns < 7)
			{
				new DropCocoon().MoveToWorld( Location, Map );
				x = this.X;
				y = this.Y;
				z = this.Z;
					
				PlaySound( 0x48E );

				Timer.DelayCall( TimeSpan.FromSeconds( 5.0 ), new TimerStateCallback( Appear_Callback ), defender );
			}
		}	
		
		private void Appear_Callback( object state )
		{
			Mobile defender = state as Mobile;
			if ( defender != null )
			{
				defender.Frozen = false;
	
				Mobile spawn;
				
				if (0.2 > Utility.RandomDouble()) {
					spawn = new BlackSolenWarrior(); 
				}	
				else {
					spawn = new BlackSolenWorker();
				}
				
				spawn.MoveToWorld( new Point3D( x, y, z), Map );
				spawn.FixedParticles( 0x36B0, 10, 25, 9540, 2413, 0, EffectLayer.Waist );
				spawn.Combatant = defender;
				maxspawns += 1; 
			}
		}
		
		public class DropCocoon : Item
		{
			public DropCocoon() : base( 4314 )
			{
				Movable = false;
				Hue = 250;
				Name = "a cocoon";

				Timer.DelayCall( TimeSpan.FromSeconds( 5.0 ), new TimerCallback( Delete ) );
			}

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

				Delete();
			}
			
		}

		public override bool OnBeforeDeath()
		{
			SpillAcid( TimeSpan.FromSeconds( 10 ), 30, 30, 1, 4 );

			return base.OnBeforeDeath();
		}

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 1 );
			writer.Write( m_BurstSac );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			
			switch( version )
			{
				case 1:
				{
					m_BurstSac = reader.ReadBool();
					break;
				}
			}	
		}
	}
}
