/*
##############################
Official Age of Valor Script
http://www.uovalor.com

Coded/Modified by Red Squirrel
redsquirrel@iceteks.com
##############################
*/
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Targeting;
using Server.Network;
using Server.Mobiles;
using Server.Items;
using Server.Spells;
using Server.Spells.First;
using Server.Spells.Second;
using Server.Spells.Third;
using Server.Spells.Fourth;
using Server.Spells.Fifth;
using Server.Spells.Sixth;
using Server.Spells.Seventh;
using Server.Spells.Necromancy;
using Server.Spells.Chivalry;
using Server.Spells.Spellweaving;
using Server.Spells.Bushido;
using Server.Spells.Ninjitsu;
using Server.Misc;
using Server.Regions;
using Server.SkillHandlers;


namespace Server.Mobiles
{

	public class SuperAI : BaseAI
	{
		private DateTime m_NextActTime; //global delay for waiting to perform another spell/action (good to save mana)
		

		public SuperAI( BaseCreature m ) : base( m )
		{
		}

		private bool targetpending=false; //this used to ensure target is only processed if it was invoked by the AI
		private DateTime targetpending_date;
		private DateTime NextRunCheck;
		
		private void SetTargPending()
		{
		targetpending=true;
		targetpending_date=DateTime.Now;
		}
		
		private bool Check4Target()
		{
		if(!targetpending)return false;
		if((targetpending_date+TimeSpan.FromSeconds(3))<DateTime.Now)targetpending=false;
		return true;
		}
		
		bool HasSpecialMove()
		{
		SpecialMove move = SpecialMove.GetCurrentMove(m_Mobile);
		return !(move==null);		
		}
		
		public override bool Think()
		{
			if ( m_Mobile.Deleted )
				return false;

			Target targ = m_Mobile.Target;

			if ( targ != null && targetpending )
			{
				targetpending=false;
				ProcessTarget( targ );
			}
			
			if(Check4Target())return true;			
			
			return base.Think();	
		}
		
		


		public virtual bool SmartAI
		{
			get{ return true; }
		}

		/*
		private const double HealChance = 0.15; // 5% chance to heal at gm necromancy, uses spirit speak healing
		*/

		private const double TeleportChance = 0.15; // 5% chance to teleport at gm magery

		
		public virtual double ScaleByMagery( double v )
		{
			return m_Mobile.Skills[SkillName.Magery].Value * v * 0.01;
		}
		
		private bool IsCasting()
		{
			if(m_Mobile.Spell != null && m_Mobile.Spell is Spell)
			{
			Spell curspell = (Spell)m_Mobile.Spell;
			
			if(curspell.IsCasting /* || curspell.IsSequencing*/)return true;		
			}
		
		return false;
		}
		
		//wether or not we should wait before performing another action
		private bool ShouldWait()
		{
		return (Check4Target() || m_NextActTime>DateTime.Now);
		}
		
		//set wait time for next action (global)
		private void SetWait()
		{
		SetWait(Utility.Random(10));
		}
		
		private void SetWait(int seconds)
		{
		m_NextActTime=DateTime.Now+TimeSpan.FromSeconds(seconds);
		}
		
		private void CheckRun(Mobile c)
		{		
		if(NextRunCheck>DateTime.Now)return;
		
			//don't get close if we have no melee capabilities - assuming we have a combatant in range
			if(m_Mobile.InRange(c,4) && !CanMelee())
			{
				if(!RunFrom(c))
				{
				WalkRandom(0,0,5);
				NextRunCheck=DateTime.Now+TimeSpan.FromSeconds(5+Utility.Random(4));
				}			
			}
			else if(!m_Mobile.InRange(c,7) && !CanMelee())RunTo(c);
			else if(CanMelee() && !m_Mobile.InRange(c,1)) RunTo(c);
		}
		
		
		//used for curse wep and consecrate mostly
		public bool CanWeaponFight()
		{
		if(CanMelee())return true;
		
		if(m_Mobile.Skills[SkillName.Archery].Value>0.1 && m_Mobile.HasLongRangeWep())return true;		
		
		return false;
		}
		
		public bool CanMelee()
		{
		bool haswep=m_Mobile.HasWep();
		
		if(m_Mobile.Skills[SkillName.Wrestling].Value>=10 && !haswep)return true;
		
		if((m_Mobile.Skills[SkillName.Swords].Value+m_Mobile.Skills[SkillName.Fencing].Value+m_Mobile.Skills[SkillName.Macing].Value)>=10 && haswep)return true;
		
		return false;
		}
		
		public override bool CanDistanceFight()
		{
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 || (m_Mobile.Skills[SkillName.Archery].Value>0.1 && m_Mobile.HasLongRangeWep())) return true;		
		
		return false;
		}		
		


		//****************************************************************************************
		
		//delay timers
		DateTime last_bandageuse;    
		DateTime last_giftofrenewal; 
		DateTime last_spiritspeak;     
		DateTime last_confidence;
		DateTime last_chugpot;				

