/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Death on Sep-12-2011 09:54:11pm
Filepath: scripts\_custom\events and scenarios\14th Anniversary\AnniversaryCake.cs
Lines of code: 117
***********************************************************/


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

namespace Server.Items
{
	public class AnniversaryCake : Item
	{
		[Constructable]
		public AnniversaryCake() : base( 2537 )
		{
			Name = "A birthday cake";
			LootType=LootType.Blessed;
			Weight = 1.0;
			
			Hue = Utility.RandomList(2210, 1173, 1168, 1151, 1160, 1165, 16, 1169, 1150, 1153, 1164, 1157, 1166, 33, 1154, 2075, 2076, 1155, 1162, 1266, 1163, 1158, 1324, 1167, 1364, 1172, 1175, 1161, 1151, 1154, 1150, 1153, 1190, 1171, 1287, 1159, 1282, 2067);
		}
		
		public override void GetProperties( ObjectPropertyList list)
		{
			base.GetProperties( list );
			list.Add( 1060658,"Ultima Online \t" + "14th Anniversary");
		}
		
		public override void OnSingleClick( Mobile from )
		{
			base.OnSingleClick( from );

			LabelTo( from, 1070880 ); // Winter 2004
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( !IsChildOf( from.Backpack ) )
			{
				from.SendLocalizedMessage( 1042010 ); // You must have the object in your backpack to use it.
			}
			else if ( from.CanBeginAction( typeof( AnniversaryCake ) ) )
			{
				from.SendMessage("You grab a piece of cake into your hands" );
				from.Target = new CakeTarget( from, this );
			}
			else
			{
				from.SendMessage("You must wait before throwing another piece of cake" );
			}
		}

		private class InternalTimer : Timer
		{
			private Mobile m_From;

			public InternalTimer( Mobile from ) : base( TimeSpan.FromSeconds( 5.0 ) )
			{
				m_From = from;
			}

			protected override void OnTick()
			{
				m_From.EndAction( typeof( AnniversaryCake ) );
			}
		}

		private class CakeTarget : Target
		{
			private Mobile m_Thrower;
			private Item m_Cake;

			public CakeTarget( Mobile thrower, Item cake ) : base ( 10, false, TargetFlags.None )
			{
				m_Thrower = thrower;
				m_Cake = cake;
			}

			protected override void OnTarget( Mobile from, object target )
			{
				if ( target == from )
				{
					from.SendLocalizedMessage( 1005576 ); // You can't throw this at yourself.
				}
				else if ( target is Mobile )
				{
					Mobile targ = (Mobile) target;
					Container pack = targ.Backpack;

					if ( pack != null && pack.FindItemByType( new Type[]{ typeof( AnniversaryCake ) } ) != null )
					{
						if ( from.BeginAction( typeof( AnniversaryCake ) ) )
						{
							new InternalTimer( from ).Start();

							from.PlaySound( 0x145 );

							from.Animate( 9, 1, 1, true, false, 0 );

							targ.SendMessage("You have been hit with cake and frosting!" );
							from.SendMessage("You successfully hit your target with a piece of cake!" );

							Effects.SendMovingEffect( from, targ, 0x36E4, 7, 0, false, true, m_Cake.Hue>1 ? m_Cake.Hue-1 : 0, 0 ); //Hue 0x47F
						}
						else
						{
							from.SendMessage("You must wait before throwing another piece of cake" );
						}
					}
					else
					{
						from.SendMessage("You can only throw cake at somebody who also has an anniversary cake!" );
					}
				}
				else
				{
					from.SendMessage("You can only throw cake at somebody who also has an anniversary cake!" );
				}
			}
		}

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