All pastes #382806 Raw Edit

Something

public text v1 · immutable
·published 2007-03-05 22:38 UTC
rendered paste body
#define	BGQUIT			1
#define BGPAUSE			2
#define BGINAV			3
#define BGWAITINGQ	4
#define BGDESERTER	5
#define BGWAIT			6
#define BGWAITSTART	7
#define BGRUN				8
#define BGDEAD			9
#define BGCOMBAT		10
#define BGMOUNT			11
#define BGNOPATH		12

#define GY_Tunnel		1
#define GY_IB				2
#define GY_SH				3
#define GY_SP				4

#define NAVIGATION_NONE 0
#define NAVIGATION_ZONE_CHANGED 1
#define NAVIGATION_PLOT 2
#define NAVIGATION_HOP 3
#define NAVIGATION_ARRIVED 4

#define NAVIGATION_DIRECT 0
#define NAVIGATION_MAP 1

#define NAVIGATION_GROW_LIMIT 50
#define NAVIGATION_GROW_Z_LIMIT 2

#include objects.iss
#include movement.iss
#include misc.iss
#include combat/warrior.iss
#include combat/mage.iss
#include combat/shaman.iss
#include combat/priest.iss
#include combat/warlock.iss
#include combat/paladin.iss
#include combat/druid.iss
#include combat/hunter.iss
#include combat/rogue.iss
#include abbot.iss

/*
 * Events:
 * REGION_ADDED [regionname]
 */

variable(global) oNavigation Mapper
      
