/**********************************************************
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\Jormundgand\Quest Giver\PalaceKey.cs
Lines of code: 62
***********************************************************/


using System;
using Server.Items;

namespace Server.Items 
{
    public class PalaceKey : Item
    {
        private DateTime m_DecayTime;
        private Timer m_Timer;

        [Constructable]
        public PalaceKey()
            : base(0x176B)
        {
            Weight = 0;
            Name = "Palace Key";
            Hue = 1153;
            LootType = LootType.Blessed;
            Movable = true;
            Visible = true;

            m_DecayTime = DateTime.Now + TimeSpan.FromDays(1);

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

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

        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;

            public InternalTimer(Item item, DateTime end)
                : base(end - DateTime.Now)
            {
                m_Item = item;
                Priority=TimerPriority.TwentyMinutes;
            }

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