/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\Dye System\PigmentTicket.cs
Lines of code: 99
***********************************************************/


using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
using Server.Commands;
using Server.Spells;
using Server.Regions;
using Server.Spells.Fourth;

namespace Server.Items
{
	public class PigmentTicket : Item
	{
		private int m_UsesRemaining;
		public override bool ForceShowProperties{ get{ return ObjectPropertyList.Enabled; } }

		
		[Constructable]
		public PigmentTicket( int uses) : base(5360)
		{
		    Name = "Pigment Ticket";
		    m_UsesRemaining = uses;
			Movable = true;
			Hue = 1154;
		}
		
		[Constructable]
		public PigmentTicket() : this(1)
		{
		}			
		
		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );
			list.Add( 1060584, m_UsesRemaining.ToString() ); // uses remaining: ~1_val~
		}

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

		public override void OnDoubleClick( Mobile from )
		{
			if ( !from.Player )return;
			
			if(from.Frozen)
			{
				from.SendMessage("You cannot use this while frozen");
				return;
			}	
			
			if ( from.InRange( GetWorldLocation(), 1 ) && CanUse( from ))
			{				
				from.Frozen=true;
				from.SendMessage("You begin to examine the ticket...");
				Timer.DelayCall( TimeSpan.FromSeconds(5), new TimerStateCallback( DoTeleport ), from );
			}
		}
		
		
		private void DoTeleport(object state)
		{
			Mobile from = state as Mobile;
			if(from==null)return;
			
			from.Frozen=false;			
			from.MoveToWorld(new Point3D(5421,1190,7),Map.Trammel);
			from.SendLocalizedMessage( 1074839 ); // As you examine the ticket, your surroundings mysteriously change!
		}
		


		public bool CanUse( Mobile m )
		{
 
			if(!RecallSpell.CheckTravel(null,m.Location,m.Map, m,false))
			{
				return false;
			}
			else if(m.Map==Map.Felucca)
			{
				m.SendMessage("You cannot use this in felucca");
				return false;
			}
			else if(m.Region.IsPartOf("DyeRoom"))
			{
				m.SendMessage("You are already in dye room!");
				return false;
			}
			
			return true;
		}

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

			writer.Write( (int)0 );

			writer.WriteEncodedInt( m_UsesRemaining );
		}

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

			int version = reader.ReadInt();

			m_UsesRemaining = reader.ReadEncodedInt();
		}

		#region IUsesRemaining Members

		[CommandProperty( AccessLevel.GameMaster )]
		public int UsesRemaining
		{
			get { return m_UsesRemaining; }
			set { m_UsesRemaining = value; InvalidateProperties(); Modify();}
		}



		#endregion

	}
}