using System;
using System.Collections;
using Server.Items;
using Server.Targeting;
using Server.Network;
using Server.Mobiles;

namespace Server.Mobiles
{
    [CorpseName("Ueberreste einer Wache")]
    public class NewWarriorGuard : BaseGoodGuard
    {
        [Constructable]
        public NewWarriorGuard()
            : base(AIType.AI_Melee)
        {
         Body = 0x190; 
         Name = NameList.RandomName( "male" );
         Hue = Utility.RandomSkinHue();

         Item hair = new Item( Utility.RandomList( 0x203B, 0x2049, 0x2048, 0x204A ) ); 
         hair.Hue = Utility.RandomNeutralHue(); 
         hair.Layer = Layer.Hair; 
         hair.Movable = false; 
         AddItem( hair );

         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 ); 

         SetStr( 95, 120 ); 
         SetDex( 95, 120 ); 
         SetInt( 25, 35 ); 
         SetDamage( 10, 20 );
	 SetHits ( 120, 150 ); 

         SetDamageType( ResistanceType.Physical, 100 ); 

         SetResistance( ResistanceType.Physical, 30, 45 ); 
         SetResistance( ResistanceType.Fire, 20, 30 ); 
         SetResistance( ResistanceType.Cold, 20, 30 ); 
         SetResistance( ResistanceType.Poison, 5, 20 ); 
         SetResistance( ResistanceType.Energy, 5, 20 ); 

         SetSkill( SkillName.Anatomy, 120.0 ); 
         SetSkill( SkillName.Tactics, 120.0 ); 
         SetSkill( SkillName.Parry, 120.0 ); 
         SetSkill( SkillName.MagicResist, 90.0 ); 
         SetSkill( SkillName.Fencing, 120.0 ); 
         SetSkill( SkillName.Archery, 120.0 ); 
         SetSkill( SkillName.Swords, 120.0 ); 
         SetSkill( SkillName.Macing, 120.0 ); 

         AddItem( new PlateChest() ); 
         AddItem( new PlateArms() ); 
         AddItem( new PlateGloves() ); 
         AddItem( new PlateGorget() ); 
         AddItem( new PlateLegs() );
	 	Surcoat Surcoat = new Surcoat(); 
         	Surcoat.Hue = 0x31E;
 	 AddItem( Surcoat );
	
	switch( Utility.Random( 3 ) )
	{
	 case 0: ///The Royal Archer///
	 	Title = "[Vallengards Schuetze]";
         	AddItem( new Helmet() );
	 		Crossbow Crossbow = new Crossbow();
			Crossbow.Movable = false;
			Crossbow.Crafter = this;
			Crossbow.Quality = WeaponQuality.Exceptional;
	 	AddItem( Crossbow );
	 		Bolt Bolt = new Bolt( 250 );
			Bolt.Movable = false;
	 	AddItem( Bolt ); break;
	 case 1: ///The Royal Pikeman///
	 	Title = "[Vallengards Pikanier]";
         	AddItem( new ChainCoif() );
	 		Spear Spear = new Spear();
			Spear.Movable = false;
			Spear.Crafter = this;
			Spear.Quality = WeaponQuality.Exceptional;
	 	AddItem( Spear ); break;
	 case 2: ///The Royal Footman///
	 	Title = "[Vallengards Soldat]";
 		AddItem( new NorseHelm() );
	 		MetalKiteShield MetalKiteShield = new MetalKiteShield(); 
         		MetalKiteShield.Hue = 0x31E;
 	 	AddItem( MetalKiteShield );
	 		Longsword Longsword = new Longsword();
			Longsword.Movable = false;
			Longsword.Crafter = this;
			Longsword.Quality = WeaponQuality.Exceptional;
	 	AddItem( Longsword ); break;
	}

         PackGold( 100, 280);
         PackItem ( new Gold( 100, 150 ) ); 
      } 

        public override void GenerateLoot()
        {
            AddLoot(LootPack.Average);
        }

	public override bool OnBeforeDeath()
	{
	    IMount mount = this.Mount;

            if ( mount != null )
	    mount.Rider = null;

	    if ( mount is Mobile )
	    ((Mobile)mount).Kill();

	    return base.OnBeforeDeath();
	}

        public override Poison PoisonImmune { get { return Poison.Lesser; } }

        public NewWarriorGuard(Serial serial)
            : base(serial)
        {
        }

        public override void OnGaveMeleeAttack(Mobile d)
        {
           if (0.2 >= Utility.RandomDouble())
               this.Say(500131);
           if (d is BaseCreature)
           {
               if ((d as BaseCreature).IsDispellable)
               {
                   d.Hits -= Utility.RandomMinMax(20, 50);
               }
           }
        }

        public override void OnGotMeleeAttack(Mobile d)
        {
            if (0.2 >= Utility.RandomDouble())
            {
                this.Say(500131);
            }

            if (this.Hits < this.HitsMax / 2)
            {
                if (BandageContext.GetContext(this) == null)
                {
                    BandageContext.BeginHeal(this, this);
                    this.Say("*macht eine Bandage drum*");
                }
            }

            if (d is BaseCreature)
            {
                BaseCreature t = (BaseCreature)d;
                if (t.Controlled && !(t as BaseCreature).IsDispellable)
                {
                    if (0.5 >= Utility.RandomDouble())
                    {
                        t.Combatant = null;
                        t.Warmode = false;
                        t.Pacify(this, DateTime.Now + TimeSpan.FromSeconds(20.0));
                    }
                    if (this.Combatant == t)
                    {
                        this.Provoke(this, t.ControlMaster, true);
                    }
                }
            }
        }

        public override void OnDamagedBySpell(Mobile d)
        {
            if (0.3 >= Utility.RandomDouble())
            {
                this.Say("Dein Zauber wird dir nicht helfen.");
            }
            if (this.Hits < this.HitsMax / 2)
            {
                if (BandageContext.GetContext(this) == null)
                {
                    BandageContext.BeginHeal(this, this);
                    this.Say("Mache eine Bandage drum.");
                }
            }

            if (d is BaseCreature)
            {
                BaseCreature t = (BaseCreature)d;
                if (t.Controlled && !(t as BaseCreature).IsDispellable)
                {
                    if (0.5 >= Utility.RandomDouble())
                    {
                        t.Combatant = null;
                        t.Warmode = false;
                        t.Pacify(this, DateTime.Now + TimeSpan.FromSeconds(20.0));

                        if (this.Combatant == t)
                        {
                            this.Provoke(this, t.ControlMaster, true);
                        }
                    }
                }
            }
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

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