All pastes #575414 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-19 00:47 UTC
rendered paste body
; Warlock routines, properly adjusted for warlocks. Original by Tenshi and Fluffster. 
; Updated by Steelx01, with modifications to downtime from Rumzuku.

;Leave this define Intact. Its testing if this file is loaded or not.
#define ROUTINES

;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------

; Desired pet.
#define PREFERREDPET Felguard

; Use Wand? 0 = NO   1 = YES    NOTE: If you are drain tanking you do not want to use your wand
#define USEWAND 0

; Use Siphon Life? 
#define SIPHON 0

; Use Immolate? 
#define IMMO 0

; Use Incinerate (only when immo is active)? 
#define INCI 0

; Use Shadowbolt to nuke? 
#define SB 0

; Use Conflagrate when ready? 
#define CONFLAG 0

; Use Unstable Affliction? 
#define UA 0

; Use Fear in case of emergency?
#define FEAR 0

; Use Howl Of Terror for multiple mobs? 
#define HOWL 1

; Use Seed of Corruption for multiple mobs? 
#define SEED 1

; Use Shadowbolt when in shadowtrance?
#define BOLT 1

; Use Shadowburn?
#define BURN 0

; How much soulshards you want minimum
#define SOULSHARDS 5

; Percentage of health you want to keep your pet above
#define PETHP 50

; Percentage of health you want to drain life at, set to around 90 for drain tanking and 60 for pet tanking
#define DRAIN 90
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------

;
; The CombatPrep function is called once you have selected a target but before you enter combat.
;
function CombatPrep()
{
	declare SoulShards int local
	declare ShardList guidlist local
	call Dismount


		; Lets Check our pet
		if ${Me.Pet.PctHPs}<PETHP&&${Me.PctHPs}>20&&${Me.Action[Health Funnel].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			echo "HF1"
			call CastSpell "Health Funnel"
			wait 50
		}
		
		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>99&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>60&&${Me.PctMana}<85&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>60&&${Me.PctMana}<85&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>60&&${Me.PctMana}<85&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>60&&${Me.PctMana}<85&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>60&&${Me.PctMana}<85&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		
		
		; If we are not sitting then lets do our downtime
		if !${Me.Sitting}
		{
			;Create a health stone if we dont have one
			call Create_HealthStone

			;If we dont have a PET make one NOW!
			if !${Me.Pet(exists)}
			{
				call UpdateHudStatus "Summoning a new pet"
				if (${Item[Soul Shard](exists)}&&${Spell[Summon PREFERREDPET](exists)}) || ${Spell[Summon PREFERREDPET](exists)}
 
                                                       	                if !${Me.Buff[Fel Domination](exists)}&&${Me.Action[Fel Domination].Usable}
                                                                                {
                                                                                            call CastSpell "Fel Domination"  ${Me.GUID}
					            wait 5
                                                                                }
				                {
					           call CastSpell "Summon PREFERREDPET"  ${Me.GUID}
					           wait 10
				                 }
			}

			; Check Fel Armor Buff
			if (!${Me.Buff[Fel Armor](exists)}&&${Spell[Fel Armor](exists)})
			{
				call UpdateHudStatus "Casting Fel Armor"
				call CastSpell "Fel Armor" ${Me.GUID}
			}

			; Check Demon Armor Buff
			if (!${Me.Buff[Demon Armor](exists)}&&!${Spell[Fel Armor](exists)})
			{
				call UpdateHudStatus "Casting Demon Armor"
				call CastSpell "Demon Armor" ${Me.GUID}
			}

			; Check Soul Link Buff
			if (!${Me.Buff[Soul Link](exists)}&&${Spell[Soul Link](exists)})
			{
				call UpdateHudStatus "Soul Link"
				call CastSpell "Soul Link" ${Me.GUID}
			}

			; Check Demon Skin Buff
			if (!${Me.Buff[Demon Skin](exists)}&&!${Spell[Demon Armor](exists)})
			{
				call UpdateHudStatus "Casting Demon Skin"
				call CastSpell "Demon Skin" ${Me.GUID}
			}

		}
DoCombatPrep:Set[FALSE]
}
function RoamPrep()


