context: using System;
  using System.Collections;
  using Server.Misc;
  using Server.Items;
  using Server.Mobiles;
  using Server.Targeting;
  
  namespace Server.Mobiles
  {
  	public class WarriorGuard : BaseGuard
  	{
  		private Timer m_AttackTimer, m_IdleTimer;
  
  		private Mobile m_Focus;
  
  		[Constructable]
  		public WarriorGuard() : this( null )
  		{
  		}
  
  		public WarriorGuard( Mobile target ) : base( target )
  		{
  			InitStats( 1000, 1000, 1000 );
  			Title = "the guard";
  
  			SpeechHue = Utility.RandomDyedHue();
  
  			Hue = Utility.RandomSkinHue();
  
  			if ( Female = Utility.RandomBool() )
  			{
  				Body = 0x191;
  				Name = NameList.RandomName( "female" );
  
  				switch( Utility.Random( 2 ) )
  				{
  					case 0: AddItem( new LeatherSkirt() ); break;
  					case 1: AddItem( new LeatherShorts() ); break;
  				}
  
  				switch( Utility.Random( 5 ) )
  				{
  					case 0: AddItem( new FemaleLeatherChest() ); break;
  					case 1: AddItem( new FemaleStuddedChest() ); break;
  					case 2: AddItem( new LeatherBustierArms() ); break;
  					case 3: AddItem( new StuddedBustierArms() ); break;
  					case 4: AddItem( new FemalePlateChest() ); break;
  				}
  			}
  			else
  			{
  				Body = 0x190;
  				Name = NameList.RandomName( "male" );
  
  				AddItem( new PlateChest() );
  				AddItem( new PlateArms() );
  				AddItem( new PlateLegs() );
  
  				switch( Utility.Random( 3 ) )
  				{
  					case 0: AddItem( new Doublet( Utility.RandomNondyedHue() ) ); break;
  					case 1: AddItem( new Tunic( Utility.RandomNondyedHue() ) ); break;
  					case 2: AddItem( new BodySash( Utility.RandomNondyedHue() ) ); break;
  				}
  			}
  
  			Item hair = new Item( Utility.RandomList( 0x203B, 0x203C, 0x203D, 0x2044, 0x2045, 0x2047, 0x2049, 0x204A ) );
  
  			hair.Hue = Utility.RandomHairHue();
  			hair.Layer = Layer.Hair;
  			hair.Movable = false;
  
  			AddItem( hair );
  
  			if( Utility.RandomBool() && !this.Female )
  			{
  				Item beard = new Item( Utility.RandomList( 0x203E, 0x203F, 0x2040, 0x2041, 0x204B, 0x204C, 0x204D ) );
  
  				beard.Hue = hair.Hue;
  				beard.Layer = Layer.FacialHair;
  				beard.Movable = false;
  
  				AddItem( beard );
  			}
  
  			Halberd weapon = new Halberd();
  
  			weapon.Movable = false;
  			weapon.Crafter = this;
  			weapon.Quality = WeaponQuality.Exceptional;
  
  			AddItem( weapon );
  
  			Container pack = new Backpack();
  
  			pack.Movable = false;
  
  			pack.DropItem( new Gold( 10, 25 ) );
  
  			AddItem( pack );
  
  			Skills[SkillName.Anatomy].Base = 120.0;
  			Skills[SkillName.Tactics].Base = 120.0;
  			Skills[SkillName.Swords].Base = 120.0;
  			Skills[SkillName.MagicResist].Base = 120.0;
  			Skills[SkillName.DetectHidden].Base = 100.0;
  
  			this.NextCombatTime = Core.Now + TimeSpan.FromSeconds( 0.5 );
  			this.Focus = target;
  		}
  
  		public WarriorGuard( Serial serial ) : base( serial )
  		{
  		}
  
  		public override bool OnBeforeDeath()
  		{
  			if ( m_Focus != null && m_Focus.Alive )
  				new AvengeTimer( m_Focus ).Start(); // If a guard dies, three more guards will spawn
  
  			return base.OnBeforeDeath();
  		}
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public override Mobile Focus
  		{
  			get
  			{
  				return m_Focus;
  			}
  			set
  			{
  				if ( Deleted )
  					return;
  
  				Mobile oldFocus = m_Focus;
  
  				if ( oldFocus != value )
  				{
  					m_Focus = value;
  
  					if ( value != null )
  						this.AggressiveAction( value );
  
  					Combatant = value;
  
  					if ( oldFocus != null && !oldFocus.Alive )
  						Say( "Thou hast suffered thy punishment, scoundrel." );
  
  					if ( value != null )
  						Say( 500131 ); // Thou wilt regret thine actions, swine!
  
  					if ( m_AttackTimer != null )
  					{
  						m_AttackTimer.Stop();
  						m_AttackTimer = null;
  					}
  
  					if ( m_IdleTimer != null )
  					{
  						m_IdleTimer.Stop();
  						m_IdleTimer = null;
  					}
  
  					if ( m_Focus != null )
  					{
  						m_AttackTimer = new AttackTimer( this );
  						m_AttackTimer.Start();
  						((AttackTimer)m_AttackTimer).DoOnTick();
  					}
  					else
  					{
  						m_IdleTimer = new IdleTimer( this );
  						m_IdleTimer.Start();
  					}
  				}
  				else if ( m_Focus == null && m_IdleTimer == null )
  				{
  					m_IdleTimer = new IdleTimer( this );
  					m_IdleTimer.Start();
  				}
  			}
  		}
  
  		public override void Serialize( GenericWriter writer )
  		{
  			base.Serialize( writer );
  
  			writer.Write( (int) 0 ); // version
  
  			writer.Write( m_Focus );
  		}
  
  		public override void Deserialize( GenericReader reader )
  		{
  			base.Deserialize( reader );
  
  			int version = reader.ReadInt();
  
  			switch ( version )
  			{
  				case 0:
  				{
  					m_Focus = reader.ReadMobile();
  
  					if ( m_Focus != null )
  					{
  
gt: 						m_AttackTimer = new AttackTimer( this );