Full Version : Ohh my another sever crash :(
xmlspawner >>Scripting Support >>Ohh my another sever crash :(


<< Prev | Next >>

Crystal Jem- 07-15-2006
Well I did it again Crash bang boom , I think it has desided it shouldn't save any player mobiles on me sad.gif , but since I'm not positive I'll ask your help to deturmen this.


[QUOTE]RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Core: Running with arguments: -debug
Scripts: Compiling C# scripts...Error:
System.Runtime.InteropServices.ExternalException: Timed out waiting for a progra
m to execute. The command being executed was "C:\WINDOWS\Microsoft.NET\Framework
\v2.0.50727\csc.exe" /noconfig /fullpaths @"C:\Documents and Settings\Jolen\Loca
l Settings\Temp\i_su39ij.cmdline".
at System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUse
rTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFi
les, String& outputName, String& errorName, String trueCmdLine)
at System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle u
serToken, String cmd, String currentDir, TempFileCollection tempFiles, String& o
utputName, String& errorName, String trueCmdLine)
at Microsoft.CSharp.CSharpCodeGenerator.Compile(CompilerParameters options, S
tring compilerDirectory, String compilerExe, String arguments, String& outputFil
e, Int32& nativeReturnValue, String trueArgs)
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters opti
ons, String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler
.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames)
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerPa
rameters options, String[] fileNames)
at Server.ScriptCompiler.CompileCSScripts(Boolean debug, Assembly& assembly)
at Server.ScriptCompiler.Compile(Boolean debug)
at Server.Core.Main(String[] args)
This exception is fatal, press return to exit


ArteGordon- 07-15-2006
this is not a crash during saving, this is a crash on restart. The compiler seems to be timing out. Perhaps you are running out of resources.

Crystal Jem- 07-15-2006
i'll defrag and find out, I do know it keeps asking me to deleate my player mobile's witch is not good. and very tyreing re makeing it lol.

ArteGordon- 07-15-2006
did you fix your serialization/deserialization in your playermobile?

Crystal Jem- 07-16-2006
QUOTE (ArteGordon @ July 16, 2006 03:25 am)
did you fix your serialization/deserialization in your playermobile?

I Added in the changes you sujested.

Disk Defrag says i have 45% free space that 16.98 GB

I also have this when i start up sad.gif

RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Core: Running with arguments: -debug
Scripts: Compiling C# scripts...done (0 errors, 0 warnings)
Scripts: Compiling VB.NET scripts...no files found.
Scripts: Verifying...done (2711 items, 620 mobiles)
Regions: Loading...done
World: Loading...An error was encountered while loading a saved object
- Type: Server.Mobiles.PlayerMobile
- Serial: 0x00000002
Delete the object? (y/n)

ArteGordon- 07-16-2006
post the Serialize and Deserialize methods that you are currently using in your Playermobile.

Crystal Jem- 07-16-2006
QUOTE (ArteGordon @ July 16, 2006 01:20 pm)
post the Serialize and Deserialize methods that you are currently using in your Playermobile.

