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

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( "a pumpkin corpse" )]
	public class PumpkinKing : BaseCreature
	{
		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 2 ) )
			{
				default:
				case 0: return WeaponAbility.ConcussionBlow;
				case 1: 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 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(1359, "Halloween Orange", 5);	
					m.SendMessage(200,"You receive a gift: Halloween Orange Dye");
					m.GiveItem(gift);				
				}
				else if(0.15 >= Utility.RandomDouble())
				{
				
					if(0.5 >= Utility.RandomDouble()) {
						gift = new HalloweenCarvedPumpkin();	
						m.SendMessage(200,"You receive a gift: Carved Pumpkin");
					}						
					else if (0.25 >= Utility.RandomDouble()) {
						gift = new HalloweenCarvedPumpkin();	
						m.SendMessage(200,"You receive a gift: Carved Pumpkin");
					}
					else {
						gift = new PlatinumToken();	
						m.SendMessage(200,"You receive a gift: Platinum Token");
					}
					m.GiveItem(gift);
				}
				else if(0.05 >= Utility.RandomDouble())
				{
					gift = new ConjurersTrinket();
					m.SendMessage(200,"You receive a gift: Conjurer's Trinket");
					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);	
		}
	
		[Constructable]
		public PumpkinKing() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.6, 1.2 )
		{
			Name = "Evil Pumpkin King";
			Body = Utility.RandomList(1246,1247);
			BaseSoundID = 0x3E9;
			Hue = 0;

			SetStr( 843, 1021 );
			SetDex( 66, 82 );
			SetInt( 57, 78 );

			SetHits( 5000, 5000 );
			SetStam( 66, 82 );
			SetMana( 57, 78 );

			SetDamage( 10, 25 );

			SetDamageType( ResistanceType.Physical, 50 );
			SetDamageType( ResistanceType.Poison, 50 );

			SetResistance( ResistanceType.Physical, 52, 56 );
			SetResistance( ResistanceType.Fire, 20, 24 );
			SetResistance( ResistanceType.Cold, 23, 26 );
			SetResistance( ResistanceType.Poison, 69, 76 );
			SetResistance( ResistanceType.Energy, 22, 26 );

			SetSkill( SkillName.MagicResist, 109.6, 111.6 );
			SetSkill( SkillName.Meditation, 109.6, 111.6 );
			SetSkill( SkillName.Tactics, 96.7, 112.7 );
			SetSkill( SkillName.Wrestling, 85.2, 102.2 );

			Fame = 10000;
			Karma = -10000;
		}

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

		public override int TreasureMapLevel{ get{ return Core.AOS ? 6 : 0; } }
		public override bool Unprovokable{ get{ return true; } }
		public override bool Uncalmable{ get{ return true; } }
		public override bool CantbeSupreme { get { return true;} }
		public override bool CantbeParagon { get { return true;} }	
		public override bool AlwaysMurderer{ get{ return true; } }

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

		public void SpawnMinion( Mobile m )
		{
			Map map = this.Map;

			if ( map == null )
			{
				return;
			}

			ExpiringWispOfMagic spawned = new ExpiringWispOfMagic();

			spawned.Team = this.Team;

			bool validLocation = false;
			Point3D loc = this.Location;

			for ( int j = 0; !validLocation && j < 20; ++j )
			{
				int x = X + Utility.Random( 3 ) - 1;
				int y = Y + Utility.Random( 3 ) - 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 );
				}
			}

			spawned.MoveToWorld( loc, map );
			spawned.Combatant = m;
		}

		public void EatMinion()
		{
			ArrayList toEat = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 15 ) )
			{
				if ( m is ExpiringWispOfMagic )
				{
					toEat.Add( m );
				}
			}

			if ( toEat.Count > 0 )
			{
				this.Say ("*The evil pumpkin absorbs the wisps of magic, replenishing health*");
				PlaySound( Utility.Random( 0x3B, 2 ) ); // Eat sound

				foreach ( Mobile m in toEat )
				{
					Hits += m.Hits * 5;
					m.FixedParticles( 0x3728, 10, 15, 9955, EffectLayer.Waist );
					m.Delete();
				}
			}
		}
		
		public override void OnDamage( int amount, Mobile attacker, bool willKill ) 
		{			
			if(attacker != null && attacker.Alive) 
			{
				double scrollmult=1;
				if(attacker is PlayerMobile && attacker.Backpack!=null && attacker.Backpack.FindItemByType(typeof(PumpkinKingHintScroll))!=null)scrollmult=0.5;
		
				if ( 0.20*scrollmult >= Utility.RandomDouble())
				{
					SpawnMinion( attacker );
				}
				else if ( 0.20*scrollmult >= Utility.RandomDouble() && (this.Hits < (this.HitsMax / 4))) 
				{
					EatMinion();
				}
			}
			base.OnDamage(amount, attacker, willKill);	
		}
	}
}