context: #region Header
  // **********
  // ServUO - AnimalTrainer.cs
  // **********
  #endregion
  
  #region References
  using System;
  using System.Collections.Generic;
  
  using Server.ContextMenus;
  using Server.Gumps;
  using Server.Items;
  using Server.Network;
  using Server.Targeting;
  #endregion
  
  namespace Server.Mobiles
  {
  	public class AnimalTrainer : BaseVendor
  	{
  		private readonly List<SBInfo> m_SBInfos = new List<SBInfo>();
  
  		[Constructable]
  		public AnimalTrainer()
  			: base("the animal trainer")
  		{
  			SetSkill(SkillName.AnimalLore, 64.0, 100.0);
  			SetSkill(SkillName.AnimalTaming, 90.0, 100.0);
  			SetSkill(SkillName.Veterinary, 65.0, 88.0);
  		}
  
  		public AnimalTrainer(Serial serial)
  			: base(serial)
  		{ }
  
  		protected override List<SBInfo> SBInfos { get { return m_SBInfos; } }
  		public override VendorShoeType ShoeType { get { return Female ? VendorShoeType.ThighBoots : VendorShoeType.Boots; } }
  
  		public override void InitSBInfo()
  		{
  			m_SBInfos.Add(new SBAnimalTrainer());
  		}
  
  		public override int GetShoeHue()
  		{
  			return 0;
  		}
  
  		public override void InitOutfit()
  		{
  			base.InitOutfit();
  
  			AddItem(Utility.RandomBool() ? new QuarterStaff() : (Item)new ShepherdsCrook());
  		}
  
  		public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list)
  		{
  			if (from.Alive)
  			{
  				list.Add(new StableEntry(this, from));
  
  				if (from.Stabled.Count > 0)
  				{
  					list.Add(new ClaimAllEntry(this, from));
  				}
  			}
  
  			base.AddCustomContextEntries(from, list);
  		}
  
  		public static int GetMaxStabled(Mobile from)
  		{
  			var taming = from.Skills[SkillName.AnimalTaming].Value;
  			var anlore = from.Skills[SkillName.AnimalLore].Value;
  			var vetern = from.Skills[SkillName.Veterinary].Value;
  			var sklsum = taming + anlore + vetern;
  
  			int max;
  
  			if (sklsum >= 240.0)
  			{
  				max = 5;
  			}
  			else if (sklsum >= 200.0)
  			{
  				max = 4;
  			}
  			else if (sklsum >= 160.0)
  			{
  				max = 3;
  			}
  			else
  			{
  				max = 2;
  			}
  			
  			// bonus SA stable slots
  			if (Core.SA) 
   			{ 
   				max += 2;
   			}
   			//bonus ToL stable slots
   			if (Core.TOL) 
   			{ 
   				max += 2;
   			}
   
  			if (taming >= 100.0)
  			{
  				max += (int)((taming - 90.0) / 10);
  			}
  
  			if (anlore >= 100.0)
  			{
  				max += (int)((anlore - 90.0) / 10);
  			}
  
  			if (vetern >= 100.0)
  			{
  				max += (int)((vetern - 90.0) / 10);
  			}
  
              return max + Server.Spells.SkillMasteries.MasteryInfo.BoardingSlotIncrease(from);
  		}
  
  		private void CloseClaimList(Mobile from)
  		{
  			from.CloseGump(typeof(ClaimListGump));
  		}
  
  		public void BeginClaimList(Mobile from)
  		{
  			if (Deleted || !from.CheckAlive())
  			{
  				return;
  			}
  
  			var list = new List<BaseCreature>();
  
  			for (var i = 0; i < from.Stabled.Count; ++i)
  			{
  				var pet = from.Stabled[i] as BaseCreature;
  
  				if (pet == null || pet.Deleted)
  				{
  					if (pet != null)
  					{
  						pet.IsStabled = false;
  						pet.StabledBy = null;
  					}
  
  					from.Stabled.RemoveAt(i--);
  					continue;
  				}
  
  				list.Add(pet);
  			}
  
  			if (list.Count > 0)
  			{
  				from.SendGump(new ClaimListGump(this, from, list));
  			}
  			else
  			{
  				SayTo(from, 502671); // But I have no animals stabled with me at the moment!
  			}
  		}
  
  		public void EndClaimList(Mobile from, BaseCreature pet)
  		{
  			if (pet == null || pet.Deleted || from.Map != Map || !from.Stabled.Contains(pet) || !from.CheckAlive())
  			{
  				return;
  			}
  
  			if (!from.InRange(this, 14))
  			{
  				from.SendLocalizedMessage(500446); // That is too far away.
  				return;
  			}
  
  			if (CanClaim(from, pet))
  			{
  				DoClaim(from, pet);
  
  				from.Stabled.Remove(pet);
  
  				if (from is PlayerMobile)
  				{
  					((PlayerMobile)from).AutoStabled.Remove(pet);
  				}
  			}
  			else
  			{
  				SayTo(from, 1049612, pet.Name); // ~1_NAME~ remained in the stables because you have too many followers.
  			}
  		}
  
  		public void BeginStable(Mobile from)
  		{
  			if (Deleted || !from.CheckAlive())
  			{
  				return;
  			}
  
  			if ((from.Backpack == null || from.Backpack.GetAmount(typeof(Gold)) < 30) && Banker.GetBalance(from) < 30)
  			{
  				SayTo(from, 1042556); // Thou dost not have enough gold, not even in thy bank account.
  				return;
  			}
  
  			/* 
  			 * I charge 30 gold per pet for a real week's stable time.
  			 * I will withdraw it from thy bank account.
  			 * Which animal wouldst thou like to stable here?
  			 */
  			from.SendLocalizedMessage(1042558);
  
  			from.Target = new StableTarget(this);
  		}
  
  		public void EndStable(Mobile from, BaseCreature pet)
  		{
  
gt: 			if (Deleted || !from.CheckAlive())