/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\Artifacts of Assimilation\artifacts\lessers\pigmentsoffel.cs
Lines of code: 142
***********************************************************/


using Server;
using System;
using Server.Misc;
using Server.Mobiles;
using Server.Items;


public class pigmentsoffel : Item
	{

	private int m_UsesRemaining;



		[Constructable]
		public pigmentsoffel() : base()
		{
		ItemID=3622;
		m_UsesRemaining = 25;
		
		if(Utility.Random(10)==5)m_UsesRemaining = 50;
		
		Name="Pigments of Felucca";		
		
		//set a random hue
		switch(Utility.Random(12))
		{
		case 0:
		Hue=1364;		
		Name +=" (Insight Blue)";
		break;
		case 1:
		Hue=26;
		Name +=" (Barbie Pink)";
		break;
		case 2:
		Hue=1161;
		Name +=" (Scorch Orange)";
		break;
		case 3:
		Hue=2210;
		Name +=" (Forest Green)";
		break;
		case 4:
		Hue=1173;
		Name +=" (Chlorine Blue)";
		break;		
		case 5:
		Hue=1154;
		Name +=" (Icy Water)";
		break;
		case 6:
		Hue=2101;
		Name +=" (Spirit Silver)";
		break;
		case 7:
		Hue=1060;
		Name +=" (Seizure Pink)";
		break;
		case 8:
		Hue=1151;
		Name +=" (Green Ice)";
		break;
		case 9:
		Hue=1152;
		Name +=" (Vorpal Blue)";
		break;
		case 10:
		Hue=1153;
		Name +=" (Snow White)";
		break;
		case 11:
		Hue=2124;
		Name +=" (Coldbite Blue)";
		break;
		}

		
		if (Hue==0)Name+=" (Dye remover formula)";
		
		}
		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );
			list.Add( 1060584, m_UsesRemaining.ToString() ); // uses remaining: ~1_val~
		}


		public override void OnDoubleClick( Mobile from )
		{
			if(from==null)return;
			if( IsAccessibleTo( from )  && IsChildOf( from.Backpack ) )
			{
				from.SendMessage( "Select an item to dye"); // Select the artifact or enhanced magic item to dye.
				from.BeginTarget( 3, false, Server.Targeting.TargetFlags.None, new TargetStateCallback( InternalCallback ), this );
			}
			else
				from.SendLocalizedMessage( 502436 ); // That is not accessible.
		}

		private void InternalCallback( Mobile from, object targeted, object state )
		{
			pigmentsoffel pigment = (pigmentsoffel)state;

			if(!IsChildOf( from.Backpack ))
			{
			from.SendMessage("Pigments must be in your backpack to be used!");
			return;
			}
			
			if( pigment.Deleted || pigment.UsesRemaining <= 0 || !from.InRange( pigment.GetWorldLocation(), 3 ) || !pigment.IsAccessibleTo( from ))
				return;

			Item i = targeted as Item;

			bool isvalid= (i is BaseArmor ||i is BaseJewel || i is Quiver || i is BaseTalisman || i is BaseWeapon || i is EtherealMount || i is BaseDecorationArtifact || i is Spellbook || i is BaseClothing || i is BaseBook);
			
			if( i == null || !isvalid)
				from.SendMessage( "This cannot be dyed" ); 
			else if( !from.InRange( i.GetWorldLocation(), 3 ) || !IsAccessibleTo( from ) || !i.IsChildOf( from.Backpack ))
				from.SendLocalizedMessage( 502436 ); // That is not accessible.
			else if( from.Items.Contains( i ) )
				from.SendLocalizedMessage( 1070930 ); // Can't dye artifacts or enhanced magic items that are being worn.
			else if( i.IsLockedDown )
				from.SendLocalizedMessage( 1070932 ); // You may not dye artifacts and enhanced magic items which are locked down.
			else if( i is PigmentsOfTokuno || i is pigmentsoffel )
				from.SendLocalizedMessage( 1042417 ); // You cannot dye that.
			else
			{
				//Notes: on OSI there IS no hue check to see if it's already hued.  and no messages on successful hue either
				i.Hue = this.Hue;

				if( --pigment.UsesRemaining <= 0 )
					pigment.Delete();
			}
		}





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

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

			writer.Write( (int)0 );

			writer.WriteEncodedInt( m_UsesRemaining );
		}

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

			int version = reader.ReadInt();

			m_UsesRemaining = reader.ReadEncodedInt();
		}

		#region IUsesRemaining Members

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

		public bool ShowUsesRemaining
		{
			get { return true; }
			set {}
		}


		#endregion
	}
	
