All pastes #436004 Raw Edit

Someone

public text v1 · immutable
·published 2007-04-12 09:10 UTC
rendered paste body
/*
Mage routine for ByteBot rev.470 by B7731

Big thanks go to Arbiter for bugreports and suggestions.


Changes:
31.3.2007 - Added Racial 'Gift of the Naaru'
						Added Additional GUI Error Msg Checks

21.3.2007 - Added Line of sight check. (thank Weebs for making it)

20.3.2007 - Lots of bugfixes
					- Seperate console in GUI for bot actions (taken from azeroths code)

19.3.2007 - Fixed mob immunity detection and spell selection based on that
					- Code cleaned up a bit
					- Intelligent strafe spot finding after frost nova (modified bytelock's res spot code)
					- Fixed but in targetting

17.3.2007 - Rewrite of Sheeping routine
					- Rewrite of Pet freeze pull

15.3.2007 - Potions
					- Removed targetting for buffs so turn on auto self cast on wow settings

14.3.2007 - Various bugfixes

12.3.2007 - Fixed a bug where the toon didnt backup from too close melee range
					- Added the use of wand & GUI option for it
					- Now only casts evocation if target is frozen or you have shield spell active
					- Fixed turning problem after kill

11.3.2007 -	Fixed automatic frost & fire ward use.
					- Fixed some double casting issues.
					- Fixed Mana stones
					- Added Scorch use percentage to GUI

10.3.2007	- Seperated Talent based combat code
					- Debug made easier by displaying all combat actions in GUI
					- Heavy modifications to NeedPull as bbot core changed
					- Some tweaking to combat sequence

9.3.2007	- Bug fixes to pulling and AOE use
					- Improments on spell range detection
					- Improved rest pulse

8.3.2007	- Pull range based on spell selection & talents
					- Changed the pull routine to use bbot grind loop
					- Added Sheep adds / stop using AOE spells when sheeped nearby
					- Modified Target priorities to take polymorph and health in account
					- Added Decursing, detection code from Shaman routine by Azeroth

7.3.2007 	- Mage specific GUI for adjusting combat behaviour
					- Improments in Combat logic
					- Forgotten Mana Shield added
					- Variable saving to ToonConfig
					- Added Upper limits for drinking and eating
					- Fixed Mob Level range changing in GUI

Features:
Water, food, mana stone - conjure and use.
- Uses mosts buffs available for mage.
- Detects and uses trinkets.
- Handles Water elemental during combat.
- Prebuff for fight and cast appropriate buffs during fight
- Uses some racial abilities. (mana tap, berserking)
- Chooses damage spell sequence by talents. (room to improve)
- Reactive use of: Frost Ward, Fire Ward & Dampen magic
- Immunity Detection & spell selection (Idea and some of the code from stealthy's routine so big credits to him)

 To Do:	
 					Improve spec detection
					Escaping
					Blink
*/

#define TOON_FROZENBACKUP 20
#define TOON_COMBATBUFF 21
#define TOON_LOWMANA 22
#define TOON_LOWHEALTH 23
#define TOON_RETARGET_SHEEP 24

#define SPEC_FIRE 0
#define SPEC_FROST 1
#define SPEC_ARCANE 2

