context: using System;
  using Server.Factions;
  using Server.Items;
  using Server.Mobiles;
  using Server.Targeting;
  
  namespace Server.Engines.Craft
  {
      public enum TinkerRecipes
      {
          InvisibilityPotion = 400,
          DarkglowPotion = 401,
          ParasiticPotion = 402,
  
          EssenceOfBattle = 450,
          PendantOfTheMagi = 451,
          ResilientBracer = 452,
          ScrappersCompendium = 453,
          HoveringWisp = 454,
      }
  
      public class DefTinkering : CraftSystem
      {
          #region Mondain's Legacy
          public override CraftECA ECA
          {
              get
              {
                  return CraftECA.ChanceMinusSixtyToFourtyFive;
              }
          }
          #endregion
  
          public override SkillName MainSkill
          {
              get
              {
                  return SkillName.Tinkering;
              }
          }
  
          public override int GumpTitleNumber
          {
              get
              {
                  return 1044007;
              }// <CENTER>TINKERING MENU</CENTER>
          }
  
          private static CraftSystem m_CraftSystem;
  
          public static CraftSystem CraftSystem
          {
              get
              {
                  if (m_CraftSystem == null)
                      m_CraftSystem = new DefTinkering();
  
                  return m_CraftSystem;
              }
          }
  
          private DefTinkering()
              : base(1, 1, 1.25)// base( 1, 1, 3.0 )
          {
          }
  
          public override double GetChanceAtMin(CraftItem item)
          {
              if (item.NameNumber == 1044258 || item.NameNumber == 1046445) // potion keg and faction trap removal kit
                  return 0.5; // 50%
  
              return 0.0; // 0%
          }
  
          public override int CanCraft(Mobile from, BaseTool tool, Type itemType)
          {
              if (tool == null || tool.Deleted || tool.UsesRemaining < 0)
                  return 1044038; // You have worn out your tool!
              else if (!BaseTool.CheckAccessible(tool, from))
                  return 1044263; // The tool must be on your person to use.
              else if (itemType != null && (itemType.IsSubclassOf(typeof(BaseFactionTrapDeed)) || itemType == typeof(FactionTrapRemovalKit)) && Faction.Find(from) == null)
                  return 1044573; // You have to be in a faction to do that.
              else if (itemType == typeof(ModifiedClockworkAssembly) && !(from is PlayerMobile && ((PlayerMobile)from).MechanicalLife))
                  return 1113034; // You haven't read the Mechanical Life Manual. Talking to Sutek might help!
  
              return 0;
          }
  
          private static readonly Type[] m_TinkerColorables = new Type[]
          {
              typeof(ForkLeft), typeof(ForkRight),
              typeof(SpoonLeft), typeof(SpoonRight),
              typeof(KnifeLeft), typeof(KnifeRight),
              typeof(Plate),
              typeof(Goblet), typeof(PewterMug),
              typeof(KeyRing),
              typeof(Candelabra), typeof(Scales),
              typeof(Key), typeof(Globe),
              typeof(Spyglass), typeof(Lantern),
              typeof(HeatingStand),
              typeof(GorgonLense), typeof(MedusaLightScales), typeof(MedusaDarkScales), typeof(RedScales), 
              typeof(BlueScales), typeof(BlackScales), typeof(GreenScales), typeof(YellowScales), typeof(WhiteScales),
              typeof(PlantPigment), typeof(SoftenedReeds), typeof(DryReeds), typeof(PlantClippings)
          };
  
          public override bool RetainsColorFrom(CraftItem item, Type type)
          {
              if (type == typeof(CrystalDust))
                  return false;
  
              bool contains = false;
              type = item.ItemType;
  
              for (int i = 0; !contains && i < m_TinkerColorables.Length; ++i)
                  contains = (m_TinkerColorables[i] == type);
  
              if (!contains && !type.IsSubclassOf(typeof(BaseIngot)))
                  return false;
  
              return contains;
          }
  
          public override void PlayCraftEffect(Mobile from)
          {
              // no sound
              //from.PlaySound( 0x241 );
          }
  
          public override int PlayEndingEffect(Mobile from, bool failed, bool lostMaterial, bool toolBroken, int quality, bool makersMark, CraftItem item)
          {
              if (toolBroken)
                  from.SendLocalizedMessage(1044038); // You have worn out your tool
  
              if (failed)
              {
                  if (lostMaterial)
                      return 1044043; // You failed to create the item, and some of your materials are lost.
                  else
                      return 1044157; // You failed to create the item, but no materials were lost.
              }
              else
              {
                  if (quality == 0)
                      return 502785; // You were barely able to make this item.  It's quality is below average.
                  else if (makersMark && quality == 2)
                      return 1044156; // You create an exceptional quality item and affix your maker's mark.
                  else if (quality == 2)
                      return 1044155; // You create an exceptional quality item.
                  else 
                      return 1044154; // You create the item.
              }
          }
  
          public override bool ConsumeOnFailure(Mobile from, Type resourceType, CraftItem craftItem)
          {
              if (resourceType == typeof(Silver))
                  return false;
  
              return base.ConsumeOnFailure(from, resourceType, craftItem);
          }
  
          public void AddJewelrySet(GemType gemType, Type itemType)
          {
              int offset = (int)gemType - 1;
  
              int index = this.AddCraft(typeof(GoldRing), 1044049, 1044176 + offset, 40.0, 90.0, typeof(IronIngot), 1044036, 2, 1044037);
              this.AddRes(index, itemType, 1044231 + offset, 1, 1044240);
  
              index = this.AddCraft(typeof(SilverBeadNecklace), 1044049, 1044185 + offset, 40.0, 90.0, typeof(IronIngot), 1044036, 2, 1044037);
              this.AddRes(index, itemType, 1044231 + offset, 1, 1044240);
  
              index = this.AddCraft(typeof(GoldNecklace), 1044049, 1044194 + offset, 40.0, 90.0, typeof(IronIngot), 1044036, 2, 1044037);
              this.AddRes(index, itemType, 1044231 + offset, 1, 1044240);
  
              index = this.AddCraft(typeof(GoldEarrings), 1044049, 1044203 + offset, 40.0, 90.0, typeof(IronIngot), 1044036, 2, 1044037);
              this.AddRes(index, itemType, 1044231 + offset, 1, 1044240);
  
              index = this.AddCraft(typeof(GoldBeadNecklace), 1044049, 1044212 + offset, 40.0, 90.0, typeof(IronIngot), 1044036, 2, 1044037);
              this.AddRes(index, itemType, 1044231 + offset, 1, 1044240);
  
              index = this.AddCraft(typeof(GoldBracelet), 1044049, 1044221 + offset, 40.0, 90.0, typeof(IronIngot), 1044036, 2, 1044037);
              this.AddRes(index, itemType, 1044231 + offset, 1, 1044240);     
               
          }
  
          public override void InitCraftList()
          {
              int index = -1;
  
              #region Jewelry
              this.AddJewelrySet(GemType.StarSapphire, typeof(StarSapphire));
              this.AddJewelrySet(GemType.Emerald, typeof(Emerald));
              this.AddJewelrySet(GemType.Sapphire, typeof(Sapphire));
              this.AddJewelrySet(GemType.Ruby, typeof(Ruby));
              this.AddJewelrySet(GemType.Citrine, typeof(Citrine));
              this.AddJewelrySet(GemType.Amethyst, typeof(Amethyst));
              this.AddJewelrySet(GemType.Tourmaline, typeof(Tourmaline));
              this.AddJewelrySet(GemType.Amber, typeof(Amber));
              this.AddJewelrySet(GemType.Diamond, typeof(Diamond));
              #endregion
  
              #region Wooden Items
              if (Core.SE)
              {
                  index = this.AddCraft(typeof(Nunchaku), 1044042, 1030158, 70.0, 120.0, typeof(IronIngot), 1044036, 3, 1044037);
                  this.AddRes(index, typeof(Board), 1044041, 8, 1044351);
                  this.SetNeededExpansion(index, Expansion.SE);
              }
  
              this.AddCraft(typeof(JointingPlane), 1044042, 1024144, 0.0, 50.0, typeof(Board), 1044041, 4, 1044351);
              this.AddCraft(typeof(MouldingPlane), 1044042, 1024140, 0.0, 50.0, typeof(Board), 1044041, 4, 1044351);
              this.AddCraft(typeof(SmoothingPlane), 1044042, 1024146, 0.0, 50.0, typeof(Board), 1044041, 4, 1044351);
              this.AddCraft(typeof(ClockFrame), 1044042, 1024173, 0.0, 50.0, typeof(Board), 1044041, 6, 1044351);
              this.AddCraft(typeof(Axle), 1044042, 1024187, -25.0, 25.0, typeof(Board), 1044041, 2, 1044351);
              this.AddCraft(typeof(RollingPin), 1044042, 1024163, 0.0, 50.0, typeof(Board), 1044041, 5, 1044351);
  
              #region High Seas
              if (Core.HS)
              {
                  AddCraft(typeof(Ramrod), 1044042, 1095839, 0.0, 50.0, typeof(Board), 1044041, 8, 1044253);
                  SetNeededExpansion(index, Expansion.HS);
  
                  index = AddCraft(typeof(Swab), 1044042, 1095840, 0.0, 50.0, typeof(Cloth), 1044286, 1, 1044253);
                  AddRes(index, typeof(Board), 1044041, 4, 1044253);
                  SetNeededExpansion(index, Expansion.HS);
              }
              #endregion
  
              #region SA
              if (Core.SA)
              {
                  index = AddCraft(typeof(SoftenedReeds), 1044042, 1112249, 75.0, 100.0, typeof(DryReeds), 1112248, 1, 1112250);
                  AddRes(index, typeof(ScouringToxin), 1112292, 2, 1112326);
                  SetRequiresBasketWeaving(index);
                  SetRequireResTarget(index);
                  SetNeededExpansion(index, Expansion.SA);
  
                  index = AddCraft(typeof(RoundBasket), 1044042, 1112293, 75.0, 100.0, typeof(SoftenedReeds), 1112249, 2, 1112251);
                  AddRes(index, typeof(Shaft), 1027125, 3, 1044351);
                  SetRequireResTarget(index);
                  SetRequiresBasketWeaving(index);
                  SetNeededExpansion(index, Expansion.SA);
  
                  index = AddCraft(typeof(RoundBasketHandles), 1044042, 1112357, 75.0, 100.0, typeof(SoftenedReeds), 1112249, 2, 1112251);
                  AddRes(index, typeof(Shaft), 1027125, 3, 1044351);
                  SetRequireResTarget(index);
                  SetRequiresBasketWeaving(index);
                  SetNeededExpansion(index, Expansion.SA);
  
                  index = AddCraft(typeof(SmallBushel), 1044042, 1112337, 75.0, 100.0, typeof(SoftenedReeds), 1112249, 1, 1112251);
                  AddRes(index, typeof(Shaft), 1027125, 2, 1044351);
                  SetRequireResTarget(index);
                  SetRequiresBasketWeaving(index);
                  SetNeededExpansion(index, Expansion.SA);
  
                  index = AddCraft(typeof(PicnicBasket2), 1044042, 1023706, 75.0, 100.0, typeof(SoftenedReeds), 1112249, 1, 1112251);
  
gt:                 AddRes(index, typeof(Shaft), 1027125, 2, 1044351);