CODE
public override void Deserialize( GenericReader reader )
 {
  base.Deserialize( reader );
  int version = reader.ReadInt();

  switch ( version )
  {
               case 28:
                   {
                       m_TamingBOBFilter = new Engines.BulkOrders.TamingBOBFilter(reader);
                       goto case 27;
                   }
               case 27:
                   {
                       m_Bioenginer = reader.ReadBool();
                       NextTamingBulkOrder = reader.ReadTimeSpan();
                       goto case 26;
                   }
               case 26:
                   {
                       m_City = (CityManagementStone)reader.ReadItem();
                       m_CityTitle = reader.ReadString();
                       m_ShowCityTitle = reader.ReadBool();
                       m_OwesBackTaxes = reader.ReadBool();
                       m_BackTaxesAmount = reader.ReadInt();
                       goto case 25;
                   }
               case 25:
   {
    int recipeCount = reader.ReadInt();

    if( recipeCount > 0 )
    {
     m_AcquiredRecipes = new Dictionary<int, bool>();

     for( int i = 0; i < recipeCount; i++ )
     {
      int r = reader.ReadInt();
      if( reader.ReadBool() ) //Don't add in recipies which we haven't gotten or have been removed
       m_AcquiredRecipes.Add( r, true );
     }
    }
    goto case 24;
   }
   case 24:
   {
    m_LastHonorLoss = reader.ReadDeltaTime();
    goto case 23;
   }
   case 23:
   {
    m_ChampionTitles = new ChampionTitleInfo( reader );
    goto case 22;
   }
   case 22:
   {
    m_LastValorLoss = reader.ReadDateTime();
    goto case 21;
   }
   case 21:
   {
    m_ToTItemsTurnedIn = reader.ReadEncodedInt();
    m_ToTTotalMonsterFame = reader.ReadInt();
    goto case 20;
   }
   case 20:
   {
    m_AllianceMessageHue = reader.ReadEncodedInt();
    m_GuildMessageHue = reader.ReadEncodedInt();

    goto case 19;
   }
   case 19:
   {
    int rank = reader.ReadEncodedInt();
    int maxRank = Guilds.RankDefinition.Ranks.Length -1;
    if( rank > maxRank )
     rank = maxRank;

    m_GuildRank = Guilds.RankDefinition.Ranks[rank];
    m_LastOnline = reader.ReadDateTime();
    goto case 18;
   }
   case 18:
   {
    m_SolenFriendship = (SolenFriendship) reader.ReadEncodedInt();

    goto case 17;
   }
   case 17: // changed how DoneQuests is serialized
   case 16:
   {
    m_Quest = QuestSerializer.DeserializeQuest( reader );

    if ( m_Quest != null )
     m_Quest.From = this;

    int count = reader.ReadEncodedInt();

    if ( count > 0 )
    {
     m_DoneQuests = new List<QuestRestartInfo>();

     for ( int i = 0; i < count; ++i )
     {
      Type questType = QuestSerializer.ReadType( QuestSystem.QuestTypes, reader );
      DateTime restartTime;

      if ( version < 17 )
       restartTime = DateTime.MaxValue;
      else
       restartTime = reader.ReadDateTime();

      m_DoneQuests.Add( new QuestRestartInfo( questType, restartTime ) );
     }
    }

    m_Profession = reader.ReadEncodedInt();
    goto case 15;
   }
   case 15:
   {
    m_LastCompassionLoss = reader.ReadDeltaTime();
    goto case 14;
   }
   case 14:
   {
    m_CompassionGains = reader.ReadEncodedInt();

    if ( m_CompassionGains > 0 )
     m_NextCompassionDay = reader.ReadDeltaTime();

    goto case 13;
   }
   case 13: // just removed m_PayedInsurance list
   case 12:
   {
    m_BOBFilter = new Engines.BulkOrders.BOBFilter( reader );
    goto case 11;
   }
   case 11:
   {
    if ( version < 13 )
    {
     List<Item> payed = reader.ReadStrongItemList();

     for ( int i = 0; i < payed.Count; ++i )
      payed[i].PayedInsurance = true;
    }

    goto case 10;
   }
   case 10:
   {
    if ( reader.ReadBool() )
    {
     m_HairModID = reader.ReadInt();
     m_HairModHue = reader.ReadInt();
     m_BeardModID = reader.ReadInt();
     m_BeardModHue = reader.ReadInt();

     // We cannot call SetHairMods( -1, -1 ) here because the items have not yet loaded
     Timer.DelayCall( TimeSpan.Zero, new TimerCallback( RevertHair ) );
    }

    goto case 9;
   }
   case 9:
   {
    SavagePaintExpiration = reader.ReadTimeSpan();

    if ( SavagePaintExpiration > TimeSpan.Zero )
    {
     BodyMod = ( Female ? 184 : 183 );
     HueMod = 0;
    }

    goto case 8;
   }
   case 8:
   {
    m_NpcGuild = (NpcGuild)reader.ReadInt();
    m_NpcGuildJoinTime = reader.ReadDateTime();
    m_NpcGuildGameTime = reader.ReadTimeSpan();
    goto case 7;
   }
   case 7:
   {
    m_PermaFlags = reader.ReadStrongMobileList();
    goto case 6;
   }
   case 6:
   {
    NextTailorBulkOrder = reader.ReadTimeSpan();
    goto case 5;
   }
   case 5:
   {
    NextSmithBulkOrder = reader.ReadTimeSpan();
    goto case 4;
   }
   case 4:
   {
    m_LastJusticeLoss = reader.ReadDeltaTime();
    m_JusticeProtectors = reader.ReadStrongMobileList();
    goto case 3;
   }
   case 3:
   {
    m_LastSacrificeGain = reader.ReadDeltaTime();
    m_LastSacrificeLoss = reader.ReadDeltaTime();
    m_AvailableResurrects = reader.ReadInt();
    goto case 2;
   }
   case 2:
   {
    m_Flags = (PlayerFlag)reader.ReadInt();
    goto case 1;
   }
   case 1:
   {
    m_LongTermElapse = reader.ReadTimeSpan();
    m_ShortTermElapse = reader.ReadTimeSpan();
    m_GameTime = reader.ReadTimeSpan();
    goto case 0;
   }
   case 0:
   {
    break;
   }
  }


public override void Serialize( GenericWriter writer )
{


//cleanup our anti-macro table
foreach ( Hashtable t in m_AntiMacroTable.Values )
{
ArrayList remove = new ArrayList();
foreach ( CountAndTimeStamp time in t.Values )
{
if ( time.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.Now )
remove.Add( time );
}

for (int i=0;i<remove.Count;++i)
t.Remove( remove[i] );
}

//decay our kills
if ( m_ShortTermElapse < this.GameTime )
{
m_ShortTermElapse += TimeSpan.FromHours( 8 );
if ( ShortTermMurders > 0 )
--ShortTermMurders;
}

if ( m_LongTermElapse < this.GameTime )
{
m_LongTermElapse += TimeSpan.FromHours( 40 );
if ( Kills > 0 )
--Kills;
}

CheckAtrophies( this );

base.Serialize( writer );

writer.Write((int)28); // version

if(TamingBOBFilter != null)
{
writer.Write(true);
m_TamingBOBFilter.Serialize(writer);
} else
{
writer.Write(false);
}

writer.Write(m_Bioenginer);

writer.Write(NextTamingBulkOrder);

if( m_AcquiredRecipes == null )
{
writer.Write( (int)0 );
}
else
{
writer.Write( m_AcquiredRecipes.Count );

foreach( KeyValuePair<int, bool> kvp in m_AcquiredRecipes )
{
writer.Write( kvp.Key );
writer.Write( kvp.Value );
}
}

writer.WriteDeltaTime( m_LastHonorLoss );

///////////////////Government Edits//////////////////////
//writer.Write((int)26); // version
writer.Write(m_City);

writer.Write(m_CityTitle);

writer.Write(m_ShowCityTitle);

writer.Write(m_OwesBackTaxes);

writer.Write(m_BackTaxesAmount);
////////////////////////end////////////////////////


writer.WriteDeltaTime( m_LastHonorLoss );

ChampionTitleInfo.Serialize( writer, m_ChampionTitles );

writer.Write( m_LastValorLoss );
writer.WriteEncodedInt( m_ToTItemsTurnedIn );
writer.Write( m_ToTTotalMonsterFame ); //This ain't going to be a small #.

writer.WriteEncodedInt( m_AllianceMessageHue );
writer.WriteEncodedInt( m_GuildMessageHue );

writer.WriteEncodedInt( m_GuildRank.Rank );
writer.Write( m_LastOnline );

writer.WriteEncodedInt( (int) m_SolenFriendship );

QuestSerializer.Serialize( m_Quest, writer );

if ( m_DoneQuests == null )
{
writer.WriteEncodedInt( (int) 0 );
}
else
{
writer.WriteEncodedInt( (int) m_DoneQuests.Count );

for ( int i = 0; i < m_DoneQuests.Count; ++i )
{
QuestRestartInfo restartInfo = m_DoneQuests[i];

QuestSerializer.Write( (Type) restartInfo.QuestType, QuestSystem.QuestTypes, writer );
writer.Write( (DateTime) restartInfo.RestartTime );
}
}

writer.WriteEncodedInt( (int) m_Profession );

writer.WriteDeltaTime( m_LastCompassionLoss );

writer.WriteEncodedInt( m_CompassionGains );

if ( m_CompassionGains > 0 )
writer.WriteDeltaTime( m_NextCompassionDay );

m_BOBFilter.Serialize( writer );

bool useMods = ( m_HairModID != -1 || m_BeardModID != -1 );

writer.Write( useMods );

if ( useMods )
{
writer.Write( (int) m_HairModID );
writer.Write( (int) m_HairModHue );
writer.Write( (int) m_BeardModID );
writer.Write( (int) m_BeardModHue );
}

writer.Write( SavagePaintExpiration );

writer.Write( (int) m_NpcGuild );
writer.Write( (DateTime) m_NpcGuildJoinTime );
writer.Write( (TimeSpan) m_NpcGuildGameTime );

writer.Write( m_PermaFlags, true );

writer.Write( NextTailorBulkOrder );

writer.Write( NextSmithBulkOrder );

writer.WriteDeltaTime( m_LastJusticeLoss );
writer.Write( m_JusticeProtectors, true );

writer.WriteDeltaTime( m_LastSacrificeGain );
writer.WriteDeltaTime( m_LastSacrificeLoss );
writer.Write( m_AvailableResurrects );

writer.Write( (int) m_Flags );

writer.Write( m_LongTermElapse );
writer.Write( m_ShortTermElapse );
writer.Write( this.GameTime );
}



public static void CheckAtrophies( Mobile m )
{
SacrificeVirtue.CheckAtrophy( m );
JusticeVirtue.CheckAtrophy( m );
CompassionVirtue.CheckAtrophy( m );
ValorVirtue.CheckAtrophy( m );
HonorVirtue.CheckAtrophy( m );

if( m is PlayerMobile )
ChampionTitleInfo.CheckAtrophy( (PlayerMobile)m );
}

public void ResetKillTime()
{
m_ShortTermElapse = this.GameTime + TimeSpan.FromHours( 8 );
m_LongTermElapse = this.GameTime + TimeSpan.FromHours( 40 );
}

[CommandProperty( AccessLevel.GameMaster )]
public DateTime SessionStart
{
get{ return m_SessionStart; }
}

[CommandProperty( AccessLevel.GameMaster )]
public TimeSpan GameTime
{
get
{
if ( NetState != null )
return m_GameTime + (DateTime.Now - m_SessionStart);
else
return m_GameTime;
}
}


I think i found them theres also a place that has player mobile's in it , should i be looking at that also? since it wont save a char.

Crystal Jem- 07-16-2006
CODE
if( Core.ML && this.Race == Race.Elf && type == ResistanceType.Energy )
   max += 5; //Intended to go after the 60 max from curse

  return max;
 }


Shouldn't there be return max amount here?

Crystal Jem- 07-16-2006
CODE
  #region FS:ATS Edits
       private Engines.BulkOrders.TamingBOBFilter m_TamingBOBFilter;
       #endregion

       #region FS:ATS Edits
       public Engines.BulkOrders.TamingBOBFilter TamingBOBFilter
       {
           get { return m_TamingBOBFilter; }
       }
       #endregion


shouldn't there just be one?

Crystal Jem- 07-16-2006
Would it be better to reinstall and do a new merge for the playersmobile.cs?

ArteGordon- 07-16-2006
In your Deserialize you need to change this

CODE

             case 28:
                  {
                      m_TamingBOBFilter = new Engines.BulkOrders.TamingBOBFilter(reader);
                      goto case 27;
                  }


to this

CODE

             case 28:
                  {
                      if(reader.ReadBool())
                      {
                        m_TamingBOBFilter = new Engines.BulkOrders.TamingBOBFilter(reader);
                      }
                      goto case 27;
                  }