objectdef oToon inherits oToonBase
{
	/*
	 * Public var
	 */
	 
	variable int MinCombatRange = 3
	variable int MaxCombatRange = 29
	variable int PrimaryStat = STAT_INT
	variable int SecondaryStat = STAT_STA
	variable bool DismountOnAggro = TRUE
	
	variable bool UseFireWard = FALSE
	variable bool UseFrostWard = FALSE
	variable bool NeedDampenMagic = FALSE
	
	variable string PullSpell = "Automatic"
	variable string ArmorSpell = "Automatic"
	variable string ShieldSpell = "Automatic"
	variable string Wards = "Automatic"
	variable string DampenMagic = "Automatic"
	variable int ShieldPCT = 110
	variable int PullRange = -1
	variable int ScorchPCT = 110
	variable int WandPCT = 10
	variable bool UseAOE = TRUE
	variable bool Trinkets = TRUE
	variable bool Racials = TRUE
	variable bool Sheep = TRUE
	
	variable int MinMana = 60
	variable int MaxMana = 95
	variable int MinHealth = 60
	variable int MaxHealth = 95
	variable int LevelBelow = 4
	variable int LevelAbove = 2
	
	variable int RepairPct = 20
	variable int KeepFreeSlots = 3
	variable bool AutoPvP = TRUE
	variable bool AutoTrainSkills = TRUE
	variable bool DismountOnAggro = FALSE
	
	variable string SheepTarget = ""
	
	variable index:string FireResistant
	variable index:string FrostResistant
	variable index:string ArcaneResistant
	
	/*
	 * Botnet 
	 */
	
	variable int TankRating = 0
	variable int HealRating = 0
	variable int DpsRating = 10
	variable int CanResurrect = 0
	
	
	/****************************************************************
	 *    Targetting Start
	 ***************************************************************/
	member WantTarget(string GUID)
	{
		variable objectref Obj
		Obj:Set[${GUID}]
		
		if ${Obj.GUID.Equal[${Me.GUID}]}
		{
			return FALSE
		}
		
		/*
		* Keep aggro related first!
		*/
		if ${Environment.ImTheTarget[${GUID}]}
		{
			return TRUE
		}

		switch ${Obj.Type}
		{
			case Player
				if ${Obj.Level} > ${This.TargetMaxLevel}
				{
					return FALSE
				}
				
				return TRUE
				break
			default
				;Keep first
				if !${Grind.InRoamRange[${GUID}]}
				{
					echo "Dont want ${GUID} ${Obj.Name} (out of roam range)"
					return FALSE
				}
				if ${Obj.Tapped} && !${Party.Members}
				{
					return FALSE
				}

				if ${Environment.NeutralNPC[${GUID}]}
				{
					return FALSE
				}
	      
				if ${Math.Distance[${Me.Z},${Obj.Z}]} > 5 && ${Math.Distance[${Me.Location},${Obj.Location}]} < 20
				{
					return FALSE
				}

				if ${Obj.Level} < ${Math.Calc[${Me.Level} - ${LevelBelow}]}
				{
					return FALSE
				}

				if ${Obj.Level} > ${Math.Calc[${Me.Level} + ${LevelAbove}]}
				{
					return FALSE
				}

				if ${Obj.FactionGroup.Equal[${Me.FactionGroup}]}
				{
					return FALSE
				}

		/*	if ${Environment.TargetFriendCount[${Obj.GUID}]} > ${Party.Members}
				{
					return FALSE
				}
			
				if !${Target.LineOfSight}
				{
					return FALSE
					echo "Dont want ${GUID} ${Obj.Name} (not in line of sight)"
				}
		*/		
		
				;Keep last
				if ${Environment.WillCollide[${Me.X},${Me.Y},${Math.Calc[${Me.Z} + 1]}],${Obj.X},${Obj.Y},${Math.Calc[${Obj.Z} + 1]}}
				{
					return FALSE
				}
				break
		}

		return TRUE
	}

	member TargetPriority(string GUID, int BasePriority)
	{
		variable objectref Data
		variable int Priority
		Data:Set[${GUID}]

		Priority:Set[${BasePriority}]
		
		if ${Environment.ImTheTarget[${GUID}]} || ${Data.Aggro}
		{
			Priority:Dec[50]
		}
		
		switch ${Data.Type}
		{
			case Player
				break
			default
				switch ${Data.ReactionLevel}
				{
					case 2
						Priority:Dec[20]
						break
					case 3
						Priority:Dec[10]
						break
					case 4
						Priority:Inc[20]
						break
				}
				break
		}

		Priority:Inc[${Data.Distance}]
		Priority:Dec[${Math.Calc[(100 - ${Data.PctHPs}) * 2]}] 
		
		if ${Target(exists)} && (${Target.GUID.Equal[${Data.GUID}]} || ${Me.Pet.Target.GUID.Equal[${Data.GUID}]})
		{
			Priority:Dec[5]
		}
		
		/* Last target of our spells get more priority, fix for target switching on pulls */
		if ${Data.GUID.Equal[${SpellTargetGUID}]}
		{
			Priority:Dec[20]
		}
		
		/* Keep the sheeped last  */
		if ${Data.Buff[Polymorph](exists)}
		{
			Priority:Inc[40]
		}	
		
		/* just a precautio */
		if ${Data.GUID.Equal[${Me.GUID}]}
		{
			Priority:Inc[1000]
		}
		
		return ${Priority}
	}
	
	method TargetSwitched()
	{
		if ${Me.Pet(exists)}
		{	
	  	WoWScript PetStopAttack()
	  }
	  if ${Me.Casting}
		{ 
	  	WoWScript SpellStopCasting()
	  }
	}
	/****************************************************************
	 *    Targetting end
	 ***************************************************************/
	 
	

	/****************************************************************
	 *    Buff start
	 ***************************************************************/	 
	member NeedBuff()
	{	
		if ${Me.Casting}
		{
			return FALSE
		}
		if !${Me.Buff[Arcane Intellect](exists)} && ${Spell[Arcane Intellect](exists)}
    { 
			return TRUE
    }
    if !${Me.Buff[Ice Barrier](exists)} && ${Spell[Ice Barrier](exists)} && (${This.ShieldSpell.Equal[Automatic]} || ${This.ShieldSpell.Equal[Ice Barrier]}) && ${This.ShieldPCT} == 110
    { 
			return TRUE
    }
     if !${Me.Buff[Mana Shield](exists)} && ${Spell[Mana Shield](exists)} && ((${This.ShieldSpell.Equal[Automatic]} && !${Spell[Ice Barrier](exists)}) || ${This.ShieldSpell.Equal[Mana Shield]}) && ${This.ShieldPCT} == 110 && !${This.ShieldSpell.Equal[Ice Barrier]}
    { 
			return TRUE
    }
    if !${Me.Buff[Molten Armor](exists)} && !${Me.Buff[Ice Armor](exists)} && !${Me.Buff[Frost Armor](exists)}
    { 
			return TRUE
    }
    if ${Me.Action["Conjure ${This.GetManaStone}"].Usable} && !${Item[${This.GetManaStone}](exists)}
    { 
			return TRUE
    }
    if ${Me.Action[Dampen Magic].Usable} && !${Me.Buff[Dampen Magic](exists)} && ${This.DampenMagic.Equal[Always On]}
    { 
			return TRUE
    }
    if ${Spell[Remove Lesser Curse](exists)} && ${This.NeedDecurse}
    { 
			return TRUE
    }
    
    
		return FALSE 
	}

	method BuffPulse()
	{
		if ${Target(exists)}
		{
			WoWScript ClearTarget()
		}
		elseif ${Me.Action[Remove Lesser Curse].Usable} && ${This.NeedDecurse}
    { 
    	This:Echo["Buff Pulse Casting: Remove Lesser Curse -> Self"]
			This:CastInstantSpell[Remove Lesser Curse, ${Me.GUID}]
    }   
		elseif ${Me.Action[Arcane Intellect].Usable} && !${Me.Buff[Arcane Intellect](exists)}
    {
    	This:Echo["Buff Pulse Casting: Arcane Intellect"]
			This:CastInstantSpell[Arcane Intellect, ${Me.GUID}]
    }  
    elseif ${Me.Action[Molten Armor].Usable} && !${Me.Buff[Molten Armor](exists)} && (${This.ArmorSpell.Equal[Automatic]} || ${This.ArmorSpell.Equal[Molten Armor]})
    { 
    	This:Echo["Buff Pulse Casting: Molten Armor"]
			This:CastInstantSpell[Molten Armor]
    }
    elseif ${Me.Action[Ice Armor].Usable} && !${Me.Buff[Ice Armor](exists)} && ((!${Spell[Molten Armor](exists)} && ${This.ArmorSpell.Equal[Automatic]}) || ${This.ArmorSpell.Equal[Ice Armor]})
    { 
    	This:Echo["Buff Pulse Casting: Ice Armor"]
			This:CastInstantSpell[Ice Armor]
    }
    elseif ${Me.Action[Frost Armor].Usable} && !${Me.Buff[Frost Armor](exists)} && ((!${Spell[Molten Armor](exists)} && !${Spell[Ice Armor](exists)} && ${This.ArmorSpell.Equal[Automatic]}) || ${This.ArmorSpell.Equal[Frost Armor]})
    { 
    	This:Echo["Buff Pulse Casting: Frost Armor"]
			This:CastInstantSpell[Frost Armor]
    }
    elseif ${Me.Action[Dampen Magic].Usable} && !${Me.Buff[Dampen Magic](exists)} && ${This.DampenMagic.Equal[Always On]}
    {
    	This:Echo["Buff Pulse Casting: Dampen Magic"]
			This:CastInstantSpell[Dampen Magic, ${Me.GUID}]
    }
    elseif ${Me.Action[Ice Barrier].Usable} && !${Me.Buff[Ice Barrier](exists)} && (${This.ShieldSpell.Equal[Automatic]} || ${This.ShieldSpell.Equal[Ice Barrier]}) && ${This.ShieldPCT} == 110
    { 
    	This:Echo["Buff Pulse Casting: Ice Barrier"]
			This:CastInstantSpell[Ice Barrier]
    }
    elseif ${Me.Action[Mana Shield].Usable} && !${Me.Buff[Mana Shield](exists)} && ((${This.ShieldSpell.Equal[Automatic]} && !${Spell[Ice Barrier](exists)}) || ${This.ShieldSpell.Equal[Mana Shield]}) && ${This.ShieldPCT} == 110 && !${This.ShieldSpell.Equal[Ice Barrier]}
    { 
    	This:Echo["Buff Pulse Casting: Mana Shield"]
			This:CastInstantSpell[Mana Shield]
    }
    elseif ${Me.Action["Conjure ${This.GetManaStone}"].Usable} && !${Item[${This.GetManaStone}](exists)}
    {    	
    	This:Echo["Buff Pulse Conjuring Manastone"]
			This:CastInstantSpell[Conjure ${This.GetManaStone}]
    }     
	}
	
	member NeedCombatBuff()
	{
    if ${Me.Action[Dampen Magic].Usable} && !${Me.Buff[Dampen Magic](exists)} && ((${This.DampenMagic.Equal[Automatic]} && ${This.NeedDampenMagic}) || ${This.DampenMagic.Equal[Always On]})
    { 
			return TRUE
    } 
    if ${Me.Action[Cold Snap].Usable} && !${Me.Buff[Ice Barrier](exists)} && ${Spell[Ice Barrier](exists)} && !${This.ShieldSpell.Equal[Off]} && !${This.ShieldSpell.Equal[Mana Barrier]} && ${This.ShieldPCT} > ${Me.PctHPs} && ${Me.PctHPs} < 50
    { 
			return TRUE
    }
   	if ${Me.Action[Ice Barrier].Usable} && !${Me.Buff[Ice Barrier](exists)} && (${This.ShieldSpell.Equal[Automatic]} || ${This.ShieldSpell.Equal[Ice Barrier]}) && ${This.ShieldPCT} > ${Me.PctHPs} 
    { 
			return TRUE
    }
    if ${Me.Action[Mana Shield].Usable} && !${Me.Buff[Mana Shield](exists)} && ((${This.ShieldSpell.Equal[Automatic]} && ${Me.PctHPs} < 30 && ${Me.PctMana} > 30) || ${This.ShieldSpell.Equal[Mana Shield]}) && ${This.ShieldPCT} > ${Me.PctHPs} && !${This.ShieldSpell.Equal[Ice Barrier]}
    { 
			return TRUE
    }
    if ${This.TrinketUsable} && ${Target.PctHPs} > 50 && ${This.Trinkets}
    { 
			return TRUE
    }
    if ${Me.Action[Combustion].Usable} && !${Me.Buff[Combustion](exists)}
    { 
			return TRUE
    }
    if ${Me.Action[Presence of Mind].Usable} && !${Me.Buff[Presence of Mind](exists)}
    { 
			return TRUE
    }
    if ${Me.Action[Berserking].Usable} && ${Me.PctHPs} < 30 && ${Target.PctHPs} > 20 && ${This.Racials}
    { 
			return TRUE
    }
    if ${Me.Action[Frost Ward].Usable} && !${Me.Buff[Frost Ward](exists)} && ((${This.UseFrostWard} && ${This.Wards.Equal[Automatic]}) || ${This.Wards.Equal[Frost On]})
		{ 
			return TRUE
		}
		if ${Me.Action[Fire Ward].Usable} && !${Me.Buff[Fire Ward](exists)} && ((${This.UseFireWard} && ${This.Wards.Equal[Automatic]}) || ${This.Wards.Equal[Fire On]})
		{ 
			return TRUE
		} 
    if ${Me.Action[Gift of the Naaru].Usable} && ${Me.PctHPs} < 40 && ${Target.PctHPs} > 20 && ${This.Racials}
    { 
			return TRUE
    }
		return FALSE 
	}

	method CombatBuffPulse()
	{
   if ${Me.Action[Dampen Magic].Usable} && !${Me.Buff[Dampen Magic](exists)} && ((${This.DampenMagic.Equal[Automatic]} && ${This.NeedDampenMagic}) || ${This.DampenMagic.Equal[Always On]})
   {
   		This:Echo["Combat Buff Casting: Dampen Magic"]
			This:CastInstantSpell[Dampen Magic, ${Me.GUID}]
    }
 	 	elseif ${Me.Action[Cold Snap].Usable} && !${Me.Action[Ice Barrier].Usable} && !${Me.Buff[Ice Barrier](exists)} && !${This.ShieldSpell.Equal[Off]} && !${This.ShieldSpell.Equal[Mana Shield]} && ${This.ShieldPCT} > ${Me.PctHPs} && ${Me.PctHPs} < 50
		{
			This:Echo["Combat Buff Casting: Cold Snap"]
			This:CastInstantSpell[Cold Snap]
		}
		elseif ${Me.Action[Ice Barrier].Usable} && !${Me.Buff[Ice Barrier](exists)} && (${This.ShieldSpell.Equal[Automatic]} || ${This.ShieldSpell.Equal[Ice Barrier]}) && ${This.ShieldPCT} > ${Me.PctHPs}
		{
			This:Echo["Combat Buff Casting: Ice Barrier"]
			This:CastInstantSpell[Ice Barrier]
		}
		elseif ${Me.Action[Mana Shield].Usable} && !${Me.Buff[Mana Shield](exists)} && ((${This.ShieldSpell.Equal[Automatic]} && ${Me.PctHPs} < 30 && ${Me.PctMana} > 30) || ${This.ShieldSpell.Equal[Mana Shield]}) && ${This.ShieldPCT} > ${Me.PctHPs} && !${This.ShieldSpell.Equal[Ice Barrier]}
    { 
    	This:Echo["Combat Buff Casting: Mana Shield"]
			This:CastInstantSpell[Mana Shield]
    }		
		elseif ${Me.Action[Fire Ward].Usable} && !${Me.Buff[Fire Ward](exists)} && ((${This.UseFireWard} && ${This.Wards.Equal[Automatic]}) || ${This.Wards.Equal[Fire On]})
		{ 
			This:Echo["Fire damage detected. Casting:Fire Ward"]
			This:CastInstantSpell[Fire Ward]
		} 
		elseif ${Me.Action[Frost Ward].Usable} && !${Me.Buff[Frost Ward](exists)} && ((${This.UseFrostWard} && ${This.Wards.Equal[Automatic]}) || ${This.Wards.Equal[Frost On]})
		{ 
			This:Echo["Frost damage detected. Casting:Frost Ward"]
			This:CastInstantSpell[Frost Ward]
		} 
		elseif ${This.TrinketUsable} && ${Target.PctHPs} > 50 && ${This.Trinkets}
		{
			This:Echo["Combat Buff: Using Trinket"]
			This:UseTrinket
		}
		elseif ${Me.Action[Combustion].Usable} && !${Me.Buff[Combustion](exists)}
		{	
			This:Echo["Combat Buff Casting: Combustion"]
			This:CastInstantSpell[Combustion]
		}
		elseif ${Me.Action[Presence of Mind].Usable} && !${Me.Buff[Presence of Mind](exists)}
		{
			This:Echo["Combat Buff Casting: Presence of Mind"]
			This:CastInstantSpell[Presence of Mind]
	 	}
	 	elseif ${Me.Action[Berserking].Usable} && ${Me.PctHPs} < 30 && ${Target.PctHPs} > 20 && ${This.Racials}
		{
			This:Echo["Combat Buff Casting: Berserking"]
			This:CastInstantSpell[Berserking]
		}	 
	 	elseif ${Me.Action[Gift of the Naaru].Usable} && ${Me.PctHPs} < 40 && ${Target.PctHPs} > 20 && ${This.Racials}
		{
			This:Echo["Combat Buff Casting: Gift of the Naaru"]
			This:CastSpell[Gift of the Naaru]
		}	 
	}	
	/****************************************************************
	 *    Buff end
	 ***************************************************************/
	 
	
	/****************************************************************
	 *    Rest start
	 ***************************************************************/	
	member NeedRest()
	{
		if ${Me.PctMana} > ${This.MaxMana} && ${Me.PctHPs} > ${This.MaxHealth}
		{
			return FALSE
		}
		elseif ${Me.PctHPs} < ${This.MinHealth} || ${Me.PctMana} < ${This.MinMana} || ${Me.Buff[Drink](exists)} || ${Me.Buff[Food](exists)}
		{
			return TRUE
		}
		return FALSE
	}

	method RestPulse()
	{
		if ${Me.Action[Conjure Food].Usable} && !${Me.Buff[Drink](exists)} && !${Me.Buff[Food](exists)} && !${Consumable.GotFood} && !${Me.Casting}
		{
			This:Echo["Rest Pulse: Conjure Food"]
	    This:CastSpell[Conjure Food]
		}
		elseif ${Me.Action[Conjure Water].Usable} && !${Me.Buff[Drink](exists)} && !${Me.Buff[Food](exists)} && !${Consumable.GotDrink} && !${Me.Casting}
		{
			This:Echo["Rest Pulse: Conjure Water"]
	    This:CastSpell[Conjure Water]
		}
		elseif !${Me.Buff[Drink](exists)} && (${Me.PctMana} < ${This.MinMana} || (${Me.Buff[Food](exists)} && ${Me.PctMana} < ${This.MaxMana})) && ${Consumable.GotDrink} && !${Me.Casting}
		{
			This:Echo["Rest Pulse: Drink"]
	    Consumable:Drink
		}
		elseif !${Me.Buff[Food](exists)} && (${Me.PctHPs} < ${This.MinHealth} || (${Me.Buff[Drink](exists)} && ${Me.PctHPs} < ${This.MaxHealth})) && ${Consumable.GotFood} && !${Me.Casting}
		{
			This:Echo["Rest Pulse: Eat"]
	  	Consumable:Eat
	  }
	}
	/****************************************************************
	 *    Rest end
	 ***************************************************************/
	 
	
	/****************************************************************
	 *    Pull selection start
	 ***************************************************************/
	 
	member NeedPull()
	{
		if ${This.NeedBuff} || ${This.NeedRest} || ${Target.Dead} || !${Target(exists)} || ${Target.Tapped} || ${Me.InCombat} || ${Movement.Moving} || !${Target.LineOfSight}
		{
			return FALSE
		} 
		elseif ${Target.Distance} < ${This.GetPullRange}
		{
			return TRUE
		}
		return FALSE
	}
	
	method PullPulse()
	{
		if ${This.TrinketUsable} && ${This.Trinkets}
		{
			This:Echo["Pulling: Use Trinket"]
			This:UseTrinket
		}
		elseif !${This.isResistant[arcane]} && ((${This.PullSpell.Equal[Automatic]} && ${This.GetSpec} == SPEC_ARCANE) || ${This.PullSpell.Equal[Arcane Missiles]} || ${This.PullSpell.Equal[Arcane Blast]} || (${This.isResistant[frost]} && ${This.isResistant[fire]}))
		{
			This:ArcanePull
		}
		elseif !${This.isResistant[fire]} && ((${This.PullSpell.Equal[Automatic]} && ${This.GetSpec} == SPEC_FIRE) || ${This.PullSpell.Equal[Fireball]} || ${This.PullSpell.Equal[Pyroblast]} || ${This.isResistant[frost]} || ${This.isResistant[arcane]})
		{
			This:FirePull			
		}
		elseif !${This.isResistant[frost]} && ((${This.PullSpell.Equal[Automatic]} && ${This.GetSpec} == SPEC_FROST) || ${This.PullSpell.Equal[Frostbolt]} || ${This.isResistant[fire]})
		{
			This:FrostPull			
		}				
	}
	
	method ArcanePull()
	{
		if ${Me.Action[Arcane Power].Usable}
		{
			This:Echo["Pulling: Arcane Power"]
			This:CastInstantSpell[Arcane Power]
		}
	  elseif ${Me.Action[Arcane Blast].Usable} && (${This.PullSpell.Equal[Automatic]} || ${This.PullSpell.Equal[Arcane Blast]})
		{
			This:Echo["Pulling: Arcane Blast"]
			This:CastSpell[Arcane Blast]
		}
		elseif ${Me.Action[Arcane Missiles].Usable}
		{
			This:Echo["Pulling: Arcane Missiles"]
			This:CastSpell[Arcane Missiles]
		}
	}
	
	method FirePull()
	{
		if ${Me.Action[Pyroblast].Usable} && (${This.PullSpell.Equal[Automatic]} || ${This.PullSpell.Equal[Pyroblast]}) && ${Target.Distance} > 15
		{
			This:Echo["Pulling: Pyroblast"]
			This:CastSpell[Pyroblast]
		}
		elseif ${Me.Action[Fireball].Usable}
		{
			This:Echo["Pulling: Fireball"]
			This:CastSpell[Fireball]
		}
	}
	
	method FrostPull()
	{
		if ${Me.Action[Summon Water Elemental].Usable} && !${Me.Pet(exists)}
		{
			This:Echo["Pulling: Summon Water Elemental"]
			This:CastInstantSpell[Summon Water Elemental]
		}
		elseif ${Me.Pet(exists)} && ${Target.Distance} < 35 && ${This.UseAOE} && ${Me.Pet.Casting.Name.NotEqual[Freeze]}
		{
			This:Echo["Pulling: Pet Nova"]	
			
			This:CastPetNova	
	  	
	  	WoWScript PetAttack()
			WoWScript AttackTarget()
	  }
	 	elseif ${Me.Action[Frostbolt].Usable}
		{
			This:Echo["Pulling: Frostbolt"]
			This:CastSpell[Frostbolt]
		}	
	}
	
	method CastPetNova()
	{
		variable float X
		variable float Y
		variable float Z
		
		X:Set[${Target.X}]
		Y:Set[${Target.Y}]
		Z:Set[${Target.Z}]

		This.SpellTargetType:Set[SPELL_TARGET_GROUND]
		
		This.SpellTargetLocation.X:Set[${X}]
		This.SpellTargetLocation.Y:Set[${Y}]
		This.SpellTargetLocation.Z:Set[${Z}]
		
		WoWPress BONUSACTIONBUTTON5
		This:Wait[100]
	}
	
	/****************************************************************
	 *    Pull end
	 ***************************************************************/
	
	method Routine()
	{	
		variable string CurrentTarget
		
		if !${Me.Attacking} && ${Me.Target(exists)}
		{
			This:Echo["Attack: Autoattack"]
			WoWScript AttackTarget()			
		}				
	 	elseif ${Me.Buff[Presence of Mind](exists)}
	 	{
	 		This:Echo["Attack cast: Pyroblast"]
			if ${Me.Action[Pyroblast].Usable} && ${Target.Distance} < ${This.GetSpellRange[35, "fire"]} && !${This.isResistant[fire]}
			{
				This:Echo["Attack cast: POM Pyroblast"]
				This:CastInstantSpell[Pyroblast]
			}
			elseif ${Me.Action[Arcane Missiles].Usable} && ${Target.Distance} < ${This.GetSpellRange[30, "arcane"]} && !${This.isResistant[arcane]}
			{
				This:Echo["Attack cast: POM Arcane Missiles"]
				This:CastInstantSpell[Arcane Missiles]
			}
		}				
		elseif ${Me.Action[Counterspell].Usable} && ${Target.Casting.ID(exists)} && ${Target.CurrentMana} > 0 && !${This.isResistant[arcane]}
		{
			This:Echo["Attack cast: Counterspell"]
			This:CastInstantSpell[Counterspell]
		}			
		elseif ${Me.Buff[Clearcast](exists)} && ${Target.Distance} < ${This.GetSpellRange[30, "arcane"]} && ${Me.Action[Arcane Missiles].Usable} && !${This.isResistant[arcane]}
		{
			This:Echo["Attack cast: Clearcast Arcane Missiles"]
			This:CastSpell[Arcane Missiles]
		}		
		elseif ${Me.Action[Polymorph].Usable} && !${This.SheepTarget.Equal[""]} && !${Unit[${This.SheepTarget}].Buff[Polymorph](exists)} && ${Target.PctHPs} > 50 && ${This.Sheep}
		{
			This:Echo["Attack cast: Polymorph"]
			/* Fix by Weebs */
			CurrentTarget:Set[${Me.Target.GUID}]
			target ${This.SheepTarget}			
			This:CastSpell[Polymorph]
			target ${CurrentTarget}
		}		
		elseif ${Me.Action[Mana Tap].Usable} && ${Target.PctMana} > 0 && ${Target.Distance} < 30
  	{
  		This:Echo["Attack cast: Mana Tap"]
	    This:CastInstantSpell[Mana Tap]
	  }
	  elseif ${Me.Action[Arcane Torrent].Usable} && ${Me.PctMana} < 50 && ${Me.Buff[Mana Tap](exists)}
	  {
	  	This:Echo["Attack cast: Arcane Torrent"]
	    This:CastInstantSpell[Arcane Torrent]
	  }		
		elseif ${Me.Action[Fire Blast].Usable} && ${Target.Distance} < ${This.GetSpellRange[20, "fire"]} && !${This.isResistant[fire]}
		{
			This:Echo["Attack cast: Fire Blast"]
			This:CastInstantSpell[Fire Blast]
		}
		elseif ${Me.Action[Frost Nova].Usable} && ${Target.Distance} < ${This.GetSpellRange[10, "frost"]} && ${This.UseAOE} && ${This.SheepTarget.Equal[""]} && !${This.isFrozen} && !${This.isResistant[frost]}
		{
			This:Echo["Attack cast: Frost Nova"]
			This:CastInstantSpell[Frost Nova]
		}
		elseif ${Me.Action["Shoot"].Usable} && !${Me.Action["Shoot"].AutoRepeat} && ${Me.PctMana} < ${This.WandPCT}
   	{
   	This:Echo["Attack cast: Wand"]
      Me.Action["Shoot"]:Use
   	}   
		elseif ${This.GetSpec} == SPEC_ARCANE && !${This.isResistant[arcane]}
		{			
			This:ArcaneAttack
		}
		elseif ${This.isResistant[frost]}
		{
			This:FireAttack
		}
		elseif ${This.isResistant[fire]}
		{
			This:FrostAttack
		}	
		elseif ${This.GetSpec} == SPEC_FIRE 
		{
			This:FireAttack
		}
		elseif ${This.GetSpec} == SPEC_FROST
		{
			This:FrostAttack
		}	
		else
		{
			This:FireAttack
		}
	}
	
	method FrostAttack()
	{
		if !${Me.Pet.Target(exists)} && ${Me.Pet(exists)} && ${Me.Target(exists)}
		{
			This:Echo["Attack: Command Elemental to Attack"]
			WoWScript PetAttack()
		}
		elseif ${Me.Action[Ice Lance].Usable} && ${This.isFrozen} && ${Target.Distance} < ${This.GetSpellRange[30, "frost"]}
		{
			This:Echo["Attack cast: Ice Lance"]
			This:CastInstantSpell[Ice Lance]
		}
		elseif ${Me.Action[Cone of Cold].Usable} && ${Target.Distance} < ${This.GetSpellRange[10, "frost"]} && ${This.UseAOE} && ${This.SheepTarget.Equal[""]}
		{
			This:Echo["Attack cast: Cone of Cold"]
			This:CastInstantSpell[Cone of Cold]
		}
		elseif ${Me.Action[Frostbolt].Usable} && ${Target.Distance} < ${This.GetSpellRange[30, "frost"]}
		{
			This:Echo["Attack cast: Frostbolt"]
			This:CastSpell[Frostbolt]
		}
	}
	
	method FireAttack()
	{
		if ${Me.Action[Dragon's Breath].Usable} && ${Target.Distance} < ${This.GetSpellRange[10, "fire"]} && ${This.UseAOE} && ${This.SheepTarget.Equal[""]}
		{  
			This:Echo["Attack cast: Dragon's Breath"]
			This:CastInstantSpell[Dragon's Breath]
		} 
		elseif ${Me.Action[Scorch].Usable} && ${Target.Distance} < 10 && ${Target.PctHPs} < ${This.ScorchPCT}
		{
			This:Echo["Attack cast: Scorch"]
			This:CastSpell[Scorch]
		}
		elseif ${Me.Action[Fireball].Usable} && ${Target.Distance} < ${This.GetSpellRange[35, "fire"]}
		{
			This:Echo["Attack cast: Fireball"]
			This:CastSpell[Fireball]
		}
	}
	
	method ArcaneAttack()
	{
		if ${Me.Action[Arcane Blast].Usable} && ${Target.Distance} < ${This.GetSpellRange[30, "arcane"]}
		{
			This:Echo["Attack cast: Arcane Blast"]
			This:CastSpell[Arcane Blast]
		}		
		elseif ${Me.Action[Arcane Missiles].Usable} && ${Target.Distance} < ${This.GetSpellRange[30, "arcane"]}
		{
			This:Echo["Attack cast: Arcane Missiles"]
			This:CastSpell[Arcane Missiles]
		}
	}
	
	/*
	 * Attack
	 */
	
	member AttackState()
	{
		if ${This.Sheep}
		{
			This.SheepTarget:Set[${This.GetSheepTarget}]
		}
		
		if !${This.DoneWaiting}
		{
			This:SetStatus["Waiting"]
			return TOON_WAIT
		}

		if !${Me.Target(exists)} && ${Me.Pet.Target(exists)}
		{
			This:SetStatus["Assisting Pet"]
			return TOON_ASSIST_PET 
		}
			
		if ${This.ValidTarget} && !${Target.Dead} && ${Target.Distance} < 9 && ${This.isFrozen}
		{
			This:SetStatus["Creating some distance to frozen mob"]
			return TOON_FROZENBACKUP
		}

		if ${Target(exists)} && ${Math.Abs[${Me.Heading}-${Me.HeadingTo[${Target.X},${Target.Y}]}]} > ${Navigator.FacePercision} && ${Target.Distance} < ${This.GetPullRange}
		{
			This:SetStatus["Facing target"]
			return TOON_NEEDFACE
		}
		
		if ${WoWScript[SpellIsTargeting()]}
		{
			This:SetStatus["Spell waiting for target"]
			return TOON_SPELLTARGET
		}
				
		if ${Me.Casting} && !${This.NeedCastInterupt}
		{
			This:SetStatus["Casting a Spell"]
			return TOON_CASTING
		}
		
		if ${This.PreviousTarget.NotEqual[""]} && ${Object[${This.PreviousTarget}](exists)} 
		{
			This:SetStatus["Retargetting last mob"]
			return TOON_TARGETPREVIOUS
		}

		if ${Target.Dead}
		{
			This:SetStatus["Target dead. Cleanup."]
			return TOON_CLEARTARGET
		}
		
		if ${This.ValidTarget} && ${This.NeedPull} && !${Me.InCombat} && ${Target.Distance} <= ${This.GetPullRange}
		{
			This:SetStatus["Pulling"]
			return TOON_PULL
		}
		
		if ${This.ValidTarget} && ${Target.Distance} >= ${This.GetPullRange}
		{
			This:SetStatus["Closing distance"]
			return TOON_ENGAGE
		}
		
		if ${This.ValidTarget} && ${Target.Distance} < ${This.MinCombatRange}
		{
			This:SetStatus["Keeping minium combat range"]
			return TOON_BACKUP
		}		
		
		if ${Target(exists)} && ${Target.Distance} > ${This.MinCombatRange} && ${Movement.Moving} && ${Target.Distance} <= ${This.GetPullRange}
		{
			This:SetStatus["Stopping movement"]
			return TOON_STOPMOVE
		}		
		
		if ${This.NeedCombatBuff}
		{
			This:SetStatus["Combat Buffs"]
			return TOON_COMBATBUFF
		}
		
		if ${Me.InCombat} && ${Me.PctMana} < 10 && ${This.IsEmergencyMana} && ${This.ValidTarget}
		{
			This:SetStatus["Low on mana. Try to get more"]
			return TOON_LOWMANA
		}
		
		if ${This.ValidTarget} && ${Me.InCombat} && ${Me.PctHPs} < 10 && ${Consumable.GotHealPotion}
		{
			This:SetStatus["Low on health. Try to get more"]
			return TOON_LOWHEALTH
		}
							
		if ${ISXWoW.Facing}
		{
			This:SetStatus["Toon turning"]
			return TOON_FACING
		}
		This:SetStatus["Attacking"]
		return TOON_ATTACK		
	}

	method AttackPulse()
	{				
		This.CurrentState:Set[${This.AttackState}]
		; echo ${This.CurrentState}
		switch ${This.CurrentState}
		{
			case TOON_CASTING
				break		
			case TOON_NEEDFACE
				Navigator:FaceXYZ[${Target.X},${Target.Y},${Target.Z}]
				break
			case TOON_FACING
				break
			case TOON_BACKUP
			  Navigator:Backup[100]
				break
			case TOON_FROZENBACKUP
				if !${Movement.Moving}
				{
					Navigator:FaceXYZ[${Target.X},${Target.Y},${Target.Z}]
					This:MoveToNovaSpot
				}
				break
			case TOON_PULL
				This:PullPulse
				break
			case TOON_ASSIST_PET
				Target ${Me.Pet.Target.GUID}
				break
			case TOON_SPELLTARGET
				switch ${This.SpellTargetType}
				{
					case SPELL_TARGET_GUID
						SpellTarget ${This.SpellTargetGUID}
						if ${WoWScript[SpellIsTargeting()]}
						{
							WoWScript SpellStopTargeting()
						}
						break
					case SPELL_TARGET_GROUND
						if ${This.SpellTargetLocation.X} != 0 && ${This.SpellTargetLocation.Y} != 0 && ${This.SpellTargetLocation.Z} != 0
						{
							ISXWoW:ClickTerrain[${This.SpellTargetLocation.X},${This.SpellTargetLocation.Y},${This.SpellTargetLocation.Z}]
							This.SpellTargetLocation.X:Set[0]
							This.SpellTargetLocation.Y:Set[0]
							This.SpellTargetLocation.Z:Set[0]
						}
						break
				}
				break
			case TOON_ENGAGE
				if !${Navigator.MovingToObject[${Target.GUID},${This.GetPullRange}]}
				{
					Navigator:MoveTo[${Target.X}, ${Target.Y}, ${Target.Z}]
				}
				break
			case TOON_COMBATBUFF
				This:CombatBuffPulse
				break
			case TOON_LOWMANA
				This:ActivateEmergencyMana
				break
			case TOON_LOWHEALTH
				Consumable:UseHealPotion
				break			
			case TOON_ATTACK
				if ${Target(exists)}
				{
					This:Routine
				}
				break
			case TOON_TARGETPREVIOUS
				Target ${This.PreviousTarget}
				This.PreviousTarget:Set[""]
				break
			case TOON_STOPMOVE
				Navigator:ResetDestination
				move -stop
				break
			case TOON_CLEARTARGET
				This:ResetReactive
				WoWScript ClearTarget()
				break
			case TOON_WAIT
				break
		}
	}
	
	/****************************************************************
	 *    Target info start
	 ***************************************************************/
	member isFrozen()
	{
		if ${Target.Buff[Frostbite](exists)} || ${Target.Buff[Freeze](exists)} || ${Target.Buff[Frost Nova](exists)}
		{
			return TRUE
		}
		else
		{
			return FALSE
		}
	}	

	member GetSheepTarget()
	{
		variable guidlist Aggros
		variable int Idx = 1
		variable int LowestHpTarget = -1
		variable int HighLevelTarget = -1
		
		/* Addtional search for untapped mobs that are sheeped */
		Aggros:Search[-units,-nearest,-aggro,-alive,-range 0-35]
		if ${Aggros.Count} == 1
		{
			if ${Aggros.Object[1].Buff[Polymorph](exists)}
			{
				echo last mob & its a sheep triggered!
				Target ${Aggros.Object[1].GUID}
				return ${Aggros.Object[1].GUID}
			}			
		}		
		Aggros:Clear
		
		Aggros:Search[-units,-nearest,-aggro,-alive,-tappedbyme,-range 0-35]

		if ${Aggros.Count} > 1
		{
			Idx:Set[1]
			do
			{
				if (${Aggros.Object[${Idx}].CreatureType.Equal[Humanoid]} || ${Aggros.Object[${Idx}].CreatureType.Equal[Beast]}) && !${Aggros.Object[${Idx}].GUID.Equal[${Target.GUID}]}
				{
					LowestHpTarget:Set[${Idx}]
					HighLevelTarget:Set[${Idx}]
				}
			}
			while ${Idx:Inc} <= ${Aggros.Count}
			
			Idx:Set[1]
			do
			{
				if ${Aggros.Object[${Idx}].Buff[Polymorph](exists)}
				{
					return ${Aggros.Object[${Idx}].GUID}
				}
				elseif ${Aggros.Object[${Idx}].CreatureType.Equal[Humanoid]} || ${Aggros.Object[${Idx}].CreatureType.Equal[Beast]}
				{
					if ${Aggros.Object[${Idx}].PctHPs} < ${Aggros.Object[${LowestHpTarget}].PctHPs} && !${Aggros.Object[${Idx}].GUID.Equal[${Target.GUID}]}
					{
						LowestHpTarget:Set[${Idx}]
					}
					if ${Aggros.Object[${Idx}].Level} > ${Aggros.Object[${HighLevelTarget}].Level} && !${Aggros.Object[${Idx}].GUID.Equal[${Target.GUID}]}
					{
						HighLevelTarget:Set[${Idx}]
					}
				}				
			}
			while ${Idx:Inc} <= ${Aggros.Count}
			
			if ${Aggros.Object[${LowestHpTarget}].PctHPs} == 100 && ${HighLevelTarget} > 0
			{
				return ${Aggros.Object[${HighLevelTarget}].GUID}
			}
			elseif ${LowestHpTarget} > 0
			{
				return ${Aggros.Object[${LowestHpTarget}].GUID}
			}
			else
			{
				return ""
			}
		}
		elseif ${Aggros.Count} == 1 && ${Aggros.Object[1].Buff[Polymorph](exists)}
		{
			return ${Aggros.Object[1].GUID}
		}
		else
		{
			return ""
		}		
	}	
	/****************************************************************
	 *    Target info end
	 ***************************************************************/
	 
	 
	/****************************************************************
	 *    Spec & spell selection start
	 ***************************************************************/
	member GetPullRange()
	{
		if ${This.PullRange} == -1
		{
			switch ${This.PullSpell}
			{
				case "Automatic"
					if ${This.GetSpec} == SPEC_ARCANE
					{
						return 29
					}
					elseif ${This.GetSpec} == SPEC_FIRE
					{
						return ${This.GetSpellRange[35, "fire"]}
					}
				case "Frostbolt"
					return ${This.GetSpellRange[30, "fost"]}
					break
				case "Fireball"
				case "Pyroblast"
					return ${This.GetSpellRange[35, "fire"]}
					break
				case "Arcane Blast"
				case "Arcane Missiles"
					return 29
					break
			}		
			return 29
		}
		else
		{
			return ${This.PullRange}
		}
	}
	
	member GetSpellRange(int base, string spellTree)
	{
		if ${spellTree.Equal[fire]}
		{
			return ${Math.Calc[${base}+(3*${Me.Talent[Flame Throwing]})-1].Round}
		}
		elseif ${spellTree.Equal[frost]}
		{
			return ${Math.Calc[${base}*(1+(0.1*${Me.Talent[Arctic Reach]}))-1].Round}
		}
		return ${base}
	}
	
	member GetSpec()
	{	
		if ${Me.Talent[Improved Arcane Missiles]} > ${Me.Talent[Improved Fireball]} && ${Me.Talent[Improved Arcane Missiles]} > ${Me.Talent[Improved Frostbolt]}
		{
			return SPEC_ARCANE
		}
		elseif ${Me.Talent[Improved Frostbolt]} > ${Me.Talent[Improved Fireball]}
		{
			return SPEC_FROST
		}		
		return SPEC_FIRE
	}
	/****************************************************************
	 *    Spec & spell selection end
	 ***************************************************************/
	 
	 
	/****************************************************************
	 *    Trinkets & emergency selection start
	 ***************************************************************/
	member TrinketUsable()
	{	
		if ${Me.Action[${Me.Equip[trinket1]}].Usable} || ${Me.Action[${Me.Equip[trinket2]}].Usable}
		{
			return TRUE			
		}
		return FALSE
	}
	
	method UseTrinket()
	{
		if ${Me.Action[${Me.Equip[trinket1]}].Usable}
		{
			Item[${Me.Equip[trinket1]}]:Use
		}
		elseif ${Me.Action[${Me.Equip[trinket2]}].Usable}
		{
			Item[${Me.Equip[trinket2]}]:Use
		}
	}
	
	member IsEmergencyMana()
	{
		if ${Item[${This.GetManaStone}].Usable}
	  {    
	  	return TRUE
	  }
	  elseif ${Me.Action[Evocation].Usable} && (${This.isFrozen} || ${Me.Buff[Ice Barrier](exists)} || ${Me.Buff[Mana Shield](exists)} || ${Me.Buff[Polymorph](exists)})
	  {
	  	return TRUE
	  }
	  elseif ${Consumable.GotManaPotion}
	  {
	  	return TRUE
	  }
	  return FALSE
	}
	
	method ActivateEmergencyMana()
	{
		if ${Item[${This.GetManaStone}].Usable}
	  {    
	  	Item[${This.GetManaStone}]:Use
	  } 
	  elseif ${Me.Action[Evocation].Usable}
	  {    
	  	This:CastSpell[Evocation]
	  }
	  elseif ${Consumable.GotManaPotion}
	  {    
	  	Consumable:UseManaPotion
	  }
	}
	
	member GetManaStone()
	{
		if ${Spell[Conjure Mana Emerald](exists)}
	  {    
	  	return "Mana Emerald"
	  } 
	  elseif ${Spell[Conjure Mana Ruby](exists)}
	  {    
	  	return "Mana Ruby"
	  }
	  elseif ${Spell[Conjure Mana Citrine](exists)}
	  {    
	  	return "Mana Citrine"
	  } 
	  elseif ${Spell[Conjure Mana Jade](exists)}
	  {    
	  	return "Mana Jade"
	  } 
	  elseif ${Spell[Conjure Mana Agate](exists)}
	  {    
	  	return "Mana Agate"
	  }
	  else
	  {
	 		return NULL
		}
	}
	
	member NeedDecurse()
	{			
		if ${BuffNum} > 56
		{
			buffNum:Set[1]
		}

		if !${Me.Buff[${BuffNum}](exists)}
		{
			return FALSE
		}
				
		if ${Me.Buff[${BuffNum}].Harmful}
		{
			if ${Me.Buff[${BuffNum}].DispelType.Equal[Curse]} && ${Spell[Remove Lesser Curse](exists)}
			{
				return TRUE
			}
		}
		BuffNum:Inc
		
		return FALSE
	}
		
	method MoveToNovaSpot()
	{
		variable guidlist MobList
		variable point3f SafeSpot
		variable point3f SafeSpotByPlayer
		variable objectref Data
		variable int Range = 9
		variable int AggroRange = 0
		variable int Degrees = 185
		variable int Idx = 1
		variable bool Orgasm = FALSE
		
		SafeSpot.X:Set[${Me.X}]
		SafeSpot.Y:Set[${Me.Y}]
		SafeSpot.Z:Set[${Me.Z}]
		
		SafeSpotByPlayer.X:Set[0]
		SafeSpotByPlayer.Y:Set[0]
		SafeSpotByPlayer.Z:Set[0]
		
		if ${Target.Distance} > 7 && ${Target.Distance} < 9
		{
			SafeSpot.X:Set[${Target.X} + ${Range}*${Math.Cos[180]}]
			SafeSpot.Y:Set[${Target.Y} - ${Range}*${Math.Sin[180]}]
			SafeSpot.Z:Set[${Target.Z} + 0.9]
			
			if !${Me.IsPathObstructed[${SafeSpot.X},${SafeSpot.Y},${SafeSpot.Z}]}
			{
				Navigator:Backup[1000]
				return
			}			
		}
		else
		{
			SafeSpot.X:Set[${Me.X}]
			SafeSpot.Y:Set[${Me.Y}]
			SafeSpot.Z:Set[${Me.Z}]
			
			MobList:Search[-units,-nonfriendly,-nocritters,-nopets,-alive,-nearest,-untapped,-range 0-40] 
			do
			{
				Degrees:Set[95]
				Degrees:Inc[${Math.Rand[170]}]
				do
				{
					SafeSpot.X:Set[${Target.X} + ${Range}*${Math.Cos[${Degrees}]}]
					SafeSpot.Y:Set[${Target.Y} - ${Range}*${Math.Sin[${Degrees}]}]
					SafeSpot.Z:Set[${Target.Z} + 0.9]
					
					Orgasm:Set[TRUE]
					Idx:Set[1]
					if ${MobList.Count}
					{
						do
						{
							Data:Set[${MobList.GUID[${Idx}]}]
							AggroRange:Set[${Environment.AggroRange[${Data.GUID}]}]
							if ${Math.Distance[${SafeSpot.X},${SafeSpot.Y},${Data.X},${Data.Y}]} < ${AggroRange}
							{
								Orgasm:Set[FALSE]
							}
						}
						while ${Idx:Inc} <= ${MobList.Count}
					}
					
					if ${Math.Distance[${SafeSpot.X},${SafeSpot.Y},${Me.X},${Me.Y}]} > 11
					{
						Orgasm:Set[FALSE]
					}
	
					if ${Orgasm}
					{
						if !${Me.IsPathObstructed[${SafeSpot.X},${SafeSpot.Y},${SafeSpot.Z}]}
						{
							if ${SafeSpot.X} >= ${Me.X}
							{
								SafeSpotByPlayer.X:Set[${Math.Calc[${SafeSpot.X} - ${Me.X}]}]
							}
							else
							{
								SafeSpotByPlayer.X:Set[${Math.Calc[${SafeSpot.X} + ${Me.X}]}]
							}
							if ${SafeSpot.Y} >= ${Me.Y}
							{
								SafeSpotByPlayer.Y:Set[${Math.Calc[${SafeSpot.Y} - ${Me.Y}]}]
							}
							else
							{
								SafeSpotByPlayer.Y:Set[${Math.Calc[${SafeSpot.Y} + ${Me.Y}]}]
							}	
							
							This:Debug["Found safespot at ${Math.Distance[${Target.X},${Target.Y},${SafeSpot.X},${SafeSpot.Y}].Int} yards from frozen target: ${SafeSpot.X} ${SafeSpot.Y} ${SafeSpot.Z}"]
							if ${SafeSpotByPlayer.Y} > 0
							{
								Navigator:FaceXYZ[${Math.Calc[(${SafeSpotByPlayer.X} * -1) + ${Me.X}]},${SafeSpot.Y},${SafeSpot.Z}]										
							}
							else
							{
								Navigator:FaceXYZ[${SafeSpot.X},${Math.Calc[(${SafeSpotByPlayer.Y} * -1) + ${Me.Y}]},${SafeSpot.Z}]
							}
							
							if (${SafeSpotByPlayer.X} > 0
							{
								Navigator:StrafeRight[5000]							
							}
							else
							{
								Navigator:StrafeLeft[5000]							
							}
							return
						}
						;Fake orgasm
						Orgasm:Set[FALSE]
					}
				}
				while ${Degrees:Inc[5]} <= 450
			}
			while ${Range:Inc[1]} <= 15
		}
		This:Debug["Could not find a decent safespot. you are screwed."]
	}
	/****************************************************************
	 *    Trinkets & emergency selection end
	 ***************************************************************/
	
	
	/****************************************************************
	 *    Reactive stuff start
	 ***************************************************************/
	member isResistant(string sDamageType)
	{
		variable uint idx = 1
		variable bool found = FALSE
		
		if ${Target(exists)} && ${Target.Type.NotEqual[Player]}
		{
			if ${sDamageType.Equal[frost]}
			{
				while ${FrostResistant.Next[${idx}](exists)}
				{
					if ${FrostResistant.Get[${idx}].Equal[${Target.Name}]}
					{
						return TRUE					
					}
					idx:Set[${FrostResistant.Next[${idx}]}]				
				}
			}
			elseif ${sDamageType.Equal[fire]}
			{
				while ${FireResistant.Next[${idx}](exists)}
				{
					if ${FireResistant.Get[${idx}].Equal[${Target.Name}]}
					{
						return TRUE				
					}
					idx:Set[${FireResistant.Next[${idx}]}]				
				}
			}
			elseif ${sDamageType.Equal[arcane]}
			{
				while ${ArcaneResistant.Next[${idx}](exists)}
				{
					if ${ArcaneResistant.Get[${idx}].Equal[${Target.Name}]}
					{
						return TRUE				
					}
					idx:Set[${ArcaneResistant.Next[${idx}]}]				
				}
			}
		}
		return FALSE
	}
	
	method ImmuneCheck(string eventid , text, Message)
	{		
		variable uint idx = 1
		variable bool found = FALSE
		
		if ${Target.Type.NotEqual[Player]}
		{
			if (${Message.Find[Frost Nova]} || ${Message.Find[Ice Lance]} || ${Message.Find[Frostbolt]} || ${Message.Find[Cone of Cold]}) && ${Message.Find[failed]} && ${Message.Find[immune]}
			{
				while ${FrostResistant.Next[${idx}](exists)}
				{
					if ${FrostResistant.Get[${idx}].Equal[${Target.Name}]}
					{
						found:Set[TRUE]					
					}
					idx:Set[${FrostResistant.Next[${idx}]}]				
				}
				
				if !${found}
				{
					This.FrostResistant:Insert[${Target.Name}]
				}
			}
			elseif (${Message.Find[Molten Armor]} || ${Message.Find[Pyroblast]} || ${Message.Find[Fireball]} || ${Message.Find[Fire Blast]}) && ${Message.Find[failed]} && ${Message.Find[immune]}
			{			
				while ${FireResistant.Next[${idx}](exists)}
				{
					if ${FireResistant.Get[${idx}].Equal[${Target.Name}]}
					{
						found:Set[TRUE]					
					}
					idx:Set[${FireResistant.Next[${idx}]}]
				}
				
				if !${found}
				{
					This.FireResistant:Insert[${Target.Name}]
				}
			}
			elseif (${Message.Find[Counterspell]} || ${Message.Find[Arcane Missiles]} || ${Message.Find[Arcane Blast]}) && ${Message.Find[failed]} && ${Message.Find[immune]}
			{			
				while ${ArcaneResistant.Next[${idx}](exists)}
				{
					if ${ArcaneResistant.Get[${idx}].Equal[${Target.Name}]}
					{
						found:Set[TRUE]					
					}
					idx:Set[${ArcaneResistant.Next[${idx}]}]
				}
				
				if !${found}
				{
					This.ArcaneResistant:Insert[${Target.Name}]
				}
			}
		}
	}
	
	method DamageCheck(string eventid , text, Message)
	{
		if ${Message.Find[hits you]} && ${Message.Find[Frost damage]}
		{
			This.UseFrostWard:Set[TRUE]
		}
		if ${Message.Find[hits you]} && !${Message.Find[Frost damage]}
		{
			This.UseFrostWard:Set[FALSE]
		}
		if ${Message.Find[hits you]} && ${Message.Find[Fire damage]}
		{
			This.UseFireWard:Set[TRUE]
		}
		if ${Message.Find[hits you]} && !${Message.Find[Fire damage]}
		{
			This.UseFireWard:Set[FALSE]
		}
	}
	
	method DampenCheck(string eventid , text, Message)
	{
		if ${Message.Find[hits you for]} && ${Message.Find[Nature damage]} || ${Message.Find[Shadow damage]} || ${Message.Find[Holy damage]} || ${Message.Find[Fire damage]} || ${Message.Find[Frost damage]}
		{
			This.NeedDampenMagic:Set[TRUE]
		}
		if ${Message.Find[hits you for]} && !${Message.Find[Nature damage]} || ${Message.Find[Shadow damage]} || ${Message.Find[Holy damage]} || ${Message.Find[Fire damage]} || ${Message.Find[Frost damage]}
		{
			This.NeedDampenMagic:Set[FALSE]
		}
	}
	
	/* Idea by Weebs */
	method LineOfSightCheck(string eventid, text, Message) 
	{ 
  	This:Debug["Message received: ${Message}"]      
  	
  	if ${Message.Equal["Target not in line of sight"]} 
    { 
	    This:Debug["Target not in line of sight. Add to Blacklist GUID: ${Target.GUID}"]      
	    Environment:BlackListGUID[${Target.GUID}]
	    Environment:ClearTarget 
	    return 
    } 
    if ${Message.Equal["Evade"]} 
    { 
	    This:Debug["Evade. Add to Blacklist GUID: ${Target.GUID}"]      
	    Environment:BlackListGUID[${Target.GUID}] 
	    Environment:ClearTarget
	    return 
    }
    if ${Message.Equal["You cannot attack that target"]} 
    { 
	    This:Debug["You cannot attack that target. Add to Blacklist GUID: ${Target.GUID}"]      
	    Environment:BlackListGUID[${Target.GUID}] 
	    Environment:ClearTarget
	    return 
    }
    if ${Message.Equal["Invalid target"]} 
    { 
	    This:Debug["Invalid target. Add to Blacklist GUID: ${Target.GUID}"]      
	    Environment:BlackListGUID[${Target.GUID}] 
	    Environment:ClearTarget
	    return 
    }
	}
	
	method ResetReactive()
	{
		This.NeedDampenMagic:Set[FALSE]
		This.UseFireWard:Set[FALSE]
		This.UseFrostWard:Set[FALSE]
	}	
	/****************************************************************
	 *    Reactive stuff end
	 ***************************************************************/
	 
	 
	/****************************************************************
	 *    ui start
	 ***************************************************************/
	method GUIToonInfo(string newmsg)
	{
		UIElement[lblLastAction@Generic@Pages@ToonGUI]:SetText[${newmsg}]
	}
				
	method ToonGUIChange(string Action)
	{
		switch ${Action}
		{
			case pull
				if ${UIElement[cmbPullSpell@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					This.PullSpell:Set[${UIElement[cmbPullSpell@Spells@Pages@ToonGUI].SelectedItem.Text}]
				}
				break
			case armor
				if ${UIElement[cmbArmorSpell@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					This.ArmorSpell:Set[${UIElement[cmbArmorSpell@Spells@Pages@ToonGUI].SelectedItem.Text}]
				}
				break
			case shield
				if ${UIElement[cmbShieldSpell@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					This.ShieldSpell:Set[${UIElement[cmbShieldSpell@Spells@Pages@ToonGUI].SelectedItem.Text}]
				}
				break
			case pullrange
				if ${UIElement[cmbPullRange@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{	
					if ${UIElement[cmbPullRange@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[Auto]}
					{
						This.PullRange:Set[-1]
					}
					else
					{
						This.PullRange:Set[${UIElement[cmbPullRange@Spells@Pages@ToonGUI].SelectedItem.Value}]
					} 
				}
				break
			case shieldpct
				if ${UIElement[cmbShieldPCT@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					if ${UIElement[cmbShieldPCT@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[Always On]}
					{
						This.ShieldPCT:Set[110]
					}
					elseif ${UIElement[cmbShieldPCT@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[Before Pull]}
					{
						This.ShieldPCT:Set[105]
					}
					else
					{
						This.ShieldPCT:Set[${UIElement[cmbShieldPCT@Spells@Pages@ToonGUI].SelectedItem.Value}]
					}
				}
				break
			case dampen
				if ${UIElement[cmbDampenMagic@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{					
					This.DampenMagic:Set[${UIElement[cmbDampenMagic@Spells@Pages@ToonGUI].SelectedItem.Text}]
				}
				break
			case wards
				if ${UIElement[cmbWards@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					This.Wards:Set[${UIElement[cmbWards@Spells@Pages@ToonGUI].SelectedItem.Text}]
				}
				break
			case aoe
				if ${UIElement[cmbUseAOE@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					if ${UIElement[cmbUseAOE@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[No]}
					{
						This.UseAOE:Set[FALSE]
					}
					else
					{
						This.UseAOE:Set[TRUE]
					}
				}
				break
			case trinkets
				if ${UIElement[cmbTrinkets@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					if ${UIElement[cmbTrinkets@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[No]}
					{
						This.Trinkets:Set[FALSE]
					}
					else
					{
						This.Trinkets:Set[TRUE]
					}
				}
				break
			case racials
				if ${UIElement[cmbRacials@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					if ${UIElement[cmbRacials@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[No]}
					{
						This.Racials:Set[FALSE]
					}
					else
					{
						This.Racials:Set[TRUE]
					}
				}
				break
			case sheep
				if ${UIElement[cmbSheep@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					if ${UIElement[cmbSheep@Spells@Pages@ToonGUI].SelectedItem.Text.Equal[No]}
					{
						This.Sheep:Set[FALSE]
					}
					else
					{
						This.Sheep:Set[TRUE]
					}
				}
				break
				case scorch
				if ${UIElement[cmbScorch@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					This.ScorchPCT:Set[${UIElement[cmbScorch@Spells@Pages@ToonGUI].SelectedItem.Value}]
				}
				break		
				case wand
				if ${UIElement[cmbWandPCT@Spells@Pages@ToonGUI].SelectedItem.Text(exists)}
				{
					This.WandPCT:Set[${UIElement[cmbWandPCT@Spells@Pages@ToonGUI].SelectedItem.Value}]
				}
				break			
			case defaultspells
				This.PullSpell:Set["Automatic"]
				This.ArmorSpell:Set["Automatic"]
				This.ShieldSpell:Set["Automatic"]				
				This.Wards:Set["Automatic"]
				This.DampenMagic:Set["Automatic"]
				This.ShieldPCT:Set[110]
				This.PullRange:Set[-1]
				This.UseAOE:Set[TRUE]
				This.Trinkets:Set[TRUE]
				This.Racials:Set[TRUE]
				This.Sheep:Set[TRUE]		
				This.ScorchPCT:Set[110]
				This.WandPCT:Set[10]	
						
				This:InitMageGui[spells]
				break
		/** Generic **/
			case minmana
				if ${UIElement[cmbMinMana@Generic@Pages@ToonGUI].SelectedItem.Value(exists)}
				{	
							This.MinMana:Set[${UIElement[cmbMinMana@Generic@Pages@ToonGUI].SelectedItem.Value}]
				}
				break	
			case maxmana
				if ${UIElement[cmbMaxMana@Generic@Pages@ToonGUI].SelectedItem.Value(exists)}
				{	
							This.MaxMana:Set[${UIElement[cmbMaxMana@Generic@Pages@ToonGUI].SelectedItem.Value}]
				}
				break	
			case minhealth
				if ${UIElement[cmbMinHealth@Generic@Pages@ToonGUI].SelectedItem.Value(exists)}
				{	
							This.MinHealth:Set[${UIElement[cmbMinHealth@Generic@Pages@ToonGUI].SelectedItem.Value}]
				}
				break
			case maxhealth
				if ${UIElement[cmbMaxHealth@Generic@Pages@ToonGUI].SelectedItem.Value(exists)}
				{	
							This.MaxHealth:Set[${UIElement[cmbMaxHealth@Generic@Pages@ToonGUI].SelectedItem.Value}]
				}
				break
			case levelbelow
				if ${UIElement[cmbLevelBelow@Generic@Pages@ToonGUI].SelectedItem.Value(exists)}
				{	
							This.LevelBelow:Set[${UIElement[cmbLevelBelow@Generic@Pages@ToonGUI].SelectedItem.Value}]
				}
				break
			case levelabove
				if ${UIElement[cmbLevelAbove@Generic@Pages@ToonGUI].SelectedItem.Value(exists)}
				{	
							This.LevelAbove:Set[${UIElement[cmbLevelAbove@Generic@Pages@ToonGUI].SelectedItem.Value}]
				}
				break
			case defaultgeneric
				This.MinMana:Set[60]
				This.MaxMana:Set[95]
				This.MinHealth:Set[60]
				This.MaxHealth:Set[90]
				This.LevelBelow:Set[4]
				This.LevelAbove:Set[2]		
						
				This:InitMageGui[generic]
				break
		}
	}
	 
	method InitMageGui(string tab)
	{		
		variable int i = 1
		for (i:Set[1] ; ${i}<=${UIElement[cmbPullSpell@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.PullSpell.Equal[${UIElement[cmbPullSpell@Spells@Pages@ToonGUI].Item[${i}].Text}]}
			{
				UIElement[cmbPullSpell@Spells@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbArmorSpell@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.ArmorSpell.Equal[${UIElement[cmbArmorSpell@Spells@Pages@ToonGUI].Item[${i}].Text}]}
			{
				UIElement[cmbArmorSpell@Spells@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbShieldSpell@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.ShieldSpell.Equal[${UIElement[cmbShieldSpell@Spells@Pages@ToonGUI].Item[${i}].Text}]}
			{
				UIElement[cmbShieldSpell@Spells@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbWards@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.Wards.Equal[${UIElement[cmbWards@Spells@Pages@ToonGUI].Item[${i}].Text}]}
			{
				UIElement[cmbWards@Spells@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbDampenMagic@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.DampenMagic.Equal[${UIElement[cmbDampenMagic@Spells@Pages@ToonGUI].Item[${i}].Text}]}
			{
				UIElement[cmbDampenMagic@Spells@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbShieldPCT@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
			if ${This.ShieldPCT} == 110
			{
				UIElement[cmbShieldPCT@Spells@Pages@ToonGUI]:SelectItem[1]
			}
			elseif ${This.ShieldPCT} == 105
			{
				UIElement[cmbShieldPCT@Spells@Pages@ToonGUI]:SelectItem[2]
			}
			elseif ${This.ShieldPCT} == ${UIElement[cmbShieldPCT@Spells@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbShieldPCT@Spells@Pages@ToonGUI]:SelectItem[${i}]
			} 
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbPullRange@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
			if ${This.PullRange} == -1
			{
				UIElement[cmbPullRange@Spells@Pages@ToonGUI]:SelectItem[1]
			}
			elseif ${This.PullRange} == ${UIElement[cmbPullRange@Spells@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbPullRange@Spells@Pages@ToonGUI]:SelectItem[${i}]
			} 
		}
		if ${This.UseAOE}
		{
			UIElement[cmbUseAOE@Spells@Pages@ToonGUI]:SelectItem[1]
		}
		else
		{
			UIElement[cmbUseAOE@Spells@Pages@ToonGUI]:SelectItem[2]
		}
		if ${This.Trinkets}
		{
			UIElement[cmbTrinkets@Spells@Pages@ToonGUI]:SelectItem[1]
		}
		else
		{
			UIElement[cmbTrinkets@Spells@Pages@ToonGUI]:SelectItem[2]
		}
	  if ${This.Racials}
		{
			UIElement[cmbRacials@Spells@Pages@ToonGUI]:SelectItem[1]
		}
		else
		{
			UIElement[cmbRacials@Spells@Pages@ToonGUI]:SelectItem[2]
		}
		if ${This.Sheep}
		{
			UIElement[cmbSheep@Spells@Pages@ToonGUI]:SelectItem[1]
		}
		else
		{
			UIElement[cmbSheep@Spells@Pages@ToonGUI]:SelectItem[2]
		}		
		for (i:Set[1] ; ${i}<=${UIElement[cmbScorch@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
			if ${This.ScorchPCT} == ${UIElement[cmbScorch@Spells@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbScorch@Spells@Pages@ToonGUI]:SelectItem[${i}]
			} 
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbWandPCT@Spells@Pages@ToonGUI].Items} ; i:Inc)
		{
			if ${This.WandPCT} == ${UIElement[cmbWandPCT@Spells@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbWandPCT@Spells@Pages@ToonGUI]:SelectItem[${i}]
			} 
		}
		
/** Generic **/
		for (i:Set[1] ; ${i}<=${UIElement[cmbMinMana@Generic@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.MinMana} == ${UIElement[cmbMinMana@Generic@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbMinMana@Generic@Pages@ToonGUI]:SelectItem[${i}]
			}
		}		
		for (i:Set[1] ; ${i}<=${UIElement[cmbMaxMana@Generic@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.MaxMana} == ${UIElement[cmbMaxMana@Generic@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbMaxMana@Generic@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbMinHealth@Generic@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.MinHealth} == ${UIElement[cmbMinHealth@Generic@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbMinHealth@Generic@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbMaxHealth@Generic@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.MaxHealth} == ${UIElement[cmbMaxHealth@Generic@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbMaxHealth@Generic@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbLevelBelow@Generic@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.LevelBelow} == ${UIElement[cmbLevelBelow@Generic@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbLevelBelow@Generic@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
		for (i:Set[1] ; ${i}<=${UIElement[cmbLevelAbove@Generic@Pages@ToonGUI].Items} ; i:Inc)
		{
		  if ${This.LevelAbove} == ${UIElement[cmbLevelAbove@Generic@Pages@ToonGUI].Item[${i}].Value}
			{
				UIElement[cmbLevelAbove@Generic@Pages@ToonGUI]:SelectItem[${i}]
			}
		}
	}
	
	method Echo(string Text)
	{
		if ${UIElement[ConsoleGUI](exists)}
		{
			UIElement[Console@Console@Pages@ToonGUI]:Echo["${Time.Time24} ${Text.Escape}"]
		}
		else
		{
			echo "${Time.Time24} ${Text}"
		}
	}
	
	method SetStatus(string Text)
	{
		UIElement[Status@Console@Pages@ToonGUI]:SetText[${Text.Escape}]
	}
	/****************************************************************
	 *    ui end
	 ***************************************************************/
	
		
	
	/****************************************************************
	 *    Config
	 ***************************************************************/
	 
	method LoadConfig()
	{
		This.MinCombatRange:Set[${This.ToonConfig.FindSetting["MinCombatRange",2]}]
		This.MaxCombatRange:Set[${This.ToonConfig.FindSetting["MaxCombatRange",30]}]
		This.RepairPct:Set[${This.ToonConfig.FindSetting["RepairPct",20]}]
		This.KeepFreeSlots:Set[${This.ToonConfig.FindSetting["KeepFreeSlots",3]}]
		This.MountDistance:Set[${This.ToonConfig.FindSetting["MountDistance",400]}]
		This.Loot:Set[${This.ToonConfig.FindSetting["Loot",TRUE]}]
		This.CorpseCampLimit:Set[${This.ToonConfig.FindSetting["CorpseCampLimit",3]}]
		This.ExitOnStuck:Set[${This.ToonConfig.FindSetting["ExitOnStuck",0]}]
		This.PrimaryStat:Set[${This.ToonConfig.FindSetting["PrimaryStat",STAT_INT]}]
		This.SecondaryStat:Set[${This.ToonConfig.FindSetting["SecondaryStat",STAT_STA]}]
		This.AutoEquip:Set[${This.ToonConfig.FindSetting["AutoEquip",FALSE]}]
		This.MinMuleItems:Set[${This.ToonConfig.FindSetting["MinMuleItems",5]}]
		This.AutoPvP:Set[${This.ToonConfig.FindSetting["AutoPvP",FALSE]}]		
		This.AutoTrainSkills:Set[${This.ToonConfig.FindSetting["AutoTrainSkills",TRUE]}]
		This.DismountOnAggro:Set[${This.ToonConfig.FindSetting["DismountOnAggro",TRUE]}]

		This.PullSpell:Set[${This.ToonConfig.FindSetting["PullSpell","Automatic"]}]
		This.ArmorSpell:Set[${This.ToonConfig.FindSetting["ArmorSpell","Automatic"]}]
		This.ShieldSpell:Set[${This.ToonConfig.FindSetting["ShieldSpell","Automatic"]}]
		
		This.Wards:Set[${This.ToonConfig.FindSetting["Wards","Automatic"]}]
		This.DampenMagic:Set[${This.ToonConfig.FindSetting["DampenMagic","Automatic"]}]
		This.ShieldPCT:Set[${This.ToonConfig.FindSetting["ShieldPCT",110]}]
		This.PullRange:Set[${This.ToonConfig.FindSetting["PullRange",-1]}]		
		This.UseAOE:Set[${This.ToonConfig.FindSetting["UseAOE",TRUE]}]
		This.Trinkets:Set[${This.ToonConfig.FindSetting["Trinkets",TRUE]}]
		This.Racials:Set[${This.ToonConfig.FindSetting["Racials",TRUE]}]
		This.Sheep:Set[${This.ToonConfig.FindSetting["Sheep",TRUE]}]
		This.ScorchPCT:Set[${This.ToonConfig.FindSetting["ScorchPCT",110]}]
		This.WandPCT:Set[${This.ToonConfig.FindSetting["WandPCT",10]}]
		
		This.MinMana:Set[${This.ToonConfig.FindSetting["MinMana",60]}]	
		This.MaxMana:Set[${This.ToonConfig.FindSetting["MaxMana",95]}]	
		This.MinHealth:Set[${This.ToonConfig.FindSetting["MinHealth",60]}]	
		This.MaxHealth:Set[${This.ToonConfig.FindSetting["MaxHealth",95]}]	
		This.LevelBelow:Set[${This.ToonConfig.FindSetting["LevelBelow",4]}]	
		This.LevelAbove:Set[${This.ToonConfig.FindSetting["LevelAbove",2]}]	
	}
	
	method SaveConfig()
	{
		This.ToonConfig.FindSetting["MinCombatRange"]:Set[${This.MinCombatRange}]
		This.ToonConfig.FindSetting["MaxCombatRange"]:Set[${This.MaxCombatRange}]
		This.ToonConfig.FindSetting["RepairPct"]:Set[${This.RepairPct}]
		This.ToonConfig.FindSetting["KeepFreeSlots"]:Set[${This.KeepFreeSlots}]
		This.ToonConfig.FindSetting["MountDistance"]:Set[${This.MountDistance}]
		This.ToonConfig.FindSetting["Loot"]:Set[${This.Loot}]
		This.ToonConfig.FindSetting["CorpseCampLimit"]:Set[${This.CorpseCampLimit}]
		This.ToonConfig.FindSetting["ExitOnStuck"]:Set[${This.ExitOnStuck}]
		This.ToonConfig.FindSetting["PrimaryStat"]:Set[${This.PrimaryStat}]
		This.ToonConfig.FindSetting["SecondaryStat"]:Set[${This.SecondaryStat}]
		This.ToonConfig.FindSetting["AutoEquip"]:Set[${This.AutoEquip}]
		This.ToonConfig.FindSetting["AutoPvP"]:Set[${This.AutoPvP}]
		This.ToonConfig.FindSetting["MinMuleItems"]:Set[${This.MinMuleItems}]
		This.ToonConfig.FindSetting["AutoTrainSkills"]:Set[${This.AutoTrainSkills}]
		This.ToonConfig.FindSetting["DismountOnAggro"]:Set[${This.DismountOnAggro}]
	
		This.ToonConfig.FindSetting["PullSpell"]:Set[${This.PullSpell}]
		This.ToonConfig.FindSetting["ArmorSpell"]:Set[${This.ArmorSpell}]	
		This.ToonConfig.FindSetting["ShieldSpell"]:Set[${This.ShieldSpell}]
		
		This.ToonConfig.FindSetting["Wards"]:Set[${This.Wards}]
		This.ToonConfig.FindSetting["DampenMagic"]:Set[${This.DampenMagic}]
		This.ToonConfig.FindSetting["ShieldPCT"]:Set[${This.ShieldPCT}]
		This.ToonConfig.FindSetting["PullRange"]:Set[${This.PullRange}]		
		This.ToonConfig.FindSetting["UseAOE"]:Set[${This.UseAOE}]
		This.ToonConfig.FindSetting["Trinkets"]:Set[${This.Trinkets}]
		This.ToonConfig.FindSetting["Racials"]:Set[${This.Racials}]
		This.ToonConfig.FindSetting["Sheep"]:Set[${This.Sheep}]
		This.ToonConfig.FindSetting["ScorchPCT"]:Set[${This.ScorchPCT}]
		This.ToonConfig.FindSetting["WandPCT"]:Set[${This.WandPCT}]
		
		This.ToonConfig.FindSetting["MinMana"]:Set[${This.MinMana}]
		This.ToonConfig.FindSetting["MaxMana"]:Set[${This.MaxMana}]
		This.ToonConfig.FindSetting["MinHealth"]:Set[${This.MinHealth}]		
		This.ToonConfig.FindSetting["MaxHealth"]:Set[${This.MaxHealth}]
		This.ToonConfig.FindSetting["LevelBelow"]:Set[${This.LevelBelow}]
		This.ToonConfig.FindSetting["LevelAbove"]:Set[${This.LevelAbove}]
	}
	/****************************************************************
	 *    config end
	 ***************************************************************/
		
	method InitToon()
	{		
	  This:Debug["MAGE.ISS REGISTER Events"]
		LavishScript:RegisterEvent[TOON_GUI_CHANGE]
		Event[TOON_GUI_CHANGE]:AttachAtom[${This.ObjectName}:ToonGUIChange]	
		Event[CHAT_MSG_SPELL_SELF_DAMAGE]:AttachAtom[${This.ObjectName}:ImmuneCheck]
		Event[CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS]:AttachAtom[${This.ObjectName}:DamageCheck]
		Event[CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE]:AttachAtom[${This.ObjectName}:DampenCheck]
		Event[UI_ERROR_MESSAGE]:AttachAtom[${This.ObjectName}:LineOfSightCheck] /* Weebs */
		This:InitMageGui[spells]
	}
	
	method Shutdown()
	{		
		This:Debug["MAGE.ISS UN-REGISTER Events"]
		
		This:SaveConfig
		
		LavishSettings["Class"]:Export["etc/class.xml"]
		Event[UI_ERROR_MESSAGE]:DetachAtom[${This.ObjectName}:ErrorMessage]		
		Event[UNIT_SPELLCAST_SUCCEEDED]:DetachAtom[${This.ObjectName}:SpellCastSucceeded]
		Event[TOON_GUI_VISIBLE]:Unregister
		
		ui -unload "class/${Me.Class}.xml"		
		
		/* Added */
		Event[TOON_GUI_CHANGE]:DetachAtom[${This.ObjectName}:ToonGUIChange]
		Event[TOON_GUI_CHANGE]:Unregister		
		Event[CHAT_MSG_SPELL_SELF_DAMAGE]:DetachAtom[${This.ObjectName}:ImmuneCheck]
		Event[CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS]:DetachAtom[${This.ObjectName}:DamageCheck]
		Event[CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE]:DetachAtom[${This.ObjectName}:DampenCheck]		
		Event[UI_ERROR_MESSAGE]:DetachAtom[${This.ObjectName}:LineOfSightCheck] /* Weebs */
	}
}