/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\Items\Skill Items\Specialized\Sand.cs
Lines of code: 79
***********************************************************/


using System;
using Server.Items;

namespace Server.Items
{
	[FlipableAttribute( 0x11EA, 0x11EB )]
	public class Sand : Item, ICommodity
	{
		string ICommodity.Description
		{
			get
			{
				return String.Format( Amount == 1 ? "{0} sand" : "{0} sand", Amount );
			}
		}

		public override int LabelNumber{ get{ return 1044626; } } // sand

		[Constructable]
		public Sand() : this( 1 )
		{
		}

		[Constructable]
		public Sand( int amount ) : base( 0x11EA )
		{
			Amount = amount;
			Stackable = true;
			Weight = 1.0;
		}
		
		
		public override void OnDoubleClick(Mobile from)
		{
			if (!from.InRange( GetWorldLocation(), 1 ) )
			{
			from.SendMessage("This is too far away");
			return;
			}
	
			int totake = 400;  //Try at 400 and work our way down

			while(this.Amount<=totake)totake-=5;
			
			if(totake<=1)
			{
			from.SendMessage("This pile is already divided");
			return;
			}
		
		   Sand pile=new Sand();
			
			bool placed=false;
			
			for(;totake>1;totake-=5)
			{
			pile.Amount=totake;
				if(from.PlaceInBackpack( pile ))
				{
				placed=true;
				break;
				}
			}
		
			if(!placed)
			{
			from.SendMessage("There is not enough room in your backpack for this");
			pile.Delete();
			}
			else
			{
			this.Amount-=totake;			
			from.SendMessage("{0} Sand has been taken from the pile",totake);
			}
			
		}		
		

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

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

			writer.Write( (int) 1 ); // version
		}

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

			int version = reader.ReadInt();

			if ( version == 0 && this.Name == "sand" )
				this.Name = null;
		}
	}
}