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

Description: 

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


using System;
using Server;
using Server.Mobiles;

namespace Server.Items
{
	public class UnholyEgg : Item, ICarvable
	{
		private SpawnTimer m_Timer;

		public override string DefaultName
		{
			get { return "unholy egg"; }
		}

		[Constructable]
		public UnholyEgg() : base( 16831 )
		{
			Movable = false;
			Hue = 1150;

			m_Timer = new SpawnTimer( this );
			m_Timer.Start();
		}

		public void Carve( Mobile from, Item item )
		{
			Effects.PlaySound( GetWorldLocation(), Map, 0x48F );
			Effects.SendLocationEffect( GetWorldLocation(), Map, 0x3728, 10, 10, 0, 0 );

			if ( 0.3 > Utility.RandomDouble() )
			{
				if ( ItemID == 16831 )
					from.SendMessage( "You destroy the egg." );
				else
					from.SendMessage( "You destroy the egg." );

				Delete();

				m_Timer.Stop();
			}
			else
			{
				if ( ItemID == 16831 )
					from.SendMessage( "You damage the egg." );
				else
					from.SendMessage( "You damage the egg." );
			}
		}

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

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

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

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

			int version = reader.ReadInt();

			m_Timer = new SpawnTimer( this );
			m_Timer.Start();
		}

		private class SpawnTimer : Timer
		{
			private Item m_Item;

			public SpawnTimer( Item item ) : base( TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 10 ) ) )
			{
				Priority = TimerPriority.FiftyMS;

				m_Item = item;
			}

			protected override void OnTick()
			{
				if ( m_Item.Deleted )
					return;

				Mobile spawn;

				spawn = new ExpiringTurkeyMinion(); 

				spawn.MoveToWorld( m_Item.Location, m_Item.Map );

				m_Item.Delete();
			}
		}
	}
}