context: using System;
  using System.Collections;
  using Server;
  using Server.Gumps;
  using Server.Mobiles;
  using Server.Targeting;
  using Server.ContextMenus;
  using Server.Regions;
  using Server.Network;
  using System.Collections.Generic;
  using Server.Items;
  using Server.Targets;
  
  namespace Server.Items
  {
  
  
  	public class MageryTrainer : Item
  	{
  
  
  		public override string DefaultName
  		{
              get { return "Magery Trainer [100GP]"; }
  		}
  
  		[Constructable]
  		public MageryTrainer() : base( 0x1F1C )
  		{
  			Weight = 1.0;
              Movable = false;
  		}
  
  		public MageryTrainer( Serial serial ) : base( serial )
  		{
  		}
  
          public override void OnDoubleClick(Mobile m)
          {
              if (m.Skills.Magery.Base <= 19.9)
              {
                  if (m.Mana >= 4)
                  {
                      if (m.SkillsTotal >= m.SkillsCap)
                      {
                          int toGain = 1;
  
                          Skills skills = m.Skills;
  
                          for (int i = 0; i < skills.Length; ++i)
                          {
                              Skill toLower = skills[i];
  
                              if (toLower != m.Skills.Magery && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                              {
                                  toLower.BaseFixedPoint -= toGain;
                                  break;
                              }
                          }
                      }
                      if (m.SkillsTotal < m.SkillsCap)
                      {
                          if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                          {
                              if (m.Skills.Magery.Base < m.Skills.Magery.Cap)
                              {
                                  m.Skills.Magery.BaseFixedPoint += 1;
                                  m.Mana -= 4;
                              }
                              else
                              {
                                  m.SendMessage("You have reached the skill cap for that skill");
                              }
                          }
                          else
                          m.SendMessage("You need 100gp in your pack to use this stone.");
                      }
                      else
                      {
                          m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                      }
  
                  }
                  else
                  {
                      m.SendMessage("You need 4 mana to use this item at your skill level.");
                  }
              }
              if (m.Skills.Magery.Base <= 39.9 && m.Skills.Magery.Base >= 20)
              {
                  if (m.Mana >= 5)
                  {
                      if (m.SkillsTotal >= m.SkillsCap)
                      {
                          int toGain = 1;
  
                          Skills skills = m.Skills;
  
                          for (int i = 0; i < skills.Length; ++i)
                          {
                              Skill toLower = skills[i];
  
                              if (toLower != m.Skills.Magery && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                              {
                                  toLower.BaseFixedPoint -= toGain;
                                  break;
                              }
                          }
                      }
                      if (m.SkillsTotal < m.SkillsCap)
                      {
                          if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                          {
                              if (m.Skills.Magery.Base < m.Skills.Magery.Cap)
                              {
                                  m.Skills.Magery.BaseFixedPoint += 1;
                                  m.Mana -= 5;
                              }
                              else
                              {
                                  m.SendMessage("You have reached the skill cap for that skill");
                              }
                          }
                          else
                          m.SendMessage("You need 100gp in your pack to use this stone.");
                      }
                      else
                      {
                          m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                      }
  
                  }
                  else
                  {
                      m.SendMessage("You need 5 mana to use this item at your skill level.");
                  }
              }
              if (m.Skills.Magery.Base <= 59.9 && m.Skills.Magery.Base >= 40)
              {
                  if (m.Mana >= 10)
                  {
                      if (m.SkillsTotal >= m.SkillsCap)
                      {
                          int toGain = 1;
  
                          Skills skills = m.Skills;
  
                          for (int i = 0; i < skills.Length; ++i)
                          {
                              Skill toLower = skills[i];
  
                              if (toLower != m.Skills.Magery && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                              {
                                  toLower.BaseFixedPoint -= toGain;
                                  break;
                              }
                          }
                      }
                      if (m.SkillsTotal < m.SkillsCap)
                      {
                          if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                          {
                              if (m.Skills.Magery.Base < m.Skills.Magery.Cap)
                              {
                                  m.Skills.Magery.BaseFixedPoint += 1;
                                  m.Mana -= 10;
                              }
                              else
                              {
                                  m.SendMessage("You have reached the skill cap for that skill");
                              }
                          }
                          else
                          m.SendMessage("You need 100gp in your pack to use this stone.");
                      }
                      else
                      {
                          m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                      }
  
                  }
                  else
                  {
                      m.SendMessage("You need 10 mana to use this item at your skill level.");
                  }
              }
              if (m.Skills.Magery.Base <= 79.9 && m.Skills.Magery.Base >= 60)
              {
                  if (m.Mana >= 20)
                  {
                      if (m.SkillsTotal >= m.SkillsCap)
                      {
                          int toGain = 1;
  
                          Skills skills = m.Skills;
  
                          for (int i = 0; i < skills.Length; ++i)
                          {
                              Skill toLower = skills[i];
  
                              if (toLower != m.Skills.Magery && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                              {
                                  toLower.BaseFixedPoint -= toGain;
                                  break;
                              }
                          }
                      }
                      if (m.SkillsTotal < m.SkillsCap)
                      {
                          if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                          {
                              if (m.Skills.Magery.Base < m.Skills.Magery.Cap)
                              {
                                  m.Skills.Magery.BaseFixedPoint += 1;
                                  m.Mana -= 20;
                              }
                              else
                              {
                                  m.SendMessage("You have reached the skill cap for that skill");
                              }
                          }
                          else
                          m.SendMessage("You need 100gp in your pack to use this stone.");
                      }
                      else
                      {
                          m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                      }
  
                  }
                  else
                  {
                      m.SendMessage("You need 20 mana to use this item at your skill level.");
                  }
              }
              if (m.Skills.Magery.Base <= 99.9 && m.Skills.Magery.Base >= 80)
              {
                  if (m.Mana >= 30)
                  {
                      if (m.SkillsTotal >= m.SkillsCap)
                      {
                          int toGain = 1;
  
                          Skills skills = m.Skills;
  
                          for (int i = 0; i < skills.Length; ++i)
                          {
                              Skill toLower = skills[i];
  
                              if (toLower != m.Skills.Magery && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                              {
                                  toLower.BaseFixedPoint -= toGain;
                                  break;
                              }
                          }
                      }
                      if (m.SkillsTotal < m.SkillsCap)
                      {
                          if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                          {
                              if (m.Skills.Magery.Base < m.Skills.Magery.Cap)
                              {
                                  m.Skills.Magery.BaseFixedPoint += 1;
                                  m.Mana -= 30;
                              }
                              else
                              {
                                  m.SendMessage("You have reached the skill cap for that skill");
                              }
                          }
                          else
                          m.SendMessage("You need 100gp in your pack to use this stone.");
                      }
                      else
                      {
                          m.SendMessage("You need 30 mana to use this item at your skill level.");
                      }
  
                  }
                  else
                  {
                      m.SendMessage("You do not have enough mana to use this item");
                  }
              }
              if (m.Skills.Magery.Base <= 119.9 && m.Skills.Magery.Base >= 100)
              {
                  if (m.Mana >= 40)
                  {
                      if (m.SkillsTotal >= m.SkillsCap)
                      {
                          int toGain = 1;
  
                          Skills skills = m.Skills;
  
                          for (int i = 0; i < skills.Length; ++i)
                          {
                              Skill toLower = skills[i];
  
                              if (toLower != m.Skills.Magery && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                              {
                                  toLower.BaseFixedPoint -= toGain;
                                  break;
                              }
                          }
                      }
                      if (m.SkillsTotal < m.SkillsCap)
                      {
                          if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                          {
                              if (m.Skills.Magery.Base < m.Skills.Magery.Cap)
                              {
                                  m.Skills.Magery.BaseFixedPoint += 1;
  
gt:                                 m.Mana -= 40;