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

Description: 

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


using System;
using Server;
using Server.Items;
using Server.Mobiles;
using System.Collections;
using Server.Targeting;
using Server.Misc;
using Server.Spells;


namespace Server.Mobiles
{
	[CorpseName( "a wisp corpse" )]
	public class ExpiringWispOfMagic : BaseCreature
	{
		public override bool DeleteCorpseOnDeath{ get{ return true; } }
		
		private DateTime DelayTimer;
		
		[Constructable]
		public ExpiringWispOfMagic() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "a wisp of magic";
			Body = 58;
			BaseSoundID = 466;
			Hue = Utility.RandomList(1175, 1157, 1359, 1163, 1155);

			SetStr( 96, 120 );
			SetDex( 91, 115 );
			SetInt( 21, 45 );

			SetHits( 80, 135 );

			SetDamage( 10, 12 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 20, 25 );
			SetResistance( ResistanceType.Fire, 10, 20 );
			SetResistance( ResistanceType.Cold, 15, 25 );
			SetResistance( ResistanceType.Poison, 15, 25 );
			SetResistance( ResistanceType.Energy, 15, 25 );

			SetSkill( SkillName.MagicResist, 75.1, 100.0 );
			SetSkill( SkillName.Tactics, 55.1, 80.0 );
			SetSkill( SkillName.Wrestling, 55.1, 75.0 );
			SetSkill( SkillName.EvalInt, 20.1, 30.0 );
			SetSkill( SkillName.Magery, 90.1, 100.0 );

			Fame = 4500;
			Karma = -4500;
			
			DelayTimer=DateTime.Now + TimeSpan.FromSeconds(Utility.RandomMinMax(5, 8));
			Timer.DelayCall( TimeSpan.FromMinutes( 15.0 ), new TimerCallback( Delete ) ); //To prevent spawn overflow
		}
		
		public override void OnThink()
		{
			if (this.Combatant!= null && this.InLOS( this.Combatant ) && this.Combatant.Hidden == true) 
			{
				this.Combatant.Hidden = false;
				this.Combatant.SendMessage("The wisp is not fooled by your attempt to hide");
			}
		
			if (this.Combatant!= null && this.InLOS( this.Combatant ) && this.Combatant.InRange( this, 2 ) && (DelayTimer < DateTime.Now)) 
			{
				this.Combatant.SendMessage("The wisp explodes, leaving behind a magical residue");
				SelfDestruct( this );
			}
			
			base.OnThink();		
		}
		
		public void SelfDestruct( Mobile wisp)
		{
		
		Map map = wisp.Map;
		
		if(map==null) return;
	
		int attackerx = wisp.X;
		int attackery = wisp.Y;	
				
		int fieldsize = 2;  
			
			for ( int ix = - fieldsize; ix <=  fieldsize; ++ix )
			{
				for ( int iy = - fieldsize; iy <=  fieldsize; ++iy )
				{
					double dist = Math.Sqrt(ix*ix+iy*iy);
					if ( dist > fieldsize )continue;
							
					int tx = attackerx+ix;
					int ty = attackery+iy;

					LandTile t = map.Tiles.GetLandTile( tx, ty );

					Point3D loc = new Point3D(tx ,ty, t.Z);
						
					if ( !Spells.SpellHelper.CheckMulti( new Point3D( tx, ty, -5 ), map ) )
					{
						//create the tile
						
						Item item = new PoisonColumn(wisp,TimeSpan.FromSeconds(7), 35, 45);
						
						if (wisp.Hue == 1155) {
							item = new PoisonColumn(wisp,TimeSpan.FromSeconds(7), 35, 45);
						}
						else if (wisp.Hue == 1163) {
							item = new CurseColumn(wisp,TimeSpan.FromSeconds(5), 35, 45);
						}
						else if (wisp.Hue == 1157) {
							item = new PainColumn(wisp,TimeSpan.FromSeconds(7), 45, 60);
						}
						else if (wisp.Hue == 1175) {
							item = new DeathColumn(wisp,TimeSpan.FromSeconds(7), 45, 60);
						}
						else if (wisp.Hue == 1359) {
							item = new FlameColumn(wisp,TimeSpan.FromSeconds(10), 70, 95);
						}
						else {
							item = new PoisonColumn(wisp,TimeSpan.FromSeconds(7), 35, 45);
						}
						item.MoveToWorld( loc, map );								
					}
				}
			}
			
			wisp.Kill();
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich, 2 );
		}
		
		public override bool BardImmune{ get{ return true; } }
		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 Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override bool NoFlee { get { return true; } }

		public ExpiringWispOfMagic( 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();
			this.Delete();
		}
	}
}

namespace Server.Items
{
	public class PoisonColumn : 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;
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				m_MinDamage = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxDamage
		{
			get
			{
				return m_MaxDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				if ( value < MinDamage )
					value = MinDamage;

				m_MaxDamage = value;
			}
		}

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

