context: using System;
  using System.Collections.Generic;
  using Server.ContextMenus;
  using Server.Engines.Craft;
  using Server.Gumps;
  using Server.Mobiles;
  using Server.Multis;
  using Server.Network;
  
  namespace Server.Items
  {
      public class Runebook : Item, ISecurable, ICraftable
      {
          public override int LabelNumber { get { return 1041267; } } // runebook
  
          public static readonly TimeSpan UseDelay = TimeSpan.FromSeconds(7.0);
  
          private BookQuality m_Quality;
  
          [CommandProperty(AccessLevel.GameMaster)]
          public BookQuality Quality
          {
              get
              {
                  return m_Quality;
              }
              set
              {
                  m_Quality = value;
                  InvalidateProperties();
              }
          }
  
          private List<RunebookEntry> m_Entries;
          private string m_Description;
          private Mobile m_Crafter;
  
          [CommandProperty(AccessLevel.GameMaster)]
          public DateTime NextUse { get; set; }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public Mobile Crafter
          {
              get
              {
                  return m_Crafter;
              }
              set
              {
                  m_Crafter = value;
                  InvalidateProperties();
              }
          }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public SecureLevel Level { get; set; }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public string Description
          {
              get
              {
                  return m_Description;
              }
              set
              {
                  m_Description = value;
                  InvalidateProperties();
              }
          }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public int CurCharges { get; set; }
  
          [CommandProperty(AccessLevel.GameMaster)]
          public int MaxCharges { get; set; }
  
          public List<Mobile> Openers { get; set; } = new List<Mobile>();
  
          public virtual int MaxEntries { get { return 16; } }
  
          [Constructable]
          public Runebook(int maxCharges, int id = 0x22C5)
              : base(Core.AOS ? id : 0xEFA)
          {
              Weight = (Core.SE ? 1.0 : 3.0);
              LootType = LootType.Blessed;
              Hue = 0x461;
  
              Layer = (Core.AOS ? Layer.Invalid : Layer.OneHanded);
  
              m_Entries = new List<RunebookEntry>();
  
              MaxCharges = maxCharges;
  
              DefaultIndex = -1;
  
              Level = SecureLevel.CoOwners;
          }
  
          [Constructable]
          public Runebook()
              : this(Core.SE ? 12 : 6)
          {
          }
  
          public List<RunebookEntry> Entries { get { return m_Entries; } }
  
          public int DefaultIndex { get; set; }
  
          public RunebookEntry Default
          {
              get
              {
                  if (DefaultIndex >= 0 && DefaultIndex < m_Entries.Count)
                      return m_Entries[DefaultIndex];
  
                  return null;
              }
              set
              {
                  if (value == null)
                      DefaultIndex = -1;
                  else
                      DefaultIndex = m_Entries.IndexOf(value);
              }
          }
  
          public Runebook(Serial serial)
              : base(serial)
          {
          }
  
          public override bool AllowEquipedCast(Mobile from)
          {
              return true;
          }
  
          public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
          {
              base.GetContextMenuEntries(from, list);
              SetSecureLevelEntry.AddTo(from, this, list);
          }
  
          public override void Serialize(GenericWriter writer)
          {
              base.Serialize(writer);
              writer.Write((int)3);
  
              writer.Write((byte)m_Quality);
  
              writer.Write(m_Crafter);
  
              writer.Write((int)Level);
  
              writer.Write(m_Entries.Count);
  
              for (int i = 0; i < m_Entries.Count; ++i)
                  m_Entries[i].Serialize(writer);
  
              writer.Write(m_Description);
              writer.Write(CurCharges);
              writer.Write(MaxCharges);
              writer.Write(DefaultIndex);
          }
  
          public override void Deserialize(GenericReader reader)
          {
              base.Deserialize(reader);
              int version = reader.ReadInt();
  
              LootType = LootType.Blessed;
  
              if (Core.SE && Weight == 3.0)
                  Weight = 1.0;
  
              switch (version)
              {
                  case 3:
                      {
                          m_Quality = (BookQuality)reader.ReadByte();
                          goto case 2;
                      }
                  case 2:
                      {
                          m_Crafter = reader.ReadMobile();
                          goto case 1;
                      }
                  case 1:
                      {
                          Level = (SecureLevel)reader.ReadInt();
                          goto case 0;
                      }
                  case 0:
                      {
                          int count = reader.ReadInt();
  
                          m_Entries = new List<RunebookEntry>(count);
  
                          for (int i = 0; i < count; ++i)
                              m_Entries.Add(new RunebookEntry(reader));
  
                          m_Description = reader.ReadString();
                          CurCharges = reader.ReadInt();
                          MaxCharges = reader.ReadInt();
                          DefaultIndex = reader.ReadInt();
  
                          break;
                      }
              }
          }
  
          public void DropRune(Mobile from, RunebookEntry e, int index)
          {
              if (DefaultIndex > index)
                  DefaultIndex -= 1;
              else if (DefaultIndex == index)
                  DefaultIndex = -1;
  
              m_Entries.RemoveAt(index);
  
  
              RecallRune rune = new RecallRune();
  
  
gt:             if (e.Galleon != null)