/**********************************************************
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\shimering effusion\Quest Giver\PrismOfLightTicket.cs
Lines of code: 89
***********************************************************/


using System;
using Server.Items;

namespace Server.Items 
{
    public class PrismOfLightTicket : Item
    {
        private DateTime m_DecayTime;
        private Timer m_Timer;
		
		public override int LabelNumber{ get{ return 1074340; } }	//rism of light admision ticket	

        [Constructable]
        public PrismOfLightTicket() : base(5360)
        { 
			Hue=1151;
            LootType = LootType.Blessed;
            Movable = true;
            Visible = true;

            m_DecayTime = DateTime.Now + TimeSpan.FromHours(12);

            m_Timer = new InternalTimer(this, m_DecayTime);
            m_Timer.Start();
        }
		

        public override void GetProperties( ObjectPropertyList list )
        {
            base.GetProperties( list );
			
			list.Add(1074841);//Double click to transport out of the Prism of Light dungeon			
			list.Add( 1075269 );//Destroyed when dropped
			
			TimeSpan TLifeSpan = m_DecayTime-DateTime.Now;			
			int LifeSpan=(int)TLifeSpan.TotalSeconds;			
            list.Add( 1072517, LifeSpan.ToString() ); // Lifespan: ~1_val~ seconds
        }
		
		
		
		public override bool OnDroppedToWorld( Mobile from, Point3D p )
		{
			this.Delete();
			return false;
		}
		
		

        public PrismOfLightTicket(Serial serial) : base(serial)
        {
        }
        
        public override void OnDoubleClick( Mobile from )
		{
			if(from.Region.IsPartOf( "Prism of Light" ))
			{
			from.SendMessage("You have been teleported outside the dungeon");
			
			Point3D changeto = new Point3D(3783,1107,20);
			
			Server.Mobiles.BaseCreature.TeleportPets( from, changeto,from.Map, false ,200, true );
			from.Location = changeto;
			}	
		}	

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

            base.OnAfterDelete();
        }

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

            writer.WriteDeltaTime(m_DecayTime);
        }

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

            m_DecayTime = reader.ReadDeltaTime();
            m_Timer = new InternalTimer(this, m_DecayTime);
            m_Timer.Start();
        }

        private class InternalTimer : Timer
        {
            private Item m_Item;
			private DateTime expire;

            public InternalTimer(Item item, DateTime end) : base(TimeSpan.FromSeconds(5),TimeSpan.FromSeconds(5))
            {
                m_Item = item;
                Priority=TimerPriority.FiveSeconds;
				expire=end;
            }

            protected override void OnTick()
            {
                m_Item.InvalidateProperties();
				
				if(DateTime.Now>expire)
				{
					m_Item.Delete();
					Stop();
				}
            }
        }
    }
} 