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

Description: 

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


using System; 
using Server;
using Server.Items;
using Server.Targeting;
using Server.Network;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Server.Mobiles
{
	[CorpseName( "The remains of Herpekitus" )]
	public class Herpekitus : BaseCreature
	{
		bool minionssummoned=false;
		bool deroot=false;
	
		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 BlackToadstool();	
						
				if(0.6 >= Utility.RandomDouble())
				{
					if(0.75 >= Utility.RandomDouble()) {
						gift = new BlackToadstool();	
						m.SendMessage(200,"You receive a gift: Black Toadstools");
					}
					else if (0.15 >= Utility.RandomDouble()) {
						gift = new GreenToadstool();
						m.SendMessage(200,"You receive a gift: Green Toadstools");
					}
					else if (0.10 >= Utility.RandomDouble()) {
						gift = new RedToadstool();
						m.SendMessage(200,"You receive a gift: Red Toadstools");
					}
					m.GiveItem(gift);			
				}
				else if(0.2 >= Utility.RandomDouble())
				{
					gift = new PigmentBottle(1157, "Halloween Red", 5);	
					m.SendMessage(200,"You receive a gift: Halloween Red Dye");
					m.GiveItem(gift);				
				}
				else if(0.15 >= Utility.RandomDouble())
				{
				
					if(0.5 >= Utility.RandomDouble()) {
						gift = new DarkTree();	
						m.SendMessage(200,"You receive a gift: Dark Tree");
					}						
					else {
						gift = new PlatinumToken();	
						m.SendMessage(200,"You receive a gift: Platinum Token");
					}
					m.GiveItem(gift);
				}
				else if(0.05 >= Utility.RandomDouble())
				{
					gift = new ConjurersGarb();
					m.SendMessage(200,"You receive a gift: Conjurer's Garb");
					m.GiveItem(gift);
				}
				else
				{
					gift = new BlackToadstool();	
					m.SendMessage(200,"You receive a gift: Black Toadstools");
					m.GiveItem(gift);
				}	
			}
		}	

		public override void OnDeath( Container c )
		{
			base.OnDeath( c );
			GiveReward(this);	
		}
		
		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 2 ) )
			{
				default:
				case 0: return WeaponAbility.CrushingBlow;
				case 1: return WeaponAbility.ConcussionBlow;
			}
		}
		
		private ArrayList spawns = new ArrayList();
	
		[Constructable]
		public Herpekitus() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "Herpekitus";
			Body = 789;
			Hue = 2075; 
			BaseSoundID = 353;

			SetStr( 756, 780 );
			SetDex( 800, 900 );
			SetInt( 100, 200 );

			SetHits( 5000, 5000 );
			SetMana( 2000 );

			SetDamage( 10, 17 );

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

			SetResistance( ResistanceType.Physical, 55, 60 );
			SetResistance( ResistanceType.Fire, 20, 30 );
			SetResistance( ResistanceType.Cold, 20, 30 );
			SetResistance( ResistanceType.Poison, 60, 80 );
			SetResistance( ResistanceType.Energy, 40, 50);

			SetSkill( SkillName.MagicResist, 15.1, 20.0 );
			SetSkill( SkillName.Meditation, 200, 400 );
			SetSkill( SkillName.Tactics, 120 );
			SetSkill( SkillName.Wrestling, 120 );

			Fame = 25000;
			Karma = -25000;

			CantWalk = true;
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich, 7 );
			AddLoot( LootPack.SuperBoss, 7 );	
		}
						
		public override bool BardImmune{ get{ return true; } }	
		public override bool Unprovokable{ get{ return true; } }
		public override bool Uncalmable{ get{ return true; } }
		public override bool BleedImmune{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override double BonusPetDamageScalar{ get{ return 1.5; } }
		public override int TreasureMapLevel{ get{ return Core.AOS ? 6 : 0; } }
		public override bool CantbeSupreme { get { return true;} }
		public override bool CantbeParagon { get { return true;} }	
		public override bool AlwaysMurderer{ get{ return true; } }

		public override void OnDamage( int amount, Mobile attacker, bool willKill ) 
		{	
		
			double scrollchance=0.20;
			if(attacker is PlayerMobile && attacker.Backpack!=null && attacker.Backpack.FindItemByType(typeof(HerpekitusHintScroll))!=null)scrollchance=0.10;
		
		
			if (this.Hits < (this.HitsMax / 3) && deroot == false) {
				this.Say("*Herpekitus pulls its roots from the ground*");
				deroot = true;
				this.CantWalk = false;
				SetSkill( SkillName.EvalInt, 80, 100.0 );
				SetSkill( SkillName.Magery, 110, 120 );
			}
			
			if (!attacker.InRange( this, 1 ) && this.InLOS( attacker ) && attacker.Alive && attacker != null)
			{
				attacker.SendMessage( "Herpekitus launches a poisonous barb at you!");
				attacker.ApplyPoison( this, Poison.Lethal );
				Effects.SendPacket( attacker, attacker.Map, new HuedEffect( EffectType.Moving, Serial.Zero, Serial.Zero, 0xC7B, this.Location, attacker.Location, 10, 0, false, false, 2075, 0 ) );
				AOS.Damage( attacker, this, Utility.RandomMinMax( 40, 60 ), 0, 0, 0, 100, 0 );
			}	
		
			if (scrollchance >= Utility.RandomDouble() && deroot == false)
			{
				SpawnRoot( attacker );
			}			
			else if (scrollchance >= Utility.RandomDouble() && GetLiveSpawns() > 0 && attacker.Alive && attacker != null) 
			{
				attacker.SendMessage("Herpekitus draws energy from its roots, launching a devastating attack your way!");
				AOS.Damage( attacker, this, GetLiveSpawns() * 10, true, 0, 0, 0, 0, 0, 0, 100, false );
			}
			
			base.OnDamage(amount, attacker, willKill );
			
		}
		
		public override void OnThink()
		{		
			if (minionssummoned == false)
			{
				minionssummoned = true;
				InitialRoots();
				
				for(int i=0;i<10;i++)
				{
					InitialRoots();
				}
				
			}	
		base.OnThink();	
		}
		
		public override void OnAfterSpawn() { 
			InitialRoots();
			base.OnAfterSpawn();
		}
		
		public void InitialRoots( )
		{
			Map map = this.Map;

			if ( map == null )
				return;
				
			Mobile spawn;
				
			if (0.75 >= Utility.RandomDouble()) {
				spawn = new HerpekitusRootBarbed();
			}
			else {
				spawn = new HerpekitusRootCasting();
			}

			spawn.Team = this.Team;

			bool validLocation = false;
			Point3D loc = this.Location;
			for ( int j = 0; !validLocation && j < 4; ++j )
			{	
				spawn.Team = this.Team;
			
				int x = X + Utility.Random( 10 ) - 1;
				int y = Y + Utility.Random( 10 ) - 1;
				int z = map.GetAverageZ( x, y );

				if ( validLocation = map.CanFit( x, y, this.Z, 16, false, false ) )
					loc = new Point3D( x, y, Z );
				else if ( validLocation = map.CanFit( x, y, z, 16, false, false ) )
					loc = new Point3D( x, y, z );
			}

			spawn.MoveToWorld( loc, map );
			spawns.Add(spawn);
		}
		
		public override bool OnBeforeDeath()
		{
			KillLiveSpawns();
			GenerateLoot ();
			return true;
		}	
		
		public void SpawnRoot( Mobile m )
		{
			if ( GetLiveSpawns() < 20 )
			{
				Map map = this.Map;

				if ( map == null )
					return;

				Mobile spawn;
				
				if (0.75 >= Utility.RandomDouble()) {
					spawn = new HerpekitusRootBarbed();
				}
				else {
					spawn = new HerpekitusRootCasting();
				}

				spawn.Team = this.Team;

				bool validLocation = false;
				Point3D loc = this.Location;
	
				for ( int j = 0; !validLocation && j < 4; ++j )
				{
					int x = X + Utility.Random( 10 ) - 1;
					int y = Y + Utility.Random( 10 ) - 1;
					int z = map.GetAverageZ( x, y );

					if ( validLocation = map.CanFit( x, y, this.Z, 16, false, false ) )
						loc = new Point3D( x, y, Z );
					else if ( validLocation = map.CanFit( x, y, z, 16, false, false ) )
						loc = new Point3D( x, y, z );
				}

				spawn.MoveToWorld( loc, map );
				spawns.Add(spawn);
				spawn.Combatant = m;
				this.Say("A root shoots up from the ground");
			}
		}
		
		private int KillLiveSpawns()
		{
		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;
					m.Kill();							
                }
				
		return live;
		}
		
		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;
				live++;							
                }
				
		return live;
		}

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 1 );
			writer.Write(minionssummoned);
			writer.Write(deroot);
			writer.WriteMobileList(spawns);			
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			minionssummoned = reader.ReadBool();
			deroot = reader.ReadBool();
			
			if(version>=1)
			{
				spawns = reader.ReadMobileList();
			}
		}
	}
}
