context: using System;
  using Server.Items;
  using Server.Network;
  using Server.Mobiles;
  using Server.Targeting;
  using System.Linq;
  
  namespace Server.Engines.Harvest
  {
      public class Lumberjacking : HarvestSystem
      {
          private static Lumberjacking m_System;
  
          public static Lumberjacking System
          {
              get
              {
                  if (m_System == null)
                      m_System = new Lumberjacking();
  
                  return m_System;
              }
          }
  
          private readonly HarvestDefinition m_Definition;
  
          public HarvestDefinition Definition
          {
              get
              {
                  return this.m_Definition;
              }
          }
  
          private Lumberjacking()
          {
              HarvestResource[] res;
              HarvestVein[] veins;
  
              #region Lumberjacking
              HarvestDefinition lumber = new HarvestDefinition();
  
              // Resource banks are every 4x3 tiles
              lumber.BankWidth = 4;
              lumber.BankHeight = 3;
  
              // Every bank holds from 20 to 45 logs
              lumber.MinTotal = 30;
              lumber.MaxTotal = 80;
  
              // A resource bank will respawn its content every 20 to 30 minutes
              lumber.MinRespawn = TimeSpan.FromMinutes(5.0);
              lumber.MaxRespawn = TimeSpan.FromMinutes(15.0);
  
              // Skill checking is done on the Lumberjacking skill
              lumber.Skill = SkillName.Lumberjacking;
  
              // Set the list of harvestable tiles
              lumber.Tiles = m_TreeTiles;
  
              // Players must be within 2 tiles to harvest
              lumber.MaxRange = 3;
  
              // Ten logs per harvest action
              lumber.ConsumedPerHarvest = 10;
              lumber.ConsumedPerFeluccaHarvest = 20;
  
              // The chopping effect
              lumber.EffectActions = new int[] { Core.SA ? 7 : 13 };
              lumber.EffectSounds = new int[] { 0x13E };
              lumber.EffectCounts = (Core.AOS ? new int[] { 1 } : new int[] { 1, 2, 2, 2, 3 });
              lumber.EffectDelay = TimeSpan.FromSeconds(1.6);
              lumber.EffectSoundDelay = TimeSpan.FromSeconds(0.9);
  
              lumber.NoResourcesMessage = 500493; // There's not enough wood here to harvest.
              lumber.FailMessage = 500495; // You hack at the tree for a while, but fail to produce any useable wood.
              lumber.OutOfRangeMessage = 500446; // That is too far away.
              lumber.PackFullMessage = 500497; // You can't place any wood into your backpack!
              lumber.ToolBrokeMessage = 500499; // You broke your axe.
  
              if (Core.ML)
              {
                  res = new HarvestResource[]
                  {
            		new HarvestResource( 00.0, 00.0, 95.0, "You put some Regular logs in your backpack",		typeof( Log ) ),
  				new HarvestResource( 20.0, 10.0, 100.0, "You put some Oak logs in your backpack",			typeof( OakLog ) ),
  				new HarvestResource( 30.0, 20.0, 105.0, "You put some Ash logs in your backpack",			typeof( AshLog ) ),
  				new HarvestResource( 40.0, 30.0, 110.0, "You put some Yew logs in your backpack",			typeof( YewLog ) ),
  				new HarvestResource( 50.0, 40.0, 115.0, "You put some Heartwood logs in your backpack",		typeof( HeartwoodLog ) ),
  				new HarvestResource( 60.0, 50.0, 120.0, "You put some Bloodwood logs in your backpack",		typeof( BloodwoodLog ) ),
  				new HarvestResource( 70.0, 60.0, 125.0, "You put some Frostwood logs in your backpack",		typeof( FrostwoodLog ) ),
  				new HarvestResource( 80.0, 70.0, 130.0, "You put some Ebony logs in your backpack",			typeof( EbonyLog ) ),
  				new HarvestResource( 90.0, 80.0, 135.0, "You put some Bamboo logs in your backpack",		typeof( BambooLog ) ),
  				new HarvestResource( 100.0, 90.0, 140.0, "You put some Purple Heart logs in your backpack",	typeof( PurpleHeartLog ) ),
  				new HarvestResource( 110.0, 100.0, 145.0, "You put some Redwood logs in your backpack",		typeof( RedwoodLog ) ),
  				new HarvestResource( 119.0, 110.0, 150.0, "You put some Petrified logs in your backpack",	typeof( PetrifiedLog ) ),
  									 																	
                  };
  
                  veins = new HarvestVein[]
                  {
  				new HarvestVein( 34.0, 0.0, res[0], null ), // this line should replace the original line
  				new HarvestVein( 11.0, 0.5, res[1], res[0] ), 	// OakLog
  				new HarvestVein( 10.0, 0.5, res[2], res[0] ), 	// AshLog
  				new HarvestVein( 09.0, 0.5, res[3], res[0] ), 	// YewLog 
  				new HarvestVein( 08.0, 0.5, res[4], res[0] ), 	// HeartwoodLog
  				new HarvestVein( 07.0, 0.5, res[5], res[0] ), 	// BloodwoodLog
  				new HarvestVein( 06.0, 0.5, res[6], res[0] ), 	// FrostwoodLog 
  				new HarvestVein( 05.0, 0.5, res[7], res[0] ), 	// EbonyLog
  				new HarvestVein( 04.0, 0.5, res[8], res[0] ), 	// BambooLog
  				new HarvestVein( 03.0, 0.5, res[9], res[0] ), 	// PurpleHeartLog
  				new HarvestVein( 02.0, 0.5, res[10], res[0] ),	// RedwoodLog
  				new HarvestVein( 01.0, 0.5, res[11], res[0] ),	// PetrifiedLog													  
                  };
  
                  lumber.BonusResources = new BonusHarvestResource[]
                  {
                      new BonusHarvestResource(0, 82.0, null, null), //Nothing
                      new BonusHarvestResource(100, 10.0, 1072548, typeof(BarkFragment)),
                      new BonusHarvestResource(100, 03.0, 1072550, typeof(LuminescentFungi)),
                      new BonusHarvestResource(100, 02.0, 1072547, typeof(SwitchItem)),
                      new BonusHarvestResource(100, 01.0, 1072549, typeof(ParasiticPlant)),
                      new BonusHarvestResource(100, 01.0, 1072551, typeof(BrilliantAmber)),
                      new BonusHarvestResource(100, 01.0, 1113756, typeof(CrystalShards), Map.TerMur),
                  };
              }
              else
              {
                  res = new HarvestResource[]
                  {
                      new HarvestResource(00.0, 00.0, 100.0, 500498, typeof(Log))
                  };
  
                  veins = new HarvestVein[]
                  {
                      new HarvestVein(100.0, 0.0, res[0], null)
                  };
              }
  
              lumber.Resources = res;
              lumber.Veins = veins;
  
              lumber.RaceBonus = Core.ML;
              lumber.RandomizeVeins = Core.ML;
  
              this.m_Definition = lumber;
              this.Definitions.Add(lumber);
              #endregion
          }
  
          public override Type MutateType(Type type, Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc, HarvestResource resource)
          {
              var newType = type;
  
              if (tool is HarvestersAxe && ((HarvestersAxe)tool).Charges > 0)
              {
                  if (type == typeof(Log))
                      newType = typeof(Board);
                  else if (type == typeof(OakLog))
                      newType = typeof(OakBoard);
                  else if (type == typeof(AshLog))
                      newType = typeof(AshBoard);
                  else if (type == typeof(YewLog))
                      newType = typeof(YewBoard);
                  else if (type == typeof(HeartwoodLog))
                      newType = typeof(HeartwoodBoard);
                  else if (type == typeof(BloodwoodLog))
                      newType = typeof(BloodwoodBoard);
                  else if (type == typeof(FrostwoodLog))
                      newType = typeof(FrostwoodBoard);
  				    else if (type == typeof(EbonyLog))
                      newType = typeof(EbonyBoard);
  				    else if (type == typeof(BambooLog))
                      newType = typeof(BambooBoard);
  				    else if (type == typeof(PurpleHeartLog))
                      newType = typeof(PurpleHeartBoard);
  				    else if (type == typeof(RedwoodLog))
                      newType = typeof(RedwoodBoard);
  				 else if (type == typeof(PetrifiedLog))
                      newType = typeof(PetrifiedBoard);
  
  
                  if (newType != type)
                  {
                      ((HarvestersAxe)tool).Charges--;
                  }
              }
  
              return newType;
          }
  
          public override void SendSuccessTo(Mobile from, Item item, HarvestResource resource)
          {
              if (item != null)
              {
                  if (item != null && item.GetType().IsSubclassOf(typeof(BaseWoodBoard)))
                  {
                      from.SendLocalizedMessage(1158776); // The axe magically creates boards from your logs.
                      return;
                  }
                  else
                  {
                      foreach (var res in m_Definition.Resources.Where(r => r.Types != null))
                      {
                          foreach (var type in res.Types)
                          {
  
gt:                             if (item.GetType() == type)