/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\events and scenarios\Halloween2011\Quests\Quest Rewards\StaffOfSparks.cs
Lines of code: 99
***********************************************************/


using System;
using Server.Network;
using Server.Items;

namespace Server.Items
{
	public class EasterSparks : BlackStaff
	{

		private int m_Charges;

		[CommandProperty( AccessLevel.GameMaster )]
		public int Charges
		{
			get{ return m_Charges; }
			set{ m_Charges = value; InvalidateProperties(); }
		}

		[Constructable]
		public EasterSparks() : this( 50 )
		{
		}

		[Constructable]
		public EasterSparks( int charges )
		{
			Name = "Easter Staff of Sparks (2012)";
			Hue = 1169;
			m_Charges = charges;
			LootType = LootType.Blessed;
		}

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

		public override void AddNameProperties( ObjectPropertyList list )
		{
			base.AddNameProperties( list );

			list.Add( 1060741, m_Charges.ToString() ); // charges: ~1_val~
		}

		public override void OnDoubleClick( Mobile from )
		{
		if ( !IsChildOf( from ) )return;
		
			BeginLaunch( from, true );
		}

		public void BeginLaunch( Mobile from, bool useCharges )
		{
			Map map = from.Map;

			if ( map == null || map == Map.Internal )
				return;

			if ( useCharges )
			{
				if ( Charges > 0 )
				{
					--Charges;
				}
				else
				{
					from.SendLocalizedMessage( 502412 ); // There are no charges left on that item.
					return;
				}
			}

			from.SendMessage( "The staff launches out a fury of fireworks!" ); 

				for(int i=3+Utility.Random(14);i>0;i--)
				{				
				Point3D ourLoc = GetWorldLocation();

				Point3D startLoc = new Point3D( ourLoc.X, ourLoc.Y, ourLoc.Z + 10 );
				Point3D endLoc = new Point3D( startLoc.X + Utility.RandomMinMax( -2, 2 ), startLoc.Y + Utility.RandomMinMax( -2, 2 ), startLoc.Z + 32 );

				Effects.SendMovingEffect( new Entity( Serial.Zero, startLoc, map ), new Entity( Serial.Zero, endLoc, map ),
					0x36E4, 5, 0, false, false );

				Timer.DelayCall( TimeSpan.FromSeconds( 1 + Utility.RandomDouble() ), new TimerStateCallback( FinishLaunch ), new object[]{ from, endLoc, map } );
				}
			
			}

		private void FinishLaunch( object state )
		{
			object[] states = (object[])state;

			Mobile from = (Mobile)states[0];
			Point3D endLoc = (Point3D)states[1];
			Map map = (Map)states[2];
			
			int hue = 1168;

			//if ( Utility.RandomBool() )
			hue = Utility.RandomList(1168, 75, 1165, 1151, 2213, 1324, 1158, 1169, 1162, 1160, 1167);
			

			//int renderMode = Utility.RandomList( 0, 2, 3, 4, 5, 7 );

			Effects.PlaySound( endLoc, map, Utility.Random( 0x11B, 4 ) );
			Effects.SendLocationEffect( endLoc, map, 0x373A + (0x10 * Utility.Random( 4 )), 16, 10, hue, 0 );
		}

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

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

			writer.Write( (int) m_Charges );
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_Charges = reader.ReadInt();
					break;
				}
			}
		}
	}
}