		public bool DoHealingAction() 
		{
		if(ShouldWait())return false;
		ArrayList actions = new ArrayList();


		int bandagedelay=(int)(7.0 + (0.5 * ((double)(120 - m_Mobile.Dex) / 10)));
		if(bandagedelay<5)bandagedelay=5;
		
		//each item type is assigned a number which we'll check for after - this number has no real meaning exept for in this function		

		if( !MortalStrike.IsWounded( m_Mobile))
		{			
			//cure or heal			

			
			if(m_Mobile.Skills[SkillName.Healing].Value>0.1 && last_bandageuse+TimeSpan.FromSeconds(bandagedelay)<DateTime.Now)
			actions.Add(1); //healing skill (this based on dex and adds 1 second delay)
			
			//heal
			if(m_Mobile.Poison==null)
			{		
			if(m_Mobile.Skills[SkillName.Magery].Value>0.1 && m_Mobile.Mana>=4 && !IsCasting())
			actions.Add(2);  //mini heal spell
			if(m_Mobile.Skills[SkillName.Magery].Value>60 && m_Mobile.Mana>=11 && !IsCasting())
			actions.Add(3);  //greater heal spell
			if(m_Mobile.Skills[SkillName.Chivalry].Value>0.1 && m_Mobile.Mana>=10 && !IsCasting())
			actions.Add(4);  //close wounds
			if(m_Mobile.Skills[SkillName.Alchemy].Value>0.1 && (last_chugpot+TimeSpan.FromSeconds(11))<DateTime.Now)
			actions.Add(9); //chug heal pot
			}
			else  //cure
			{
			if(m_Mobile.Skills[SkillName.Chivalry].Value>10 && m_Mobile.Mana>=10 && !IsCasting())
			actions.Add(5);  //clense by fire
			if(m_Mobile.Skills[SkillName.Magery].Value>20 && m_Mobile.Mana>=6 && !IsCasting())
			actions.Add(6);  //cure spell		
			if(m_Mobile.Skills[SkillName.Alchemy].Value>0.1 && (last_chugpot+TimeSpan.FromSeconds(11))<DateTime.Now)
			actions.Add(11); //chug heal pot			
			}
		}
		
		if(m_Mobile.Skills[SkillName.SpiritSpeak].Value>0.1 && m_Mobile.Mana>=10 && (last_spiritspeak+TimeSpan.FromSeconds(10))<DateTime.Now && !IsCasting())
		actions.Add(7); //spirit speak skill
		
		if(m_Mobile.Skills[SkillName.Spellweaving].Value>0.1 && m_Mobile.Mana>=24 && (last_giftofrenewal+TimeSpan.FromMinutes(6))<DateTime.Now && !IsCasting())
		actions.Add(8); //gift of renewal spell
		
		if(m_Mobile.Skills[SkillName.Bushido].Value>25 && m_Mobile.Mana>=10 && last_confidence+TimeSpan.FromSeconds(10)<DateTime.Now && !IsCasting())
		actions.Add(10); //confidence
		

		if(actions.Count<=0)return false;

		
			//do one of the actions
			switch((int)actions[Utility.Random(actions.Count)])
			{
				case 1:
				SetTargPending();
				Bandage band = new Bandage();
				last_bandageuse=DateTime.Now;
				
				band.OnDoubleClick( m_Mobile);
						
				m_Mobile.DebugSay("using bandage (delay {0})",bandagedelay);
				return true;
				//-----------------------
				case 2:
				SetTargPending();
				new HealSpell( m_Mobile, null ).Cast();
			    m_Mobile.DebugSay("heal spell");
				return true;
				//-----------------------
				case 3:
				SetTargPending();
				new GreaterHealSpell( m_Mobile, null ).Cast();			
				m_Mobile.DebugSay("greater heal spell");
				return true;
				//-----------------------
				case 4:
				SetTargPending();
				new CloseWoundsSpell( m_Mobile, null ).Cast();		
				m_Mobile.DebugSay("close wounds");
				return true;
				//-----------------------
				case 5:
				SetTargPending();
				new CleanseByFireSpell( m_Mobile, null ).Cast();
				m_Mobile.DebugSay("clense by fire");
				return true;
				//-----------------------
				case 6:
				SetTargPending();
				new CureSpell( m_Mobile, null ).Cast();
				m_Mobile.DebugSay("cure spell");
				return true;
				//-----------------------
				case 7:		
				m_Mobile.UseSkill( SkillName.SpiritSpeak );		
				last_spiritspeak=DateTime.Now;
				m_Mobile.DebugSay("spirit speak skill");
				return true;
				//-----------------------
				case 8:		
				SetTargPending();
				new GiftOfRenewalSpell( m_Mobile, null ).Cast();	
				last_giftofrenewal=DateTime.Now;
				m_Mobile.DebugSay("Gift of renewal spell");
				return true;
				//-----------------------		
				case 9:		
				GreaterHealPotion healpot = new GreaterHealPotion();
				last_chugpot=DateTime.Now;
				
				healpot.Drink( m_Mobile );
				
				m_Mobile.DebugSay("chug heal pot");
				return true;
				//-----------------------		
				case 10:		
				new Confidence( m_Mobile, null ).Cast();	
				last_confidence=DateTime.Now;
				m_Mobile.DebugSay("confidence");
				return true;
				//-----------------------			
				case 11:		
				GreaterCurePotion curepot = new GreaterCurePotion();
				last_chugpot=DateTime.Now;
				
				curepot.Drink( m_Mobile );
				
				m_Mobile.DebugSay("chug cure pot");
				return true;
				//-----------------------				
			}
		
		return false;
		}

		//****************************************************************************************
		
		//delay timers
		
		
		public bool DoReveilAction()
		{
		if(ShouldWait())return false;
		ArrayList actions = new ArrayList();
		
		if(m_Mobile.Controlled)return false; //we don't want pets to use this, since they can reveil their owners/friends
		
		if(m_Mobile.Skills[SkillName.Magery].Value>40 && m_Mobile.Mana>=30 && !IsCasting())
		actions.Add(1); //reveil spell
		if(m_Mobile.Skills[SkillName.DetectHidden].Value>0.1)
		actions.Add(2); //detect hidden skill	

		
		if(actions.Count<=0)return false;
		//do one of the actions
		switch((int)actions[Utility.Random(actions.Count)])
		{
			case 1:
			SetTargPending();
			new RevealSpell( m_Mobile, null ).Cast();		
					
			m_Mobile.DebugSay("reveil");
			return true;
			//-----------------------	
			case 2:
			SetTargPending();
			m_Mobile.UseSkill( SkillName.DetectHidden );
			
			m_Mobile.DebugSay("detect hidden");
			return true;
			//-----------------------				
		}

		return false;	
		}
		


		//****************************************************************************************
		
		//delay timers
		DateTime last_attunement;
		DateTime last_invis;
		
