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


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

namespace Server.Items
{
	public class DelayDelete : Item
	{
		private Item todel;
		
		[Constructable]
		public DelayDelete(Item todelete,TimeSpan delay) : base(0)
		{
			Movable=false;
			Visible=false;
			
			todel=todelete;
			
			
			this.MoveToWorld(new Point3D(0,0,-100),Map.Trammel); //just shove it in the sea 
			
			new ExpireTimer(this,delay).Start();
		}

		
		public DelayDelete( Serial serial ) : base( serial )
		{
		}		
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			writer.Write(todel);
		}

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

			int version = reader.ReadInt();
			todel=reader.ReadItem();
					
			this.Delete();
		}
		
		public override void OnDelete()
		{
			if(todel!=null)todel.Delete();
			base.OnDelete();
		}
		
		
		
		private class ExpireTimer : Timer
		{
			private DelayDelete m_owner;

			public ExpireTimer( DelayDelete owner,TimeSpan delay ) : base( delay )
			{
				Priority = TimerPriority.OneSecond;
				m_owner=owner;
			}

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