/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Death on Apr-18-2011 09:34:34pm
Filepath: scripts\_custom\events and scenarios\Easter 2011\RobinEgg.cs
Lines of code: 85
***********************************************************/


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

//using System.Collections;
//using System.Collections.Generic;
//using Server.Targeting;
//using Server.ContextMenus;
//using Server.Network;
//using Server.Regions;

namespace Server.Items
{
	public class RobinEgg : Item
	{
		 
		//public static string Pirate;
		public bool IsSpawned = false;
		private ArrayList spawns = new ArrayList();		
		 
		[Constructable]
		public RobinEgg() : base(Utility.RandomList(5928, 2538, 3884))
		{
			Hue = 1165; 		
			LootType=LootType.Blessed;
			Name = "a robin's egg";
			Weight = 0.5;
		}
		
		public bool IsOwner( Mobile mob )
		{
			BaseHouse house = BaseHouse.FindHouseAt( this );

			return ( house != null && house.IsOwner( mob ) );
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( !this.IsLockedDown )
				from.SendLocalizedMessage( 502693 ); // Remember, this only works when locked down.
			else if (!from.InRange( this, 2 ))
				from.SendMessage( "You are too far away" );
			else if (!IsSpawned && from.Alive && from != null)
			{
				IsSpawned = true;
				Map map = from.Map;
				int x = from.X + Utility.RandomMinMax( -2, 2 );
				int y = from.Y + Utility.RandomMinMax( -2, 2 );
				int z = from.Z;
				//BaseCreature spawn;
				
				for(int i = 0; i < 5; i++) {
					BaseCreature spawn = new Robin(); 
					//spawn.SetControlMaster( from );
					spawn.SummonMaster = from;
					x = from.X + Utility.RandomMinMax( -2, 2 );
					y = from.Y + Utility.RandomMinMax( -2, 2 );
					z = from.Z;
					if ( map.CanSpawnMobile( new Point3D( x, y, z) ) )
					{
						spawn.MoveToWorld( new Point3D( x, y, z ), Map );
					}
					else {
						spawn.MoveToWorld( from.Location, from.Map );	
					}
					spawns.Add(spawn);	
				}
				
				from.SendMessage( "The egg seems to have attracted a group of robins" );
				from.PlaySound(Utility.RandomList(0x019, 0x01D, 0x01F));
				Timer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerCallback( ResetSpawn ) );
			}
		}
		
		public void ResetSpawn( )
		{
			IsSpawned = false; 
		}
		
		public override void GetProperties( ObjectPropertyList list)
		{
			base.GetProperties( list );
			list.Add( 1060658,"Easter \t" + "2011");
		}

		public RobinEgg( 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();
		}
	}
}