{

   declare tempint int local 0
   tempint:Inc
   declare HostileList guidlist local
   HostileList:Search[-players,-pvp,-nearest,-alive,-hostile,-range 0-100]
   if ${MyMount(exists)} && !${Me.Mount(exists)} && !${Me.Buff[Ghost](exists)} && !${Me.Buff[Wisp](exists)}  && !${HostileList.Count} && !${WoWScript[IsIndoors('player')]}
   {
      if ${MountSpell}
      {
         while ${Movement.Speed}
         {
            move -stop
           waitframe
         }
         cast "${MyMount}"
      }
      else
      {
         while ${Movement.Speed}
         {
            move -stop
           waitframe
         }
         Item["${MyMount}"]:Use
      }
      if ${Me.Casting}
      {
         while !${Me.Mount(exists)} && ${tempint} < 15
         {
            echo in loop...
            tempint:Inc
            wait 3
         }
      }
   }
}

/* START ADVANCEPREP CODE */
function AdvancePrep()
{
   declare tempint int local 0
   tempint:Inc
   declare HostileList guidlist local
   HostileList:Search[-players,-pvp,-nearest,-alive,-hostile,-range 0-100]
   if ${MyMount(exists)} && !${Me.Mount(exists)} && !${Me.Buff[Ghost](exists)} && !${Me.Buff[Wisp](exists)}  && !${HostileList.Count} && !${WoWScript[IsIndoors('player')]}
   {
      if ${MountSpell}
      {
         while ${Movement.Speed}
         {
            move -stop
           waitframe
         }
         cast "${MyMount}"
      }
      else
      {
         while ${Movement.Speed}
         {
            move -stop
           waitframe
         }
         Item["${MyMount}"]:Use
      }
      if ${Me.Casting}
      {
         while !${Me.Mount(exists)} && ${tempint} < 15
         {
            echo in loop...
            tempint:Inc
            wait 3
         }
      }
   }
}