function main()
{
	declare AVBOTVERSION	string script "1.1.6"
	declare CurrentRegion lnavregionref script
	declare ZoneRegion lnavregionref script
	declare TmpRegion lnavregionref script
	declare PathFinder dijkstrapathfinder script
	declare CurrentPath lnavpath script
	declare DestinationRegion	lnavregionref script

	declare NewPathFinder astarpathfinder script
	declare NewCurrentPath lnavpath script

	declare BadConnection lnavconnection script
	declare CurrentLocation point3f script
	
	declare ConfigFile filepath script "${Script.CurrentDirectory}/avbot_config.xml"
	declare	GOTSTUCK	int	script 0
	declare BGPERSON string script "NONE"
	declare BGPERSONX int script 0
	declare BGPERSONY int script 0
	declare BGPERSONZ int script 0
	declare BGQUEZONE string script "Orgrimmar"
	declare FIGHTX	int script 0
	declare FIGHTY	int script 0
	declare FIGHTZ	int script 0
	declare MYMOUNT	string script "NONE"
	declare MYMOUNTBUFF string script "NONE"
	declare PULSETIME int script 0
	
	declare i int script 1
	declare lasthop int script 1
	declare DORUN int 0 global
	declare BGBOT 				int 		global
	declare BGBOTSTATUS		string	global
	declare DESERTER 			int			global
	declare JOINS 				int			global
	declare BONUS					int			global
	declare KILLS					int			global
	declare GY 						int			global 0
	declare HORDE_WINS		int			global 0
	declare ALIANCE_WINS	int			global 0
	
	BONUS:Set[0]
	KILLS:Set[0]
	DESERTER:Set[0]
	JOINS:Set[0]


	ABPERSONX:Set[-8391.0]
 	ABPERSONY:Set[268.3]
  ABPERSONZ:Set[120.9]


	Mapper:Plugin
	Mapper:Initialize

	AddTrigger AddHonor "[Event:@*@:CHAT_MSG_COMBAT_HONOR_GAIN](\"@*@ dies, honorable kill Rank:@*@ (Estimated Honor Points: @points@)\"@*@)"
	AddTrigger AddHonor2 "[Event:@*@:CHAT_MSG_COMBAT_HONOR_GAIN](\"You have been awarded @points@ honor@*@)"
	;\"
	AddTrigger PulseUpdate "[Event:@*@:PLAYTIME_CHANGED] (@*@)"
	AddTrigger UpdateWhisper "[Event:@eventid@:CHAT_MSG_WHISPER](\"@message@\",\"@speaker@\",\"@language@\",\"@something@\",\"@something@\",\"@something@\",@something@,@something@,\"@something@\",@something@)"	
	AddTrigger UpdateWhisper "[Event:@eventid@:CHAT_MSG_SAY](\"@message@\",\"@speaker@\",\"@language@\",\"@something@\",\"@something@\",\"@something@\",@something@,@something@,\"@something@\",@something@)"	
	Event[OnFrame]:AttachAtom[PulseUpdate]

	call AddHud
	call Load_Config
	
	echo "BGPERSON: ${BGPERSON}"
	echo "BGPERSONX: ${BGPERSONX}"
	echo "BGPERSONY: ${BGPERSONY}"
	echo "BGPERSONZ: ${BGPERSONZ}"
	echo "BGQUEZONE: ${BGQUEZONE}/${WoWScript[GetRealZoneText()]}"
	echo "FIGHTX: ${FIGHTX}"
	echo "FIGHTY: ${FIGHTY}"
	echo "FIGHTZ: ${FIGHTZ}"
	echo "MYMOUNT: ${MYMOUNT}"
	echo "MYMOUNTBUFF: ${MYMOUNTBUFF}"
	echo "AVBot v${AVBOTVERSION} now online."
	do
	{
		AVStatus:Set[${WoWScript[GetBattlefieldStatus(1)]}]
    ABStatus:Set[${WoWScript[GetBattlefieldStatus(2)]}]
    WSGStatus:Set[${WoWScript[GetBattlefieldStatus(3)]}]
		
		ZoneRegion:SetRegion[${LNavRegion[${WoWScript[GetRealZoneText()]}].FQN}]
		
		ISXWoW:ResetIdle

;--------------------------------------------------- Check if we are at the BG Chick--------------------------------------
		if ${Math.Distance[${Me.X},${Me.Y},${BGPERSONX},${BGPERSONY}]}>10&&${WoWScript[GetRealZoneText()].Equal["${BGQUEZONE}"]}
		{
			call Update_State BGRUN
			call UpdateHudStatus "Not at the BG Quer, moving there"
			call MoveMeThere ${BGPERSONX} ${BGPERSONY} ${BGPERSONZ}
			if ${Math.Distance[${Me.X},${Me.Y},${BGPERSONX},${BGPERSONY}]}<15
			{
				call movetocont ${BGPERSONX} ${BGPERSONY} 2
			}
			move -stop
		}
		
		if ${Me.Buff[Deserter](exists)}
		{
			call Update_State BGDESERTER
		}
		
		if !${Me.Buff[Deserter](exists)} && ${BGBOT}==BGDESERTER
		{
			call UpdateHudStatus "Dester Flaged: Waiting for it to expire"
			DESERTER:Inc
			call Update_State BGWAIT
		}
		
		call pulse_update
		
		
;-----------------------------------------------------If we are in AB, run script------------------------------------------------
		if ${WoWScript[GetRealZoneText()].Equal["Arathi Basin"]}
		{
			call UpdateHudStatus "AB Poped joined it"
			JOINS:Inc
			call do_ab
			move -stop
		}
;-----------------------------------------------------------If in AV start script---------------------------------------		
		; If we are in AV already lets do our thing
		if ${WoWScript[GetRealZoneText()].Equal["Alterac Valley"]}
		{
			call UpdateHudStatus "AV Poped joined it"
			JOINS:Inc
			call Do_AV
			move -stop
			call Update_State BGINAV
		}
	
		; If we are in Orgrimmar we should be queing
		if ${WoWScript[GetRealZoneText()].Equal["${BGQUEZONE}"]}
		{
;-------------------------------------------Join AB if window comes up-------------------------------------------------------
			if ${WoWScript[GetBattlefieldStatus(2)].Equal["confirm"]}
			{
				call UpdateHudStatus "AB poped joining it now"
				WoWScript StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY")
				wait 2
				WoWScript AcceptBattlefieldPort(2,1)
				while ${WoWScript[GetRealZoneText()].NotEqual["Arathi Basin"]}
				{
					wait 1
					waitframe
				}
			}
			
;------------------------------------------------------------Join AV if window comes up--------------------------------------------			
				if ${WoWScript[GetBattlefieldStatus(1)].Equal["confirm"]}
			{
				call UpdateHudStatus "AV poped joining it now"
				WoWScript StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY")
				wait 2
				WoWScript AcceptBattlefieldPort(1,1)
				while ${WoWScript[GetRealZoneText()].NotEqual["Alterac Valley"]}
				{
					wait 1
					waitframe
				}
			}
			
;------------------------------------------------------------------ See if we are in the que for AV + queue up-------------------------------
			if !${WoWScript[GetBattlefieldTimeWaited(1)]} && ${WoWScript[GetBattlefieldStatus(1)].NotEqual["confirm"]}&&!${Me.Buff[Deserter](exists)}
			{
				call UpdateHudStatus "Quing for AV now"
				;We are not int he que lets que up
   			Unit[${BGPERSON}]:Use
   			wait 20

   			WoWScript SelectGossipOption(1)
   			wait 20

   			WoWScript JoinBattlefield(0)
				wait 20
				
;				WoWScript ToggleQuestLog()
				wait 1
;				WoWScript ToggleQuestLog()
				call Update_State BGWAITINGQ
			}
;----------------------------------------------Go to the AB lady and queue up----------------------------------------------------
			if ${WoWScript[GetBattlefieldStatus(2)].NotEqual["confirm"]} && ${WoWScript[GetBattlefieldStatus(2)].NotEqual["queued"]}
  {
    Target "The Black Bride"
    wait 20
    Unit["The Black Bride"]:Use
    wait 20
    WoWScript SelectGossipOption(1)
    wait 20
    WoWScript JoinBattlefield(0)
    wait 20
    Press Esc
  }
			
			
		}
		wait 1s		
	}
	while ${BGBOT}!=BGQUIT
	call RemoveHud

}