		//stuff to defend ourselves
		public bool DoDefensiveAction(bool fighting)
		{
		if(ShouldWait())return false;
		ArrayList actions = new ArrayList();
		
		if(m_Mobile.Skills[SkillName.Spellweaving].Value>0.1 && m_Mobile.Mana>=24 && (last_attunement+TimeSpan.FromMinutes(5))<DateTime.Now && !IsCasting())
		actions.Add(1); //attunement
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 && m_Mobile.Mana>=5 && !IsCasting() && fighting)
		actions.Add(2); //clumbsy (to disturb)
		if(m_Mobile.Skills[SkillName.Magery].Value>70 && m_Mobile.Mana>=30 && !m_Mobile.Hidden && 0.2>Utility.RandomDouble() && !IsCasting())
		actions.Add(3); //invisibility
		if(m_Mobile.Skills[SkillName.Bushido].Value>50 && m_Mobile.Mana>=15 && !HasSpecialMove())
		actions.Add(4);	//counter attack
		if(m_Mobile.Skills[SkillName.Bushido].Value>70 && m_Mobile.Mana>=20 && !HasSpecialMove() && !IsCasting())
		actions.Add(5);	//evasion
		if(m_Mobile.Skills[SkillName.Necromancy].Value>30 && m_Mobile.Mana>=25 && !IsCasting() && fighting)
		actions.Add(6);	//blood oath
		if(m_Mobile.Skills[SkillName.Ninjitsu].Value>70 && m_Mobile.Mana>=30 && 0.7>Utility.RandomDouble())
		actions.Add(7);	//smoke bomb	
		if(m_Mobile.Skills[SkillName.Hiding].Value>50 && !fighting)
		actions.Add(8); //hiding
		