function Dismount()
{
   if ${MountSpell}
   {
      while ${Me.Mount(exists)}
      {
         cast "${MyMount}"
         debug("Trying to remove my mount!")
         wait 2
      }
   }
   else
   {
      while ${Me.Mount(exists)}
      {
         Item["${MyMount}"]:Use
         debug("Trying to remove my mount!")
         wait 2
      }
   }
}
function Attack(string AttackGUID)
{

	declare SavX float local ${Me.X}
	declare SavY float local ${Me.Y}
	declare SavZ float local ${Me.Z}
	declare BailOut int local ${Math.Calc[${LavishScript.RunningTime}+(1000*${CombatBailout})]}
	declare HavePulled bool local FALSE
	declare StuckCheck bool local FALSE
	declare StuckCheckCount int local 0
	declare StuckCheckTime int local
	declare Aggros guidlist local
	declare MovedBackMulti bool local FALSE
	declare SoulShards int local
	declare ShardList guidlist local
	declare Wanding bool local FALSE
	declare Petsent bool local FALSE



	if ${AttackGUID.Equal[NULL]}||${AttackGUID.Equal[NOTARGET]}
	{
		call UpdateHudStatus "No target to attack"
	}

	call UpdateHudStatus "Attacking ${Object[${AttackGUID}].Name}"

	Do
	{
		SavX:Set[${Me.X}]
		SavY:Set[${Me.Y}]
		SavZ:Set[${Me.Z}]

		; Ensure we are still facing our target loc
		call SmartFacePrecision ${Object[${AttackGUID}].X} ${Object[${AttackGUID}].Y}

		; Check we still have a valid target
		if !${Object[${AttackGUID}](exists)}
		{
			call UpdateHudStatus "Target lost"
			TargetGUID:Set[NOTARGET]
			Return
		}

		; Check if the target is engaged already
		if ${Object[${AttackGUID}].Tapped}
		{
			call UpdateHudStatus "Target already engaged"
			TargetGUID:Set[NOTARGET]
			Return
		}
		

		; If we dont have our chosen unit targeted and were in range target it
		if !${Target.GUID.Equal[${AttackGUID}]}&&${Object[${AttackGUID}].Distance}<${TargetingRange}
		{
			#ifdef DEBUG
			call Debug "Targeting Unit ${Object[${AttackGUID}].Distance}[${AttackGUID}]"
			#endif
			Target ${AttackGUID}
			wait 10
		}

		; Once our target is in range turn on attack
		if !${Me.Attacking}&&${Target(exists)}&&!${Me.Equip[18](exists)}
		{
			WoWScript AttackTarget()
		}

		; Check we havent picked up an aggro other than the mob we have targeted.
		Aggros:Search[-units,-nearest,-aggro,-alive,-range 0-10,-players,-pvp flag]
		if !${HavePulled}&&${Aggros.Count}>0&&${Aggros[1].GUID.NotEqual[${AttackGUID}]}
		{
			debug("Untargeted Unit ${Object[${Aggros[1].GUID}].Name} has aggroed exiting Attack routine")
			return
		}
		Aggros:Clear

		; If we are not close enough for spell then move closer
		if ${Object[${AttackGUID}].Distance}>${PullingRange}
		{
			call UpdateHudStatus "Moving closer to target"
			call SmartFacePrecision ${Object[${AttackGUID}].X} ${Object[${AttackGUID}].Y}
			wowpress -hold moveforward
			wait 20
			wowpress -release moveforward
		}

		; Check if we have pulled yet and if not do so.
		if ${Object[${AttackGUID}].Distance}<${PullingRange}&&!${HavePulled}
		{

			if ${Me.Pet(exists)}
			{
				;call UpdateHudStatus "Sending in Pet"
				wowscript PetAttack()
				Petsent:Set[TRUE]
			}


			if ${Spell[Curse of Agony](exists)}&&!${Spell[Curse of Agony].Cooldown}
			{
				if ${Wanding}
				{
					Wanding:Set[FALSE]
					wowscript SpellStopCasting()
					wait 10
				}
				call CastSpell "Curse of Agony" ${AttackGUID}
				wait 5
			}
			else
			{
				; Were not high enough pull with Shadow Bolt
				if ${Wanding}
				{
					Wanding:Set[FALSE]
					wowscript SpellStopCasting()
					wait 10
				}

			}
			HavePulled:Set[TRUE]
		}


		; This should be called if we tried to pull but the mob was too far away
		if !${Me.Pet.Target(exists)}&&!${Petsent}
		{
			call UpdateHudStatus "Pet wasnt sent"
			wowscript PetAttack()
			Petsent:Set[TRUE]
		}
;----------------------------------------------------------------------------------------------------------
		; Start main attack routine
;----------------------------------------------------------------------------------------------------------

		Aggros:Search[-units,-nearest,-aggro,-alive,-range 0-20]
		if ${Aggros.Count}>2
		{
		                 if !${Unit[${AttackGUID}].Buff[Howl of Terror](exists)}&&${Me.Action[Howl of Terror].Usable}&&${Unit[${AttackGUID}].PctHPs}>30&&HOWL==1
		                {
			              call CastSpell "Howl of Terror" ${AttackGUID}
			              wait ${Me.Casting}
		                }

		                 if !${Unit[${AttackGUID}].Buff[Seed of Corruption](exists)}&&${Me.Action[Seed of Corruption].Usable}&&${Unit[${AttackGUID}].PctHPs}>20&&SEED==1
		                {
			              call CastSpell "Seed of Corruption" ${AttackGUID}
			              wait ${Me.Casting}
		                }
		}

		; Normal Attacks on Main Target
		; If all curses are on and we have a wand and not wanding lets wand
		if !${Wanding}&&!${Me.Casting}&&${Me.Equip[18](exists)}
                                {                        
			; Assume it is TRUE now and will turn off if not eligible
			Wanding:Set[TRUE]
			if ${Me.Action[Curse of Agony].Usable}
			{
				if !${Unit[${AttackGUID}].Buff[Curse of Agony](exists)}
				{
					; They dont have it why are we wanding?
					Wanding:Set[FALSE]
				}
			}

			if ${Me.Action[Curse of Agony].Usable}
			{
				if !${Unit[${AttackGUID}].Buff[Corruption](exists)}
				{
					; They dont have it why are we wanding?
					Wanding:Set[FALSE]
				}
			}

			if ${Me.Action[Siphon Life].Usable}&&SIPHON==1
			{
				if !${Unit[${AttackGUID}].Buff[Siphon Life](exists)}
				{
					; They dont have it why are we wanding?
					Wanding:Set[FALSE]
				}
			}

			if ${Me.Action[Unstable Affliction].Usable}&&UA==1
			{
				if !${Unit[${AttackGUID}].Buff[Unstable Affliction](exists)}
				{
					; They dont have it why are we wanding?
					Wanding:Set[FALSE]
				}
			}

			if ${Me.Action[Immolate].Usable}&&IMMO==1
			{
				if !${Unit[${AttackGUID}].Buff[Immolate](exists)}
				{
					; They dont have it why are we wanding?
					Wanding:Set[FALSE]
				}
			}

			if USEWAND==0
			{
				Wanding:Set[FALSE]
			}
			; Now that we have checked all Dots lets ethier wand or turn it off
			if ${Wanding}
			{
				call CastSpell "Shoot" ${AttackGUID}
			}
			else
			{
				wowscript SpellStopCasting()
				wait 5
			}
		}

		; We shouldnt be wanding now if we need to apply any of the spells listed below
		
		
		; Lets Check our pet
		if ${Me.Pet.PctHPs}<PETHP&&${Me.PctHPs}>20&&${Me.Action[Health Funnel].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			echo "HF3"
			call CastSpell "Health Funnel"
			wait 50
		}
		
		
		if !${Unit[${AttackGUID}].Buff[Siphon Life](exists)}&&${Me.Action[Siphon Life].Usable}&&${Unit[${AttackGUID}].PctHPs}>25&&SIPHON==1
		{
			call CastSpell "Siphon Life" ${AttackGUID}
			wait 5
		}
		
	    if !${Unit[${AttackGUID}].Buff[Corruption](exists)}&&${Me.Action[Corruption].Usable}&&${Unit[${AttackGUID}].PctHPs}>35
		{
			call CastSpell "Corruption" ${AttackGUID}
			wait 5
		}

		if !${Unit[${AttackGUID}].Buff[Curse of Agony](exists)}&&${Me.Action[Curse of Agony].Usable}&&${Unit[${AttackGUID}].PctHPs}>50
		{
			call CastSpell "Curse of Agony" ${AttackGUID}
			wait 5
		}

		if !${Unit[${AttackGUID}].Buff[Immolate](exists)}&&${Me.Action[Immolate].Usable}&&${Unit[${AttackGUID}].PctHPs}>50&&IMMO==1
		{
			call CastSpell "Immolate" ${AttackGUID}
			wait ${Me.Casting}
			wait 30
		}




		if !${Unit[${AttackGUID}].Buff[Unstable Affliction](exists)}&&${Me.Action[Unstable Affliction].Usable}&&${Unit[${AttackGUID}].PctHPs}>50&&UA==1
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Unstable Affliction" ${AttackGUID}
			wait ${Me.Casting}
		}

		if ${Me.Action[Shadow Bolt].Usable}&&${Me.PctMana}>40&&${Unit[${AttackGUID}].PctHPs}>30&&SB==1
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Shadow Bolt" ${AttackGUID}
			wait ${Me.Casting}
		}

		if ${Unit[${AttackGUID}].Buff[Immolate](exists)}&&${Me.Action[Incinerate].Usable}&&${Me.PctMana}>30&&${Unit[${AttackGUID}].PctHPs}>25&&INCI==1
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Incinerate" ${AttackGUID}
			wait ${Me.Casting}
		}

		if ${Unit[${AttackGUID}].Buff[Immolate](exists)}&&${Me.Action[Conflagrate].Usable}&&${Unit[${AttackGUID}].PctHPs}>20&&CONFLAG==1
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Conflagrate" ${AttackGUID}
			wait 5
		}

		if !${Me.Pet(exists)}&&!${Me.Buff[Fel Domination](exists)}&&${Me.Action[Fel Domination].Usable}
                                {

			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
                                                call CastSpell "Fel Domination"  ${Me.GUID}
			wait 5
			call CastSpell "Summon PREFERREDPET"  ${Me.GUID}
			wait 10
                                }


		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>89&&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}
		
		; If we are getting low on health lets suck it from the target
		if ${Me.PctHPs}<DRAIN&&${Me.Action[Drain Life].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Drain Life" ${AttackGUID}
			wait 5
		}


		; If I have Dark Pact and a pet I need its mana
		if ${Me.Pet(exists)}&&${Me.Action[Dark Pact].Usable}&&${Me.PctMana}<90&& ${Me.Pet.PctMana}>99
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
				echo "Pet has full mana, we need to take some of it, DARK PACT"
				call CastSpell "Dark Pact"
		}

		; If I have Dark Pact and a pet I need its mana
		if ${Me.Pet(exists)}&&${Me.Action[Dark Pact].Usable}&&${Me.PctMana}<50&& ${Me.Pet.PctMana}>10
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			if ${Me.Pet.PctMana}>10&&${Me.PctMana}<90
			{
				echo "My mana is less then 50%, pet has more then 10% mana, DARK PACT"
				call CastSpell "Dark Pact"
			}
		}

		; If mob is low on health and we need to drain its soul do it
		ShardList:Search[-items,-inventory,Soul Shard]
		if ${ShardList.Count}< SOULSHARDS && ${Unit[${AttackGUID}].PctHPs}<30
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Drain Soul" ${AttackGUID}
		}

		; If all is good and mana is low lets TAP some mana
		if ${Me.PctHPs}>95&${Me.PctMana}<56&${Me.Action[Life Tap].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Life Tap" ${Me.GUID}
			wait 5
		}

		; Lets Check our pet
		if ${Me.Pet.PctHPs}<50&&${Me.PctHPs}>20&&${Me.Action[Health Funnel].Usable}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			echo "HF2"
			call CastSpell "Health Funnel"
			wait 50
		}

		; If we are in a Shadow Trance toss that Shadow Bolt
		if ${Me.Buff[Shadow Trance](exists)}&&${Me.Action[Shadow Bolt].Usable}&&BOLT==1
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Shadow Bolt" ${AttackGUID}
		}

		; If we have Shadowburn and mob is < 30% and we have more then 3 Soul Shards toss it
		ShardList:Search[-items,-inventory,Soul Shard]
		if ${Me.Action[Shadowburn].Usable}&&${Unit[${AttackGUID}].PctHPs}<30&&${ShardList.Count}>3&&BURN==1
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
			call CastSpell "Shadowburn" ${AttackGUID}
		}
		; Check if we wish to flee combat or not
		Aggros:Search[-units,-nearest,-aggro,-alive, -range 0-${Math.Calc[${MaxRoam}/2]}]

                                ; If I am low or the pet is, fear
		if ${Me.PctHPs}<35||${Me.Pet.PctHPs}<30||!${Me.Pet(exists)}
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
		                if ${Me.Action[Fear].Usable}&&!${Unit[${AttackGUID}].Buff[Fear](exists)}&&${Object[${AttackGUID}].Distance}<20&&FEAR==1
                                                {
                                                                call CastSpell "Fear" ${AttackGUID}
			                wait ${Me.Casting}
                                                }
		}

		; If I am low, deathcoil
		if ${Me.PctHPs}<30
		{
			if ${Wanding}
			{
				Wanding:Set[FALSE]
				wowscript SpellStopCasting()
				wait 5
			}
		                if ${Me.Action[Death Coil].Usable}&&!${Unit[${AttackGUID}].Buff[Death Coil](exists)}
                                                {
                                                                call UpdateHudStatus "DEATHCOIL! I WIN!"
                                                                call CastSpell "Death Coil" ${AttackGUID}
                                                                wait 5
                                                }
		}

		; If we are still low use a health stone, and a health pot
		if ${Me.PctHPs}<25
		{
			call Use_HealthStone
                                                wait 5
                                                call DrinkBestHealingPotion
		}

		; Bail out of we are low
		if ${Me.PctHPs}<10
		{
			call UpdateHudStatus "LOW HEALTH BAILING OUT!"
			RLG:Set[TRUE]
			return
		}

		if (${Aggros.Count}>=${Math.Calc[${PanicThreshold}*2]})||(${Aggros.Count}>${PanicThreshold}&&(${Me.PctHPs}<40||((${Me.PctHPs}<20&&${Me.PctMana}<10)&&${Object[AttackGUID].PctHPs}>30))
		{
			call Debug "I have ${Aggros.Count} Aggro mobs. I'm fucked."
			RLG:Set[TRUE]
			return
		}
		Aggros:Clear

		;If too far away run forward
		if ${Object[${AttackGUID}].Distance}>${RangedMaxDist}&&!${Me.Casting}
		{
			debug("Too far closing")
			;press and hold the forward button
			wowpress -release movebackward
			wowpress -hold moveforward
		}

		;If too close then run backward
		if ${Object[${AttackGUID}].Distance}<${CombatMinDist}&&!${Me.Casting}
		{
			debug("Too close backing up")
			;press and hold the backward button
			wowpress -release moveforward
			wowpress -hold movebackward
		}

		;If we are close enough stop running
		if (${Object[${AttackGUID}].Distance}>${RangedMinDist}&&${Object[${AttackGUID}].Distance}<${RangedMaxDist})||${Me.Casting}
		{
			wowpress -release moveforward
			wowpress -release movebackward
			StuckCheck:Set[FALSE]
		}

		; Check to make sure we have moved if not then try and avoid the
		; obstacle thats in our path
		if ${Math.Distance[${Me.X},${Me.Y},${Me.Z},${SavX},${SavY},${SavZ}]}<1&&${Object[${AttackGUID}].Distance}>${RangedMaxDist}
		{
			; I think i might be stuck so save off the current time
			if !${StuckCheck}
			{
				debug("I might be stuck")
				StuckCheck:Set[TRUE]
				StuckCheckTime:Set[${LavishScript.RunningTime}]
			}
			else
			{
				; If I am still stuck after 5 seconds then try and avoid the obstacle.
				if ${Math.Calc[${LavishScript.RunningTime}-${StuckCheckTime}]}>5000
				{
					debug("Yep I am stuck trying to free myself")
					call Obstacle
					StuckCheckCount:Inc
					StuckCheck:Set[FALSE]
				}
			}
		}

		; If I have moved away from my saved spot reset my stuck toggle
		if ${StuckCheck}&&${Math.Distance[${Me.X},${Me.Y},${Me.Z},${SavX},${SavY},${SavZ}]}>3
		{
			debug("I am no longer stuck")
			StuckCheck:Set[FALSE]
			StuckCheckCount:Set[0]
		}

		;If I am stuck too many times then quit.
		if ${StuckCheckCount}>10
		{
			debug("Got stuck to often")
			call ExitGame
		}

		; Check if we have exceeded bail out timer and the mob is still at full health
		if ${LavishScript.RunningTime}>${BailOut}&&${Object[${TargetGUID}].PctHPs}>99
		{
			GUIDBlacklist:Set[${TargetGUID},AVOID]
			call UpdateHudStatus "Combat timeout reached"
			TargetGUID:Set[NOTARGET]
			return
		}
		call SmartFacePrecision ${Object[${AttackGUID}].X} ${Object[${AttackGUID}].Y}

	}
	while !${Object[${AttackGUID}].Dead}&&!${Me.Dead}

	; Update stats
	if !${Me.Dead}
	{
		call UpdateStats
	}

	wowpress -release movebackward
	wowpress -release moveforward


	;Reset flags to do combat prep and downtime if we are not still aggroed
	Aggros:Search[-units,-nearest,-aggro,-alive,-range 0-50]
	if !${Aggros.Count}
	{
		call Debug "Resetting Downtime and CombatPrep Flags"
		DoDowntime:Set[TRUE]
		DoCombatPrep:Set[TRUE]
	}
	Aggros:Clear
}