;----------------------------------------------------------------------AV SCRIPT------------------------------------------------



function Do_AV()
{
	declare AggroList guidlist local
	declare TargetList guidlist local
	
	; Wait for the gates to be opened
	if ${WoWScript[GetBattlefieldInstanceRunTime()]}>0
	{
		while ${WoWScript[GetBattlefieldInstanceRunTime()]}<131165
		{
			call Update_State BGWAITSTART
	
			if ${BGBOT}==BGQUIT
			{
				return
			}
			ISXWoW:ResetIdle
			wait 1s
		}
	}
	else
	{
		call UpdateHudStatus "LUA BGStat Rimer BUG starting now waiting for 2 minutes"
		wait 1200
	}

	call Update_State BGINAV

	; Set our current region
	ZoneRegion:SetRegion[${LNavRegion[${WoWScript[GetRealZoneText()]}].FQN}]
	
	; Main loop until BG is finished
	while !${WoWScript[GetBattlefieldInstanceExpiration()]}
	{
		if ${BGBOT}==BGQUIT
		{
			return
		}
		; Reset our Idle time just incase
		ISXWoW:ResetIdle
		
		; If we are dead... Release us
		if ${Me.Dead}
		{
			WoWScript RepopMe()
		}
		
		; If we are not dead... Lets do some mapping
;		if !${Me.Dead}
;		{
			;echo "Should be Pulsing"
;			Mapper:Pulse
;		}
		
		; If we are dead or a ghost.. Lets not move
		if ${Me.Dead}||${Me.Ghost}
		{
			call Update_State BGDEAD
			move -stop
		}
		
		i:Set[1]
		
		; Targetting Start
		; If we currently have a target... Lets clear it
		if ${Target(exists)}
		{
			wowscript ClearTarget()
		}
		
		;Check if we have agro
		AggroList:Search[-players,-pvp,-alive,-hostile,-nearest,-targetingme,-lineofsight,-range 0-50]
		; If we have agro lets fight that one
		if ${AggroList.Count}>0&&!${Me.Dead}&&!${Me.Ghost}
		{
			echo "Agro"
			target ${AggroList.GUID[1]}
		}
		else
		{
			; If we dont have agro lets try to find someone to kill
			TargetList:Search[-players,-pvp,-hostile,-nearest,-nopets,-alive,-lineofsight,-range 0-50]  
			if ${TargetList.Count}>0
			{
				echo "Targeting"
				target ${TargetList.GUID[1]}
			}
		}
		
		; Sanity Checking of the current target
		if ${Target.Type.Equal[Unit]}
		{
			; We have a Mob not a player.
			if ${Math.Calc[${Target.Z}-${Me.Z}]}>5
			{
				call UpdateHudStatus "Mob to far above me ignoring"
				wowscript ClearTarget()
			}
		}
		
		; If we now have a target and are not dead or a ghost lets get busy
		if ${Target(exists)}&&!${Me.Dead}&&!${Me.Ghost}
		{
			echo "Killing ${Target}"
			call DoDismount
			call kill_target ${Target.GUID}
		}
		
		if !${Me.InCombat}&&!${Me.Ghost}&&!${Me.Dead}
		{
			call check_buffs
		}
		; Need to remove the Battle Stance part but leaving there for stopping
;		if ${Me.Buff[Battle Stance](exists)}&&!${Me.Dead}&&!${Me.Ghost}
		if !${Me.Dead}&&!${Me.Ghost}
		{
			i:Inc
			CurrentLocation.X:Set[${Me.X}]
			CurrentLocation.Y:Set[${Me.Y}]
			CurrentLocation.Z:Set[${Me.Z} + ${Math.Calc[${Me.Height} / 2]}]

			;echo "Best Container: ${ZoneRegion.BestContainer[${CurrentLocation.X},${CurrentLocation.Y},${CurrentLocation.Z}].ID}"
			CurrentRegion:SetRegion[${ZoneRegion.BestContainer[${CurrentLocation.X},${CurrentLocation.Y},${CurrentLocation.Z}].ID}]
			;echo "Current Point:" ${CurrentRegion.FQN} ${Math.Distance[${CurrentRegion.CenterPoint.X},${CurrentRegion.CenterPoint.Y},0,${Me.X}, ${Me.Y}, 0]}

			PathFinder:Reset
			CurrentPath:Clear

			;1981.57 -4787.25 55.80
			;673.57 -371.15 29.78 SP GY
			if ${WoWScript[GetRealZoneText()].Equal[Alterac Valley]}
			{
				DestinationRegion:SetRegion[${ZoneRegion.BestContainer[${FIGHTX},${FIGHTY},${FIGHTZ}].ID}]
			}
			else
			{
				DestinationRegion:SetRegion[${ZoneRegion.BestContainer[1979,-4788, 56].ID}]
			}

			;		DestinationRegion:SetRegion[${CurrentRegion.NearestChild[1981,-4787,55].FQN}]
			;echo "BOOGER: ${CurrentRegion.FQN},${DestinationRegion.FQN}"
			if ${CurrentRegion.FQN.Equal[${DestinationRegion.FQN}]}
			{
				;echo "We are already here"
				;cast "Berserker Stance"
				move -stop
			}
			PathFinder:SelectPath[${CurrentRegion.FQN},${DestinationRegion.FQN},CurrentPath]
			;		PathFinder:SelectPath[${CurrentRegion},${LNavRegion["Hall of the Brave-2"]},CurrentPath]

			;echo "HOPS: ${CurrentPath.Hops} I: ${i}"
;			if ${CurrentPath.Hops}!=${lasthop}
;			{
				; We have recalculated redo our path
;				i:Set[2]
;				lasthop:Set[${CurrentPath.Hops}]
;			}

			; If we dont have a path lets try to move back to a last known good one
			if ${CurrentPath.Hops} == 0
			{
				call Update_State BGNOPATH
				echo No Path! Moving directly
				move -stop
			}
			else
			{
				; We have a path... So lets get the next hop
				i:Set[1]
				; Make sure our next hop is at least 15 feet away from us
				do
				{
					i:Inc
				}
				while ${Math.Distance[${Me.X},${Me.Y},${CurrentPath.Region[${i}].CenterPoint.X},${CurrentPath.Region[${i}].CenterPoint.Y}]}<15
				
				;echo "Next Spot: ${CurrentPath.Region[${i}].CenterPoint.X} ${CurrentPath.Region[${i}].CenterPoint.Y}"
				; If it is not X=0/Y=0 then lets set our current good and move to the next hop
				if ${CurrentPath.Region[${i}].CenterPoint.X}!=0&&${CurrentPath.Region[${i}].CenterPoint.Y}!=0
				{
					; Mount if we are outdoors and Not in combat
					if !${WoWScript[IsIndoors()](exists)} && !${Me.InCombat} && !${Me.Buff[${MYMOUNTBUFF}](exists)}
					{
						call Update_State BGMOUNT
						call UpdateHudStatus "Mounting up"
						move -stop
						wait 10
						call DoMount
					}
					; Need to check if path is obstructed if so remove it and retry
					if ${Me.IsPathObstructed[${CurrentPath.Region[${i}].CenterPoint},9999,${Me.Location}]}
					{
						call UpdateHudStatus "Weighting next hop since it is obstructed"
						; need to do a check if it is over a certain number dont bother becuase this is appearntly our only path just try it
						; Need to do a check if we are rooted if so dont inc this
						CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[${Math.Calc[${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}+4]}]
						call UpdateHudStatus "Weight now ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}"
					}
					else
					{
						call Update_State BGRUN
						call movetocont ${CurrentPath.Region[${i}].CenterPoint.X} ${CurrentPath.Region[${i}].CenterPoint.Y} 5
						
						;If we didnt get stuck and this connection was weighted.. Lets Lower it since we got there through it
						if ${GOTSTUCK}==0 && ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}>0
						{
							CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[${Math.Calc[${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}-4]}]
							if ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}<0
							{
								CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[0]
							}
							call UpdateHudStatus "Weight now ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}"
						}
						if ${GOTSTUCK}==1
						{
							call UpdateHudStatus "We got stuck weighting next hop"
							; Need to do a check if it is over a certain number dont bother becuase this is appearntly our only path
							; Need to do a check if we are rooted if so dont inc this
							;CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[4]
							CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[${Math.Calc[${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}+4]}]
							call UpdateHudStatus "Weight now ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}"
						}
						GOTSTUCK:Set[0]
					}
				}
				else
				{
					; Stop because we have a fucked up x/y
					move -stop
				}
			}
			waitframe
		}
	}
	WINNER:Set[${WoWScript[GetBattlefieldWinner()]}]
	if ${WINNER}==0
	{
		HORDE_WINS:Inc
	}
	if ${WINNER}==1
	{
		ALIANCE_WINS:Inc
	}

	call Update_State BGWAITINGQ
	WoWScript LeaveBattlefield()
	wait 300
}