Crystal Jem- 07-16-2006
QUOTE (ArteGordon @ July 16, 2006 04:46 pm)
In your Deserialize you need to change this

CODE

             case 28:
                  {
                      m_TamingBOBFilter = new Engines.BulkOrders.TamingBOBFilter(reader);
                      goto case 27;
                  }


to this

CODE

             case 28:
                  {
                      if(reader.ReadBool())
                      {
                        m_TamingBOBFilter = new Engines.BulkOrders.TamingBOBFilter(reader);
                      }
                      goto case 27;
                  }


theres more wrong it's still asking for the playermobiles to be deleated on start up.

any sujestions?

1. reinstall from runuo 2.0 ?
2. take out the avanced animals taming and goverment and reinstall both with redoing the playermobile from scratch again.
3. just redo the player mobile.cs
4. keep trying with what we already have.

ArteGordon- 07-16-2006
I would suggest going back to a previous save that was made before you added the custom scripts, and a fresh system before you added the customs.
Then I would suggest adding them one at a time instead of trying to do both at once.
And make sure that after installing each one that you are able to load old and new saves. That will tell you whether you did the Ser/Deser correctly.

Theoderic- 07-16-2006
I have to same problem not long ago.. Your problem is in Serialization and deserialization on this script..

What is resolution?.. Easy.. You copy in next script ser/deser and paste this (bad des/ser) script .. and restart server. i maybe that is problem.

Crystal Jem- 07-16-2006
QUOTE (ArteGordon @ July 16, 2006 06:48 pm)
I would suggest going back to a previous save that was made before you added the custom scripts, and a fresh system before you added the customs.
Then I would suggest adding them one at a time instead of trying to do both at once.
And make sure that after installing each one that you are able to load old and new saves. That will tell you whether you did the Ser/Deser correctly.

i didn't add then at once i added the advanced taming frist then the goverment one , but they both did changed to the playermobile.cs and puttign them in seprate again wont change that sad.gif.
I'm trying a fresh merge i just got done doing. this time it will me all my falt.

Here it is but i don't know if you'll be able to see the difrences.

CODE
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Misc;
using Server.Items;
using Server.Gumps;
using Server.Multis;
using Server.Engines.Help;
using Server.ContextMenus;
using Server.Network;
using Server.Spells;
using Server.Spells.Fifth;
using Server.Spells.Sixth;
using Server.Spells.Seventh;
using Server.Spells.Necromancy;
using Server.Spells.Ninjitsu;
using Server.Spells.Bushido;
using Server.Targeting;
using Server.Engines.Quests;
using Server.Factions;
using Server.Regions;
using Server.Accounting;
using Server.Engines.CannedEvil;
using Server.Engines.Craft;

namespace Server.Mobiles
{
#region Enums
[Flags]
public enum PlayerFlag // First 16 bits are reserved for default-distro use, start custom flags at 0x00010000
{
 None    = 0x00000000,
 Glassblowing  = 0x00000001,
 Masonry    = 0x00000002,
 SandMining   = 0x00000004,
 StoneMining   = 0x00000008,
 ToggleMiningStone = 0x00000010,
 KarmaLocked   = 0x00000020,
 AutoRenewInsurance = 0x00000040,
 UseOwnFilter  = 0x00000080,
 PublicMyRunUO  = 0x00000100,
 PagingSquelched  = 0x00000200,
 Young    = 0x00000400,
 AcceptGuildInvites = 0x00000800,
 DisplayChampionTitle= 0x00001000
}

public enum NpcGuild
{
 None,
 MagesGuild,
 WarriorsGuild,
 ThievesGuild,
 RangersGuild,
 HealersGuild,
 MinersGuild,
 MerchantsGuild,
 TinkersGuild,
 TailorsGuild,
 FishermensGuild,
 BardsGuild,
 BlacksmithsGuild
}

public enum SolenFriendship
{
 None,
 Red,
 Black
}
#endregion

public class PlayerMobile : Mobile, IHonorTarget
{
 #region FS:ATS Edtis
 private DateTime m_NextTamingBulkOrder;
 private bool m_Bioenginer;