function Downtime()
{

	; If we are dead or a ghost why are we here?
	if ${Me.Dead} || ${Me.Ghost}
	{
		; Reset downtime flag
		DoDowntime:Set[FALSE]
		return
	}

	Do
	{
		; If I am full and still eatting or drinking lets stand back up
		if ${Me.Buff[Drink](exists)} || ${Me.Buff[Food](exists)}
		{
			if ${Me.PctMana}>99 && ${Me.PctHPs}>99
			{
				if ${Me.Sitting}
				{
					wowpress SITORSTAND
				}
			}
		}

		if ${Me.PctMana}<${MinManaPct}&&!${Me.Buff[Drink](exists)}
		{
			call Drink
			wait 15 ${Me.Buff[Drink](exists)}
		}
		if ${Me.PctHPs}<${MinHealthPct}&&!${Me.Buff[Food](exists)}
		{
			call Eat
			wait 15 ${Me.Buff[Food](exists)}
		}

		; If we are not sitting then lets do our downtime
		if !${Me.Sitting}
		{
			; Create a health stone if we dont have one
			call Create_HealthStone

		                if ${Me.PctHPs}>${MinHealthPct}&&${Me.PctMana}<${MinManaPct}&&${Me.Action[Life Tap].Usable}&&!${Me.Sitting}
		                {
			                 Cast "Life Tap" 
			                 wait 5
		                }

			;If we dont have a PET make one NOW!
			if !${Me.Pet(exists)}
			{
				call UpdateHudStatus "Summoning a new pet"
				if (${Item[Soul Shard](exists)}&&${Spell[Summon PREFERREDPET](exists)}) || ${Spell[Summon PREFERREDPET](exists)}
 
                                                       	                if !${Me.Buff[Fel Domination](exists)}&&${Me.Action[Fel Domination].Usable}
                                                                                {
                                                                                            call CastSpell "Fel Domination"  ${Me.GUID}
					            wait 5
                                                                                }
				                {
					           call CastSpell "Summon PREFERREDPET"  ${Me.GUID}
					           wait 10
				                 }
			}

			; Check Fel Armor Buff
			if (!${Me.Buff[Fel Armor](exists)}&&${Spell[Fel Armor](exists)})
			{
				call UpdateHudStatus "Casting Fel Armor"
				call CastSpell "Fel Armor" ${Me.GUID}
			}

			; Check Demon Armor Buff
			if (!${Me.Buff[Demon Armor](exists)}&&!${Spell[Fel Armor](exists)})
			{
				call UpdateHudStatus "Casting Demon Armor"
				call CastSpell "Demon Armor" ${Me.GUID}
			}

			; Check Soul Link Buff
			if (!${Me.Buff[Soul Link](exists)}&&${Spell[Soul Link](exists)})
			{
				call UpdateHudStatus "Soul Link"
				call CastSpell "Soul Link" ${Me.GUID}
			}

			; Check Demon Skin Buff
			if (!${Me.Buff[Demon Skin](exists)}&&!${Spell[Demon Armor](exists)})
			{
				call UpdateHudStatus "Casting Demon Skin"
				call CastSpell "Demon Skin" ${Me.GUID}
			}

			; Check Detect Invisibility Buff
			;if (!${Me.Buff[Detect Invisibility](exists)}&&${Spell[Detect Invisibility](exists)})
			;{
			;	call UpdateHudStatus "Casting Detect Invisibility"
			;	call CastSpell "Detect Invisibility" ${Me.GUID}
			;}

			; Check Detect Lesser Invisibility
			;if (!${Me.Buff[Detect Lesser Invisibility](exists)}&&${Spell[Detect Lesser Invisibility](exists)})&&!${Spell[Detect Invisibility](exists)}
			;{
			;	call UpdateHudStatus "Casting Detect Lesser Invisibility"
			;	call CastSpell "Detect Lesser Invisibility" ${Me.GUID}
			;}

		}

		; If we are dead or a ghost why are we here?
		if ${Me.Dead} || ${Me.Ghost}
		{
			; Reset downtime flag
			DoDowntime:Set[FALSE]
			return
		}

		; If we are in combat stop reseting
		if ${Me.InCombat}
		{
			call UpdateHudStatus "Agroed getting out of Downtime"
			DoDowntime:Set[FALSE]
			return
		}

                                ;check for full mana, no eating
                                if ${Me.Buff[Drink](exists)} && ${Me.PctMana}>99&&!${Me.Buff[Food](exists)}&&${Me.PctHPs}<99
                                {
                                         wowpress MOVEFORWARD
                                         wait 20
                                }

                                ;check for full hp, no drinking
                                if ${Me.Buff[Food](exists)}&&${Me.PctHPs}>99&&!${Me.Buff[Drink](exists)}&&${Me.PctMana}<99
                                {
                                         wowpress MOVEFORWARD
                                         wait 20
                                 }

                                  ;check for full hp and mana, both
                                  if ${Me.Buff[Food](exists)}&&${Me.PctHPs}>99&&${Me.Buff[Drink](exists)}&&${Me.PctMana}>99
                                 {
                                         wowpress MOVEFORWARD
                                         wait 20
                                 }

	}
	while ${Me.PctHPs}<${MinHealthPct} || ${Me.PctMana}<${MinManaPct} || ${Me.Buff[Drink](exists)} || ${Me.Buff[Food](exists)}

	if ${Me.Sitting}
	{
		wowpress SITORSTAND
	}


	; Reset downtime flag
	DoDowntime:Set[FALSE]
}