atom toggle()
{
	echo "Changing it"
	if ${DORUN}
	{
		DORUN:Set[0]
		return
	}
	DORUN:Set[1]
}

function kill_target(string TargetGUID)
{

;	Mapper:Plugin
	ZoneRegion:SetRegion[${LNavRegion[${WoWScript[GetRealZoneText()]}].FQN}]
	
	if ${This.CollisionTest[${Me.X},${Me.Y},${Me.Z},${Target.X},${Target.Y},${Target.Z}]}
	{
		call UpdateHudStatus "Can't get to ${Target}, clearing that out"
		wowscript ClearTarget()
		return
	}
	
	call UpdateHudStatus "Attacking ${Target}"

	WoWScript AttackTarget()
	if ${Me.Class.Equal[Warrior]}
	{
		call UpdateHudStatus "I am doing Warrior Fighting"
		call fight_warrior ${TargetGUID}
		return
	}
	if ${Me.Class.Equal[Mage]}
	{
		call UpdateHudStatus "I am doing Mage Fighting"
		call fight_mage ${TargetGUID}
		return
	}
	if ${Me.Class.Equal[Warlock]}
	{
		call UpdateHudStatus "I am doing Warlock Fighting"
		call fight_warlock ${TargetGUID}
		return
	}

	if ${Me.Class.Equal[priest]}
	{
		call UpdateHudStatus "I am doing Priest Fighting"
		call fight_priest ${TargetGUID}
		return
	}

	if ${Me.Class.Equal[Hunter]}
	{
		call UpdateHudStatus "I am doing Hunter Fighting"
		call fight_hunter ${TargetGUID}
		return
	} 	

	if ${Me.Class.Equal[Shaman]}
	{
		call UpdateHudStatus "I am doing Shaman Fighting"
		call fight_shaman ${TargetGUID}
		return
	}

	if ${Me.Class.Equal[Paladin]}
	{
		call UpdateHudStatus "I am doing Paladin Fighting"
		call fight_paladin ${TargetGUID}
		return
	}

	if ${Me.Class.Equal[Rogue]}
	{
		call UpdateHudStatus "I am doing Rogue Fighting"
		call fight_rogue ${TargetGUID}
		return
	}

	if ${Me.Class.Equal[Druid]}
	{
		call UpdateHudStatus "I am doing Druid Fighting"
		call fight_druid ${TargetGUID}
		return
	}
}

