/**********************************************************
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\Malevolent\Malevolent.cs
Lines of code: 368

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;
using Server.Mobiles;
using Server.Misc;
using Server.Spells;

namespace Server.Mobiles 
{ 
	[CorpseName( "a reaper's corpse" )] 
	public class Malevolent : BaseCreature 
	{ 
	
		private bool m_Mist;
		private DateTime MembraneTimer;
		private DateTime FieldTimer;
		private DateTime DelayTimer;//
		private int spawntype = 0;
		
		Random MembraneFuse = new Random(); 
	
	
		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(1175, "Halloween Black", 5);	
					m.SendMessage(200,"You receive a gift: Halloween Black Dye");
					m.GiveItem(gift);				
				}
				else if(0.15 >= Utility.RandomDouble())
				{
				
					if(0.5 >= Utility.RandomDouble()) {
						gift = new SkullsOnAPike();	
						m.SendMessage(200,"You receive a gift: Skulls on a Pike");
					}						
					else if (0.25 >= Utility.RandomDouble()) {
						gift = new GrimWarning();
						m.SendMessage(200,"You receive a gift: Grim Warning");
					}
					else {
						gift = new PlatinumToken();	
						m.SendMessage(200,"You receive a gift: Platinum Token");
					}
					m.GiveItem(gift);
				}
				else if(0.05 >= Utility.RandomDouble())
				{
					gift = new ConjurersSash();
					m.SendMessage(200,"You receive a gift: Conjurer's Sash");
					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 Malevolent() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 ) 
		{ 
			Name = "Malevolent";
			Title = "The Reaper";
			Hue = 0;
			Female = true;
			Body = 0x191;
			HairItemID = 8253;
			HairHue = 1150;

			SetStr( 586, 785 );
			SetDex( 177, 255 );
			SetInt( 351, 450 );
			
			SetMana( 1000, 1500);

			SetHits( 5000, 5000 );

			SetDamage( 19, 23 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 80, 90 );
			SetResistance( ResistanceType.Fire, 20, 30 );
			SetResistance( ResistanceType.Cold, 80, 90 );
			SetResistance( ResistanceType.Poison, 90, 100 );
			SetResistance( ResistanceType.Energy, 20, 30 );

			SetSkill( SkillName.Anatomy, 50.1, 75.0 );
			SetSkill( SkillName.SpiritSpeak, 99.1, 100 );
			SetSkill( SkillName.Necromancy, 99.1, 100.0 );
			SetSkill( SkillName.Meditation, 90.1, 100.0 );
			SetSkill( SkillName.MagicResist, 90.1, 100.0 );
			SetSkill( SkillName.Tactics, 90.1, 100.0 );
			SetSkill( SkillName.Swords, 97.6, 100.0 );

			Fame = 20000;
			Karma = -20000;
				
			Item Cloak = new HoodedShroudOfShadows();
			Cloak.Movable = false;
			Cloak.Hue = 1175;
			AddItem( Cloak );
			
			Item blade = new Scythe();
			blade.Movable = false;
			blade.Hue = 1193;
			AddItem( blade );
		}

		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 bool Uncalmable{ get{ return true; } }
		public override bool NoFlee { get { return true; } }				

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich, 7 );
			AddLoot( LootPack.SuperBoss, 7 );	
		}
		
		public override void OnThink()
		{
		
			BoneHound spawn;
		
			if (this.Hits <= 3000 && spawntype == 0)
			{
				spawntype += 1;
				this.Say( "Come forth, my pet!" );
				
				for(int i=0;i<1;i++)
				{
					spawn = new BoneHound();
					spawn.HitsMaxSeed=spawn.HitsMaxSeed*2;
					spawn.Hits=spawn.HitsMaxSeed;
					SetTempSummon(this,spawn);
					spawn.MoveToWorld( this.Location, this.Map );
				}				
			}
		
			if ( this.Alive && this!=null && m_Mist == true && (MembraneTimer < DateTime.Now) ) {
				PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "*Death has been cast!*" );
				
				List<Mobile> tohit = new List<Mobile>();
				
				foreach ( Mobile m in this.GetMobilesInRange( 20 ) )
				{
					if ( m != null && m.Alive && this.InLOS( m ) && m != this && CanBeHarmful( m ) && ShouldHarm( m ))
					{
						tohit.Add(m);
					}
				}
				
				
				for(int i=0;i<tohit.Count;i++)
				{
					Mobile m = tohit[i];
					
					if ( m.Player && m.Alive && m != null )
					{
			
						Item scroll = m.Backpack.FindItemByType(typeof(MalevolentHintScroll));
		
						if (scroll != null && 0.5 >= Utility.RandomDouble() ) { 
							m.SendMessage("Your scroll has protected you from instant death!");
						}
						else {
							m.SendMessage("Your life escapes you as you are hit by the death spell");
							m.Kill();
						}
					}
					else {
						m.SendMessage("Your life escapes you as you are hit by the death spell");
						m.Kill();
					}
					
				}	
				
				DelayTimer=DateTime.Now + TimeSpan.FromSeconds(Utility.RandomMinMax(45, 80));
				m_Mist = false;
			}	
			else if ( this.Alive && this!=null && m_Mist == true ) {
				this.FixedParticles( 0x373A, 1, 15, 9913, 1193, 7, EffectLayer.Head );
			}
			
			if (0.2 >= Utility.RandomDouble() && 0.2 >= Utility.RandomDouble() && m_Mist == false && (DelayTimer < DateTime.Now))
			{
				PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "*Prepares to cast a powerful spell*" );
				m_Mist = true;
				MembraneTimer=DateTime.Now + TimeSpan.FromSeconds(MembraneFuse.Next( 10, 15 ));
			}	
			
			if (0.2 >= Utility.RandomDouble() && 0.2 >= Utility.RandomDouble() && (FieldTimer < DateTime.Now))
			{
				PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "*Fields of death surround you!*" );
				DeathFields();
				FieldTimer=DateTime.Now + TimeSpan.FromSeconds(Utility.RandomMinMax(75, 120));
			}	
			
			base.OnThink();	
		}
		
		private void DeathFields()
		{
			Map map = this.Map;
		
			int x;
			int y;
			int z;
			
			if (Utility.Random(2) == 1)
				this.PlaySound( 837 ); 
			else
				this.PlaySound( 477 ); 
							
			for (int i = 0; i < 90; i++)
			{
				x = this.X + Utility.RandomMinMax( -22, 22 );
				y = this.Y + Utility.RandomMinMax( -22, 22 );
				z = this.Z;
				
				Point3D fieldloc = new Point3D( x, y, z);
				
				if(!this.InLOS(fieldloc))
				{
					i--;
					continue;
				}
				
				if ( map.CanSpawnMobile(fieldloc) )
				{
					Point3D loc = new Point3D(x ,y, z);
					Item item = new DeathFields(this,TimeSpan.FromSeconds(60));
					item.MoveToWorld( loc, map );	
				}
			}
		}	

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

		public override void Serialize( GenericWriter writer ) 
		{ 
			base.Serialize( writer ); 
			writer.Write( (int) 0 ); 
			writer.Write(spawntype);
		} 

		public override void Deserialize( GenericReader reader ) 
		{ 
			base.Deserialize( reader ); 
			int version = reader.ReadInt(); 
			spawntype = reader.ReadInt();
		} 
	}
}

namespace Server.Items
{
	public class DeathFields : Item
	{
		private TimeSpan m_Duration;
		private int m_MinDamage;
		private int m_MaxDamage;
		private Mobile m_Owner;

		private DateTime m_Created;

		private Timer m_Timer;



		[CommandProperty( AccessLevel.GameMaster )]
		public TimeSpan Duration{ get{ return m_Duration; } set{ m_Duration = value; } }

		[CommandProperty( AccessLevel.GameMaster )]
		public Mobile Owner
		{
			get
			{
				return m_Owner;
			}
			set
			{
				m_Owner = value;
			}
		}		

		[Constructable]
		public DeathFields() : this(null, TimeSpan.FromSeconds( 5.0 ))
		{
		}

		public override string DefaultName { get { return "field of death"; } }

		[Constructable]
		public DeathFields(Mobile powner, TimeSpan duration)	: base( 14732 )
		{
		
			Hue = 1167;
			Movable = false;
			m_Created = DateTime.Now;
			m_Duration = duration;
			m_Owner=powner;

			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 0 ), new TimerCallback( OnTick ) );
		}

		public override void OnAfterDelete()
		{
			if( m_Timer != null )
				m_Timer.Stop();
		}

		private void OnTick()
		{
			DateTime now = DateTime.Now;
			TimeSpan age = now - m_Created;

			if( age > m_Duration )
				Delete();
			else
			{
				
				ArrayList toDamage = new ArrayList();

				foreach( object o in GetObjectsInRange( 0 ) )
				{		
					if ( o is Mobile )
					{
						if (o is Malevolent || o is BoneHound) {
						}
						else {
							toDamage.Add( o );
						}
					}			
				}

				for( int i = 0; i < toDamage.Count; i++ )
				{
					if(toDamage[i] is Mobile)
					{
						Mobile m = toDamage[i] as Mobile;

						if(!m.Blessed && m.Alive)
						{
							Damage( m );
						}		
					}
					else if(toDamage[i] is Item)
					{
					((Item)toDamage[i]).Trigger(m_Owner,this,TriggerType.Heat);
					}
				}
			}
		}



		public void Damage( Mobile m )
		{
		if(m==null)return;
		
		
		if ( m.Player && m.Alive && m != null )
		{
				
			Item scroll = m.Backpack.FindItemByType(typeof(MalevolentHintScroll));
			
			if (scroll != null && 0.5 >= Utility.RandomDouble() ) {
				m.SendMessage("Your scroll has protected you from instant death!");
			}
			else {
				m.SendMessage("Your life escapes you as you step in the field of death");
				m.Kill();
			}
		}
		else {
			m.SendMessage("Your life escapes you as you step in the field of death");
			m.Kill();
		}
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

		public override void Deserialize( GenericReader reader )
		{
		this.Delete();
		}
	}
}