context: using System;
  using System.Collections;
  using System.Collections.Generic;
  using Server;
  using Server.Items;
  using Server.Gumps;
  using Server.Network;
  
  namespace Server.Mobiles
  {
  	public class CustomHairstylist : BaseVendor
  	{
  		private ArrayList m_SBInfos = new ArrayList();
  		protected override ArrayList SBInfos { get { return m_SBInfos; } }
  
  		public override bool ClickTitle { get { return false; } }
  
  		public override bool IsActiveBuyer { get { return false; } }
  		public override bool IsActiveSeller { get { return true; } }
  
  		public override bool OnBuyItems( Mobile buyer, List<BuyItemResponse> list )
  		{
  			return false;
  		}
  
  		public static readonly object From = new object();
  		public static readonly object Vendor = new object();
  		public static readonly object Price = new object();
  
  		private static HairstylistBuyInfo[] m_HumanMaleSellList = new HairstylistBuyInfo[]
  			{
  				new HairstylistBuyInfo( 1018357, 50000, false, typeof( ChangeHairstyleGump ), new object[]
  					{ From, Vendor, Price, false, ChangeHairstyleEntry.HumanMaleHairEntries } ),
  				new HairstylistBuyInfo( 1018358, 50000, true, typeof( ChangeHairstyleGump ), new object[]
  					{ From, Vendor, Price, true, ChangeHairstyleEntry.BeardEntries } ),
  				new HairstylistBuyInfo( 1018359, 50, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.HumanRegularEntries } ),
  				new HairstylistBuyInfo( 1018360, 500000, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.HumanBrightEntries } ),
  				new HairstylistBuyInfo( 1018361, 30000, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, false, ChangeHairHueEntry.HumanRegularEntries } ),
  				new HairstylistBuyInfo( 1018362, 30000, true, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, false, true, ChangeHairHueEntry.HumanRegularEntries } ),
  				new HairstylistBuyInfo( 1018363, 500000, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, false, ChangeHairHueEntry.HumanBrightEntries } ),
  				new HairstylistBuyInfo( 1018364, 500000, true, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, false, true, ChangeHairHueEntry.HumanBrightEntries } )
  			};
  
  		private static HairstylistBuyInfo[] m_HumanFemaleSellList = new HairstylistBuyInfo[]
  			{
  				new HairstylistBuyInfo( 1018357, 50000, false, typeof( ChangeHairstyleGump ), new object[]
  					{ From, Vendor, Price, false, ChangeHairstyleEntry.HumanFemaleHairEntries } ),
  				new HairstylistBuyInfo( 1018359, 50, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.HumanRegularEntries } ),
  				new HairstylistBuyInfo( 1018360, 500000, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.HumanBrightEntries } )
  			};
  
  		private static HairstylistBuyInfo[] m_ElfMaleSellList = new HairstylistBuyInfo[]
  			{
  				new HairstylistBuyInfo( 1018357, 50000, false, typeof( ChangeHairstyleGump ), new object[]
  					{ From, Vendor, Price, false, ChangeHairstyleEntry.ElfMaleHairEntries } ),
  				new HairstylistBuyInfo( 1018359, 50, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.ElfRegularEntries } ),
  				new HairstylistBuyInfo( 1018360, 500000, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.ElfBrightEntries } )
  			};
  
  		private static HairstylistBuyInfo[] m_ElfFemaleSellList = new HairstylistBuyInfo[]
  			{
  				new HairstylistBuyInfo( 1018357, 50000, false, typeof( ChangeHairstyleGump ), new object[]
  					{ From, Vendor, Price, false, ChangeHairstyleEntry.ElfFemaleHairEntries } ),
  				new HairstylistBuyInfo( 1018359, 50, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.ElfRegularEntries } ),
  				new HairstylistBuyInfo( 1018360, 500000, false, typeof( ChangeHairHueGump ), new object[]
  					{ From, Vendor, Price, true, true, ChangeHairHueEntry.ElfBrightEntries } )
  			};
  
  		public override void VendorBuy( Mobile from )
  		{
  			if ( from.Race == Race.Human )
  				from.SendGump( new HairstylistBuyGump( from, this, from.Female ? m_HumanFemaleSellList : m_HumanMaleSellList ) );
  			else if ( from.Race == Race.Elf )
  				from.SendGump( new HairstylistBuyGump( from, this, from.Female ? m_ElfFemaleSellList : m_ElfMaleSellList ) );
  			else if ( from.Race == Race.Gargoyle )
  				from.SendLocalizedMessage( 1112474 ); // A hairstylist cannot style your horns!
  		}
  
  		[Constructable]
  		public CustomHairstylist()
  			: base( "the hairstylist" )
  		{
  		}
  
  		public override int GetHairHue()
  		{
  			return RandomBrightHue();
  		}
  
  		public override VendorShoeType ShoeType
  		{
  			get { return Utility.RandomBool() ? VendorShoeType.Shoes : VendorShoeType.Sandals; }
  		}
  
  		public override void InitOutfit()
  		{
  			base.InitOutfit();
  
  			AddItem( new Robe( Utility.RandomPinkHue() ) );
  		}
  
  		public override void InitSBInfo()
  		{
  		}
  
  		public CustomHairstylist( Serial serial )
  			: base( serial )
  		{
  		}
  
  		public override void Serialize( GenericWriter writer )
  		{
  			base.Serialize( writer );
  
  			writer.Write( (int) 0 ); // version
  		}
  
  		public override void Deserialize( GenericReader reader )
  		{
  			base.Deserialize( reader );
  
  			/*int version = */
  			reader.ReadInt();
  		}
  	}
  
  	public class HairstylistBuyInfo
  	{
  		private int m_Title;
  		private string m_TitleString;
  		private int m_Price;
  		private bool m_FacialHair;
  		private Type m_GumpType;
  		private object[] m_GumpArgs;
  
  		public int Title { get { return m_Title; } }
  		public string TitleString { get { return m_TitleString; } }
  		public int Price { get { return m_Price; } }
  		public bool FacialHair { get { return m_FacialHair; } }
  		public Type GumpType { get { return m_GumpType; } }
  		public object[] GumpArgs { get { return m_GumpArgs; } }
  
  		public HairstylistBuyInfo( int title, int price, bool facialHair, Type gumpType, object[] args )
  		{
  			m_Title = title;
  			m_Price = price;
  			m_FacialHair = facialHair;
  			m_GumpType = gumpType;
  			m_GumpArgs = args;
  		}
  
  		public HairstylistBuyInfo( string title, int price, bool facialHair, Type gumpType, object[] args )
  		{
  			m_TitleString = title;
  			m_Price = price;
  			m_FacialHair = facialHair;
  			m_GumpType = gumpType;
  			m_GumpArgs = args;
  		}
  	}
  
  	public class HairstylistBuyGump : Gump
  	{
  		public override int TypeID { get { return 0xF3E83; } }
  
  		private Mobile m_From;
  		private Mobile m_Vendor;
  		private HairstylistBuyInfo[] m_SellList;
  
  		public HairstylistBuyGump( Mobile from, Mobile vendor, HairstylistBuyInfo[] sellList )
  			: base( 50, 50 )
  		{
  			m_From = from;
  			m_Vendor = vendor;
  			m_SellList = sellList;
  
  			from.CloseGump<HairstylistBuyGump>();
  			from.CloseGump<ChangeHairHueGump>();
  			from.CloseGump<ChangeHairstyleGump>();
  
  			bool isFemale = ( from.Female || from.Body.IsFemale );
  
  			int balance = Banker.GetBalance( from );
  			int canAfford = 0;
  
  			for ( int i = 0; i < sellList.Length; ++i )
  			{
  				if ( balance >= sellList[i].Price && ( !sellList[i].FacialHair || !isFemale ) )
  					++canAfford;
  			}
  
  			AddPage( 0 );
  
  			AddBackground( 50, 10, 450, 100 + ( canAfford * 25 ), 2600 );
  
  			AddHtmlLocalized( 100, 40, 350, 20, 1018356, false, false ); // Choose your hairstyle change:
  
  			int index = 0;
  
  			for ( int i = 0; i < sellList.Length; ++i )
  			{
  				if ( balance >= sellList[i].Price && ( !sellList[i].FacialHair || !isFemale ) )
  				{
  					if ( sellList[i].TitleString != null )
  						AddHtml( 140, 75 + ( index * 25 ), 300, 20, sellList[i].TitleString, false, false );
  					else
  						AddHtmlLocalized( 140, 75 + ( index * 25 ), 300, 20, sellList[i].Title, false, false );
  
  					AddButton( 100, 75 + ( index++ * 25 ), 4005, 4007, 1 + i, GumpButtonType.Reply, 0 );
  				}
  			}
  		}
  
  		public override void OnResponse( NetState sender, RelayInfo info )
  		{
  			int index = info.ButtonID - 1;
  
  			if ( index >= 0 && index < m_SellList.Length )
  			{
  				HairstylistBuyInfo buyInfo = m_SellList[index];
  
  				int balance = Banker.GetBalance( m_From );
  
  				bool isFemale = ( m_From.Female || m_From.Body.IsFemale );
  
  				if ( buyInfo.FacialHair && isFemale )
  				{
  					// You cannot place facial hair on a woman!
  					m_Vendor.PrivateOverheadMessage( MessageType.Regular, 0x3B2, 1010639, m_From.NetState );
  				}
  				else if ( balance >= buyInfo.Price )
  				{
  					try
  					{
  						object[] origArgs = buyInfo.GumpArgs;
  						object[] args = new object[origArgs.Length];
  
  						for ( int i = 0; i < args.Length; ++i )
  						{
  							if ( origArgs[i] == CustomHairstylist.Price )
  								args[i] = m_SellList[index].Price;
  							else if ( origArgs[i] == CustomHairstylist.From )
  								args[i] = m_From;
  							else if ( origArgs[i] == CustomHairstylist.Vendor )
  								args[i] = m_Vendor;
  							else
  								args[i] = origArgs[i];
  						}
  
  						Gump g = Activator.CreateInstance( buyInfo.GumpType, args ) as Gump;
  
  						m_From.SendGump( g );
  					}
  					catch
  					{
  					}
  				}
  				else
  				{
  					// You cannot afford my services for that style.
  					m_Vendor.PrivateOverheadMessage( MessageType.Regular, 0x3B2, 1042293, m_From.NetState );
  				}
  			}
  		}
  	}
  
  	public class ChangeHairHueEntry
  	{
  		private string m_Name;
  		private int[] m_Hues;
  
  		public string Name { get { return m_Name; } }
  		public int[] Hues { get { return m_Hues; } }
  
  		public ChangeHairHueEntry( string name, int[] hues )
  		{
  			m_Name = name;
  			m_Hues = hues;
  		}
  
  		public ChangeHairHueEntry( string name, int start, int count )
  		{
  			m_Name = name;
  
  			m_Hues = new int[count];
  
  			for ( int i = 0; i < count; ++i )
  				m_Hues[i] = start + i;
  		}
  
  		public static readonly ChangeHairHueEntry[] HumanBrightEntries = new ChangeHairHueEntry[]
  			{
  				new ChangeHairHueEntry( "*****", 12, 10 ),
  				new ChangeHairHueEntry( "*****", 32, 5 ),
  				new ChangeHairHueEntry( "*****", 38, 8 ),
  				new ChangeHairHueEntry( "*****", 54, 3 ),
  				new ChangeHairHueEntry( "*****", 62, 10 ),
  				new ChangeHairHueEntry( "*****", 81, 2 ),
  				new ChangeHairHueEntry( "*****", 89, 2 ),
  				new ChangeHairHueEntry( "*****", 1153, 2 )
  			};
  
  		public static readonly ChangeHairHueEntry[] HumanRegularEntries = new ChangeHairHueEntry[]
  			{
  				new ChangeHairHueEntry( "*****", 1602, 26 ),
  				new ChangeHairHueEntry( "*****", 1628, 27 ),
  				new ChangeHairHueEntry( "*****", 1502, 32 ),
  				new ChangeHairHueEntry( "*****", 1302, 32 ),
  				new ChangeHairHueEntry( "*****", 1402, 32 ),
  
gt: 				new ChangeHairHueEntry( "*****", 1202, 24 ),