function check_buffs()
{
	if ${Me.Class.Equal[Warrior]}
	{
		call buff_warrior
		return
	}
	if ${Me.Class.Equal[Mage]}
	{
		call buff_mage
		return
	}
	if ${Me.Class.Equal[Warlock]}
	{
		call buff_warlock
		return
	}

	if ${Me.Class.Equal[priest]}
	{
		call buff_priest
		return
	}

	if ${Me.Class.Equal[Hunter]}
	{
		call buff_hunter
		return
	} 	

	if ${Me.Class.Equal[Shaman]}
	{
		call buff_shaman
		return
	}

	if ${Me.Class.Equal[Paladin]}
	{
		call buff_paladin
		return
	}

	if ${Me.Class.Equal[Rogue]}
	{
		call buff_rogue
		return
	}

	if ${Me.Class.Equal[Druid]}
	{
		call buff_druid
		return
	}
}

function AddHud()
{
	UI -load "${Script.CurrentDirectory}/avbot-ui.xml"
}

function RemoveHud()
{
	UI -unload "${Script.CurrentDirectory}/avbot-ui.xml"
}

function pulse_update()
{

;	BGBOTSTATUS:Set[UNKNOWN]
	Switch ${BGBOT}
	{
		case BGQUIT
			BGBOTSTATUS:Set[Quitting]
			break
		case BGPAUSE
			BGBOTSTATUS:Set[Pausing]
			break
		case BGINAV
			BGBOTSTATUS:Set[In AV]
			break
		case BGWAITINGQ
			BGBOTSTATUS:Set[Qued]
			break
		case BGDESERTER
			BGBOTSTATUS:Set[DESERTER]
			break
		case BGWAIT
			BGBOTSTATUS:Set[Waiting]
			break
		case BGWAITSTART
			BGBOTSTATUS:Set["Wait Start"]
			break
		case BGRUN
			BGBOTSTATUS:Set["Running"]
			break
		case BGDEAD
			BGBOTSTATUS:Set["Dead"]
			break
		case BGCOMBAT
			BGBOTSTATUS:Set["In Combat"]
			break
		case BGMOUNT
			BGBOTSTATUS:Set["Mounting"]
			break
		case BGNOPATH
			BGBOTSTATUS:Set["NO PATH"]
			break
	}
}

