context: using System;
  using System.Collections;
  using System.Collections.Generic;
  using Server;
  using Server.Gumps;
  using Server.Network;
  using Server.Multis;
  using Server.Engines.Craft;
  using Server.ContextMenus;
  
  namespace Server.Items
  {
  	public class Runebook : Item, ISecurable, ICraftable
  	{
  		public static readonly TimeSpan UseDelay = TimeSpan.FromSeconds( 7.0 );
  
  		private List<RunebookEntry> m_Entries;
  		private string m_Description;
  		private int m_CurCharges, m_MaxCharges;
  		private int m_DefaultIndex;
  		private SecureLevel m_Level;
  		private Mobile m_Crafter;
  		
  		private DateTime m_NextUse;
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public DateTime NextUse
  		{
  			get{ return m_NextUse; }
  			set{ m_NextUse = value; }
  		}
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public Mobile Crafter
  		{
  			get{ return m_Crafter; }
  			set{ m_Crafter = value; InvalidateProperties(); }
  		}
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public SecureLevel Level
  		{
  			get{ return m_Level; }
  			set{ m_Level = value; }
  		}
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public string Description
  		{
  			get
  			{
  				return m_Description;
  			}
  			set
  			{
  				m_Description = value;
  				InvalidateProperties();
  			}
  		}
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public int CurCharges
  		{
  			get
  			{
  				return m_CurCharges;
  			}
  			set
  			{
  				m_CurCharges = value;
  			}
  		}
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public int MaxCharges
  		{
  			get
  			{
  				return m_MaxCharges;
  			}
  			set
  			{
  				m_MaxCharges = value;
  			}
  		}
  
  		public override int LabelNumber{ get{ return 1041267; } } // runebook
  
  		[Constructable]
  		public Runebook( int maxCharges ) : base( Core.AOS ? 0x22C5 : 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>();
  
  			m_MaxCharges = maxCharges;
  
  			m_DefaultIndex = -1;
  
  			m_Level = SecureLevel.CoOwners;
  		}
  
  		[Constructable]
  		public Runebook() : this( Core.SE ? 12 : 6 )
  		{
  		}
  
  		public List<RunebookEntry> Entries
  		{
  			get
  			{
  				return m_Entries;
  			}
  		}
  
  		public RunebookEntry Default
  		{
  			get
  			{
  				if ( m_DefaultIndex >= 0 && m_DefaultIndex < m_Entries.Count )
  					return m_Entries[m_DefaultIndex];
  
  				return null;
  			}
  			set
  			{
  				if ( value == null )
  					m_DefaultIndex = -1;
  				else
  					m_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) 2 );
  
  			writer.Write( m_Crafter );
  
  			writer.Write( (int) m_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( m_CurCharges );
  			writer.Write( m_MaxCharges );
  			writer.Write( m_DefaultIndex );
  		}
  
  		public override void Deserialize( GenericReader reader )
  		{
  			base.Deserialize( reader );
  
  			LootType = LootType.Blessed;
  
  			if( Core.SE && Weight == 3.0 )
  				Weight = 1.0;
  
  			int version = reader.ReadInt();
  
  			switch ( version )
  			{
  				case 2:
  				{
  					m_Crafter = reader.ReadMobile();
  					goto case 1;
  				}
  				case 1:
  				{
  					m_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();
  					m_CurCharges = reader.ReadInt();
  					m_MaxCharges = reader.ReadInt();
  
gt: 					m_DefaultIndex = reader.ReadInt();