context: using System;
  using Server.Targeting;
  
  namespace Server.Items
  {
      public class UtilityItem
      {
          static public int RandomChoice(int itemID1, int itemID2)
          {
              int iRet = 0;
              switch ( Utility.Random(2) )
              {
                  default:
                  case 0:
                      iRet = itemID1;
                      break;
                  case 1:
                      iRet = itemID2;
                      break;
              }
              return iRet;
          }
      }
  
      public class Dough : Item
      {
          [Constructable]
          public Dough()
              : base(0x103d)
          {
              this.Stackable = Core.ML;
              this.Weight = 1.0;
          }
  
          public Dough(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();
          }
  
          #if false
  		public override void OnDoubleClick( Mobile from )
  		{
  			if ( !Movable )
  				return;
  
  			from.Target = new DoughTarget( this );
  		}
          #endif
  
          private class DoughTarget : Target
          {
              private readonly Dough m_Item;
  
              public DoughTarget(Dough item)
                  : base(1, false, TargetFlags.None)
              {
                  this.m_Item = item;
              }
  
              protected override void OnTarget(Mobile from, object targeted)
              {
                  if (this.m_Item.Deleted)
                      return;
  
                  if (targeted is Eggs)
                  {
                      this.m_Item.Delete();
  
                      ((Eggs)targeted).Consume();
  
                      from.AddToBackpack(new UnbakedQuiche());
                      from.AddToBackpack(new Eggshells());
                  }
                  else if (targeted is CheeseWheel)
                  {
                      this.m_Item.Delete();
  
                      ((CheeseWheel)targeted).Consume();
  
                      from.AddToBackpack(new CheesePizza());
                  }
                  else if (targeted is Sausage)
                  {
                      this.m_Item.Delete();
  
                      ((Sausage)targeted).Consume();
  
                      from.AddToBackpack(new SausagePizza());
                  }
                  else if (targeted is Apple)
                  {
                      this.m_Item.Delete();
  
                      ((Apple)targeted).Consume();
  
                      from.AddToBackpack(new UnbakedApplePie());
                  }
                  else if (targeted is Peach)
                  {
                      this.m_Item.Delete();
  
                      ((Peach)targeted).Consume();
  
                      from.AddToBackpack(new UnbakedPeachCobbler());
                  }
              }
          }
      }
  
      public class SweetDough : Item
      {
          public override int LabelNumber
          {
              get
              {
                  return 1041340;
              }
          }// sweet dough
  
          [Constructable]
          public SweetDough()
              : base(0x103d)
          {
              this.Stackable = Core.ML;
              this.Weight = 1.0;
              this.Hue = 150;
          }
  
          public SweetDough(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();
  
              if (this.Hue == 51)
                  this.Hue = 150;
          }
  
          #if false
  		public override void OnDoubleClick( Mobile from )
  		{
  			if ( !Movable )
  				return;
  
  			from.Target = new SweetDoughTarget( this );
  		}
          #endif
  
          private class SweetDoughTarget : Target
          {
              private readonly SweetDough m_Item;
  
              public SweetDoughTarget(SweetDough item)
                  : base(1, false, TargetFlags.None)
              {
                  this.m_Item = item;
              }
  
              protected override void OnTarget(Mobile from, object targeted)
              {
                  if (this.m_Item.Deleted)
                      return;
  
                  if (targeted is BowlFlour)
                  {
                      this.m_Item.Delete();
                      ((BowlFlour)targeted).Delete();
  
                      from.AddToBackpack(new CakeMix());
                  }
                  else if (targeted is Campfire)
                  {
                      from.PlaySound(0x225);
                      this.m_Item.Delete();
                      SweetDoughTimer t = new SweetDoughTimer(from, (Campfire)targeted);
                      t.Start();
                  }
              }
  			
              private class SweetDoughTimer : Timer
              {
                  private readonly Mobile m_From;
                  private readonly Campfire m_Campfire;
  
                  public SweetDoughTimer(Mobile from, Campfire campfire)
                      : base(TimeSpan.FromSeconds(5.0))
                  {
                      this.m_From = from;
                      this.m_Campfire = campfire;
                  }
  
                  protected override void OnTick()
                  {
                      if (this.m_From.GetDistanceToSqrt(this.m_Campfire) > 3)
                      {
                          this.m_From.SendLocalizedMessage(500686); // You burn the food to a crisp! It's ruined.
                          return;
                      }
  
                      if (this.m_From.CheckSkill(SkillName.Cooking, 0, 10))
                      {
                          if (this.m_From.AddToBackpack(new Muffins()))
                              this.m_From.PlaySound(0x57);
                      }
                      else
                      {
                          this.m_From.SendLocalizedMessage(500686); // You burn the food to a crisp! It's ruined.
                      }
                  }
              }
          }
      }
  
      public class JarHoney : Item
      {
          [Constructable]
          public JarHoney()
              : base(0x9ec)
          {
              this.Weight = 1.0;
              this.Stackable = true;
          }
  
          public JarHoney(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();
              this.Stackable = true;
          }
  
          /*public override void OnDoubleClick( Mobile from )
          {
          if ( !Movable )
          return;
  
          from.Target = new JarHoneyTarget( this );
          }*/
  
          private class JarHoneyTarget : Target
          {
              private readonly JarHoney m_Item;
  
              public JarHoneyTarget(JarHoney item)
                  : base(1, false, TargetFlags.None)
              {
                  this.m_Item = item;
              }
  
              protected override void OnTarget(Mobile from, object targeted)
              {
                  if (this.m_Item.Deleted)
                      return;
  
                  if (targeted is Dough)
                  {
                      this.m_Item.Delete();
                      ((Dough)targeted).Consume();
  
                      from.AddToBackpack(new SweetDough());
                  }
  				
                  if (targeted is BowlFlour)
                  {
                      this.m_Item.Consume();
                      ((BowlFlour)targeted).Delete();
  
                      from.AddToBackpack(new CookieMix());
                  }
              }
          }
      }
  
      public class BowlFlour : Item
      {
          [Constructable]
          public BowlFlour()
              : base(0xa1e)
          {
              this.Weight = 1.0;
          }
  
          public BowlFlour(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 WoodenBowl : Item
      {
          [Constructable]
          public WoodenBowl()
              : base(0x15f8)
          {
              this.Weight = 1.0;
          }
  
          public WoodenBowl(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();
          }
      }
  
      // ********** PitcherWater **********
      /*public class PitcherWater : Item
      {
      [Constructable]
      public PitcherWater() : base(Utility.Random( 0x1f9d, 2 ))
      {
      Weight = 1.0;
      }
  
      public PitcherWater( 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 override void OnDoubleClick( Mobile from )
      {
      if ( !Movable )
      return;
  
      from.Target = new InternalTarget( this );
      }
  
      private class InternalTarget : Target
      {
      private PitcherWater m_Item;
  
      public InternalTarget( PitcherWater item ) : base( 1, false, TargetFlags.None )
      {
      m_Item = item;
      }
  
      protected override void OnTarget( Mobile from, object targeted )
      {
      if ( m_Item.Deleted ) return;
  
      if ( targeted is BowlFlour )
      {
      m_Item.Delete();
      ((BowlFlour)targeted).Delete();
  
      from.AddToBackpack( new Dough() );
      from.AddToBackpack( new WoodenBowl() );
      }
      }
      }
      }*/
  
      [TypeAlias("Server.Items.SackFlourOpen")]
      public class SackFlour : Item, IHasQuantity
      {
          private int m_Quantity;
  
          [CommandProperty(AccessLevel.GameMaster)]
          public int Quantity
          {
              get
              {
                  return this.m_Quantity;
              }
              set
              {
                  if (value < 0)
                      value = 0;
                  else if (value > 20)
                      value = 20;
  
                  this.m_Quantity = value;
  
                  if (this.m_Quantity == 0)
                      this.Delete();
                  else if (this.m_Quantity < 20 && (this.ItemID == 0x1039 || this.ItemID == 0x1045))
                      ++this.ItemID;
              }
          }
  
          [Constructable]
          public SackFlour()
              : base(0x1039)
          {
              this.Weight = 5.0;
              this.m_Quantity = 20;
          }
  
          public SackFlour(Serial serial)
              : base(serial)
          {
          }
  
          public override void Serialize(GenericWriter writer)
          {
              base.Serialize(writer);
  
              writer.Write((int)2); // version
  
              writer.Write((int)this.m_Quantity);
          }
  
          public override void Deserialize(GenericReader reader)
          {
              base.Deserialize(reader);
  
              int version = reader.ReadInt();
  
              switch ( version )
              {
                  case 2:
                  case 1:
                      {
                          this.m_Quantity = reader.ReadInt();
                          break;
                      }
                  case 0:
                      {
                          this.m_Quantity = 20;
                          break;
                      }
              }
  
              if (version < 2 && this.Weight == 1.0)
                  this.Weight = 5.0;
          }
  
          public override void OnDoubleClick(Mobile from)
          {
              if (!this.Movable)
                  return;
  
              if ((this.ItemID == 0x1039 || this.ItemID == 0x1045))
                  ++this.ItemID;
              #if false
  			this.Delete();
  			from.AddToBackpack( new SackFlourOpen() );
              #endif
          }
      }
  
      #if false
  	public class SackFlourOpen : Item
  	{
  		public override int LabelNumber{ get{ return 1024166; } } // open sack of flour
  
  		[Constructable]
  		public SackFlourOpen() : base(UtilityItem.RandomChoice( 0x1046, 0x103a ))
  		{
  			Weight = 1.0;
  		}
  
  		public SackFlourOpen( Serial serial ) : base( serial )
  		{
  		}
  
  		public override void Serialize( GenericWriter writer )
  		{
  			base.Serialize( writer );
  
  
gt: 			writer.Write( (int) 0 ); // version