context: using System;
  using Server.Factions;
  using Server.Guilds;
  using Server.Gumps;
  using Server.Multis;
  using Server.Network;
  using Server.GuildConfiguration;
  
  namespace Server.Items
  {
      public class Guildstone : Item, IAddon, IChopable
      {
          private Guild m_Guild;
          private string m_GuildName;
          private string m_GuildAbbrev;
  
          [CommandProperty(AccessLevel.GameMaster)]
          public string GuildName
          {
              get
              {
                  return m_GuildName;
              }
              set
              {
                  m_GuildName = value;
                  InvalidateProperties();
              }
          }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public string GuildAbbrev
          {
              get
              {
                  return m_GuildAbbrev;
              }
              set
              {
                  m_GuildAbbrev = value;
                  InvalidateProperties();
              }
          }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public Guild Guild
          {
              get
              {
                  return m_Guild;
              }
          }
  
          public override int LabelNumber
          {
              get
              {
                  return 1041429;
              }
          }// a guildstone
  
          public Guildstone(Guild g)
              : this(g, g.Name, g.Abbreviation)
          {
          }
  
          public Guildstone(Guild g, string guildName, string abbrev)
              : base(GuildConfig.NewGuildSystemEnabled ? 0xED6 : 0xED4)
          {
              m_Guild = g;
              m_GuildName = guildName;
              m_GuildAbbrev = abbrev;
  
              Movable = false;
          }
  
          public Guildstone(Serial serial)
              : base(serial)
          {
          }
  
          public override void Serialize(GenericWriter writer)
          {
              base.Serialize(writer);
  
              if (m_Guild != null && !m_Guild.Disbanded)
              {
                  m_GuildName = m_Guild.Name;
                  m_GuildAbbrev = m_Guild.Abbreviation;
              }
  
              writer.Write((int)3); // version
  
              writer.Write(m_BeforeChangeover);
  
              writer.Write(m_GuildName);
              writer.Write(m_GuildAbbrev);
  
              writer.Write(m_Guild);
          }
  
          private bool m_BeforeChangeover;
          public override void Deserialize(GenericReader reader)
          {
              base.Deserialize(reader);
  
              int version = reader.ReadInt();
  
              switch( version )
              {
                  case 3:
                      {
                          m_BeforeChangeover = reader.ReadBool();
                          goto case 2;
                      }
                  case 2:
                      {
                          m_GuildName = reader.ReadString();
                          m_GuildAbbrev = reader.ReadString();
  
                          goto case 1;
                      }
                  case 1:
                      {
                          m_Guild = reader.ReadGuild() as Guild;
  
                          goto case 0;
                      }
                  case 0:
                      {
                          break;
                      }
              }
  
              if (GuildConfig.NewGuildSystemEnabled && ItemID == 0xED4)
                  ItemID = 0xED6;
  
              if (version <= 2)
                  m_BeforeChangeover = true;
  
              if (GuildConfig.NewGuildSystemEnabled && m_BeforeChangeover)
                  Timer.DelayCall(TimeSpan.Zero, new TimerCallback(AddToHouse));
  
              if (!GuildConfig.NewGuildSystemEnabled && m_Guild == null)
                  Delete();
          }
  
          private void AddToHouse()
          {
              BaseHouse house = BaseHouse.FindHouseAt(this);
  
              if (GuildConfig.NewGuildSystemEnabled && m_BeforeChangeover && house != null && !house.Addons.Contains(this))
              {
                  house.Addons.Add(this);
                  m_BeforeChangeover = false;
              }
          }
  
          public override void GetProperties(ObjectPropertyList list)
          {
              base.GetProperties(list);
  
              if (m_Guild != null && !m_Guild.Disbanded)
              {
                  string name;
                  string abbr;
  
                  if ((name = m_Guild.Name) == null || (name = name.Trim()).Length <= 0)
                      name = "(unnamed)";
  
                  if ((abbr = m_Guild.Abbreviation) == null || (abbr = abbr.Trim()).Length <= 0)
                      abbr = "";
  
                  //list.Add( 1060802, Utility.FixHtml( name ) ); // Guild name: ~1_val~
                  list.Add(1060802, String.Format("{0} [{1}]", Utility.FixHtml(name), Utility.FixHtml(abbr)));
              }
              else if (m_GuildName != null && m_GuildAbbrev != null)
              {
                  list.Add(1060802, String.Format("{0} [{1}]", Utility.FixHtml(m_GuildName), Utility.FixHtml(m_GuildAbbrev)));
              }
          }
  
          public override void OnSingleClick(Mobile from)
          {
              base.OnSingleClick(from);
  
              if (m_Guild != null && !m_Guild.Disbanded)
              {
                  string name;
  
                  if ((name = m_Guild.Name) == null || (name = name.Trim()).Length <= 0)
                      name = "(unnamed)";
  
                  LabelTo(from, name);
              }
              else if (m_GuildName != null)
              {
                  LabelTo(from, m_GuildName);
              }
          }
  
          public override void OnAfterDelete()
          {
              if (!GuildConfig.NewGuildSystemEnabled && m_Guild != null && !m_Guild.Disbanded)
                  m_Guild.Disband();
          }
  
          public override void OnDoubleClick(Mobile from)
          {
              if (GuildConfig.NewGuildSystemEnabled)
                  return;
  
              if (m_Guild == null || m_Guild.Disbanded)
              {
                  Delete();
              }
              else if (!from.InRange(GetWorldLocation(), 2))
              {
                  from.SendLocalizedMessage(500446); // That is too far away.
              }
  
gt:             else if (m_Guild.Accepted.Contains(from))