/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\ML Peerless + misc areas\demitel\mobiles\humusminion.cs
Lines of code: 234
***********************************************************/


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


namespace Server.Items
{
	public class tempfirecollumn : 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 tempfirecollumn() : this(null, TimeSpan.FromSeconds( 10.0 ), 5, 15 )
		{
		}

		public override string DefaultName { get { return "fire"; } }

		[Constructable]
		public tempfirecollumn(Mobile powner, TimeSpan duration, int minDamage, int maxDamage )	: base( 0x3709 )
		{
			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 || o is Item)
					{
						toDamage.Add( o );
					}				
				}

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

						if(m_Owner!=null && m_Owner.ShouldHarm(m))
						{
						m_Owner.DoHarmful( m );	
						Damage( m );
						}
						else if(m_Owner==null && HarmItem.ShouldHarm(m))
						{
						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_Owner, Utility.RandomMinMax(MinDamage,MaxDamage), 0, 100, 0, 0, 0 );
		}

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

		public override void Serialize( GenericWriter writer )
		{			
		}

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





namespace Server.Mobiles
{
	[CorpseName( "a humus minion corpse" )]
	public class humusminion : BaseCreature
	{
	
		
		[Constructable]
		public humusminion () : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "a humus minion";
			Body = Utility.RandomList( 60, 61 );
			BaseSoundID = 362;
			Hue = 1161;

			SetStr( 541, 560 );
			SetDex( 146, 182 );
			SetInt( 301, 540 );

			SetHits( 541, 658 );

			SetDamage( 13, 19 );

			SetDamageType( ResistanceType.Physical, 0 );
			SetDamageType( ResistanceType.Fire, 100 );

			SetResistance( ResistanceType.Physical, 60, 80 );
			SetResistance( ResistanceType.Fire, 100, 120 );
			SetResistance( ResistanceType.Cold, 0, 10 );
			SetResistance( ResistanceType.Poison, 50, 70 );
			SetResistance( ResistanceType.Energy, 30, 50 );

			SetSkill( SkillName.EvalInt, 60, 90 );
			SetSkill( SkillName.Magery, 70, 90 );
			SetSkill( SkillName.Meditation,60, 90 );
			SetSkill( SkillName.MagicResist, 50, 90 );
			SetSkill( SkillName.Tactics, 60, 90 );
			SetSkill( SkillName.Wrestling, 60, 90 );

			Fame = 19000;
			Karma = -7000;

			VirtualArmor = 46;

			
			PackItem( new SulfurousAsh( Utility.Random( 8, 30 ) ) );

			PackReg( 3 );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.UltraRich );
			AddLoot( LootPack.MedScrolls, 5 );
		}

		public override bool ReacquireOnMovement{ get{ return true; } }
		public override bool HasBreath{ get{ return true; } } // fire breath enabled
		public override int TreasureMapLevel{ get{ return 4; } }
		public override int Meat{ get{ return 10; } }
		public override int Hides{ get{ return 24; } }
		public override HideType HideType{ get{ return HideType.Horned; } }
		public override int Scales{ get{ return 5; } }
		public override ScaleType ScaleType{ get{ return ( Body == 60 ? ScaleType.Yellow : ScaleType.Red ); } }
		public override FoodType FavoriteFood{ get{ return FoodType.Meat | FoodType.Fish; } }

		public humusminion( Serial serial ) : base( serial )
		{
		}
		
		public override void OnDamage( int amount, Mobile attacker, bool willKill )
		{
		base.OnDamage(amount,attacker,willKill);
		if(attacker==null)	return;
		
		if(Utility.Random(20)!=15)return;
		if(!attacker.InRange( this, 20 ))return;
		
		//do fire field


		Map map = attacker.Map;
		
		if(map==null)	return;
	
		int attackerx = attacker.X;
		int attackery = attacker.Y;	
				
		int fieldsize = 3 + Utility.Random(4);  //3-7 radius
			
				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 tempfirecollumn(this,TimeSpan.FromSeconds( 5 + Utility.Random(10)),10,35);
								item.MoveToWorld( loc, map );								
							}
					}
			}
				
				
				
		attacker.SendMessage("You become engulfed in flames!");
		attacker.PlaySound( 840 );
				
		}
	
		

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