atom AddHonor(string Line, int points)
{
	KILLS:Inc
	BONUS:Inc[${points}]
	call UpdateHudStatus "Honor Update: KILL: ${points} for ${BONUS} KILLS: ${KILLS}"
}

atom AddHonor2(string Line, int points)
{
	echo Adding Bonus
	BONUS:Inc[${points}]
	call UpdateHudStatus "Honor Update: BONUS ${points} for ${BONUS}"
}

function UpdateHudStatus(string StatusMessage)
{
	UIElement[BGStatus@Status@BGBotTab@BGBot]:Echo["${Time}: ${StatusMessage}"]
	redirect -append "${Script.CurrentDirectory}/ChatLog.txt" echo "${Time}: ${StatusMessage}"
}

atom UpdateWhisper(string Line,string eventid, string message, string speaker, string language, ... junk)
{
	ReceivedWhispers:Inc
	UIElement[BGWhispers@Whispers@BGBotTab@BGBot]:Echo["[${Time}] ${speaker}: ${message}"]
	redirect -append "${Script.CurrentDirectory}/WhisperLog.txt" echo "${Time} ${speaker}: ${message}"
}


function MoveMeThere(int TOX, int TOY, int TOZ)
{
	declare i int local 0

	do
	{
		CurrentLocation.X:Set[${Me.X}]
		CurrentLocation.Y:Set[${Me.Y}]
		CurrentLocation.Z:Set[${Me.Z} + ${Math.Calc[${Me.Height} / 2]}]

		CurrentRegion:SetRegion[${ZoneRegion.BestContainer[${CurrentLocation.X},${CurrentLocation.Y},${CurrentLocation.Z}].ID}]

		PathFinder:Reset
		CurrentPath:Clear

		DestinationRegion:SetRegion[${ZoneRegion.BestContainer[${TOX},${TOY},${TOZ}].ID}]

		if ${CurrentRegion.FQN.Equal[${DestinationRegion.FQN}]}
		{
			move -stop
		}
		PathFinder:SelectPath[${CurrentRegion.FQN},${DestinationRegion.FQN},CurrentPath]

		; If we dont have a path lets try to move back to a last known good one
		if ${CurrentPath.Hops} == 0
		{
			echo No Path!
			move -stop
			return
		}
		else
		{
			; We have a path... So lets get the next hop
			i:Set[1]
			; Make sure our next hop is at least 15 feet away from us
			do
			{
				i:Inc
			}
			while ${Math.Distance[${Me.X},${Me.Y},${CurrentPath.Region[${i}].CenterPoint.X},${CurrentPath.Region[${i}].CenterPoint.Y}]}<8

			if ${CurrentPath.Region[${i}].CenterPoint.X}!=0&&${CurrentPath.Region[${i}].CenterPoint.Y}!=0
			{
				; Need to check if path is obstructed if so remove it and retry
				if ${Me.IsPathObstructed[${CurrentPath.Region[${i}].CenterPoint},9999,${Me.Location}]}
				{
					call UpdateHudStatus "Weighting next hop since it is obstructed"
					CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[${Math.Calc[${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}+4]}]
					call UpdateHudStatus "Weight now ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}"
				}
				else
				{
					call Update_State BGRUN
					call movetocont ${CurrentPath.Region[${i}].CenterPoint.X} ${CurrentPath.Region[${i}].CenterPoint.Y} 5
					if ${GOTSTUCK}==1
					{
						call UpdateHudStatus "We got stuck weighting next hop"
						;CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[4]
						CurrentPath.Connection[${Math.Calc[${i}-1]}]:SetDistance[${Math.Calc[${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}+4]}]
						call UpdateHudStatus "Weight now ${CurrentPath.Connection[${Math.Calc[${i}-1]}].Distance}"
					}
					GOTSTUCK:Set[0]
				}
			}
			else
			{
				; Stop because we have a fucked up x/y
				move -stop
			}
		}
		wait 2
	}
	while ${Math.Distance[${Me.X},${Me.Y},${TOX},${TOY}]}>8
}

