/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jan-01-2012 10:09:12pm
Filepath: scripts\events and scenarios\Christmas\items\SantaVillageKey.cs
Lines of code: 101

Description: 

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


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

namespace Server.Items
{

	public class SantaVillageKey : Item
	{		
		private DateTime m_ExpireDate;		
		

		[Constructable]
		public SantaVillageKey() : base(0x100F)
		{
			Hue=1151;
			Name="Key to Santa's Village";	
			LootType=LootType.Blessed;
			
			
			m_ExpireDate = new DateTime(2012, 1, 1);  //hard coded expiry date			
		}
		
		public override void OnDoubleClick( Mobile from )
		{
			if(DateTime.Now>m_ExpireDate)
			{
				from.SendMessage("I'm afraid Santa's Village is closed for the season, this key has expired!");
				this.Delete();
				return;
			}
			
			if(!Server.Spells.Fourth.RecallSpell.CheckTravel(null,from.Location, from.Map, from,false))
			{
				from.SendMessage("You cannot use this now");		
				return;
			}
			
			
			from.SendMessage("A portal opens to Santa's Village!");
			
			Effects.PlaySound(from.Location,from.Map, 0x20E );			
			new InternalItem(new Point3D(5254,455,16),Map.Trammel).MoveToWorld(from.Location,from.Map);
			
		}	

		
		
		

		

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

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

			writer.Write( (int) 0 ); // version
			writer.Write(m_ExpireDate);

		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();			
			m_ExpireDate = reader.ReadDateTime();
		}
		
		
		public override void OnAfterLoad()
		{
			if(DateTime.Now>m_ExpireDate)  //check if it has expired, if yes delete it
			{
				this.Delete();  
			}
		}
		
		
		[DispellableField]
		private class InternalItem : Moongate
		{
			public override bool ShowFeluccaWarning{ get{ return Core.AOS; } }
			public override bool CheckTravel{get{return true;}}			

			public InternalItem( Point3D target, Map map ) : base( target, map )
			{
				Map = map;

				Hue=1152;

				Dispellable = true;

				InternalTimer t = new InternalTimer( this );
				t.Start();
			}
			
			

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

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

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

			private class InternalTimer : Timer
			{
				private Item m_Item;

				public InternalTimer( Item item ) : base( TimeSpan.FromSeconds( 15.0 ) )
				{
					Priority = TimerPriority.OneSecond;
					m_Item = item;
				}

				protected override void OnTick()
				{
					m_Item.Delete();
				}
			}
		}
		
		
		
	}	
}