/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\resources\DiamondNeedle.cs
Lines of code: 80
***********************************************************/


using System;
using Server;
using Server.Targeting;

namespace Server.Items
{
	public class DiamondNeedle : Item
	{
	
		[Constructable]
		public DiamondNeedle() : this( 1 )
		{
		}
	
		[Constructable]
		public DiamondNeedle( int amount ) : base( 3906 )
		{
			Hue = 90;
			Name = "Diamond Needle";
			Weight = 1.0;
			Stackable = true;
			Amount = amount;
		}

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

		public override void OnDoubleClick( Mobile from )
		{
			if ( !IsChildOf( from.Backpack ) )
			{
				// The item must be in your backpack to use it.
				from.SendLocalizedMessage( 1060640 );
			}
			else
			{
				from.Target = new ArmorTarget( this );
				from.SendMessage( "Empower which armor?" );
			}					
		}
		
		private class ArmorTarget : Target
		{
			private DiamondNeedle m_Needle;

			public ArmorTarget( DiamondNeedle powder ) : base( 2, false, TargetFlags.None )
			{
				m_Needle = powder;
			}
			
			protected override void OnTarget( Mobile from, object targeted ) 
			{ 
				if ( targeted is BaseArmor )
				{
					BaseArmor ar = (BaseArmor)targeted;

					if ( ar.IsChildOf( from.Backpack ) && m_Needle.IsChildOf( from.Backpack ) )
					{
						if( ar.ArmorAttributes.SelfRepair < 5 )
						{
							from.FixedParticles( 0x37C4, 1, 8, 9916, 90, 3, EffectLayer.Head );
							from.FixedParticles( 0x37C4, 1, 8, 9502, 90, 4, EffectLayer.Head );
							from.PlaySound( 0x210 );
							from.FixedParticles( 0x373A, 1, 17, 9903, 90, 4, EffectLayer.Head );
							from.PlaySound( 0x244 );
							ar.ArmorAttributes.SelfRepair += 1;
							from.SendMessage( "The needle pierces through your armor, giving it new power" );
							m_Needle.Consume();
						}
						else
							from.SendMessage( "That cannot be empowered any further" );
					}
				}
				else
					from.SendMessage( "That cannot be empowered" );
			}
		}

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

			writer.Write( (int) 0 );
		}

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

			int version = reader.ReadInt();
		}
	}
}