/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\ML Peerless + misc areas\Melisande\Rare Drop\melholysquirrel.cs
Lines of code: 144
***********************************************************/


using System;
using Server.Mobiles;
using Server.Items;
using Server.Gumps;
using System.Collections;
using Server.Targeting;
using Server.Spells.Chivalry;


namespace Server.Mobiles
{
	[CorpseName( "an albino squirrel corpse" )]
	[TypeAlias( "Server.Mobiles.holysquirrel" )]
	public class melholysquirrel : BaseCreature
	{
	private Mobile lastcombatant = null;
	private Mobile healtarget;	
	private DateTime lastheal;

	
		[Constructable]
		public melholysquirrel() : base( AIType.AI_Super, FightMode.Evil, 10, 1, 0.12, 0.19 )
		{
			Name = "a holy squirrel";
			Body = 278;
			BaseSoundID = 0x188;
			
			Hue = 1153;
			

			SetStr( 94 );
			SetDex( 265 );
			SetInt( 230 );

			SetHits( 153 );
			SetMana( 560 );

			SetDamage( 7, 13 );

			SetDamageType( ResistanceType.Physical, 60 );
			SetDamageType( ResistanceType.Energy, 40 );			

			
			//caps
			Skills[SkillName.Magery].Cap=Utility.Random(100,120);
			Skills[SkillName.EvalInt].Cap=Utility.Random(100,120);
			Skills[SkillName.Chivalry].Cap=Utility.Random(100,200);
			Skills[SkillName.Spellweaving].Cap=Utility.Random(100,130);

			//default resists
			SetResistance( ResistanceType.Physical, 90 );
			SetResistance( ResistanceType.Fire, 90 );
			SetResistance( ResistanceType.Cold, 90 );
			SetResistance( ResistanceType.Poison, 70 );
			SetResistance( ResistanceType.Energy, 90 );
			
			//default skills			
			SetSkill( SkillName.Magery, 95.1, 97.0 );			
			SetSkill( SkillName.MagicResist, 85.1, 90.0 );
			SetSkill( SkillName.Tactics, 39.3, 94.0 );
			SetSkill( SkillName.Wrestling, 49.3, 94.0 );
			SetSkill( SkillName.Chivalry, 70.3, 94.0 );
			SetSkill( SkillName.Spellweaving, 100, 130.0 );
			

			Fame = 3000;
			Karma = 15000;

			VirtualArmor = 18;
		

			Tamable = true;
			ControlSlots = 3;
			MinTameSkill = 95.1;
		}

		public override FoodType FavoriteFood{ get{ return FoodType.FruitsAndVegies | FoodType.Gold; } }
		
		
		public override double GetControlChance( Mobile m )
		{
			return 1.0;
		}			
		
		public void DoHeal()
		{
		if((lastheal+TimeSpan.FromSeconds(4))>DateTime.Now)return;
		lastheal=DateTime.Now;
		
		if(healtarget==null)return;
		if(!healtarget.InRange(this,2))return;
		
		if(healtarget.Poison!=null)new CleanseByFireSpell( this, null ).Cast();
		else if(healtarget.Alive && healtarget.Hits<healtarget.HitsMax)new CloseWoundsSpell( this, null ).Cast();
		else if(!healtarget.Alive)new NobleSacrificeSpell( this, null ).Cast();
		}
		
		
		
		public override void OnThink()
        {	
			base.OnThink();
			
			if(Combatant!=null)return;
		
			//check if beneficial target is pending (most likely a heal - but slight chance to pickup any other spell it happened to be casting)
			Target targ = this.Target;
			
			if(targ!=null && ((targ.Flags & TargetFlags.Beneficial) != 0) && healtarget!=null)
			{
			if(healtarget!=null)targ.Invoke( this, healtarget );			
			else this.Target.Cancel( this, TargetCancelType.Canceled );
			}
			
		
		
			if(this.Spell!=null && this.Spell.IsCasting)return;
		
			if (ControlOrder==OrderType.Stay || ControlOrder==OrderType.Come || ControlOrder==OrderType.Follow)
			{

				if(this.ControlMaster!=null)
				{
				healtarget=this.ControlMaster;
					if(healtarget.Hits<healtarget.HitsMax)
					{
					DoHeal();
					return;
					}
				}
				else if(this.SummonMaster!=null)
				{
				healtarget=this.SummonMaster;
					if(healtarget.Hits<healtarget.HitsMax)
					{
					DoHeal();
					return;
					}
				}
				
			}
			
			if(healtarget!=null && InRange(healtarget,2) && healtarget.Hits<healtarget.HitsMax && healtarget.Karma>=0)DoHeal();
									
			
			if(Hits<(HitsMax/3))	healtarget=this;
			
			if(Combatant!=null)lastcombatant=Combatant;			
		}
		
		
		public override void OnMovement( Mobile m, Point3D oldLocation )
		{
		if((lastheal+TimeSpan.FromSeconds(5))>DateTime.Now)return;

			if ( !m.Frozen && InRange( m, 2 ) && !InRange( oldLocation, 2 ) && !InRange( m, 1 ) && InLOS( m ) && m.Player && m!=ControlMaster && m!=SummonMaster)
			{

				if (!m.Alive && m==lastcombatant )
				{
				Say("You tried to hurt me and deserve to remain dead!");
				return;				
				}
				else if(!m.Alive && m.Karma<=0)
				{
				Say("I do not help evil scum like thee!");
				return;
				}


			
				if(m.Hits<m.HitsMax)
				{
				healtarget=m;
				DoHeal();
				return;
				}
			}
		}

		public override int Meat{ get{ return 2; } }
		public override int Hides{ get{ return 6; } }
		
		public melholysquirrel(Serial serial) : base(serial)
		{
		}

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