 [CommandProperty( AccessLevel.GameMaster )]
 public TimeSpan NextTamingBulkOrder
 {
  get
  {
   TimeSpan ts = m_NextTamingBulkOrder - DateTime.Now;

   if ( ts < TimeSpan.Zero )
    ts = TimeSpan.Zero;

   return ts;
  }
  set
  {
   try{ m_NextTamingBulkOrder = DateTime.Now + value; }
   catch{}
  }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool Bioenginer
 {
  get{ return m_Bioenginer; }
  set{ m_Bioenginer = value; }
 }
 #endregion
 
 private class CountAndTimeStamp
 {
  private int m_Count;
  private DateTime m_Stamp;

  public CountAndTimeStamp()
  {
  }

  public DateTime TimeStamp { get{ return m_Stamp; } }
  public int Count
  {
   get { return m_Count; }
   set { m_Count = value; m_Stamp = DateTime.Now; }
  }
 }

 private DesignContext m_DesignContext;

 private NpcGuild m_NpcGuild;
 private DateTime m_NpcGuildJoinTime;
 private TimeSpan m_NpcGuildGameTime;
 private PlayerFlag m_Flags;
 private int m_StepsTaken;
 private int m_Profession;


// Start FSGov Edits

 private CityManagementStone m_City;
 private string m_CityTitle;
 private bool m_ShowCityTitle;
 private bool m_OwesBackTaxes;
 private int m_BackTaxesAmount;

 public bool Hallucinating;

 [CommandProperty( AccessLevel.GameMaster )]
 public bool IsHallucinating
 {
  get{ return Hallucinating; }
  set{ Hallucinating = value; InvalidateProperties(); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public CityManagementStone City
 {
  get{ return m_City; }
  set{ m_City = value; InvalidateProperties(); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public string CityTitle
 {
  get{ return m_CityTitle; }
  set{ m_CityTitle = value; InvalidateProperties(); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool ShowCityTitle
 {
  get{ return m_ShowCityTitle; }
  set{ m_ShowCityTitle = value; InvalidateProperties(); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool OwesBackTaxes
 {
  get{ return m_OwesBackTaxes; }
  set{ m_OwesBackTaxes = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public int BackTaxesAmount
 {
  get{ return m_BackTaxesAmount; }
  set{ m_BackTaxesAmount = value; }
 }

 //End FSGov Edits



 private DateTime m_LastOnline;
 private Server.Guilds.RankDefinition m_GuildRank;

 private int m_GuildMessageHue, m_AllianceMessageHue;

 [CommandProperty( AccessLevel.Counselor, AccessLevel.Owner )]
 public new Account Account
 {
  get { return base.Account as Account; }
  set { base.Account = value; }
 }

 #region Getters & Setters
 public Server.Guilds.RankDefinition GuildRank
 {
  get
  {
   if( this.AccessLevel >= AccessLevel.GameMaster )
    return Server.Guilds.RankDefinition.Leader;
   else
    return m_GuildRank;
  }
  set{ m_GuildRank = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public int GuildMessageHue
 {
  get{ return m_GuildMessageHue; }
  set{ m_GuildMessageHue = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public int AllianceMessageHue
 {
  get { return m_AllianceMessageHue; }
  set { m_AllianceMessageHue = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public int Profession
 {
  get{ return m_Profession; }
  set{ m_Profession = value; }
 }

 public int StepsTaken
 {
  get{ return m_StepsTaken; }
  set{ m_StepsTaken = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public NpcGuild NpcGuild
 {
  get{ return m_NpcGuild; }
  set{ m_NpcGuild = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public DateTime NpcGuildJoinTime
 {
  get{ return m_NpcGuildJoinTime; }
  set{ m_NpcGuildJoinTime = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public DateTime LastOnline
 {
  get{ return m_LastOnline; }
  set{ m_LastOnline = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public TimeSpan NpcGuildGameTime
 {
  get{ return m_NpcGuildGameTime; }
  set{ m_NpcGuildGameTime = value; }
 }

 private int m_ToTItemsTurnedIn;

 [CommandProperty( AccessLevel.GameMaster )]
 public int ToTItemsTurnedIn
 {
  get { return m_ToTItemsTurnedIn; }
  set { m_ToTItemsTurnedIn = value; }
 }

 private int m_ToTTotalMonsterFame;

 [CommandProperty( AccessLevel.GameMaster )]
 public int ToTTotalMonsterFame
 {
  get { return m_ToTTotalMonsterFame; }
  set { m_ToTTotalMonsterFame = value; }
 }

 #endregion

 #region PlayerFlags
 public PlayerFlag Flags
 {
  get{ return m_Flags; }
  set{ m_Flags = value; }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool PagingSquelched
 {
  get{ return GetFlag( PlayerFlag.PagingSquelched ); }
  set{ SetFlag( PlayerFlag.PagingSquelched, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool Glassblowing
 {
  get{ return GetFlag( PlayerFlag.Glassblowing ); }
  set{ SetFlag( PlayerFlag.Glassblowing, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool Masonry
 {
  get{ return GetFlag( PlayerFlag.Masonry ); }
  set{ SetFlag( PlayerFlag.Masonry, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool SandMining
 {
  get{ return GetFlag( PlayerFlag.SandMining ); }
  set{ SetFlag( PlayerFlag.SandMining, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool StoneMining
 {
  get{ return GetFlag( PlayerFlag.StoneMining ); }
  set{ SetFlag( PlayerFlag.StoneMining, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool ToggleMiningStone
 {
  get{ return GetFlag( PlayerFlag.ToggleMiningStone ); }
  set{ SetFlag( PlayerFlag.ToggleMiningStone, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool KarmaLocked
 {
  get{ return GetFlag( PlayerFlag.KarmaLocked ); }
  set{ SetFlag( PlayerFlag.KarmaLocked, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool AutoRenewInsurance
 {
  get{ return GetFlag( PlayerFlag.AutoRenewInsurance ); }
  set{ SetFlag( PlayerFlag.AutoRenewInsurance, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool UseOwnFilter
 {
  get{ return GetFlag( PlayerFlag.UseOwnFilter ); }
  set{ SetFlag( PlayerFlag.UseOwnFilter, value ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool PublicMyRunUO
 {
  get{ return GetFlag( PlayerFlag.PublicMyRunUO ); }
  set{ SetFlag( PlayerFlag.PublicMyRunUO, value ); InvalidateMyRunUO(); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public bool AcceptGuildInvites
 {
  get{ return GetFlag( PlayerFlag.AcceptGuildInvites ); }
  set{ SetFlag( PlayerFlag.AcceptGuildInvites, value ); }
 }
 #endregion


 public static Direction GetDirection4( Point3D from, Point3D to )
 {
  int dx = from.X - to.X;
  int dy = from.Y - to.Y;

  int rx = dx - dy;
  int ry = dx + dy;

  Direction ret;

  if ( rx >= 0 && ry >= 0 )
   ret = Direction.West;
  else if ( rx >= 0 && ry < 0 )
   ret = Direction.South;
  else if ( rx < 0 && ry < 0 )
   ret = Direction.East;
  else
   ret = Direction.North;

  return ret;
 }

 public override bool OnDroppedItemToWorld( Item item, Point3D location )
 {
  if ( !base.OnDroppedItemToWorld( item, location ) )
   return false;

  BounceInfo bi = item.GetBounce();

  if ( bi != null )
  {
   Type type = item.GetType();

   if ( type.IsDefined( typeof( FurnitureAttribute ), true ) || type.IsDefined( typeof( DynamicFlipingAttribute ), true ) )
   {
    object[] objs = type.GetCustomAttributes( typeof( FlipableAttribute ), true );

    if ( objs != null && objs.Length > 0 )
    {
     FlipableAttribute fp = objs[0] as FlipableAttribute;

     if ( fp != null )
     {
      int[] itemIDs = fp.ItemIDs;

      Point3D oldWorldLoc = bi.m_WorldLoc;
      Point3D newWorldLoc = location;

      if ( oldWorldLoc.X != newWorldLoc.X || oldWorldLoc.Y != newWorldLoc.Y )
      {
       Direction dir = GetDirection4( oldWorldLoc, newWorldLoc );

       if ( itemIDs.Length == 2 )
       {
        switch ( dir )
        {
         case Direction.North:
         case Direction.South: item.ItemID = itemIDs[0]; break;
         case Direction.East:
         case Direction.West: item.ItemID = itemIDs[1]; break;
        }
       }
       else if ( itemIDs.Length == 4 )
       {
        switch ( dir )
        {
         case Direction.South: item.ItemID = itemIDs[0]; break;
         case Direction.East: item.ItemID = itemIDs[1]; break;
         case Direction.North: item.ItemID = itemIDs[2]; break;
         case Direction.West: item.ItemID = itemIDs[3]; break;
        }
       }
      }
     }
    }
   }
  }

  return true;
 }

 public bool GetFlag( PlayerFlag flag )
 {
  return ( (m_Flags & flag) != 0 );
 }

 public void SetFlag( PlayerFlag flag, bool value )
 {
  if ( value )
   m_Flags |= flag;
  else
   m_Flags &= ~flag;
 }

 public DesignContext DesignContext
 {
  get{ return m_DesignContext; }
  set{ m_DesignContext = value; }
 }

 public static void Initialize()
 {
  if ( FastwalkPrevention )
  {
   PacketHandler ph = PacketHandlers.GetHandler( 0x02 );

   ph.ThrottleCallback = new ThrottlePacketCallback( MovementThrottle_Callback );
  }

  EventSink.Login += new LoginEventHandler( OnLogin );
  EventSink.Logout += new LogoutEventHandler( OnLogout );
  EventSink.Connected += new ConnectedEventHandler( EventSink_Connected );
  EventSink.Disconnected += new DisconnectedEventHandler( EventSink_Disconnected );
 }

 public override void OnSkillInvalidated( Skill skill )
 {
  if ( Core.AOS && skill.SkillName == SkillName.MagicResist )
   UpdateResistances();
 }

 public override int GetMaxResistance( ResistanceType type )
 {
  int max = base.GetMaxResistance( type );

  if ( type != ResistanceType.Physical && 60 < max && Spells.Fourth.CurseSpell.UnderEffect( this ) )
   max = 60;

  if( Core.ML && this.Race == Race.Elf && type == ResistanceType.Energy )
   max += 5; //Intended to go after the 60 max from curse

  return max;
 }

 protected override void OnRaceChange( Race oldRace )
 {
  ValidateEquipment();
  UpdateResistances();
 }

 public override int MaxWeight { get { return (((Core.ML && this.Race == Race.Human) ? 100 : 40) + (int)(3.5 * this.Str)); } }

 private int m_LastGlobalLight = -1, m_LastPersonalLight = -1;

 public override void OnNetStateChanged()
 {
  m_LastGlobalLight = -1;
  m_LastPersonalLight = -1;
 }

 public override void ComputeBaseLightLevels( out int global, out int personal )
 {
  global = LightCycle.ComputeLevelFor( this );

  if ( this.LightLevel < 21 && AosAttributes.GetValue( this, AosAttribute.NightSight ) > 0 )
   personal = 21;
  else
   personal = this.LightLevel;
 }

 public override void CheckLightLevels( bool forceResend )
 {
  NetState ns = this.NetState;

  if ( ns == null )
   return;

  int global, personal;

  ComputeLightLevels( out global, out personal );

  if ( !forceResend )
   forceResend = ( global != m_LastGlobalLight || personal != m_LastPersonalLight );

  if ( !forceResend )
   return;

  m_LastGlobalLight = global;
  m_LastPersonalLight = personal;

  ns.Send( GlobalLightLevel.Instantiate( global ) );
  ns.Send( new PersonalLightLevel( this, personal ) );
 }

 public override int GetMinResistance( ResistanceType type )
 {
  int magicResist = (int)(Skills[SkillName.MagicResist].Value * 10);
  int min = int.MinValue;

  if ( magicResist >= 1000 )
   min = 40 + ((magicResist - 1000) / 50);
  else if ( magicResist >= 400 )
   min = (magicResist - 400) / 15;

  if ( min > MaxPlayerResistance )
   min = MaxPlayerResistance;

  int baseMin = base.GetMinResistance( type );

  if ( min < baseMin )
   min = baseMin;

  return min;
 }

 private static void OnLogin( LoginEventArgs e )
 {
  Mobile from = e.Mobile;

  CheckAtrophies( from );

  if ( AccountHandler.LockdownLevel > AccessLevel.Player )
  {
   string notice;

   Accounting.Account acct = from.Account as Accounting.Account;

   if ( acct == null || !acct.HasAccess( from.NetState ) )
   {
    if ( from.AccessLevel == AccessLevel.Player )
     notice = "The server is currently under lockdown. No players are allowed to log in at this time.";
    else
     notice = "The server is currently under lockdown. You do not have sufficient access level to connect.";

    Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerStateCallback( Disconnect ), from );
   }
   else if ( from.AccessLevel >= AccessLevel.Administrator )
   {
    notice = "The server is currently under lockdown. As you are an administrator, you may change this from the [Admin gump.";
   }
   else
   {
    notice = "The server is currently under lockdown. You have sufficient access level to connect.";
   }

   from.SendGump( new NoticeGump( 1060637, 30720, notice, 0xFFC000, 300, 140, null, null ) );
  }
 }

 private bool m_NoDeltaRecursion;

 public void ValidateEquipment()
 {
  if ( m_NoDeltaRecursion || Map == null || Map == Map.Internal )
   return;

  if ( this.Items == null )
   return;

  m_NoDeltaRecursion = true;
  Timer.DelayCall( TimeSpan.Zero, new TimerCallback( ValidateEquipment_Sandbox ) );
 }

 private void ValidateEquipment_Sandbox()
 {
  try
  {
   if ( Map == null || Map == Map.Internal )
    return;

   List<Item> items = this.Items;

   if ( items == null )
    return;

   bool moved = false;

   int str = this.Str;
   int dex = this.Dex;
   int intel = this.Int;

   #region Factions
   int factionItemCount = 0;
   #endregion

   Mobile from = this;

   #region Ethics
   Ethics.Ethic ethic = Ethics.Ethic.Find( from );
   #endregion

   for ( int i = items.Count - 1; i >= 0; --i )
   {
    if ( i >= items.Count )
     continue;

    Item item = items[i];

    #region Ethics
    if ( ( item.SavedFlags & 0x100 ) != 0 )
    {
     if ( item.Hue != Ethics.Ethic.Hero.Definition.PrimaryHue )
     {
      item.SavedFlags &= ~0x100;
     }
     else if ( ethic != Ethics.Ethic.Hero )
     {
      from.AddToBackpack( item );
      moved = true;
      continue;
     }
    }
    else if ( ( item.SavedFlags & 0x200 ) != 0 )
    {
     if ( item.Hue != Ethics.Ethic.Evil.Definition.PrimaryHue )
     {
      item.SavedFlags &= ~0x200;
     }
     else if ( ethic != Ethics.Ethic.Evil )
     {
      from.AddToBackpack( item );
      moved = true;
      continue;
     }
    }
    #endregion

    if ( item is BaseWeapon )
    {
     BaseWeapon weapon = (BaseWeapon)item;

     bool drop = false;

     if( dex < weapon.DexRequirement )
      drop = true;
     else if( str < AOS.Scale( weapon.StrRequirement, 100 - weapon.GetLowerStatReq() ) )
      drop = true;
     else if( intel < weapon.IntRequirement )
      drop = true;
     else if( weapon.RequiredRace != null && weapon.RequiredRace != this.Race )
      drop = true;

     if ( drop )
     {
      string name = weapon.Name;

      if ( name == null )
       name = String.Format( "#{0}", weapon.LabelNumber );

      from.SendLocalizedMessage( 1062001, name ); // You can no longer wield your ~1_WEAPON~
      from.AddToBackpack( weapon );
      moved = true;
     }
    }
    else if ( item is BaseArmor )
    {
     BaseArmor armor = (BaseArmor)item;

     bool drop = false;

     if ( !armor.AllowMaleWearer && !from.Female && from.AccessLevel < AccessLevel.GameMaster )
     {
      drop = true;
     }
     else if ( !armor.AllowFemaleWearer && from.Female && from.AccessLevel < AccessLevel.GameMaster )
     {
      drop = true;
     }
     else if( armor.RequiredRace != null && armor.RequiredRace != this.Race )
     {
      drop = true;
     }
     else
     {
      int strBonus = armor.ComputeStatBonus( StatType.Str ), strReq = armor.ComputeStatReq( StatType.Str );
      int dexBonus = armor.ComputeStatBonus( StatType.Dex ), dexReq = armor.ComputeStatReq( StatType.Dex );
      int intBonus = armor.ComputeStatBonus( StatType.Int ), intReq = armor.ComputeStatReq( StatType.Int );

      if( dex < dexReq || (dex + dexBonus) < 1 )
       drop = true;
      else if( str < strReq || (str + strBonus) < 1 )
       drop = true;
      else if( intel < intReq || (intel + intBonus) < 1 )
       drop = true;
     }

     if ( drop )
     {
      string name = armor.Name;

      if ( name == null )
       name = String.Format( "#{0}", armor.LabelNumber );

      if ( armor is BaseShield )
       from.SendLocalizedMessage( 1062003, name ); // You can no longer equip your ~1_SHIELD~
      else
       from.SendLocalizedMessage( 1062002, name ); // You can no longer wear your ~1_ARMOR~

      from.AddToBackpack( armor );
      moved = true;
     }
    }
    else if ( item is BaseClothing )
    {
     BaseClothing clothing = (BaseClothing)item;

     bool drop = false;

     if ( !clothing.AllowMaleWearer && !from.Female && from.AccessLevel < AccessLevel.GameMaster )
     {
      drop = true;
     }
     else if ( !clothing.AllowFemaleWearer && from.Female && from.AccessLevel < AccessLevel.GameMaster )
     {
      drop = true;
     }
     else if( clothing.RequiredRace != null && clothing.RequiredRace != this.Race )
     {
      drop = true;
     }
     else
     {
      int strBonus = clothing.ComputeStatBonus( StatType.Str );
      int strReq = clothing.ComputeStatReq( StatType.Str );

      if( str < strReq || (str + strBonus) < 1 )
       drop = true;
     }

     if ( drop )
     {
      string name = clothing.Name;

      if ( name == null )
       name = String.Format( "#{0}", clothing.LabelNumber );

      from.SendLocalizedMessage( 1062002, name ); // You can no longer wear your ~1_ARMOR~

      from.AddToBackpack( clothing );
      moved = true;
     }
    }

    FactionItem factionItem = FactionItem.Find( item );

    if ( factionItem != null )
    {
     bool drop = false;

     Faction ourFaction = Faction.Find( this );

     if ( ourFaction == null || ourFaction != factionItem.Faction )
      drop = true;
     else if ( ++factionItemCount > FactionItem.GetMaxWearables( this ) )
      drop = true;

     if ( drop )
     {
      from.AddToBackpack( item );
      moved = true;
     }
    }
   }

   if ( moved )
    from.SendLocalizedMessage( 500647 ); // Some equipment has been moved to your backpack.
  }
  catch ( Exception e )
  {
   Console.WriteLine( e );
  }
  finally
  {
   m_NoDeltaRecursion = false;
  }
 }

 public override void Delta( MobileDelta flag )
 {
  base.Delta( flag );

  if ( (flag & MobileDelta.Stat) != 0 )
   ValidateEquipment();

  if ( (flag & (MobileDelta.Name | MobileDelta.Hue)) != 0 )
   InvalidateMyRunUO();
 }

 private static void Disconnect( object state )
 {
  NetState ns = ((Mobile)state).NetState;

  if ( ns != null )
   ns.Dispose();
 }

 private static void OnLogout( LogoutEventArgs e )
 {
 }

 private static void EventSink_Connected( ConnectedEventArgs e )
 {
  PlayerMobile pm = e.Mobile as PlayerMobile;

  if ( pm != null )
  {
   pm.m_SessionStart = DateTime.Now;

   if ( pm.m_Quest != null )
    pm.m_Quest.StartTimer();

   pm.BedrollLogout = false;
   pm.LastOnline = DateTime.Now;
  }

  Timer.DelayCall( TimeSpan.Zero, new TimerStateCallback( ClearSpecialMovesCallback ), e.Mobile );
 }

 private static void ClearSpecialMovesCallback( object state )
 {
  Mobile from = (Mobile)state;

  SpecialMove.ClearAllMoves( from );
 }

 private static void EventSink_Disconnected( DisconnectedEventArgs e )
 {
  Mobile from = e.Mobile;
  DesignContext context = DesignContext.Find( from );

  if ( context != null )
  {
   /* Client disconnected
    *  - Remove design context
    *  - Eject all from house
    *  - Restore relocated entities
    */

   // Remove design context
   DesignContext.Remove( from );

   // Eject all from house
   from.RevealingAction();

   foreach ( Item item in context.Foundation.GetItems() )
    item.Location = context.Foundation.BanLocation;

   foreach ( Mobile mobile in context.Foundation.GetMobiles() )
    mobile.Location = context.Foundation.BanLocation;

   // Restore relocated entities
   context.Foundation.RestoreRelocatedEntities();
  }

  PlayerMobile pm = e.Mobile as PlayerMobile;

  if ( pm != null )
  {
   pm.m_GameTime += (DateTime.Now - pm.m_SessionStart);

   if ( pm.m_Quest != null )
    pm.m_Quest.StopTimer();

   pm.m_SpeechLog = null;
   pm.LastOnline = DateTime.Now;
  }
 }

 public override void RevealingAction()
 {
  if ( m_DesignContext != null )
   return;

  Spells.Sixth.InvisibilitySpell.RemoveTimer( this );

  base.RevealingAction();
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public override bool Hidden
 {
  get
  {
   return base.Hidden;
  }
  set
  {
   base.Hidden = value;

   RemoveBuff( BuffIcon.Invisibility ); //Always remove, default to the hiding icon EXCEPT in the invis spell where it's explicitly set

   if( !Hidden )
   {
    RemoveBuff( BuffIcon.HidingAndOrStealth );
   }
   else// if( !InvisibilitySpell.HasTimer( this ) )
   {
    BuffInfo.AddBuff( this, new BuffInfo( BuffIcon.HidingAndOrStealth, 1075655 ) ); //Hidden/Stealthing & You Are Hidden
   }
  }
 }

 public override void OnSubItemAdded( Item item )
 {
  if ( AccessLevel < AccessLevel.GameMaster && item.IsChildOf( this.Backpack ) )
  {
   int maxWeight = WeightOverloading.GetMaxWeight( this );
   int curWeight = Mobile.BodyWeight + this.TotalWeight;

   if ( curWeight > maxWeight )
    this.SendLocalizedMessage( 1019035, true, String.Format( " : {0} / {1}", curWeight, maxWeight ) );
  }
 }

 public override bool CanBeHarmful( Mobile target, bool message, bool ignoreOurBlessedness )
 {
  if ( m_DesignContext != null || (target is PlayerMobile && ((PlayerMobile)target).m_DesignContext != null) )
   return false;

  if ( (target is BaseVendor && ((BaseVendor)target).IsInvulnerable) || target is PlayerVendor || target is TownCrier )
  {
   if ( message )
   {
    if ( target.Title == null )
     SendMessage( "{0} the vendor cannot be harmed.", target.Name );
    else
     SendMessage( "{0} {1} cannot be harmed.", target.Name, target.Title );
   }

   return false;
  }

  return base.CanBeHarmful( target, message, ignoreOurBlessedness );
 }

 public override bool CanBeBeneficial( Mobile target, bool message, bool allowDead )
 {
  if ( m_DesignContext != null || (target is PlayerMobile && ((PlayerMobile)target).m_DesignContext != null) )
   return false;

  return base.CanBeBeneficial( target, message, allowDead );
 }

 public override bool CheckContextMenuDisplay( IEntity target )
 {
  return ( m_DesignContext == null );
 }

 public override void OnItemAdded( Item item )
 {
  base.OnItemAdded( item );

  if ( item is BaseArmor || item is BaseWeapon )
  {
   Hits=Hits; Stam=Stam; Mana=Mana;
  }

  if ( this.NetState != null )
   CheckLightLevels( false );

  InvalidateMyRunUO();
 }

 public override void OnItemRemoved( Item item )
 {
  base.OnItemRemoved( item );

  if ( item is BaseArmor || item is BaseWeapon )
  {
   Hits=Hits; Stam=Stam; Mana=Mana;
  }

  if ( this.NetState != null )
   CheckLightLevels( false );

  InvalidateMyRunUO();
 }

 public override double ArmorRating
 {
  get
  {
   //BaseArmor ar;
   double rating = 0.0;

   AddArmorRating( ref rating, NeckArmor );
   AddArmorRating( ref rating, HandArmor );
   AddArmorRating( ref rating, HeadArmor );
   AddArmorRating( ref rating, ArmsArmor );
   AddArmorRating( ref rating, LegsArmor );
   AddArmorRating( ref rating, ChestArmor );
   AddArmorRating( ref rating, ShieldArmor );

   return VirtualArmor + VirtualArmorMod + rating;
  }
 }

 private void AddArmorRating( ref double rating, Item armor )
 {
  BaseArmor ar = armor as BaseArmor;

  if( ar != null && ( !Core.AOS || ar.ArmorAttributes.MageArmor == 0 ))
   rating += ar.ArmorRatingScaled;
 }

 #region [Stats]Max
 [CommandProperty( AccessLevel.GameMaster )]
 public override int HitsMax
 {
  get
  {
   int strBase;
   int strOffs = GetStatOffset( StatType.Str );

   if ( Core.AOS )
   {
    strBase = this.Str; //this.Str already includes GetStatOffset/str
    strOffs = AosAttributes.GetValue( this, AosAttribute.BonusHits );

    if ( AnimalForm.UnderTransformation( this, typeof( BakeKitsune ) ) || AnimalForm.UnderTransformation( this, typeof( GreyWolf ) ) )
     strOffs += 20;
   }
   else
   {
    strBase = this.RawStr;
   }

   return (strBase / 2) + 50 + strOffs;
  }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public override int StamMax
 {
  get{ return base.StamMax + AosAttributes.GetValue( this, AosAttribute.BonusStam ); }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public override int ManaMax
 {
  get{ return base.ManaMax + AosAttributes.GetValue( this, AosAttribute.BonusMana ) + ((Core.ML && Race == Race.Elf) ? 20 : 0); }
 }
 #endregion

 #region Stat Getters/Setters

 [CommandProperty( AccessLevel.GameMaster )]
 public override int Str
 {
  get
  {
   if( Core.ML && this.AccessLevel == AccessLevel.Player )
    return Math.Min( base.Str, 150 );

   return base.Str;
  }
  set
  {
   base.Str = value;
  }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public override int Int
 {
  get
  {
   if( Core.ML && this.AccessLevel == AccessLevel.Player )
    return Math.Min( base.Int, 150 );

   return base.Int;
  }
  set
  {
   base.Int = value;
  }
 }

 [CommandProperty( AccessLevel.GameMaster )]
 public override int Dex
 {
  get
  {
   if( Core.ML && this.AccessLevel == AccessLevel.Player )
    return Math.Min( base.Dex, 150 );

   return base.Dex;
  }
  set
  {
   base.Dex = value;
  }
 }

 #endregion

 public override bool Move( Direction d )
 {
  NetState ns = this.NetState;

  if ( ns != null )
  {
   List<Gump> gumps = ns.Gumps;

   for ( int i = 0; i < gumps.Count; ++i )
   {
    if ( gumps[i] is ResurrectGump )
    {
     if ( Alive )
     {
      CloseGump( typeof( ResurrectGump ) );
     }
     else
     {
      SendLocalizedMessage( 500111 ); // You are frozen and cannot move.
      return false;
     }
    }
   }
  }

  TimeSpan speed = ComputeMovementSpeed( d );

  bool res;

  if ( !Alive )
   Server.Movement.MovementImpl.IgnoreMovableImpassables = true;

  res = base.Move( d );

  Server.Movement.MovementImpl.IgnoreMovableImpassables = false;

  if ( !res )
   return false;

  m_NextMovementTime += speed;

  return true;
 }

 public override bool CheckMovement( Direction d, out int newZ )
 {
  DesignContext context = m_DesignContext;

  if ( context == null )
   return base.CheckMovement( d, out newZ );

  HouseFoundation foundation = context.Foundation;

  newZ = foundation.Z + HouseFoundation.GetLevelZ( context.Level, context.Foundation );

  int newX = this.X, newY = this.Y;
  Movement.Movement.Offset( d, ref newX, ref newY );

  int startX = foundation.X + foundation.Components.Min.X + 1;
  int startY = foundation.Y + foundation.Components.Min.Y + 1;
  int endX = startX + foundation.Components.Width - 1;
  int endY = startY + foundation.Components.Height - 2;

  return ( newX >= startX && newY >= startY && newX < endX && newY < endY && Map == foundation.Map );
 }

 public override bool AllowItemUse( Item item )
 {
  return DesignContext.Check( this );
 }

 public SkillName[] AnimalFormRestrictedSkills{ get{ return m_AnimalFormRestrictedSkills; } }

 private SkillName[] m_AnimalFormRestrictedSkills = new SkillName[]
 {
  SkillName.ArmsLore, SkillName.Begging, SkillName.Discordance, SkillName.Forensics,
  SkillName.Inscribe, SkillName.ItemID, SkillName.Meditation, SkillName.Peacemaking,
  SkillName.Provocation, SkillName.RemoveTrap, SkillName.SpiritSpeak, SkillName.Stealing,
  SkillName.TasteID
 };

 public override bool AllowSkillUse( SkillName skill )
 {
  if ( AnimalForm.UnderTransformation( this ) )
  {
   for( int i = 0; i < m_AnimalFormRestrictedSkills.Length; i++ )
   {
    if( m_AnimalFormRestrictedSkills[i] == skill )
    {
     SendLocalizedMessage( 1070771 ); // You cannot use that skill in this form.
     return false;
    }
   }
  }

  return DesignContext.Check( this );
 }

 private bool m_LastProtectedMessage;
 private int m_NextProtectionCheck = 10;

 public virtual void RecheckTownProtection()
 {
  m_NextProtectionCheck = 10;

  Regions.GuardedRegion reg = (Regions.GuardedRegion) this.Region.GetRegion( typeof( Regions.GuardedRegion ) );
  bool isProtected = ( reg != null && !reg.IsDisabled() );

  if ( isProtected != m_LastProtectedMessage )
  {
   if ( isProtected )
    SendLocalizedMessage( 500112 ); // You are now under the protection of the town guards.
   else
    SendLocalizedMessage( 500113 ); // You have left the protection of the town guards.

   m_LastProtectedMessage = isProtected;
  }
 }

 public override void MoveToWorld( Point3D loc, Map map )
 {
  base.MoveToWorld( loc, map );

  RecheckTownProtection();
 }

 public override void SetLocation( Point3D loc, bool isTeleport )
 {
  if ( !isTeleport && AccessLevel == AccessLevel.Player )
  {
   // moving, not teleporting
   int zDrop = ( this.Location.Z - loc.Z );

   if ( zDrop > 20 ) // we fell more than one story
    Hits -= ((zDrop / 20) * 10) - 5; // deal some damage; does not kill, disrupt, etc
  }

  base.SetLocation( loc, isTeleport );

  if ( isTeleport || --m_NextProtectionCheck == 0 )
   RecheckTownProtection();
 }

 public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
 {
  base.GetContextMenuEntries( from, list );

  if ( from == this )
  {
   if ( m_Quest != null )
    m_Quest.GetContextMenuEntries( list );

   if ( Alive && InsuranceEnabled )
   {
    list.Add( new CallbackEntry( 6201, new ContextCallback( ToggleItemInsurance ) ) );

    if ( AutoRenewInsurance )
     list.Add( new CallbackEntry( 6202, new ContextCallback( CancelRenewInventoryInsurance ) ) );
    else
     list.Add( new CallbackEntry( 6200, new ContextCallback( AutoRenewInventoryInsurance ) ) );
   }

   BaseHouse house = BaseHouse.FindHouseAt( this );

   if ( house != null )
   {
    if ( Alive && house.InternalizedVendors.Count > 0 && house.IsOwner( this ) )
     list.Add( new CallbackEntry( 6204, new ContextCallback( GetVendor ) ) );

    if ( house.IsAosRules )
     list.Add( new CallbackEntry( 6207, new ContextCallback( LeaveHouse ) ) );
   }

   if ( m_JusticeProtectors.Count > 0 )
    list.Add( new CallbackEntry( 6157, new ContextCallback( CancelProtection ) ) );

   if( Alive )
    list.Add( new CallbackEntry( 6210, new ContextCallback( ToggleChampionTitleDisplay ) ) );
  }
 }

 private void CancelProtection()
 {
  for ( int i = 0; i < m_JusticeProtectors.Count; ++i )
  {
   Mobile prot = m_JusticeProtectors[i];

   string args = String.Format( "{0}\t{1}", this.Name, prot.Name );

   prot.SendLocalizedMessage( 1049371, args ); // The protective relationship between ~1_PLAYER1~ and ~2_PLAYER2~ has been ended.
   this.SendLocalizedMessage( 1049371, args ); // The protective relationship between ~1_PLAYER1~ and ~2_PLAYER2~ has been ended.
  }

  m_JusticeProtectors.Clear();
 }

 #region Insurance

 private void ToggleItemInsurance()
 {
  if ( !CheckAlive() )
   return;

  BeginTarget( -1, false, TargetFlags.None, new TargetCallback( ToggleItemInsurance_Callback ) );
  SendLocalizedMessage( 1060868 ); // Target the item you wish to toggle insurance status on <ESC> to cancel
 }

 private bool CanInsure( Item item )
 {
  if ( item is Container || item is BagOfSending || item is KeyRing )
   return false;

  if ( (item is Spellbook && item.LootType == LootType.Blessed)|| item is Runebook || item is PotionKeg || item is Sigil )
   return false;

  if ( item.Stackable )
   return false;

  if ( item.LootType == LootType.Cursed )
   return false;

  if ( item.ItemID == 0x204E ) // death shroud
   return false;

  return true;
 }

 private void ToggleItemInsurance_Callback( Mobile from, object obj )
 {
  if ( !CheckAlive() )
   return;

  Item item = obj as Item;

  if ( item == null || !item.IsChildOf( this ) )
  {
   BeginTarget( -1, false, TargetFlags.None, new TargetCallback( ToggleItemInsurance_Callback ) );
   SendLocalizedMessage( 1060871, "", 0x23 ); // You can only insure items that you have equipped or that are in your backpack
  }
  else if ( item.Insured )
  {
   item.Insured = false;

   SendLocalizedMessage( 1060874, "", 0x35 ); // You cancel the insurance on the item

   BeginTarget( -1, false, TargetFlags.None, new TargetCallback( ToggleItemInsurance_Callback ) );
   SendLocalizedMessage( 1060868, "", 0x23 ); // Target the item you wish to toggle insurance status on <ESC> to cancel
  }
  else if ( !CanInsure( item ) )
  {
   BeginTarget( -1, false, TargetFlags.None, new TargetCallback( ToggleItemInsurance_Callback ) );
   SendLocalizedMessage( 1060869, "", 0x23 ); // You cannot insure that
  }
  else if ( item.LootType == LootType.Blessed || item.LootType == LootType.Newbied || item.BlessedFor == from )
  {
   BeginTarget( -1, false, TargetFlags.None, new TargetCallback( ToggleItemInsurance_Callback ) );
   SendLocalizedMessage( 1060870, "", 0x23 ); // That item is blessed and does not need to be insured
   SendLocalizedMessage( 1060869, "", 0x23 ); // You cannot insure that
  }
  else
  {
   if ( !item.PayedInsurance )
   {
    if ( Banker.Withdraw( from, 600 ) )
    {
     SendLocalizedMessage( 1060398, "600" ); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
     item.PayedInsurance = true;
    }
    else
    {
     SendLocalizedMessage( 1061079, "", 0x23 ); // You lack the funds to purchase the insurance
     return;
    }
   }

   item.Insured = true;

   SendLocalizedMessage( 1060873, "", 0x23 ); // You have insured the item

   BeginTarget( -1, false, TargetFlags.None, new TargetCallback( ToggleItemInsurance_Callback ) );
   SendLocalizedMessage( 1060868, "", 0x23 ); // Target the item you wish to toggle insurance status on <ESC> to cancel
  }
 }

 private void AutoRenewInventoryInsurance()
 {
  if ( !CheckAlive() )
   return;

  SendLocalizedMessage( 1060881, "", 0x23 ); // You have selected to automatically reinsure all insured items upon death
  AutoRenewInsurance = true;
 }

 private void CancelRenewInventoryInsurance()
 {
  if ( !CheckAlive() )
   return;

  if( Core.SE )
  {
   if( !HasGump( typeof( CancelRenewInventoryInsuranceGump ) ) )
    SendGump( new CancelRenewInventoryInsuranceGump( this ) );
  }
  else
  {
   SendLocalizedMessage( 1061075, "", 0x23 ); // You have cancelled automatically reinsuring all insured items upon death
   AutoRenewInsurance = false;
  }
 }

 private class CancelRenewInventoryInsuranceGump : Gump
 {
  private PlayerMobile m_Player;

  public CancelRenewInventoryInsuranceGump( PlayerMobile player ) : base( 250, 200 )
  {
   m_Player = player;

   AddBackground( 0, 0, 240, 142, 0x13BE );
   AddImageTiled( 6, 6, 228, 100, 0xA40 );
   AddImageTiled( 6, 116, 228, 20, 0xA40 );
   AddAlphaRegion( 6, 6, 228, 142 );

   AddHtmlLocalized( 8, 8, 228, 100, 1071021, 0x7FFF, false, false ); // You are about to disable inventory insurance auto-renewal.

   AddButton( 6, 116, 0xFB1, 0xFB2, 0, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 40, 118, 450, 20, 1060051, 0x7FFF, false, false ); // CANCEL

   AddButton( 114, 116, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0 );
   AddHtmlLocalized( 148, 118, 450, 20, 1071022, 0x7FFF, false, false ); // DISABLE IT!
  }

  public override void OnResponse( NetState sender, RelayInfo info )
  {
   if ( !m_Player.CheckAlive() )
    return;

   if ( info.ButtonID == 1 )
   {
    m_Player.SendLocalizedMessage( 1061075, "", 0x23 ); // You have cancelled automatically reinsuring all insured items upon death
    m_Player.AutoRenewInsurance = false;
   }
   else
   {
    m_Player.SendLocalizedMessage( 1042021 ); // Cancelled.
   }
  }
 }
 #endregion

 private void GetVendor()
 {
  BaseHouse house = BaseHouse.FindHouseAt( this );

  if ( CheckAlive() && house != null && house.IsOwner( this ) && house.InternalizedVendors.Count > 0 )
  {
   CloseGump( typeof( ReclaimVendorGump ) );
   SendGump( new ReclaimVendorGump( house ) );
  }
 }

 private void LeaveHouse()
 {
  BaseHouse house = BaseHouse.FindHouseAt( this );

  if ( house != null )
   this.Location = house.BanLocation;
 }

 private delegate void ContextCallback();

 private class CallbackEntry : ContextMenuEntry
 {
  private ContextCallback m_Callback;

  public CallbackEntry( int number, ContextCallback callback ) : this( number, -1, callback )
  {
  }

  public CallbackEntry( int number, int range, ContextCallback callback ) : base( number, range )
  {
   m_Callback = callback;
  }

  public override void OnClick()
  {
   if ( m_Callback != null )
    m_Callback();
  }
 }

 public override void DisruptiveAction()
 {
  if( Meditating )
  {
   RemoveBuff( BuffIcon.ActiveMeditation );
  }

  base.DisruptiveAction();
 }
 public override void OnDoubleClick( Mobile from )
 {
  if ( this == from && !Warmode )
  {
   IMount mount = Mount;

   if ( mount != null && !DesignContext.Check( this ) )
    return;
  }

  base.OnDoubleClick( from );
 }

 public override void DisplayPaperdollTo( Mobile to )
 {
  if ( DesignContext.Check( this ) )
   base.DisplayPaperdollTo( to );
 }

 private static bool m_NoRecursion;

 public override bool CheckEquip( Item item )
 {
  if ( !base.CheckEquip( item ) )
   return false;

  #region Factions
  FactionItem factionItem = FactionItem.Find( item );

  if ( factionItem != null )
  {
   Faction faction = Faction.Find( this );

   if ( faction == null )
   {
    SendLocalizedMessage( 1010371 ); // You cannot equip a faction item!
    return false;
   }
   else if ( faction != factionItem.Faction )
   {
    SendLocalizedMessage( 1010372 ); // You cannot equip an opposing faction's item!
    return false;
   }
   else
   {
    int maxWearables = FactionItem.GetMaxWearables( this );

    for ( int i = 0; i < Items.Count; ++i )
    {
     Item equiped = Items[i];

     if ( item != equiped && FactionItem.Find( equiped ) != null )
     {
      if ( --maxWearables == 0 )
      {
       SendLocalizedMessage( 1010373 ); // You do not have enough rank to equip more faction items!
       return false;
      }
     }
    }
   }
  }
  #endregion

  if ( this.AccessLevel < AccessLevel.GameMaster && item.Layer != Layer.Mount && this.HasTrade )
  {
   BounceInfo bounce = item.GetBounce();

   if ( bounce != null )
   {
    if ( bounce.m_Parent is Item )
    {
     Item parent = (Item) bounce.m_Parent;

     if ( parent == this.Backpack || parent.IsChildOf( this.Backpack ) )
      return true;
    }
    else if ( bounce.m_Parent == this )
    {
     return true;
    }
   }

   SendLocalizedMessage( 1004042 ); // You can only equip what you are already carrying while you have a trade pending.
   return false;
  }

  return true;
 }

 public override bool CheckTrade( Mobile to, Item item, SecureTradeContainer cont, bool message, bool checkItems, int plusItems, int plusWeight )
 {
  int msgNum = 0;

  if ( cont == null )
  {
   if ( to.Holding != null )
    msgNum = 1062727; // You cannot trade with someone who is dragging something.
   else if ( this.HasTrade )
    msgNum = 1062781; // You are already trading with someone else!
   else if ( to.HasTrade )
    msgNum = 1062779; // That person is already involved in a trade
  }

  if ( msgNum == 0 )
  {
   if ( cont != null )
   {
    plusItems += cont.TotalItems;
    plusWeight += cont.TotalWeight;
   }

   if ( this.Backpack == null || !this.Backpack.CheckHold( this, item, false, checkItems, plusItems, plusWeight ) )
    msgNum = 1004040; // You would not be able to hold this if the trade failed.
   else if ( to.Backpack == null || !to.Backpack.CheckHold( to, item,