		if(actions.Count<=0)return false;


		
		//do one of the actions
		switch((int)actions[Utility.Random(actions.Count)])
		{
			case 1:
			new AttunementSpell( m_Mobile, null ).Cast();	
			last_attunement=DateTime.Now;		
					
			m_Mobile.DebugSay("attunement");
			return true;
			//-----------------------		
			case 2:
			SetTargPending();
			new ClumsySpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("clumbsy");
			return true;
			//-----------------------					
			case 3:
			SetTargPending();
			SetWait();
			m_Mobile.Combatant=null;
			m_Mobile.Warmode = false;			
			Action = ActionType.Wander;
			new InvisibilitySpell( m_Mobile, null ).Cast();
			return true;
			//-----------------------			
			case 4:
			new CounterAttack( m_Mobile, null ).Cast();	
			SetWait(15);
			m_Mobile.DebugSay("counter attack");
			return true;
			//-----------------------	
			case 5:
			new Evasion( m_Mobile, null ).Cast();	
			m_Mobile.DebugSay("evasion");
			return true;
			//-----------------------			
			case 6:
			SetTargPending();
			new BloodOathSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("blood oath");
			return true;
			//-----------------------			
			case 7:
			SmokeBomb  bomb = new SmokeBomb();
			SetWait();			
			bomb.OnDoubleClick( m_Mobile);
			m_Mobile.Combatant=null;
			m_Mobile.Warmode = false;			
			Action = ActionType.Wander;
			m_Mobile.DebugSay("smoke bomb ");
			return true;
			//-----------------------				
			case 8:
			SetWait();
			m_Mobile.UseSkill(SkillName.Hiding);
			m_Mobile.Warmode = false;
			m_Mobile.Combatant=null;
			Action = ActionType.Wander;
			m_Mobile.DebugSay("hiding skill");
			return true;
			//-----------------------						
			
		}
		
		
		return false;
		}

		
		
		//****************************************************************************************
		//delay timers
		DateTime last_consecrate;
		DateTime last_divinefury;
		
		//any damaging, or otherwise harmful action, including spells that increase the next harmful action
		public bool DoOffensiveAction()
		{
		if(ShouldWait())return false;
		ArrayList actions = new ArrayList();
		
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 && m_Mobile.Mana>=5 )actions.Add(1); //magic arrow
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 && m_Mobile.Mana>=10 && m_Mobile.InRange(m_Mobile.Combatant,3))actions.Add(2); //harm
		if(m_Mobile.Skills[SkillName.Magery].Value>15 && m_Mobile.Mana>=15)actions.Add(3); //fireball
		if(m_Mobile.Skills[SkillName.Magery].Value>15 && m_Mobile.Mana>=15)actions.Add(4); //poison
		if(m_Mobile.Skills[SkillName.Magery].Value>30 && m_Mobile.Mana>=24)actions.Add(5); //lightning
		if(m_Mobile.Skills[SkillName.Magery].Value>45 && m_Mobile.Mana>=24)actions.Add(6); //mind blast
		if(m_Mobile.Skills[SkillName.Magery].Value>60 && m_Mobile.Mana>=30)actions.Add(7); //ebolt
		if(m_Mobile.Skills[SkillName.Magery].Value>60 && m_Mobile.Mana>=30)actions.Add(8); //explosion
		if(m_Mobile.Skills[SkillName.Magery].Value>74 && m_Mobile.Mana>=45)actions.Add(9); //flame strike
		
		if(m_Mobile.Skills[SkillName.Bushido].Value>65 && m_Mobile.Mana>=10)actions.Add(10); //lightning strike

		if(m_Mobile.Skills[SkillName.Chivalry].Value>20 && m_Mobile.Mana>=15 && (last_consecrate+TimeSpan.FromSeconds(10))<DateTime.Now && CanWeaponFight())actions.Add(11); //consecrate
		
		if(m_Mobile.Skills[SkillName.Necromancy].Value>0.1 && m_Mobile.Mana>=10 && CanWeaponFight())actions.Add(12); //curse wep
		if(m_Mobile.Skills[SkillName.Necromancy].Value>30 && m_Mobile.Mana>=10)actions.Add(13); //pain spike
		if(m_Mobile.Skills[SkillName.Necromancy].Value>70 && m_Mobile.Mana>=40)actions.Add(14); //strangle
		if(m_Mobile.Skills[SkillName.Necromancy].Value>60 && m_Mobile.Mana>=25)actions.Add(15); //poison strike (custom)
		if(m_Mobile.Skills[SkillName.Necromancy].Value>75 && m_Mobile.Mana>=30 && m_Mobile.InRange(m_Mobile.Combatant,3))actions.Add(16); //wither (custom)
		if(m_Mobile.Skills[SkillName.Necromancy].Value>90 && m_Mobile.Mana>=50)actions.Add(17); //vengeful spirit (custom)
		
		if(m_Mobile.Skills[SkillName.Chivalry].Value>65 && m_Mobile.Mana>=15 && m_Mobile.InRange(m_Mobile.Combatant,2))actions.Add(18); //holy light		
		
		if(m_Mobile.Skills[SkillName.Necromancy].Value>0.1 && m_Mobile.Mana>=10)actions.Add(19); //evil omen
		
		if(m_Mobile.Skills[SkillName.Spellweaving].Value>70 && m_Mobile.Mana>=70)actions.Add(20); //Essense of wind (custom)
		if(m_Mobile.Skills[SkillName.Spellweaving].Value>15 && m_Mobile.Mana>=40)actions.Add(21); //Thunder storm (custom)
		
		if(m_Mobile.Skills[SkillName.Ninjitsu].Value>50 && m_Mobile.Mana>=40 && m_Mobile.Hidden && m_Mobile.AllowedStealthSteps>0)actions.Add(22); //backstab
		if(m_Mobile.Skills[SkillName.Ninjitsu].Value>95 && m_Mobile.Mana>=45)actions.Add(23); 	//death strike	
		if(m_Mobile.Skills[SkillName.Ninjitsu].Value>90 && m_Mobile.Mana>=25 && !m_Mobile.Hidden)actions.Add(24); 	//KI attack
		if(m_Mobile.Skills[SkillName.Ninjitsu].Value>40 && m_Mobile.Mana>=35 && m_Mobile.Hidden && m_Mobile.AllowedStealthSteps>0)actions.Add(25); 	//suprise attack

		if(m_Mobile.Skills[SkillName.Chivalry].Value>10 && m_Mobile.Mana>=30 && (last_divinefury+TimeSpan.FromSeconds(10))<DateTime.Now)actions.Add(26); //divine fury		

		if(m_Mobile.Skills[SkillName.Spellweaving].Value>99 && m_Mobile.Mana>=70 && m_Mobile.Combatant!=null && m_Mobile.Combatant.Hits<(m_Mobile.Combatant.HitsMax/10))
		actions.Add(27); //word of death
		
		
		if(actions.Count<=0)return false;

		//do one of the actions
		switch((int)actions[Utility.Random(actions.Count)])
		{	
			case 1:
			SetTargPending();
			new MagicArrowSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("magic arrow");
			return true;	
			//-----------------------					
			case 2:
			SetTargPending();
			new HarmSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("harm");
			return true;	
			//-----------------------					
			case 3:
			SetTargPending();
			new FireballSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("fire ball");
			return true;	
			//-----------------------		
			case 4:
			SetTargPending();
			new PoisonSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("poison");
			return true;	
			//-----------------------		
			case 5:
			SetTargPending();
			new LightningSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("lightning");
			return true;	
			//-----------------------		
			case 6:
			SetTargPending();
			new MindBlastSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("mind blast");
			return true;	
			//-----------------------		
			case 7:
			SetTargPending();
			new EnergyBoltSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("e bolt");
			return true;	
			//-----------------------		
			case 8:
			SetTargPending();
			new ExplosionSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("explosion");
			return true;	
			//-----------------------		
			case 9:
			SetTargPending();
			new FlameStrikeSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("flame strike");
			return true;	
			//-----------------------		
			case 10:
			SpecialMove.SetCurrentMove( m_Mobile, new LightningStrike() );
					
			m_Mobile.DebugSay("lightning strike");
			return true;	
			//-----------------------		
			case 11:
			new ConsecrateWeaponSpell( m_Mobile, null ).Cast();	
			last_consecrate=DateTime.Now;								
			m_Mobile.DebugSay("consecrate wep");
			return true;	
			//-----------------------		
			case 12:
			new CurseWeaponSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("Curse wep");
			return true;	
			//-----------------------		
			case 13:
			SetTargPending();
			new PainSpikeSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("pain spike");
			return true;	
			//-----------------------		
			case 14:
			SetTargPending();
			new StrangleSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("strangle");
			return true;	
			//-----------------------		
			case 15:
			SetTargPending();
			new PoisonStrikeCreatureSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("poison strike");
			return true;	
			//-----------------------		
			case 16:
			new WitherCreatureSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("wither");
			return true;	
			//-----------------------		
			case 17:
			SetTargPending();
			new VengefulSpiritCreatureSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("vengeful spirit");
			return true;	
			//-----------------------		
			case 18:
			new HolyLightCreatureSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("holy light");
			return true;	
			//-----------------------			
			case 19:
			SetTargPending();			
			new EvilOmenSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("evil omen");
			return true;	
			//-----------------------			
			case 20:
			new EssenceOfWindCreatureSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("essense of wind");
			return true;	
			//-----------------------		
			case 21:	
			new ThunderstormCreatureSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("thunder storm");
			return true;	
			//-----------------------					
			case 22:	
			SpecialMove.SetCurrentMove( m_Mobile, new Backstab() );
					
			m_Mobile.DebugSay("backstab");
			return true;	
			//-----------------------		
			case 23:	
			SpecialMove.SetCurrentMove( m_Mobile, new DeathStrike() );
					
			m_Mobile.DebugSay("death strike");
			return true;	
			//-----------------------				
			case 24:	
			SpecialMove.SetCurrentMove( m_Mobile, new KiAttack() );
					
			m_Mobile.DebugSay("KI attack");
			return true;	
			//-----------------------				
			case 25:	
			SpecialMove.SetCurrentMove( m_Mobile, new SurpriseAttack() );
					
			m_Mobile.DebugSay("supprise attack");
			return true;	
			//-----------------------				
			case 26:
			new DivineFurySpell( m_Mobile, null ).Cast();	
			last_divinefury=DateTime.Now;				
			m_Mobile.DebugSay("divine fury");
			return true;		
			//-----------------------				
			case 27:
			SetTargPending();
			new WordOfDeathSpell( m_Mobile, null ).Cast();	
			m_Mobile.DebugSay("word of death");
			return true;				
		}
		
	
		
		
		return false;
		}
		

		//****************************************************************************************
		
		//both buffs and debuff related actions - rare enough occurences, usually if we have lot of extra mana
		public bool DoBuffAction(bool fighting)
		{
		if(ShouldWait())return false;
		ArrayList actions = new ArrayList();
		
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 && m_Mobile.Mana>=10 && fighting && !IsCasting())actions.Add(1); //weaken
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 && m_Mobile.Mana>=10 && fighting && !IsCasting())actions.Add(2); //feeblemind
		if(m_Mobile.Skills[SkillName.Magery].Value>20 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(3); //Agility
		if(m_Mobile.Skills[SkillName.Magery].Value>20 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(4); //Cunning
		if(m_Mobile.Skills[SkillName.Magery].Value>20 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(5); //Strenght
		if(m_Mobile.Skills[SkillName.Magery].Value>30 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(5); //Bless
		if(m_Mobile.Skills[SkillName.Magery].Value>30 && m_Mobile.Mana>=20 && fighting && !IsCasting())actions.Add(6); //Curse		
		if(m_Mobile.Skills[SkillName.Magery].Value>30 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(7); //Mana drain	
		if(m_Mobile.Skills[SkillName.Magery].Value>30 && m_Mobile.Mana>=20 && fighting && !IsCasting() && m_Mobile.Body.IsHuman)actions.Add(8);//IncognitoSpell
		if(m_Mobile.Skills[SkillName.Chivalry].Value>10 && m_Mobile.Mana>=30 && !IsCasting())actions.Add(9);//remove curse
		if(m_Mobile.Skills[SkillName.Necromancy].Value>25 && m_Mobile.Mana>=30 && fighting && !IsCasting())actions.Add(11);//corpse skin
		if(m_Mobile.Skills[SkillName.Magery].Value>80 && m_Mobile.Mana>=40 && fighting && !IsCasting())actions.Add(12);//mana vampire
			
		if(actions.Count<=0)return false;

		//do one of the actions
		switch((int)actions[Utility.Random(actions.Count)])
		{
			case 1:
			SetTargPending();
			new WeakenSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("weaken");
			return true;		
			//-----------------------				
			case 2:
			SetTargPending();
			new FeeblemindSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("feeblemind");
			return true;		
			//-----------------------					
			case 3:
			SetTargPending();
			new AgilitySpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("agility");
			return true;		
			//-----------------------					
			case 4:
			SetTargPending();
			new CunningSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("cunning");
			return true;		
			//-----------------------		
			case 5:
			SetTargPending();
			new StrengthSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("strength");
			return true;		
			//-----------------------				
			case 6:
			SetTargPending();
			new CurseSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("curse");
			return true;		
			//-----------------------						
			case 7:
			SetTargPending();
			new ManaDrainSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("mana drain");
			return true;		
			//-----------------------				
			case 8:
			new IncognitoSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("Incognito");
			return true;		
			//-----------------------				
			case 9:
			SetTargPending();
			new RemoveCurseSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("remove curse");
			return true;		
			//-----------------------				
			case 11:
			SetTargPending();
			new CorpseSkinSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("corpse skin");
			return true;		
			//-----------------------				
			case 12:
			SetTargPending();
			new ManaVampireSpell( m_Mobile, null ).Cast();	
					
			m_Mobile.DebugSay("mana vampire");
			return true;		
			//-----------------------					
		}
		
		
		
		
		return false;
		}		
		
		//****************************************************************************************		
		
		//anything that can dispel
		public bool DoDispelAction()
		{
		if(ShouldWait())return false;
			ArrayList actions = new ArrayList();
			
			if(m_Mobile.Skills[SkillName.Magery].Value>65 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(1); //dispel
			if(m_Mobile.Skills[SkillName.Chivalry].Value>45 && m_Mobile.Mana>=20 && !IsCasting())actions.Add(2); //dispel evil
			

			
			if(actions.Count<=0)return false;

			//do one of the actions
			switch((int)actions[Utility.Random(actions.Count)])
			{
				case 1:
				SetTargPending();
				new DispelSpell( m_Mobile, null ).Cast();	
						
				m_Mobile.DebugSay("dispel");
				return true;
				//-----------------------		
				case 2:
				new DispelEvilSpell( m_Mobile, null ).Cast();	
						
				m_Mobile.DebugSay("dispel evil");
				return true;
				//-----------------------					
				
			}
		return false;			
		}
		

		
		
		
//------------------------------------------------------------------------------------------------------------------------------------
		
		
		
	
		

		public override bool DoActionWander()
		{
		if(last_invis+TimeSpan.FromSeconds(6)>DateTime.Now)return true;  //if we're hidden, don't do anything for a bit
		if(m_Mobile.Meditating)return true; //if we're meditating, don't move
		
			if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
			{
				m_Mobile.DebugSay( "I am going to attack {0}", m_Mobile.FocusMob.Name );

				m_Mobile.Combatant = m_Mobile.FocusMob;
				Action = ActionType.Combat;
				m_NextActTime = DateTime.Now;
			}
			else if (m_Mobile.Hits<(m_Mobile.HitsMax-10) && 0.05>Utility.RandomDouble())
			{
			DoHealingAction();
			}			
			else
			{
			DoReveilAction();
				m_Mobile.DebugSay( "I am wandering" );

				m_Mobile.Warmode = false;

				base.DoActionWander();
			}

			return true;
		}

		public void RunTo( Mobile m )
		{
				if ( !m_Mobile.InRange( m, m_Mobile.RangeFight ) )
				{
					if ( !MoveTo( m, true, 1 ) )
						OnFailedMove();
				}
				else if ( m_Mobile.InRange( m, m_Mobile.RangeFight - 1 ) )
				{
					RunFrom( m );
				}
			
		}

		public bool RunFrom( Mobile m )
		{
			return Run( (m_Mobile.GetDirectionTo( m ) - 4) & Direction.Mask );
		}

		public void OnFailedMove()
		{
		if(CanDistanceFight() && m_Mobile.Combatant!=null && m_Mobile.InLOS(m_Mobile.Combatant))return;
			if ( !m_Mobile.DisallowAllMoves && (SmartAI ? Utility.Random( 4 ) == 0 : ScaleByMagery( TeleportChance ) > Utility.RandomDouble())
			&& m_Mobile.Skills[SkillName.Magery].Value>=20)
			{
				if ( m_Mobile.Target != null )
					m_Mobile.Target.Cancel( m_Mobile, TargetCancelType.Canceled );

				new TeleportSpell( m_Mobile, null ).Cast();

				m_Mobile.DebugSay( "I am stuck, I'm going to try teleporting away" );
			}
			else if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
			{
				if ( m_Mobile.Debug )
					m_Mobile.DebugSay( "My move is blocked, so I am going to attack {0}", m_Mobile.FocusMob.Name );

				m_Mobile.Combatant = m_Mobile.FocusMob;
				Action = ActionType.Combat;
			}
			else
			{
				m_Mobile.DebugSay( "I am stuck" );
			}
		
		}

		public bool Run( Direction d )
		{
			if ( (m_Mobile.Spell != null && m_Mobile.Spell.IsCasting) || m_Mobile.Paralyzed || m_Mobile.Frozen || m_Mobile.DisallowAllMoves )
				return false;

			m_Mobile.Direction = d | Direction.Running;

			if ( !DoMove( m_Mobile.Direction, true ) )
			{
				//OnFailedMove();
				return false;
			}	
				
				return true;
			}

		
		

		public override bool DoActionCombat()
		{
			Mobile c = m_Mobile.Combatant;
			m_Mobile.Warmode = true;

			if ( c == null || c.Deleted || !c.Alive || c.IsDeadBondedPet || !m_Mobile.CanSee( c ) || !m_Mobile.CanBeHarmful( c, false ) || c.Map != m_Mobile.Map )
			{
				// Our combatant is deleted, dead, hidden, or we cannot hurt them
				// Try to find another combatant

				if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
				{
					if ( m_Mobile.Debug )
						m_Mobile.DebugSay( "Something happened to my combatant, so I am going to fight {0}", m_Mobile.FocusMob.Name );

					m_Mobile.Combatant = c = m_Mobile.FocusMob;
					m_Mobile.FocusMob = null;
				}
				else
				{
					m_Mobile.DebugSay( "Something happened to my combatant, and nothing is around. I am on guard." );
					Action = ActionType.Guard;
					return true;
				}
			}

			if ( !m_Mobile.InLOS( c ) )
			{
				if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
				{
					m_Mobile.Combatant = c = m_Mobile.FocusMob;
					m_Mobile.FocusMob = null;
				}
			}

			//if ( SmartAI && !m_Mobile.StunReady && m_Mobile.Skills[SkillName.Wrestling].Value >= 80.0 && m_Mobile.Skills[SkillName.Anatomy].Value >= 80.0 )
			//	EventSink.InvokeStunRequest( new StunRequestEventArgs( m_Mobile ) );

			if ( !m_Mobile.InRange( c, m_Mobile.RangePerception ) )
			{
				// They are somewhat far away, can we find something else?

				if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
				{
					m_Mobile.Combatant = m_Mobile.FocusMob;
					m_Mobile.FocusMob = null;
				}
				else if ( !m_Mobile.InRange( c, m_Mobile.RangePerception * 3 ) )
				{
					m_Mobile.Combatant = null;
				}

				c = m_Mobile.Combatant;

				if ( c == null )
				{
					m_Mobile.DebugSay( "My combatant has fled, so I am on guard" );
					Action = ActionType.Guard;

					return true;
				}
			}

			if ( !m_Mobile.Controlled && !m_Mobile.Summoned && !m_Mobile.IsParagon )
			{
				if ( m_Mobile.Hits < m_Mobile.HitsMax * 20/100 )
				{
					// We are low on health, should we flee?

					bool flee = false;

					if ( m_Mobile.Hits < c.Hits )
					{
						// We are more hurt than them

						int diff = c.Hits - m_Mobile.Hits;

						flee = ( Utility.Random( 0, 100 ) > (10 + diff) ); // (10 + diff)% chance to flee
					}
					else
					{
						flee = Utility.Random( 0, 100 ) > 10; // 10% chance to flee
					}
					
					if ( flee )
					{
						if ( m_Mobile.Debug )
							m_Mobile.DebugSay( "I am going to flee from {0}", c.Name );
							
						RunFrom( c );

						Action = ActionType.Flee;
						return true;
					}
				}
			}

			if ( !ShouldWait() && DateTime.Now > m_NextActTime && m_Mobile.InRange( c, 12 ) )
			{
				// We are ready to do something

								
				Mobile toDispel = FindDispelTarget( true );
				
				bool didaction=false;

				//typecasting FTW
				double percentmana=(double)((double)m_Mobile.Mana/(double)m_Mobile.ManaMax)*100.0;
				double percenthits=(double)((double)m_Mobile.Hits/(double)m_Mobile.HitsMax)*100.0;
				
				//m_Mobile.DebugSay("hits percent: {0}",percenthits);//debug
				
				if (toDispel != null && 0.4>Utility.RandomDouble()) // Something dispellable is attacking
				{
				didaction = DoDispelAction();
				}				

				if (!didaction && percenthits<(40+Utility.Random(40)) && 0.5>Utility.RandomDouble()) // should cure/heal
				{				
				if(0.7>Utility.RandomDouble())didaction = DoHealingAction();
				if(!didaction) didaction = DoDefensiveAction(m_Mobile.Combatant!=null);		
				}
				
				if(!didaction && percentmana>20+Utility.Random(50) && 0.9>Utility.RandomDouble()) //deal offensive action if at 10% mana or more
				{
				didaction=DoOffensiveAction();
				}
				else if(0.3>Utility.RandomDouble())didaction=DoReveilAction();
				
				if(!didaction && percentmana>60 && 0.6>Utility.RandomDouble()) //do a buff/debuf spell
				{
				didaction = DoBuffAction(m_Mobile.Combatant!=null);				
				}
				
				if (!didaction && percenthits<30 && 0.6>Utility.RandomDouble()) //defensive action
				{				
				didaction = DoDefensiveAction(m_Mobile.Combatant!=null);
				}				
				
				if (!didaction && percenthits<10 && 0.3>Utility.RandomDouble()) //if we did not do an action we might as well heal
				{				
				didaction = DoHealingAction();
				}				
				
				
								
				if(Utility.Random(130)<percentmana)
				{
				SetWait(Utility.Random(1,4));  //random delay between doing an action, bigger chance if our mana is low
				}
				
				CheckRun( c );				
			}
			else if ( m_Mobile.Spell == null || !m_Mobile.Spell.IsCasting )
			{
				CheckRun( c );
			}

			return true;
		}

		public override bool DoActionGuard()
		{
		m_Mobile.DebugSay( "I am on guard");
			if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
			{
				if ( m_Mobile.Debug )
					m_Mobile.DebugSay( "I am going to attack {0}", m_Mobile.FocusMob.Name );

				m_Mobile.Combatant = m_Mobile.FocusMob;
				Action = ActionType.Combat;
			}
			
			
			
			if(m_Mobile.Hits<(m_Mobile.HitsMax-10) & 0.9>Utility.RandomDouble())DoHealingAction();
			else DoReveilAction();

			return base.DoActionGuard();
		}

		public override bool DoActionFlee()
		{
			Mobile c = m_Mobile.Combatant;
			m_Mobile.DebugSay( "I am fleeing");
			
            if ( m_Mobile.Hits > (m_Mobile.HitsMax / 2) )
			{
				m_Mobile.DebugSay( "I am stronger now, my guard is up" );
				Action = ActionType.Guard;
			}
			else if ( AcquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
			{
				if ( m_Mobile.Debug )
					m_Mobile.DebugSay( "I am scared of {0}", m_Mobile.FocusMob.Name );

				RunFrom( m_Mobile.FocusMob );
				m_Mobile.FocusMob = null;
			}
			else if (m_Mobile.Hits > (m_Mobile.HitsMax / 3))
			{
				m_Mobile.DebugSay( "Area seems clear, but my guard is up" );

				Action = ActionType.Guard;
				m_Mobile.Warmode = true;
			}

			return true;
		}

		public Mobile FindDispelTarget( bool activeOnly )
		{
			if ( m_Mobile.Deleted || m_Mobile.Int < 95 || CanDispel( m_Mobile ) || m_Mobile.AutoDispel )
				return null;

			if ( activeOnly )
			{
				List<AggressorInfo> aggressed = m_Mobile.Aggressed;
				List<AggressorInfo> aggressors = m_Mobile.Aggressors;

				Mobile active = null;
				double activePrio = 0.0;

				Mobile comb = m_Mobile.Combatant;

				if ( comb != null && !comb.Deleted && comb.Alive && !comb.IsDeadBondedPet && m_Mobile.InRange( comb, 12 ) && CanDispel( comb ) )
				{
					active = comb;
					activePrio = m_Mobile.GetDistanceToSqrt( comb );

					if ( activePrio <= 2 )
						return active;
				}

				for ( int i = 0; i < aggressed.Count; ++i )
				{
					AggressorInfo info = (AggressorInfo)aggressed[i];
					Mobile m = (Mobile)info.Defender;

					if ( m != comb && m.Combatant == m_Mobile && m_Mobile.InRange( m, 12 ) && CanDispel( m ) )
					{
						double prio = m_Mobile.GetDistanceToSqrt( m );

						if ( active == null || prio < activePrio )
						{
							active = m;
							activePrio = prio;

							if ( activePrio <= 2 )
								return active;
						}
					}
				}

				for ( int i = 0; i < aggressors.Count; ++i )
				{
					AggressorInfo info = (AggressorInfo)aggressors[i];
					Mobile m = (Mobile)info.Attacker;

					if ( m != comb && m.Combatant == m_Mobile && m_Mobile.InRange( m, 12 ) && CanDispel( m ) )
					{
						double prio = m_Mobile.GetDistanceToSqrt( m );

						if ( active == null || prio < activePrio )
						{
							active = m;
							activePrio = prio;

							if ( activePrio <= 2 )
								return active;
						}
					}
				}

				return active;
			}
			else
			{
				Map map = m_Mobile.Map;

				if ( map != null )
				{
					Mobile active = null, inactive = null;
					double actPrio = 0.0, inactPrio = 0.0;

					Mobile comb = m_Mobile.Combatant;

					if ( comb != null && !comb.Deleted && comb.Alive && !comb.IsDeadBondedPet && CanDispel( comb ) )
					{
						active = inactive = comb;
						actPrio = inactPrio = m_Mobile.GetDistanceToSqrt( comb );
					}

					foreach ( Mobile m in m_Mobile.GetMobilesInRange( 12 ) )
					{
						if ( m != m_Mobile && CanDispel( m ) )
						{
							double prio = m_Mobile.GetDistanceToSqrt( m );

							if ( !activeOnly && (inactive == null || prio < inactPrio) )
							{
								inactive = m;
								inactPrio = prio;
							}

							if ( (m_Mobile.Combatant == m || m.Combatant == m_Mobile) && (active == null || prio < actPrio) )
							{
								active = m;
								actPrio = prio;
							}
						}
					}

					return active != null ? active : inactive;
				}
			}

			return null;
		}

		public bool CanDispel( Mobile m )
		{
			return ( m is BaseCreature && ((BaseCreature)m).Summoned && m_Mobile.CanBeHarmful( m, false ) && !((BaseCreature)m).IsAnimatedDead );
		}

		private static int[] m_Offsets = new int[]
			{
				-1, -1,
				-1,  0,
				-1,  1,
				 0, -1,
				 0,  1,
				 1, -1,
				 1,  0,
				 1,  1,

				-2, -2,
				-2, -1,
				-2,  0,
				-2,  1,
				-2,  2,
				-1, -2,
				-1,  2,
				 0, -2,
				 0,  2,
				 1, -2,
				 1,  2,
				 2, -2,
				 2, -1,
				 2,  0,
				 2,  1,
				 2,  2
			};

		private void ProcessTarget( Target targ )
		{
			bool isDispel = ( targ is DispelSpell.InternalTarget || targ is MassDispelSpell.InternalTarget);
			bool isParalyze = ( targ is ParalyzeSpell.InternalTarget );
			bool isTeleport = ( targ is TeleportSpell.InternalTarget );
			bool isReveal = (targ is RevealSpell.InternalTarget || targ is SkillHandlers.DetectHidden.InternalTarget);
			bool teleportAway = false;

			Mobile toTarget=m_Mobile.Combatant;

			if ( isDispel )
			{
				toTarget = FindDispelTarget( false );

				if ( !SmartAI && toTarget != null )
					RunTo( toTarget );
				else if ( toTarget != null && m_Mobile.InRange( toTarget, 10 ) )
					RunFrom( toTarget );
			}
			else if(isReveal) //target random land tile
			{
			Map map = m_Mobile.Map;
			int detectrange=targ.Range-2;
			
				for ( int i = 0; i < 30; ++i )
				{
					Point3D randomPoint = new Point3D( m_Mobile.X - detectrange + Utility.Random( detectrange * 2 + 1 ), m_Mobile.Y - detectrange + Utility.Random( detectrange * 2 + 1 ), 0 );

					LandTarget lt = new LandTarget( randomPoint, map );

					if ( m_Mobile.InLOS( lt ) )
					{
						targ.Invoke( m_Mobile, new LandTarget( randomPoint, map ) );
						return;
					}
				}

				targ.Cancel( m_Mobile, TargetCancelType.Canceled );	
			}
			else if ( SmartAI && (isParalyze || isTeleport) )
			{
				toTarget = FindDispelTarget( true );

				if ( toTarget == null )
				{
					toTarget = m_Mobile.Combatant;

					if ( toTarget != null )
						CheckRun( toTarget );
				}
				else if ( m_Mobile.InRange( toTarget, 10 ) )
				{
					RunFrom( toTarget );
					teleportAway = true;
				}
				else
				{
					teleportAway = true;
				}
			}
			else
			{
				toTarget = m_Mobile.Combatant;

				if ( toTarget != null )
					CheckRun( toTarget );
			}

			if ( (targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null)
			{
				if ( (targ.Range == -1 || m_Mobile.InRange( toTarget, targ.Range )) && m_Mobile.CanSee( toTarget ) && m_Mobile.InLOS( toTarget ) )
				{
					targ.Invoke( m_Mobile, toTarget );
				}
				else if ( isDispel )
				{
			       targ.Cancel( m_Mobile, TargetCancelType.Canceled );
				}
			}
			else if ( (targ.Flags & TargetFlags.Beneficial) != 0)
			{
				targ.Invoke( m_Mobile, m_Mobile );
			}			
			else if ( isTeleport && toTarget != null )
			{
				Map map = m_Mobile.Map;

				if ( map == null )
				{
					targ.Cancel( m_Mobile, TargetCancelType.Canceled );
					return;
				}

				int px, py;

				if ( teleportAway )
				{
					int rx = m_Mobile.X - toTarget.X;
					int ry = m_Mobile.Y - toTarget.Y;

					double d = m_Mobile.GetDistanceToSqrt( toTarget );

					px = toTarget.X + (int)(rx * (10 / d));
					py = toTarget.Y + (int)(ry * (10 / d));
				}
				else
				{
					px = toTarget.X;
					py = toTarget.Y;
				}

				for ( int i = 0; i < m_Offsets.Length; i += 2 )
				{
					int x = m_Offsets[i], y = m_Offsets[i + 1];

					Point3D p = new Point3D( px + x, py + y, 0 );

					LandTarget lt = new LandTarget( p, map );

					if ( (targ.Range == -1 || m_Mobile.InRange( p, targ.Range )) && m_Mobile.InLOS( lt ) && map.CanSpawnMobile( px + x, py + y, lt.Z ) && !SpellHelper.CheckMulti( p, map ) )
					{
						targ.Invoke( m_Mobile, lt );
						return;
					}
				}

				int teleRange = targ.Range;

				if ( teleRange < 0 )
					teleRange = 12;

				for ( int i = 0; i < 10; ++i )
				{
					Point3D randomPoint = new Point3D( m_Mobile.X - teleRange + Utility.Random( teleRange * 2 + 1 ), m_Mobile.Y - teleRange + Utility.Random( teleRange * 2 + 1 ), 0 );

					LandTarget lt = new LandTarget( randomPoint, map );

					if ( m_Mobile.InLOS( lt ) && map.CanSpawnMobile( lt.X, lt.Y, lt.Z ) && !SpellHelper.CheckMulti( randomPoint, map ) )
					{
						targ.Invoke( m_Mobile, new LandTarget( randomPoint, map ) );
						return;
					}
				}

				targ.Cancel( m_Mobile, TargetCancelType.Canceled );
			}
			else
			{
				targ.Cancel( m_Mobile, TargetCancelType.Canceled );
			}
			
		}
	}
}