function Load_Config()
{
	
	if !${ConfigFile.PathExists}
	{
		call UpdateHudStatus "Generating default configuration files"
		SettingXML[${ConfigFile}].Set[General Options]:Set[BGPERSON,"Kartra Bloodsnarl"]
		SettingXML[${ConfigFile}].Set[General Options]:Set[BGPERSONX,1981]
		SettingXML[${ConfigFile}].Set[General Options]:Set[BGPERSONY,-4788]
		SettingXML[${ConfigFile}].Set[General Options]:Set[BGPERSONZ,56]
		SettingXML[${ConfigFile}].Set[General Options]:Set[BGQUEZONE,"Orgrimmar"]
		SettingXML[${ConfigFile}].Set[AV Options]:Set[FIGHTX,706]
		SettingXML[${ConfigFile}].Set[AV Options]:Set[FIGHTY,-34]
		SettingXML[${ConfigFile}].Set[AV Options]:Set[FIGHTZ,51]
		SettingXML[${ConfigFile}].Set[Mount Options]:Set[MYMOUNT,"Great White Kodo"]
		SettingXML[${ConfigFile}].Set[Mount Options]:Set[MYMOUNTBUFF,"Great White Kodo"]
		SettingXML[${ConfigFile}]:Save
	}
	
	call UpdateHudStatus "Loaded configuration file ${ConfigFile}"
	SettingXML[${ConfigFile}]:Unload

	BGPERSON:Set[${SettingXML[${ConfigFile}].Set[General Options].GetString[BGPERSON,"Kartra Bloodsnarl"]}]
	BGPERSONX:Set[${SettingXML[${ConfigFile}].Set[General Options].GetInt[BGPERSONX,1981]}]
	BGPERSONY:Set[${SettingXML[${ConfigFile}].Set[General Options].GetInt[BGPERSONY,-4788]}]
	BGPERSONZ:Set[${SettingXML[${ConfigFile}].Set[General Options].GetInt[BGPERSONZ,56]}]
	BGQUEZONE:Set[${SettingXML[${ConfigFile}].Set[General Options].GetString[BGQUEZONE,"Orgrimmar"]}]
	FIGHTX:Set[${SettingXML[${ConfigFile}].Set[AV Options].GetInt[FIGHTX,1981]}]
	FIGHTY:Set[${SettingXML[${ConfigFile}].Set[AV Options].GetInt[FIGHTY,-4788]}]
	FIGHTZ:Set[${SettingXML[${ConfigFile}].Set[AV Options].GetInt[FIGHTZ,56]}]
	MYMOUNT:Set[${SettingXML[${ConfigFile}].Set[Mount Options].GetString[MYMOUNT,"Great White Kodo"]}]
	MYMOUNTBUFF:Set[${SettingXML[${ConfigFile}].Set[Mount Options].GetString[MYMOUNTBUFF,"Great White Kodo"]}]

}

function Update_State(int STATE)
{
	if ${BGBOT}==BGQUIT
	{
		; We have executed a quit lets not change that state
		return
	}
	; If it currently isnt that we will change it
	if ${BGBOT}!=${STATE}
	{
		BGBOT:Set[${STATE}]
		call pulse_update
	}
}

atom atexit()
{
	ui -unload "${Script.CurrentDirectory}/avbot-ui.xml"
}