/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\special\RadiatingLakeTile.cs
Lines of code: 338
***********************************************************/


using System;
using System.Collections;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using Server.Commands;

namespace Server.Items
{
	public class RadiatingLakeTile : Item
	{
		private TimeSpan m_Duration;
		private int m_MinDamage;
		private int m_MaxDamage;
		private int m_range;
		
		private int m_d1,m_d2,m_d3,m_d4,m_d5,m_d6,m_d7;
		
		private int m_clilocmsg;		
		private string m_stringmsg;
		private int m_sound;
		private int m_effecthue;
		private int m_effectid;
		
		private int m_PoisonType=-1;
		private int m_delay=2;
		
		bool timerstarted=false;


		private Timer m_Timer;
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamagePhysical
		{
			get
			{
				return m_d1;
			}
			set
			{
				m_d1 = value;Modify();
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamageFire
		{
			get
			{
				return m_d2;
			}
			set
			{
				m_d2 = value;Modify();
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamageCold
		{
			get
			{
				return m_d3;
			}
			set
			{
				m_d3 = value;Modify();
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamagePoison
		{
			get
			{
				return m_d4;
			}
			set
			{
				m_d4 = value;Modify();
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamageEnergy
		{
			get
			{
				return m_d5;
			}
			set
			{
				m_d5 = value;Modify();
			}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamageChaos
		{
			get
			{
				return m_d6;
			}
			set
			{
				m_d6 = value;Modify();
			}
		}	
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int DamageDirect
		{
			get
			{
				return m_d7;
			}
			set
			{
				m_d7 = value;Modify();
			}
		}			


		[CommandProperty( AccessLevel.GameMaster )]
		public string OnDamageMessage
		{
			get
			{
				return m_stringmsg;
			}
			set
			{
				m_stringmsg = value;Modify();
			}
		}		

		[CommandProperty( AccessLevel.GameMaster )]
		public int OnDamageLocalMessage
		{
			get
			{
				return m_clilocmsg;
			}
			set
			{
				m_clilocmsg = value;Modify();
			}
		}			
		
		

		[CommandProperty( AccessLevel.GameMaster )]
		public int Range
		{
			get
			{
				return m_range;
			}
			set
			{
				m_range = value;Modify();
			}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MinDamage
		{
			get
			{
				return m_MinDamage;
			}
			set
			{
				m_MinDamage = value;Modify();
			}
		}

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

				m_MaxDamage = value;Modify();
			}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int Sound
		{
			get
			{
				return m_sound;
			}
			set
			{
				m_sound = value;Modify();
			}
		}			
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int EffectHue
		{
			get
			{
				return m_effecthue;
			}
			set
			{
				m_effecthue = value;Modify();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int EffectID
		{
			get
			{
				return m_effectid;
			}
			set
			{
				m_effectid = value;Modify();
			}
		}	

		[CommandProperty( AccessLevel.GameMaster )]
		public int PoisonType
		{
			get
			{
				return m_PoisonType+1;
			}
			set
			{
				m_PoisonType = value-1;
				
				//poisons go from 0-4 but we'll display/set them as 1-5				
				
				if(m_PoisonType>4)m_PoisonType=4;Modify();
			}
		}		

		[CommandProperty( AccessLevel.GameMaster )]
		public int Delay
		{
			get
			{
				return m_delay;
			}
			set
			{
				m_delay = value;Modify();
			}
		}			

		[Constructable]
		public RadiatingLakeTile() : this(3, 6)
		{
		}

		[Constructable]
		public RadiatingLakeTile(int minDamage, int maxDamage): base( 0x122A )
		{
			Hue = 253;
			ItemID = 4650;
			Visible = false;
			Movable = false;

			m_MinDamage = minDamage;
			m_MaxDamage = maxDamage;
		}
		
		public override bool HandlesOnMovement{ get{ return true; } }

		public override void OnMovement( Mobile m, Point3D oldLocation )
		{
			if((m_Timer==null || !m_Timer.Running) && m.InRange(this,Range))
			{
			
				if(m_Timer ==null || !m_Timer.Running) m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( m_delay ), new TimerCallback( OnTick ) );
			timerstarted=true;
			}				
		}
		
		public override void OnDoubleClick( Mobile from )
		{
		if(from.AccessLevel>AccessLevel.Player)RegionBounds.ShowObjectBounds(from,this,this.Range);
		}		
		
		

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


		
		private void OnTick()
		{				
				
			DamageAura da = new DamageAura();
			
			da.SetDamage(MinDamage,MaxDamage);
			da.SetDamageType(m_d1,m_d2,m_d3,m_d4,m_d5,m_d6,m_d7);
			da.SetEffect(m_effectid,9502,m_effecthue,3,m_sound);
			
			TextDefinition td;			
			if(m_clilocmsg!=0)td=m_clilocmsg;
			else td=m_stringmsg;
			
			da.SetText(td);
			da.SetRange(Range);	
			da.SetPoison(m_PoisonType);
				
			if(da.ItemDoAura(this)<=0)m_Timer.Stop();

		}



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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.WriteEncodedInt( 3 ); // version
			writer.Write(m_range);
			writer.Write(m_MinDamage);
			writer.Write(m_MaxDamage);	

			writer.Write(m_d1);
			writer.Write(m_d2);
			writer.Write(m_d3);
			writer.Write(m_d4);
			writer.Write(m_d5);
			writer.Write(m_d6);
			writer.Write(m_d7);
			
			writer.Write(m_clilocmsg);
			writer.Write(m_stringmsg);
			
			writer.Write(m_effecthue);
			writer.Write(m_effectid);
			writer.Write(m_sound);
			
			writer.Write((int)m_PoisonType);
			writer.Write((int)m_delay);			
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadEncodedInt();
			
			m_range=reader.ReadInt();
			m_MinDamage=reader.ReadInt();
			m_MaxDamage=reader.ReadInt();
			
			m_d1=reader.ReadInt();
			m_d2=reader.ReadInt();
			m_d3=reader.ReadInt();
			m_d4=reader.ReadInt();
			m_d5=reader.ReadInt();
			m_d6=reader.ReadInt();
			if(version>=3)m_d7=reader.ReadInt();
			
			m_clilocmsg=reader.ReadInt();
			m_stringmsg=reader.ReadString();	

			if(version==0)
			{
			m_effecthue=1150;
			m_effectid=0x374A;
			m_sound=0x10B;
			}
			if(version>=1)
			{
			m_effecthue=reader.ReadInt();
			m_effectid=reader.ReadInt();
			m_sound=reader.ReadInt();
			}
			if(version>=2)
			{
			m_PoisonType=reader.ReadInt();
			m_delay=reader.ReadInt();
			}
		}
	}

}