function Create_HealthStone()
{
	declare ShardList guidlist local

	; If we are already casting.. Return from here
	if ${Me.Casting}
	{
		return;
	}
	; If we already have a healthstone just return back
	if ${Item[Healthstone](exists)}
	{
		return
	}

	ShardList:Search[-items,-inventory,Soul Shard]

	; If we dont have enough shards then dont make
	if ${ShardList.Count}<= 1
	{
		call UpdateHudStatus "Not enough shards to make a health stone"
		return
	}

	if ${Spell[Create Healthstone (Master)](exists)}
	{
		cast "Create Healthstone (Master)"
		wait 40
		return
	} 

	if ${Spell[Create Healthstone (Major)](exists)}
	{
		cast "Create Healthstone (Major)"
		wait 40
		return
	}
	if ${Spell[Create Healthstone (Greater)](exists)}
	{
		cast "Create Healthstone (Greater)"
		wait 40
		return
	}
	if ${Spell[Create Healthstone](exists)}
	{
		cast "Create Healthstone"
		wait 40
		return
	}
	if ${Spell[Create Healthstone (Lesser)](exists)}
	{
		cast "Create Healthstone (Lesser)"
		wait 40
		return
	}
	if ${Spell[Create Healthstone (Minor)](exists)}
	{
		cast "Create Healthstone (Minor)"
		wait 40
		return
	}
}

function Use_HealthStone()
{

	if ${Item[Master Healthstone](exists)}
	{
		Item[Master Healthstone]:Use
		return
	}

	if ${Item[Major Healthstone](exists)}
	{
		Item[Major Healthstone]:Use
		return
	}
	if ${Item[Greater Healthstone](exists)}
	{
		Item[Greater Healthstone]:Use
		return
	}
	if ${Item[Healthstone](exists)}
	{
		Item[Healthstone]:Use
		return
	}
	if ${Item[Lesser Healthstone](exists)}
	{
		Item[Lesser Healthstone]
		return
	}
	if ${Item[Minor Healthstone](exists)}
	{
		Item[Minor Healthstone]:Use
		return
	}

}