context: using System;
  using Server.Items;
  using Server.Mobiles;
  using Server.Multis;
  using Server.Network;
  using Server.Prompts;
  using Server.Targeting;
  
  namespace Server.Gumps
  {
      public abstract class BaseVendorRentalGump : Gump
      {
          protected BaseVendorRentalGump(GumpType type, VendorRentalDuration duration, int price, int renewalPrice,
              Mobile landlord, Mobile renter, bool landlordRenew, bool renterRenew, bool renew)
              : base(100, 100)
          {
              if (type == GumpType.Offer)
                  this.Closable = false;
  
              this.AddPage(0);
  
              this.AddImage(0, 0, 0x1F40);
              this.AddImageTiled(20, 37, 300, 308, 0x1F42);
              this.AddImage(20, 325, 0x1F43);
  
              this.AddImage(35, 8, 0x39);
              this.AddImageTiled(65, 8, 257, 10, 0x3A);
              this.AddImage(290, 8, 0x3B);
  
              this.AddImageTiled(70, 55, 230, 2, 0x23C5);
  
              this.AddImage(32, 33, 0x2635);
              this.AddHtmlLocalized(70, 35, 270, 20, 1062353, 0x1, false, false); // Vendor Rental Contract
  
              this.AddPage(1);
  
              if (type != GumpType.UnlockedContract)
              {
                  this.AddImage(65, 60, 0x827);
                  this.AddHtmlLocalized(79, 58, 270, 20, 1062370, 0x1, false, false); // Landlord:
                  this.AddLabel(150, 58, 0x64, landlord != null ? landlord.Name : "");
  
                  this.AddImageTiled(70, 80, 230, 2, 0x23C5);
              }
  
              if (type == GumpType.UnlockedContract || type == GumpType.LockedContract)
                  this.AddButton(30, 96, 0x15E1, 0x15E5, 0, GumpButtonType.Page, 2);
              this.AddHtmlLocalized(50, 95, 150, 20, 1062354, 0x1, false, false); // Contract Length
              this.AddHtmlLocalized(230, 95, 270, 20, duration.Name, 0x1, false, false);
  
              if (type == GumpType.UnlockedContract || type == GumpType.LockedContract)
                  this.AddButton(30, 116, 0x15E1, 0x15E5, 1, GumpButtonType.Reply, 0);
              this.AddHtmlLocalized(50, 115, 150, 20, 1062356, 0x1, false, false); // Price Per Rental
              this.AddLabel(230, 115, 0x64, price > 0 ? price.ToString() : "FREE");
  
              this.AddImageTiled(50, 160, 250, 2, 0x23BF);
  
              if (type == GumpType.Offer)
              {
                  this.AddButton(67, 180, 0x482, 0x483, 2, GumpButtonType.Reply, 0);
                  this.AddHtmlLocalized(100, 180, 270, 20, 1049011, 0x28, false, false); // I accept!
  
                  this.AddButton(67, 210, 0x47F, 0x480, 0, GumpButtonType.Reply, 0);
                  this.AddHtmlLocalized(100, 210, 270, 20, 1049012, 0x28, false, false); // No thanks, I decline.
              }
              else
              {
                  this.AddImage(49, 170, 0x61);
                  this.AddHtmlLocalized(60, 170, 250, 20, 1062355, 0x1, false, false); // Renew On Expiration?
  
                  if (type == GumpType.LockedContract || type == GumpType.UnlockedContract || type == GumpType.VendorLandlord)
                      this.AddButton(30, 192, 0x15E1, 0x15E5, 3, GumpButtonType.Reply, 0);
                  this.AddHtmlLocalized(85, 190, 250, 20, 1062359, 0x1, false, false); // Landlord:
                  this.AddHtmlLocalized(230, 190, 270, 20, landlordRenew ? 1049717 : 1049718, 0x1, false, false); // YES / NO
  
                  if (type == GumpType.VendorRenter)
                      this.AddButton(30, 212, 0x15E1, 0x15E5, 4, GumpButtonType.Reply, 0);
                  this.AddHtmlLocalized(85, 210, 250, 20, 1062360, 0x1, false, false); // Renter:
                  this.AddHtmlLocalized(230, 210, 270, 20, renterRenew ? 1049717 : 1049718, 0x1, false, false); // YES / NO
  
                  if (renew)
                  {
                      this.AddImage(49, 233, 0x939);
                      this.AddHtmlLocalized(70, 230, 250, 20, 1062482, 0x1, false, false); // Contract WILL renew
                  }
                  else
                  {
                      this.AddImage(49, 233, 0x938);
                      this.AddHtmlLocalized(70, 230, 250, 20, 1062483, 0x1, false, false); // Contract WILL NOT renew
                  }
              }
  
              this.AddImageTiled(30, 283, 257, 30, 0x5D);
              this.AddImage(285, 283, 0x5E);
              this.AddImage(20, 288, 0x232C);
  
              if (type == GumpType.LockedContract)
              {
                  this.AddButton(67, 295, 0x15E1, 0x15E5, 5, GumpButtonType.Reply, 0);
                  this.AddHtmlLocalized(85, 294, 270, 20, 1062358, 0x28, false, false); // Offer Contract To Someone
              }
              else if (type == GumpType.VendorLandlord || type == GumpType.VendorRenter)
              {
                  if (type == GumpType.VendorLandlord)
                      this.AddButton(30, 250, 0x15E1, 0x15E1, 6, GumpButtonType.Reply, 0);
                  this.AddHtmlLocalized(85, 250, 250, 20, 1062499, 0x1, false, false); // Renewal Price
                  this.AddLabel(230, 250, 0x64, renewalPrice.ToString());
  
                  this.AddHtmlLocalized(60, 294, 270, 20, 1062369, 0x1, false, false); // Renter:
                  this.AddLabel(120, 293, 0x64, renter != null ? renter.Name : "");
              }
  
              if (type == GumpType.UnlockedContract || type == GumpType.LockedContract)
              {
                  this.AddPage(2);
  
                  for (int i = 0; i < VendorRentalDuration.Instances.Length; i++)
                  {
                      VendorRentalDuration durationItem = VendorRentalDuration.Instances[i];
  
                      this.AddButton(30, 76 + i * 20, 0x15E1, 0x15E5, 0x10 | i, GumpButtonType.Reply, 1);
                      this.AddHtmlLocalized(50, 75 + i * 20, 150, 20, durationItem.Name, 0x1, false, false);
                  }
              }
          }
  
          protected enum GumpType
          {
              UnlockedContract,
              LockedContract,
              Offer,
              VendorLandlord,
              VendorRenter
          }
          public override void OnResponse(NetState sender, RelayInfo info)
          {
              Mobile from = sender.Mobile;
  
              if (!this.IsValidResponse(from))
                  return;
  
              if ((info.ButtonID & 0x10) != 0) // Contract duration
              {
                  int index = info.ButtonID & 0xF;
  
                  if (index < VendorRentalDuration.Instances.Length)
                  {
                      this.SetContractDuration(from, VendorRentalDuration.Instances[index]);
                  }
              }
              else
              {
                  switch ( info.ButtonID )
                  {
                      case 1: // Price Per Rental
                          this.SetPricePerRental(from);
                          break;
                      case 2: // Accept offer
                          this.AcceptOffer(from);
                          break;
                      case 3: // Renew on expiration - landlord
                          this.LandlordRenewOnExpiration(from);
                          break;
                      case 4: // Renew on expiration - renter
                          this.RenterRenewOnExpiration(from);
                          break;
                      case 5: // Offer Contract To Someone
                          this.OfferContract(from);
                          break;
                      case 6: // Renewal price
                          this.SetRenewalPrice(from);
                          break;
                      default:
                          this.Cancel(from);
                          break;
                  }
              }
          }
  
          protected abstract bool IsValidResponse(Mobile from);
  
          protected virtual void SetContractDuration(Mobile from, VendorRentalDuration duration)
          {
          }
  
          protected virtual void SetPricePerRental(Mobile from)
          {
          }
  
          protected virtual void AcceptOffer(Mobile from)
          {
          }
  
          protected virtual void LandlordRenewOnExpiration(Mobile from)
          {
          }
  
          protected virtual void RenterRenewOnExpiration(Mobile from)
          {
          }
  
          protected virtual void OfferContract(Mobile from)
          {
          }
  
          protected virtual void SetRenewalPrice(Mobile from)
          {
          }
  
          protected virtual void Cancel(Mobile from)
          {
          }
      }
  
      public class VendorRentalContractGump : BaseVendorRentalGump
      {
          private readonly VendorRentalContract m_Contract;
          public VendorRentalContractGump(VendorRentalContract contract, Mobile from)
              : base(
              contract.IsLockedDown ? GumpType.LockedContract : GumpType.UnlockedContract, contract.Duration,
              contract.Price, contract.Price, from, null, contract.LandlordRenew, false, false)
          {
              this.m_Contract = contract;
          }
  
          protected override bool IsValidResponse(Mobile from)
          {
              return this.m_Contract.IsUsableBy(from, true, true, true, true);
          }
  
          protected override void SetContractDuration(Mobile from, VendorRentalDuration duration)
          {
              this.m_Contract.Duration = duration;
  
              from.SendGump(new VendorRentalContractGump(this.m_Contract, from));
          }
  
          protected override void SetPricePerRental(Mobile from)
          {
              from.SendLocalizedMessage(1062365); // Please enter the amount of gold that should be charged for this contract (ESC to cancel):
              from.Prompt = new PricePerRentalPrompt(this.m_Contract);
          }
  
          protected override void LandlordRenewOnExpiration(Mobile from)
          {
  
gt:             this.m_Contract.LandlordRenew = !this.m_Contract.LandlordRenew;