		public override string DefaultName { get { return "spell residue"; } }

		[Constructable]
		public PoisonColumn(Mobile powner, TimeSpan duration, int minDamage, int maxDamage )	: base( 0x3709 )
		{
		
			Hue = 1155;
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
			m_Created = DateTime.Now;
			m_Duration = duration;
			m_Owner=powner;

			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 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 PumpkinKing || o is ExpiringWispOfMagic) {
						}
						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;
			AOS.Damage( m, m, Utility.RandomMinMax(MinDamage,MaxDamage), 0, 0, 0, 100, 0 );
			m.SendMessage("The magical residue damages you. You have been poisoned.");
			m.ApplyPoison( m, Poison.Lethal );
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

		public override void Deserialize( GenericReader reader )
		{
		this.Delete();
		}
	}
	
	public class CurseColumn : 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;
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				m_MinDamage = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxDamage
		{
			get
			{
				return m_MaxDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				if ( value < MinDamage )
					value = MinDamage;

				m_MaxDamage = value;
			}
		}

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

		public override string DefaultName { get { return "spell residue"; } }

		[Constructable]
		public CurseColumn(Mobile powner, TimeSpan duration, int minDamage, int maxDamage )	: base( 0x3709 )
		{
		
			Hue = 1163;
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
			m_Created = DateTime.Now;
			m_Duration = duration;
			m_Owner=powner;

			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 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 PumpkinKing || o is ExpiringWispOfMagic) {
						}
						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;
			AOS.Damage( m, m, Utility.RandomMinMax(MinDamage,MaxDamage), 0, 0, 0, 0, 100 );
			m.SendMessage("The magical residue damages you. You feel slow.");
			Server.Items.BaseWeapon.Mute(m,15,4);
			Server.Spells.Spell.Mute(m,15,4);
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

		public override void Deserialize( GenericReader reader )
		{
		this.Delete();
		}
	}
	
	public class DeathColumn : 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;
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				m_MinDamage = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxDamage
		{
			get
			{
				return m_MaxDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				if ( value < MinDamage )
					value = MinDamage;

				m_MaxDamage = value;
			}
		}

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

		public override string DefaultName { get { return "spell residue"; } }

		[Constructable]
		public DeathColumn(Mobile powner, TimeSpan duration, int minDamage, int maxDamage )	: base( 0x3709 )
		{
		
			Hue = 1175;
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
			m_Created = DateTime.Now;
			m_Duration = duration;
			m_Owner=powner;

			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 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 PumpkinKing || o is ExpiringWispOfMagic) {
						}
						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;
			AOS.Damage( m, m, Utility.RandomMinMax(MinDamage,MaxDamage), 0, 0, 100, 0, 0 );
			m.Hits -= 5; 
			m.Mana -= 5; 
			m.Stam -= 5; 
			m.SendMessage("The magical residue damages you. You feel drained.");
			
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

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

public class PainColumn : 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;
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				m_MinDamage = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxDamage
		{
			get
			{
				return m_MaxDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				if ( value < MinDamage )
					value = MinDamage;

				m_MaxDamage = value;
			}
		}

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

		public override string DefaultName { get { return "spell residue"; } }

		[Constructable]
		public PainColumn(Mobile powner, TimeSpan duration, int minDamage, int maxDamage )	: base( 0x3709 )
		{
		
			Hue = 1157;
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
			m_Created = DateTime.Now;
			m_Duration = duration;
			m_Owner=powner;

			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 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 PumpkinKing || o is ExpiringWispOfMagic) {
						}
						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;
			AOS.Damage( m, m, Utility.RandomMinMax(MinDamage,MaxDamage), 100, 0, 0, 0, 0 );
			BleedAttack.BeginBleed(m,m);
			MortalStrike.BeginWound(m, TimeSpan.FromSeconds(6.0));
			m.SendMessage("The magical residue damages you. You are cut and unable to heal");
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

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

////////////////////////////////////////////////////////////////////	

public class FlameColumn : 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;
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				m_MinDamage = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxDamage
		{
			get
			{
				return m_MaxDamage;
			}
			set
			{
				if ( value < 1 )
					value = 1;

				if ( value < MinDamage )
					value = MinDamage;

				m_MaxDamage = value;
			}
		}

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

		public override string DefaultName { get { return "spell residue"; } }

		[Constructable]
		public FlameColumn(Mobile powner, TimeSpan duration, int minDamage, int maxDamage )	: base( 0x3709 )
		{
		
			Hue = 1359;
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
			m_Created = DateTime.Now;
			m_Duration = duration;
			m_Owner=powner;

			m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 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 PumpkinKing || o is ExpiringWispOfMagic) {
						}
						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;
			AOS.Damage( m, m, Utility.RandomMinMax(MinDamage,MaxDamage), 0, 100, 0, 0, 0 );
			m.SendMessage("The magical residue damages you. You take a large amount of damage");
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

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