/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\Dye System\PigmentKeg.cs
Lines of code: 98
***********************************************************/


using System;
using Server.Network;
using Server;
using Server.Targeting; 
using Server.Items;
using Server.Mobiles;
using Server.Targets;
using System.Collections;
using System.Collections.Generic;

namespace Server.Items
{
	
	public class PigmentKeg : Item
	{
		private string colorname;

		[CommandProperty( AccessLevel.GameMaster )]
		public string ColorName
		{
			get { return colorname; }
			set { colorname = value; InvalidateProperties();Modify(); }
		}

		[Constructable]
		public PigmentKeg(int hue, string label) : base( 6464 )
		{
			Weight = 20.0;
			Hue = hue;
			colorname = label;
			Name = "A keg of pigments";
			Movable = false;
		}
		
		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );
			if (colorname != null) {
				list.Add( 1060658,"Pigment Color \t" + colorname);
			}
		}

		public override void OnDoubleClick( Mobile from )
		{		
				
				Item ticket = from.Backpack.FindItemByType(typeof(PigmentTicket));
				Item bm = from.Backpack.FindItemByType(typeof(Bottle));
				Item am = null;
				
				Item [] amarray= from.Backpack.FindItemsByType(typeof(PigmentBottle),false);
				
				bool consumebottle=true;
				
				for(int i=0;i<amarray.Length;i++)
				{
					if (amarray[i].Hue==this.Hue)
					{
					am=amarray[i];
					consumebottle=false;
					break;
					}
				}
				
				
				if (ticket != null) {
					if (am != null && am.Hue == this.Hue)
					{
						from.SendMessage("You fill your pigment bottle with more dye"); 
						PigmentBottle bottle = (PigmentBottle)am;
						PigmentTicket pt = (PigmentTicket)ticket;
						pt.UsesRemaining--;
						if (pt.UsesRemaining <= 0) pt.Delete();
						bottle.UsesRemaining++;
						from.PlaySound(574);
						if(consumebottle)from.Backpack.ConsumeTotal(typeof(Bottle), 1);
					}
					else if (bm != null) {
						from.SendLocalizedMessage( 502242 ); //You pour some of the keg's contents into an empty bottle...
						from.PlaySound(574);
						PigmentTicket pt = (PigmentTicket)ticket;
						pt.UsesRemaining--;
						if (pt.UsesRemaining <= 0) pt.Delete();
						if(consumebottle)from.Backpack.ConsumeTotal(typeof(Bottle), 1);
						from.AddToBackpack(new PigmentBottle(this.Hue, colorname));
					}
					else {
						from.SendLocalizedMessage( 1044558 ); //You don't have any empty bottles.
					}
				}
				else {
					from.SendMessage("You cannot gather dye unless you have a pigment ticket in your bag"); 
				}
		}
		
		public PigmentKeg( Serial serial ) : base( serial )
		{
		}
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			writer.Write((string)colorname);
			
	
		}

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

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