Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if PQR_Addon_Loaded == nil then
- PQR_Addon_Loaded = true
- --PQR
- --These are functions that are expected to be loaded prior to general bot functionality.
- function PQR_Debug(strText, debugLevel)
- if PQR_DebugLevel == "Disabled" then
- return
- end
- if debugLevel == nil then
- debugLevel = ""
- end
- if PQR_DebugLevel == "Profile" then
- --ONLY display information on the profile level debug.
- if debugLevel == "Profile" then
- PQR_WriteToChat(strText, "Debug")
- end
- elseif PQR_DebugLevel == "Basic" then
- --Display all debug info that doesn't have "Advanced" tag.
- if debugLevel ~= "Advanced" then
- PQR_WriteToChat(strText, "Debug")
- end
- elseif PQR_DebugLevel == "Advanced" then
- --Display ALL data.
- PQR_WriteToChat(strText, "Debug")
- else
- --Do nothing.
- end
- end
- function PQR_DebugP(strText)
- PQR_Debug(strText, "Profile")
- end
- function PQR_SetDebug(enabled)
- if enabled == true then
- PQR_DebugEnabled = true
- else
- PQR_DebugEnabled = false
- end
- end
- function PQR_WriteToChat(strText, strSuffix)
- if PQR_ShowChat == true then
- if strSuffix == nil then
- print("|cffff7d0a<|r|cffffd200PQR|r|cffff7d0a>|r "..strText)
- else
- print("|cffff7d0a<|r|cffffd200PQR "..strSuffix.."|r|cffff7d0a>|r "..strText)
- end
- end
- end
- function PQR_LoadLua(fileName, forceRefresh)
- if fileName == nil then
- return false
- end
- if forceRefresh == true then
- --user wants to force re-run the Lua file.
- if PQR_LuaTable[fileName] ~= nil then
- PQR_Debug("Loading Lua File: "..fileName)
- PQR_LuaLoadedTable[fileName] = true
- PQR_LuaTable[fileName]()
- return true
- else
- return false
- end
- else
- --user only wants to run the Lua file once per session.
- if PQR_LuaTable[fileName] ~= nil then
- if PQR_LuaLoadedTable[fileName] == true then
- --we have already loaded the selected file.
- return true
- else
- --we need to run the lua file
- PQR_LuaLoadedTable[fileName] = true
- PQR_Debug("Loading Lua File: "..fileName)
- PQR_LuaTable[fileName]()
- return true
- end
- else
- return false
- end
- end
- --if we somehow got here...
- return false
- end
- --Setup the update frames.
- --This is considered the 'engine' of the bot, and is constantly being called every frame draw.
- --The bot supports 2 concurrent rotations, the normal 1-4 rotation and an interrupt rotation.
- function PQR_EventSend_OnUpdate(self, elapsed)
- PQR_EventSendElapsed = PQR_EventSendElapsed + elapsed
- while (PQR_EventSendElapsed > 0.1) do
- PQR_EventSendElapsed = PQR_EventSendElapsed - 0.1
- if PQR_SendEvents then
- PQR_SendEvents()
- end
- end
- end
- function PQR_StopRotation()
- PQR_ChangeRotation = true
- end
- function PQR_SwapRotation(newRotation, setRotation)
- local currentRotation = PQR_CurrentRotationNumber
- if currentRotation == nil then
- currentRotation = 0
- end
- if setRotation ~= nil then
- currentRotation = setRotation
- end
- if tonumber(newRotation) == nil then
- --swap by name
- if newRotation == nil then
- return false
- end
- if strtrim(newRotation) == "" then
- return false
- end
- if PQR_Rotations[newRotation] == nil then
- return false
- else
- local rotationName = strtrim(newRotation)
- local tblRotationName = { strsplit(" ", rotationName) }
- local lbound = 0
- local ubound = 0
- rotationName = ""
- for i=1,100 do
- --find the last ( and the last )
- if tblRotationName[i] == nil then
- break
- end
- if strfind(tblRotationName[i], "[(]") then
- lbound = i
- end
- end
- if lbound > 1 then
- for i=1,lbound -1 do
- rotationName = rotationName.." "..tblRotationName[i]
- end
- end
- if PQR_RotationName == "* "..strtrim(rotationName) then
- return false
- end
- if currentRotation == 0 then
- PQR_RotationName = "* "..strtrim(rotationName)
- PQR_ChangeRotation = true
- PQR_SwappedRotation = true
- end
- PQR[currentRotation] = PQR_Rotations[newRotation]
- return true
- end
- else
- --swap by number
- if newRotation < 1 or newRotation > 4 then
- return false
- end
- local rotationName = loadstring("return PQR_Rotation"..newRotation)()
- if rotationName == nil then
- return false
- end
- local tblRotationName = { strsplit(" ", rotationName) }
- local lbound = 0
- local ubound = 0
- rotationName = ""
- for i=1,100 do
- --find the last ( and the last )
- if tblRotationName[i] == nil then
- break
- end
- if strfind(tblRotationName[i], "[(]") then
- lbound = i
- end
- end
- if lbound > 1 then
- for i=1,lbound -1 do
- rotationName = rotationName.." "..tblRotationName[i]
- end
- end
- if PQR_RotationName == "* "..strtrim(rotationName) then
- return false
- end
- if currentRotation == 0 then
- PQR_SwappedRotation = true
- PQR_RotationName = strtrim(rotationName)
- PQR_ChangeRotation = true
- end
- PQR[currentRotation] = PQR[newRotation]
- return true
- end
- end
- function PQR_EventFrame_OnUpdate(self, elapsed)
- if UnitName == nil then
- --Not ingame, don't do anything.
- PQR_totalElapsed1 = 0
- PQR_totalElapsed2 = 0
- return
- end
- --Rotation mode
- PQR_totalElapsed1 = PQR_totalElapsed1 + elapsed
- while (PQR_totalElapsed1 > PQR_UpdateInterval1) do
- PQR_totalElapsed1 = PQR_totalElapsed1 - PQR_UpdateInterval1
- --Code here executes every Xms (default 100ms, set by user)
- local castManual = tonumber(PQR_CastManual())
- if castManual > 0 then
- PQR_RegisterMovement(PQR_totalElapsed1)
- PQR_ManualLoaded = true
- PQR_ExecuteRotation(castManual)
- end
- if PQR_ChangeRotation == true then
- PQR_ChangeRotation = false
- if PQR_RotationName == PQR_RunningRotationName then
- --we were passed a change request from the currently running profile.
- if PQR_RotationEnabled == true then
- PlaySound(PQR_soundStopRotation, "Master")
- PQR_Event("PQR_RotationChanged")
- PQR_WriteToChat(PQR_RotationName.." Disabled.")
- PQR_RotationEnabled = false
- PQR_RunningRotationName = ""
- else
- --Start rotation
- PlaySound(PQR_soundStartRotation, "Master")
- PQR_Event("PQR_RotationChanged", PQR_RotationName)
- PQR_WriteToChat(PQR_RotationName.." Enabled.")
- PQR_RunningRotationName = PQR_RotationName
- PQR_RotationEnabled = true
- --set the flag for profiles
- PQR_RotationStarted = true
- end
- else
- --we were passed a change request with a new profile name.
- if PQR_RunningRotationName ~= "" then
- if PQR_SwappedRotation ~= true then
- PQR_WriteToChat(PQR_RunningRotationName.." Disabled.")
- PlaySound(PQR_soundChangeRotation, "Master")
- end
- else
- PlaySound(PQR_soundStartRotation, "Master")
- end
- PQR_Event("PQR_RotationChanged", PQR_RotationName)
- PQR_WriteToChat(PQR_RotationName.." Enabled.")
- if PQR_SwappedRotation ~= true then
- PQR_RunningRotationName = PQR_RotationName
- end
- PQR_RotationEnabled = true
- --set the flag for profiles
- PQR_ResetMovementTime = 0.5
- PQR_SpellAvailableTime = 0.125
- PQR_RotationStarted = true
- PQR_SwappedRotation = false
- end
- end
- if PQR_RotationEnabled then
- PQR_RegisterMovement(PQR_totalElapsed1)
- PQR_ExecuteRotation(0)
- end
- end
- --Interrupt mode
- PQR_totalElapsed2 = PQR_totalElapsed2 + elapsed
- while (PQR_totalElapsed2 > PQR_UpdateInterval2) do
- PQR_RegisterMovement(PQR_totalElapsed2)
- PQR_totalElapsed2 = PQR_totalElapsed2 - PQR_UpdateInterval2
- --Code here executes every 50ms.
- if PQR_ChangeInterrupt == true then
- PQR_ChangeInterrupt = false
- if PQR_InterruptName == PQR_RunningInterruptName then
- --we were passed a change request from the currently running profile.
- if PQR_InterruptEnabled == true then
- PlaySound(PQR_soundStopInterrupt, "Master")
- PQR_Event("PQR_InterruptChanged")
- PQR_WriteToChat(PQR_InterruptName.." Disabled.", "Interrupt")
- PQR_InterruptEnabled = false
- PQR_RunningInterruptName = ""
- else
- PlaySound(PQR_soundStartInterrupt, "Master")
- PQR_Event("PQR_InterruptChanged", PQR_InterruptName)
- PQR_WriteToChat(PQR_InterruptName.." Enabled.", "Interrupt")
- PQR_RunningInterruptName = PQR_InterruptName
- PQR_InterruptEnabled = true
- --set the flag for profiles
- PQR_InterruptStarted = true
- end
- else
- --we were passed a change request with a new profile name.
- if PQR_RunningInterruptName ~= "" then
- PQR_WriteToChat(PQR_RunningInterruptName.." Disabled.", "Interrupt")
- end
- PlaySound(PQR_soundStartInterrupt, "Master")
- PQR_Event("PQR_InterruptChanged", PQR_InterruptName)
- PQR_WriteToChat(PQR_InterruptName.." Enabled.", "Interrupt")
- PQR_RunningInterruptName = PQR_InterruptName
- PQR_InterruptEnabled = true
- --set the flag for profiles
- PQR_InterruptStarted = true
- end
- end
- if PQR_InterruptEnabled then
- --Cast next interrupt.
- PQR_ExecuteInterrupt()
- end
- end
- end
- function PQR_SetupInterruptTable()
- if PQR == nil then
- PQR = {}
- end
- PQR.interruptTable = {}
- PQR.interruptTable.spell = {}
- PQR.interruptPriorityTable = {}
- PQR.interruptPriorityTable.index = {}
- PQR.interruptPriorityTable.ability = {}
- PQR.interruptPriorityTable.spellid = {}
- PQR.interruptPriorityTable.target = {}
- PQR.interruptPriorityTable.actions = {}
- PQR.interruptPriorityTable.lua = {}
- PQR.interruptPriorityTable.recast = {}
- PQR.interruptPriorityTable.delay = {}
- PQR.interruptPriorityTable.cancelChannel = {}
- PQR.interruptPriorityTable.skipUnknown = {}
- PQR.interruptPriorityTable.requireCombat = true
- end
- function PQR_SetupTables()
- --Creates a clean priorityTable
- if PQR == nil then
- PQR = {}
- end
- for i=0,4 do
- PQR[i] = {}
- PQR[i].priorityTable = {}
- PQR[i].priorityTable.index = {}
- PQR[i].priorityTable.ability = {}
- PQR[i].priorityTable.spellid = {}
- PQR[i].priorityTable.target = {}
- PQR[i].priorityTable.actions = {}
- PQR[i].priorityTable.lua = {}
- PQR[i].priorityTable.recast = {}
- PQR[i].priorityTable.delay = {}
- PQR[i].priorityTable.cancelChannel = {}
- PQR[i].priorityTable.skipUnknown = {}
- PQR[i].priorityTable.requireCombat = true
- end
- --delayTable is used to pause the rotation on UNIT_SPELLCAST_SENT/FAILED so a player spamming an ability can cast that ability
- --ex: Divine Shield would be on the delayTable since it is on GCD and the bot spamming it would prevent it.
- PQR.delayTable = {}
- PQR.delayTable.spell = {}
- PQR.delayTable.item = {}
- PQR.delayTable.delay = {}
- PQR.delayTable.delayTime = {}
- PQR.losTable = {}
- PQR.losTable.name = {}
- PQR.losTable.time = {}
- PQR_Rotations = {}
- PQR_Rotations.priorityTable = {}
- PQR_Rotations.priorityTable.index = {}
- PQR_Rotations.priorityTable.ability = {}
- PQR_Rotations.priorityTable.spellid = {}
- PQR_Rotations.priorityTable.target = {}
- PQR_Rotations.priorityTable.actions = {}
- PQR_Rotations.priorityTable.lua = {}
- PQR_Rotations.priorityTable.recast = {}
- PQR_Rotations.priorityTable.delay = {}
- PQR_Rotations.priorityTable.cancelChannel = {}
- PQR_Rotations.priorityTable.skipUnknown = {}
- PQR_Rotations.priorityTable.requireCombat = true
- PQR_Rotations.priorityTable.rotationName = true
- end
- function PQR_EventFrame_OnEvent(self, event, ...)
- -- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- -- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
- if event == "PLAYER_ENTERING_WORLD" then
- PQR_EventFrame:Show()
- elseif event == "PLAYER_LOGOUT" then
- --Clean up when we are logging out.
- PQR_RotationEnabled = false
- PQR_InterruptEnabled = false
- PQR_RunningInterruptName = ""
- PQR_RunningRotationName = ""
- PQR_SetupTables()
- PQR_SetupInterruptTable()
- elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
- local unitCaster, unitSpell, _, _, unitSpellID = ...
- if unitCaster ~= "player" then
- return
- end
- PQR_SetRecastDelay(unitSpellID)
- --REMOVE DELAY CODING
- local spell = PQR.delayTable.spell[unitSpell]
- if spell ~= nil then
- --just remove the delay, this message indicates casting succeeded.
- PQR_Debug("DELAY: Removed "..unitSpell.." as the cast was successful.")
- PQR.delayTable.delayTime[unitSpell] = 0
- end
- elseif event == "UNIT_SPELLCAST_START" then
- local unitCaster, unitSpell, _, _, unitSpellID = ...
- if unitCaster ~= "player" then
- return
- end
- PQR_SetRecastDelay(unitSpellID, true)
- elseif event == "UNIT_SPELLCAST_INTERRUPTED" then
- local unitCaster, unitSpell, _, _, unitSpellID = ...
- if unitCaster ~= "player" then
- return
- end
- PQR_ResetRecastDelay(unitSpellID)
- elseif event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_FAILED_QUIET" then
- local unitCaster, unitSpell, _, _, unitSpellID = ...
- if unitCaster ~= "player" then
- return
- end
- --DELAY CODING
- local incrementDelay = PQR.delayTable.delay[unitSpell]
- local item = PQR.delayTable.item[unitSpell]
- if incrementDelay ~= nil then
- --This spell has a delay associated with it.
- if item == nil or item == "" or item == 0 then
- --no item ID to check.. check if the spell is on cooldown.
- local spellStart, spellDuration = GetSpellCooldown(unitSpellID)
- local spellCooldown = spellStart - GetTime() + spellDuration
- local gcdSpell = PQR_GCDSpellID()
- local gcdStartTime, gcdDuration = GetSpellCooldown(gcdSpell)
- local gcdTimeLeft = gcdStartTime + gcdDuration - GetTime()
- if gcdTimeLeft < 0 then
- gcdTimeLeft = 0
- end
- spellCooldown = spellCooldown - gcdTimeLeft
- if spellCooldown > 0 then
- --This spell is on cooldown, remove it's delay
- PQR_Debug("DELAY: "..unitSpell.." was not added. Spell is on cooldown > GCD.")
- PQR.delayTable.delayTime[unitSpell] = 0
- else
- --This spell is not on CD... increment it's delay time.
- PQR_Debug("DELAY: "..unitSpell.." was added.")
- PQR.delayTable.delayTime[unitSpell] = GetTime() + incrementDelay
- end
- else
- --item ID to check
- local itemStart, itemDuration, itemEnabled = GetItemCooldown(item)
- local itemCooldown = itemStart - GetTime() + itemDuration
- if itemCooldown > 0 then
- PQR_Debug("DELAY: "..unitSpell.." was not added. Item is on cooldown.")
- --This item is on CD, remove it's delay.
- PQR.delayTable.delayTime[unitSpell] = 0
- else
- --This item is not on CD, increment it's delay time.
- PQR_Debug("DELAY: "..unitSpell.." was added.")
- PQR.delayTable.delayTime[unitSpell] = GetTime() + incrementDelay
- end
- end
- end
- elseif event == "UI_ERROR_MESSAGE" then
- local errorMessage = ...
- PQR_LastUIError[errorMessage] = GetTime()
- if errorMessage == SPELL_FAILED_NOT_BEHIND then
- PQR_BehindTime = GetTime()
- elseif errorMessage == SPELL_FAILED_LINE_OF_SIGHT then
- --code here for LOS failure.
- if PQR_LastTarget ~= "" then
- if PQR_LastCastTime > GetTime() - 1 then
- PQR.losTable.name[PQR_LastTarget] = PQR_LastTarget
- PQR.losTable.time[PQR_LastTarget] = PQR_LastCastTime
- PQR_Debug("Added LOS record for "..PQR_LastTarget..".", "Advanced")
- PQR_LastTarget = ""
- PQR_LastCastTime = 0
- end
- end
- end
- end
- end
- function PQR_ExecuteRotation(rotationNumber)
- --Check if we are in combat.
- local inCombat = UnitAffectingCombat("player")
- if inCombat == nil then
- inCombat = UnitAffectingCombat("pet")
- end
- --Does this rotation require combat?
- local requireCombat = PQR[rotationNumber].priorityTable.requireCombat
- --If we are not in combat and this rotation requires combat, and we are in auto-mode... cancel this.
- if (requireCombat == true and inCombat ~= 1) and rotationNumber == 0 then
- return
- end
- local nextAbility = PQR_NextAbility(rotationNumber)
- if nextAbility ~= -1 then
- --we have an ability to cast.
- local abilityName = PQR[rotationNumber].priorityTable.ability[nextAbility]
- local spellID = PQR[rotationNumber].priorityTable.spellid[nextAbility]
- local spellTarget = PQR[rotationNumber].priorityTable.target[nextAbility]
- local actions = PQR[rotationNumber].priorityTable.actions[nextAbility]
- PQR_Event("PQR_ExecutingAbility", abilityName, spellID, rotationNumber)
- PQR_CastAbility(abilityName, spellID, spellTarget, actions)
- else
- --Send empty ability
- PQR_Event("PQR_ExecutingAbility", nil, nil, rotationNumber)
- end
- end
- function PQR_ExecuteInterrupt()
- --Check if we are in combat.
- local inCombat = UnitAffectingCombat("player")
- if inCombat == nil then
- inCombat = UnitAffectingCombat("pet")
- end
- --Does this rotation require combat?
- local requireCombat = PQR.interruptPriorityTable.requireCombat
- local playerChanneling = PQR_IsChanneling()
- for i=0,1023 do
- if PQR.interruptPriorityTable.index[i] ~= nil then
- local abilityName = PQR.interruptPriorityTable.ability[i]
- local spellID = PQR.interruptPriorityTable.spellid[i]
- local spellTarget = PQR.interruptPriorityTable.target[i]
- local actions = PQR.interruptPriorityTable.actions[i]
- local skipUnknown = PQR.interruptPriorityTable.skipUnknown[i]
- if spellID == 0 then
- if (playerChanneling == PQR.interruptPriorityTable.cancelChannel[i]) or (playerChanneling == false) then
- PQR_CurrentRotationNumber = 5
- PQR_CurrentAbilityName = abilityName
- local testLua = PQR.interruptPriorityTable.lua[i]()
- PQR_CurrentAbilityName = nil
- PQR_CurrentRotationNumber = nil
- if testLua == true then
- PQR_Event("PQR_ExecutingAbility", abilityName, spellID, 5)
- PQR_Debug("Ability "..abilityName.." returned true.")
- if actions ~= nil then
- local tbl = { strsplit("|", actions) }
- for i=1,100 do
- if tbl[i] == nil then
- break
- end
- if tbl[i] ~= "" then
- PQR_Debug("Running Action "..abilityName.." ("..tbl[i]..")")
- RunMacroText(tbl[i])
- end
- end
- end
- end
- end
- else
- local isSpellKnown = IsSpellKnown(spellID)
- if isSpellKnown == true or skipUnknown == false then
- if PQR_SpellAvailable(spellID) then
- --spell is available
- if PQR.interruptPriorityTable.delay[i] <= (GetTime() * 1000) then
- --spell is not being delayed.
- if (playerChanneling == PQR.interruptPriorityTable.cancelChannel[i]) or (playerChanneling == false) then
- --player is not channeling or the spell allows cancel-channel
- PQR_CurrentRotationNumber = 5
- PQR_CurrentAbilityName = abilityName
- local testLua = PQR.interruptPriorityTable.lua[i]()
- PQR_CurrentAbilityName = nil
- PQR_CurrentRotationNumber = nil
- if testLua == true then
- PQR_Debug("Ability "..abilityName.." returned true.")
- --Ability returned true
- if actions ~= nil then
- --Perform any actions if necessary.
- local tbl = { strsplit("|", actions) }
- for i=1,100 do
- if tbl[i] == nil then
- break
- end
- if tbl[i] ~= "" then
- PQR_Debug("Running Action "..abilityName.." ("..tbl[i]..")")
- RunMacroText(tbl[i])
- end
- end
- end
- --cast the spell.
- PQR_CastAbility(abilityName, spellID, spellTarget, actions)
- PQR_Event("PQR_ExecutingAbility", abilityName, spellID, 5)
- end
- end
- end
- end
- else
- PQR_Debug(abilityName.." is an unknown spell ID. SPELL SKIPPED.", "Advanced")
- end
- end
- else
- --no more abilities in this rotation.
- break
- end
- end
- end
- function PQR_CastAbility(abilityName, spellID, spellTarget, actions)
- if actions ~= nil and actions ~= "" then
- --we have actions to send.
- local tbl = { strsplit("|", actions) }
- for i=1,100 do
- if tbl[i] == nil then
- break
- end
- if tbl[i] ~= "" then
- PQR_Debug("Running Action "..abilityName.." ("..tbl[i]..")")
- RunMacroText(tbl[i])
- end
- end
- end
- if spellID ~= 0 then
- PQR_LastCastTime = GetTime()
- local spellName = GetSpellInfo(spellID)
- if spellTarget == "click" then
- PQR_Debug("Casting "..abilityName.." ("..spellName..") on MOUSE LOCATION")
- local friendPlates = GetCVar("nameplateShowFriends")
- local enemyPlates = GetCVar("nameplateShowEnemies")
- SetCVar("nameplateShowFriends", 0)
- SetCVar("nameplateShowEnemies", 0)
- local spellToCast = GetSpellInfo(spellID)
- CastSpellByName(spellToCast)
- --CastSpellByID(spellID)
- local oldtargetName = UnitName("target")
- CameraOrSelectOrMoveStart()
- CameraOrSelectOrMoveStop()
- SetCVar("nameplateShowFriends", friendPlates)
- SetCVar("nameplateShowEnemies", enemyPlates)
- local newTargetName = UnitName("target")
- if oldTargetName ~= nil then
- if oldTargetName ~= newTargetName then
- TargetLastTarget()
- end
- else
- ClearTarget()
- end
- elseif spellTarget == "custom" then
- if UnitExists(PQR_CustomTarget) then
- PQR_Debug("Casting "..abilityName.." ("..spellName..") on "..UnitName(PQR_CustomTarget), "Advanced")
- PQR_LastTarget = UnitName(PQR_CustomTarget)
- local spellToCast = GetSpellInfo(spellID)
- --CastSpellByID(spellID, PQR_CustomTarget)
- CastSpellByName(spellToCast, PQR_CustomTarget)
- else
- if PQR_CustomTarget == nil then
- PQR_CustomTarget = "no_target_specified"
- end
- PQR_Debug("Custom target does not exist. ("..PQR_CustomTarget..")")
- end
- PQR_CustomTarget = ""
- else
- PQR_Debug("Casting "..abilityName.." ("..spellName..") on "..spellTarget, "Advanced")
- if UnitExists(spellTarget) then
- PQR_LastTarget = UnitName(spellTarget)
- end
- local spellToCast = GetSpellInfo(spellID)
- --CastSpellByID(spellID, spellTarget)
- CastSpellByName(spellToCast, spellTarget)
- end
- end
- end
- function PQR_NextAbility(rotationNumber)
- --Find the next ability to cast in the indicated rotation.
- local nextAbility = -1
- if PQR[rotationNumber] ~= nil then
- --Loop through the PQR[i].priorityTable for the next ability to cast.
- local playerChanneling = PQR_IsChanneling()
- --If a global pause has been set, don't do anything.
- if PQR_IsRotationDelayed() then
- PQR_Debug("DELAY: Rotation is delayed. Spell or item use attemped.")
- else
- for i=0,1023 do
- if PQR[rotationNumber].priorityTable.index[i] ~= nil then
- local spellID = PQR[rotationNumber].priorityTable.spellid[i]
- local skipUnknown = PQR[rotationNumber].priorityTable.skipUnknown[i]
- if spellID ~= 0 then
- --we have an ability with a spell ID attached to it, also do a PQR_SpellAvailable()
- local isSpellKnown = IsSpellKnown(spellID)
- if isSpellKnown == true or skipUnknown == false then
- if PQR_SpellAvailable(spellID) then
- --spell is available.
- if PQR[rotationNumber].priorityTable.delay[i] <= (GetTime() * 1000) then
- --spell isn't being delayed.
- if (playerChanneling == PQR[rotationNumber].priorityTable.cancelChannel[i]) or (playerChanneling == false) then
- --not channeling, or the spell is allowed to break channeling
- PQR_CurrentRotationNumber = rotationNumber
- PQR_CurrentAbilityName = PQR[rotationNumber].priorityTable.ability[i]
- local testLua = PQR[rotationNumber].priorityTable.lua[i]()
- PQR_CurrentAbilityName = nil
- PQR_CurrentRotationNumber = nil
- if PQR_ChangeRotation == true then
- return -1
- end
- if testLua == true then
- PQR_Debug(PQR[rotationNumber].priorityTable.ability[i].. " returned true. Executing ability.")
- return i
- end
- end
- end
- end
- else
- PQR_Debug(PQR[rotationNumber].priorityTable.ability[i].." is an unknown spell ID. SPELL SKIPPED.", "Advanced")
- end
- else
- --0 spell ID....
- if (playerChanneling == PQR[rotationNumber].priorityTable.cancelChannel[i]) or (playerChanneling == false) then
- PQR_CurrentRotationNumber = rotationNumber
- PQR_CurrentAbilityName = PQR[rotationNumber].priorityTable.ability[i]
- local testLua = PQR[rotationNumber].priorityTable.lua[i]()
- PQR_CurrentAbilityName = nil
- PQR_CurrentRotationNumber = nil
- if PQR_ChangeRotation == true then
- return -1
- end
- if testLua == true then
- --test code returned true
- PQR_Debug(PQR[rotationNumber].priorityTable.ability[i].. " returned true. Executing ability.")
- return i
- end
- end
- end
- else
- --no further abilities in this rotation
- break
- end
- end
- end
- end
- return nextAbility
- end
- function PQR_IsChanneling()
- local _, _, _, _, _, playerChanneling = UnitChannelInfo("player")
- local isPlayerChanneling = false
- if playerChanneling ~= nil then
- local currentTime = GetTime() * 1000
- if (playerChanneling - currentTime) > 100 then
- isPlayerChanneling = true
- end
- end
- return isPlayerChanneling
- end
- function PQR_GCDSpellID()
- local _, playerClass = UnitClass("player")
- if playerClass == "DEATHKNIGHT" then
- return 52375
- elseif playerClass == "DRUID" then
- return 774
- elseif playerClass == "HUNTER" then
- return 56641
- elseif playerClass == "MAGE" then
- return 1459
- elseif playerClass == "PALADIN" then
- return 85256
- elseif playerClass == "PRIEST" then
- return 2050
- elseif playerClass == "ROGUE" then
- return 1752
- elseif playerClass == "SHAMAN" then
- return 45284
- elseif playerClass == "WARLOCK" then
- return 980
- elseif playerClass == "WARRIOR" then
- return 1715
- elseif playerClass == "MONK" then
- return 100780
- else
- return 0
- end
- end
- function PQR_SpellAvailable(spellID)
- local gcdSpell = PQR_GCDSpellID()
- local gcdStartTime, gcdDuration = GetSpellCooldown(gcdSpell)
- local spellStartTime, spellDuration = GetSpellCooldown(spellID)
- local spellUsable = IsUsableSpell(spellID)
- local spellAvailable = false
- if spellUsable then
- if spellStartTime ~= nil and gcdStartTime ~= nil then
- local spellTimeLeft = spellStartTime + spellDuration - GetTime()
- local gcdTimeLeft = gcdStartTime + gcdDuration - GetTime()
- if gcdTimeLeft <= 0 then
- --Our GCD spell is not on CD.
- if spellTimeLeft <= PQR_SpellAvailableTime then
- --spell will be off CD within 50ms.
- spellAvailable = true
- end
- else
- --Out GCD spell is on CD.
- if spellTimeLeft <= gcdTimeLeft + PQR_SpellAvailableTime then
- --spell time left is less than GCD time left + 50ms.
- spellAvailable = true
- end
- end
- end
- end
- return spellAvailable
- end
- function PQR_AddAllAbilities(rotationName, requireCombat, abilityName, spid, actn, testCode, recastDelay, targetCast, cancelChannel, skipUnknown)
- if PQR_Rotations[rotationName] == nil then
- --setup this table
- PQR_Rotations[rotationName] = {}
- PQR_Rotations[rotationName].priorityTable = {}
- PQR_Rotations[rotationName].priorityTable.index = {}
- PQR_Rotations[rotationName].priorityTable.ability = {}
- PQR_Rotations[rotationName].priorityTable.spellid = {}
- PQR_Rotations[rotationName].priorityTable.target = {}
- PQR_Rotations[rotationName].priorityTable.actions = {}
- PQR_Rotations[rotationName].priorityTable.lua = {}
- PQR_Rotations[rotationName].priorityTable.recast = {}
- PQR_Rotations[rotationName].priorityTable.delay = {}
- PQR_Rotations[rotationName].priorityTable.cancelChannel = {}
- PQR_Rotations[rotationName].priorityTable.skipUnknown = {}
- PQR_Rotations[rotationName].priorityTable.requireCombat = requireCombat
- PQR_Rotations[rotationName].priorityTable.rotationName = rotationName
- end
- for i=0,1023 do
- if PQR_Rotations[rotationName].priorityTable.index[i] == nil then
- PQR_Debug("Added "..abilityName.." at index "..i.." in rotation "..rotationName, "Advanced")
- PQR_Rotations[rotationName].priorityTable.index[i] = i
- PQR_Rotations[rotationName].priorityTable.ability[i] = abilityName
- PQR_Rotations[rotationName].priorityTable.spellid[i] = spid
- PQR_Rotations[rotationName].priorityTable.target[i] = targetCast
- PQR_Rotations[rotationName].priorityTable.actions[i] = actn
- PQR_Rotations[rotationName].priorityTable.lua[i] = loadstring(testCode)
- PQR_Rotations[rotationName].priorityTable.recast[i] = recastDelay
- PQR_Rotations[rotationName].priorityTable.delay[i] = 0
- PQR_Rotations[rotationName].priorityTable.cancelChannel[i] = cancelChannel
- PQR_Rotations[rotationName].priorityTable.skipUnknown[i] = skipUnknown
- break
- end
- end
- end
- function PQR_AddAbility(rotationNumber, abilityName, spid, actn, testCode, recastDelay, targetCast, cancelChannel, skipUnknown)
- for i=0,1023 do
- if PQR[rotationNumber].priorityTable.index[i] == nil then
- PQR_Debug("Added "..abilityName.." at index "..i.." in rotation "..rotationNumber)
- --create the function for this ability
- PQR[rotationNumber].priorityTable.index[i] = i
- PQR[rotationNumber].priorityTable.ability[i] = abilityName
- PQR[rotationNumber].priorityTable.spellid[i] = spid
- PQR[rotationNumber].priorityTable.target[i] = targetCast
- PQR[rotationNumber].priorityTable.actions[i] = actn
- PQR[rotationNumber].priorityTable.lua[i] = loadstring(testCode)
- PQR[rotationNumber].priorityTable.recast[i] = recastDelay
- PQR[rotationNumber].priorityTable.delay[i] = 0
- PQR[rotationNumber].priorityTable.cancelChannel[i] = cancelChannel
- PQR[rotationNumber].priorityTable.skipUnknown[i] = skipUnknown
- break
- end
- end
- end
- function PQR_AddInterruptAbility(abilityName, spid, actn, testCode, recastDelay, targetCast, cancelChannel, skipUnknown)
- for i=0,1023 do
- if PQR.interruptPriorityTable.index[i] == nil then
- --create the function for this test.
- PQR.interruptPriorityTable.index[i] = i
- PQR.interruptPriorityTable.ability[i] = abilityName
- PQR.interruptPriorityTable.spellid[i] = spid
- PQR.interruptPriorityTable.target[i] = targetCast
- PQR.interruptPriorityTable.actions[i] = actn
- PQR.interruptPriorityTable.lua[i] = loadstring(testCode)
- PQR.interruptPriorityTable.recast[i] = recastDelay
- PQR.interruptPriorityTable.delay[i] = 0
- PQR.interruptPriorityTable.cancelChannel[i] = cancelChannel
- PQR.interruptPriorityTable.skipUnknown[i] = skipUnknown
- break
- end
- end
- end
- function PQR_AddInterrupt(spellName)
- if tonumber(spellName) ~= nil then
- spellName = GetSpellInfo(spellName)
- end
- for i=0,1023 do
- if PQR.interruptTable.spell[i] == spellName then
- PQR_Debug("Spell "..spellName.." was already on the interrupt list at position "..i)
- break
- end
- if PQR.interruptTable.spell[i] == nil then
- PQR_Debug("Added "..spellName.." to interrupt list at position "..i)
- PQR.interruptTable.spell[i] = spellName
- break
- end
- end
- end
- function PQR_ResetInterruptList()
- PQR.interruptTable.spell = {}
- end
- function PQR_IsInterruptAll()
- if PQR_InterruptAll == true then
- return true
- else
- return false
- end
- end
- function PQR_IsOnInterruptList(spellName)
- for i=0,1023 do
- if PQR.interruptTable.spell[i] == nil then
- return false
- end
- if PQR.interruptTable.spell[i] == spellName then
- return true
- end
- end
- return false
- end
- function UnitBuffID(unit, spellID, filter)
- local spellName = GetSpellInfo(spellID)
- if filter == nil then
- return UnitBuff(unit, spellName)
- else
- local exactSearch = strfind(strupper(filter), "EXACT")
- local playerSearch = strfind(strupper(filter), "PLAYER")
- if exactSearch then
- --using the index does not support filter.
- for i=1,40 do
- local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitBuff(unit, i)
- if buffSpellID ~= nil then
- if buffSpellID == spellID then
- if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
- return UnitBuff(unit, i)
- end
- end
- else
- return nil
- end
- end
- else
- --just pass the filter to UnitBuff and return.
- return UnitBuff(unit, spellName, nil, filter)
- end
- end
- end
- function UnitDebuffID(unit, spellID, filter)
- local spellName = GetSpellInfo(spellID)
- if filter == nil then
- return UnitDebuff(unit, spellName)
- else
- local exactSearch = strfind(strupper(filter), "EXACT")
- local playerSearch = strfind(strupper(filter), "PLAYER")
- if exactSearch then
- --using the index does not support filter.
- for i=1,40 do
- local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitDebuff(unit, i)
- if buffSpellID ~= nil then
- if buffSpellID == spellID then
- if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
- return UnitDebuff(unit, i)
- end
- end
- else
- return nil
- end
- end
- else
- --just pass the filter to UnitDebuff and return.
- return UnitDebuff(unit, spellName, nil, filter)
- end
- end
- end
- function PQR_UnitBuffID(unit, spellID, filter)
- local spellName = GetSpellInfo(spellID)
- if filter == nil then
- return UnitBuff(unit, spellName)
- else
- local exactSearch = strfind(strupper(filter), "EXACT")
- local playerSearch = strfind(strupper(filter), "PLAYER")
- if exactSearch then
- --using the index does not support filter.
- for i=1,40 do
- local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitBuff(unit, i)
- if buffSpellID ~= nil then
- if buffSpellID == spellID then
- if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
- return UnitBuff(unit, i)
- end
- end
- else
- return nil
- end
- end
- else
- --just pass the filter to UnitBuff and return.
- return UnitBuff(unit, spellName, nil, filter)
- end
- end
- end
- function PQR_UnitDebuffID(unit, spellID, filter)
- local spellName = GetSpellInfo(spellID)
- if filter == nil then
- return UnitDebuff(unit, spellName)
- else
- local exactSearch = strfind(strupper(filter), "EXACT")
- local playerSearch = strfind(strupper(filter), "PLAYER")
- if exactSearch then
- --using the index does not support filter.
- for i=1,40 do
- local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitDebuff(unit, i)
- if buffSpellID ~= nil then
- if buffSpellID == spellID then
- if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
- return UnitDebuff(unit, i)
- end
- end
- else
- return nil
- end
- end
- else
- --just pass the filter to UnitDebuff and return.
- return UnitDebuff(unit, spellName, nil, filter)
- end
- end
- end
- function PQR_ResetRecastDelay(spellID)
- if spellID == nil or spellID == 0 then
- return
- end
- local spellName = GetSpellInfo(spellID)
- PQR_Debug("ResetRecastDelay called for spell "..spellName, "Advanced")
- if PQR_InterruptEnabled then
- --interrupt enabled
- for i=0,1023 do
- if PQR.interruptPriorityTable.index[i] == nil then
- break
- end
- if PQR.interruptPriorityTable.spellid[i] == spellID then
- PQR.interruptPriorityTable.delay[i] = 0
- end
- end
- end
- if PQR_RotationEnabled then
- --auto mode
- for y=0,4 do
- for i=0,1023 do
- if PQR[y].priorityTable.index[i] == nil then
- break
- end
- if PQR[y].priorityTable.spellid[i] == spellID then
- PQR[y].priorityTable.delay[i] = 0
- end
- end
- end
- else
- --manual mode
- for y=1,4 do
- for i=0,1023 do
- if PQR[y].priorityTable.index[i] == nil then
- break
- end
- if PQR[y].priorityTable.spellid[i] == spellID then
- PQR[y].priorityTable.delay[i] = 0
- end
- end
- end
- end
- end
- function PQR_SetRecastDelay(spellID, addCastTime)
- if spellID == nil or spellID == 0 then
- return
- end
- local castingSpellName,_, _, _, _, _, castTime = GetSpellInfo(spellID)
- if castingSpellName == nil then
- return
- end
- PQR_Debug("SetRecastDelay called for "..castingSpellName, "Advanced")
- --Add delays to interrupt mode if necessary.
- if PQR_InterruptEnabled then
- for i=0,1023 do
- if PQR.interruptPriorityTable.index[i] == nil then
- break
- end
- if PQR.interruptPriorityTable.spellid[i] == spellID and PQR.interruptPriorityTable.recast[i] ~= 0 then
- --set a delay
- if addCastTime then
- PQR.interruptPriorityTable.delay[i] = (GetTime() * 1000) + PQR.interruptPriorityTable.recast[i] + castTime
- else
- PQR.interruptPriorityTable.delay[i] = (GetTime() * 1000) + PQR.interruptPriorityTable.recast[i]
- end
- end
- end
- end
- if PQR_RotationEnabled then
- for y=0,4 do
- for i=0,1023 do
- if PQR[y].priorityTable.index[i] == nil then
- break
- end
- if PQR[y].priorityTable.spellid[i] == spellID and PQR[y].priorityTable.recast[i] ~= 0 then
- if addCastTime then
- PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i] + castTime
- else
- PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i]
- end
- end
- end
- end
- else
- if PQR_ManualLoaded then
- for y=1,4 do
- for i=0,1023 do
- if PQR[y].priorityTable.index[i] == nil then
- break
- end
- if PQR[y].priorityTable.spellid[i] == spellID and PQR[y].priorityTable.recast[i] ~= 0 then
- if addCastTime then
- PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i] + castTime
- else
- PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i]
- end
- end
- end
- end
- end
- end
- end
- function PQR_Cast(rotationNumber)
- local cvarValue = GetCVar("PQR")
- if cvarValue == nil then
- cvarValue = 0
- RegisterCVar("PQR", cvarValue)
- end
- if rotationNumber >= 1 or rotationNumber <= 4 then
- cvarValue = rotationNumber
- end
- SetCVar("PQR", cvarValue)
- end
- function PQR_CastManual()
- local cvarValue = GetCVar("PQR")
- if cvarValue == nil then
- cvarValue = 0
- RegisterCVar("PQR", cvarValue)
- end
- SetCVar("PQR", 0)
- return cvarValue
- end
- function PQR_RegisterMovement(elapsed)
- local playerMovementSpeed = GetUnitSpeed("player")
- if playerMovementSpeed ~= 0 then
- PQR_CurrentMovingTime = PQR_CurrentMovingTime + elapsed
- PQR_CurrentStationaryTime = 0
- else
- if PQR_CurrentStationaryTime < PQR_ResetMovementTime then
- PQR_CurrentStationaryTime = PQR_CurrentStationaryTime + elapsed
- end
- if PQR_CurrentStationaryTime > PQR_ResetMovementTime then
- PQR_CurrentMovingTime = 0
- end
- end
- end
- function PQR_IsMoving(seconds)
- if seconds == nil then
- seconds = 1
- end
- local moltenFeathers = PQR_UnitBuffID("player", 98767)
- if PQR_CurrentMovingTime >= seconds and moltenFeathers == nil then
- return true
- else
- return false
- end
- end
- function PQR_IsCastingSpell(spellID)
- local spellName = GetSpellInfo(spellID)
- local spellCasting = UnitCastingInfo("player")
- if spellCasting == nil then
- spellCasting = UnitChannelInfo("player")
- end
- if spellCasting == spellName then
- return true
- else
- return false
- end
- end
- function PQR_NotBehindTarget(seconds)
- if seconds == nil then
- seconds = 1
- end
- if PQR_BehindTime + seconds > GetTime() then
- return true
- else
- return false
- end
- end
- function PQR_DelayRotation(seconds)
- if seconds == nil then
- seconds = 1
- end
- local newDelay = GetTime() + seconds
- PQR.delayTable.spell["custom"] = "custom"
- PQR.delayTable.item["custom"] = nil
- PQR.delayTable.delay["custom"] = seconds
- PQR.delayTable.delayTime["custom"] = newDelay
- end
- function PQR_AddToSpellDelayList(spell, item, seconds)
- if tonumber(spell) ~= nil then
- --spell ID
- spell = GetSpellInfo(spell)
- end
- if seconds == nil then
- seconds = 1
- end
- PQR.delayTable.spell[spell] = spell
- PQR.delayTable.item[spell] = item
- PQR.delayTable.delay[spell] = seconds
- PQR.delayTable.delayTime[spell] = 0
- end
- function PQR_IsRotationDelayed()
- --returns true if the rotation is delayed, false otherwise.
- for k,v in pairs(PQR.delayTable.delayTime) do
- if v > GetTime() then
- return true
- end
- end
- return false
- end
- function PQR_IsOutOfSight(unit, seconds)
- if UnitExists(unit) then
- unit = UnitName(unit)
- else
- return false
- end
- local iceTombPlayer = UnitDebuffID("player", 104451)
- local iceTombUnit = UnitDebuffID(unit, 104451)
- if iceTombPlayer or iceTombUnit then
- return true
- end
- if seconds == nil then
- seconds = 3
- end
- for k,v in pairs(PQR.losTable.name) do
- if v == unit then
- if PQR.losTable.time[v] > GetTime() - seconds then
- return true
- end
- end
- end
- return false
- end
- function PQR_Event(eventName, ...)
- if PQR_EventsEnabled ~= true then
- return
- end
- if eventName == nil then
- eventName = ""
- end
- eventName = strtrim(eventName)
- local cVarValue = GetCVar("PQREvent")
- if cVarValue == nil then
- RegisterCVar("PQREvent", "")
- cVarValue = ""
- end
- local tblArgs = { ... }
- local addCall = "if "..eventName.." then "..eventName.."("
- for i = 1,5 do
- local varArg = tblArgs[i]
- if i ~= 1 then
- addCall = addCall..", "
- end
- if varArg == nil then
- addCall = addCall.."nil"
- elseif tonumber(varArg) ~= nil then
- addCall = addCall..varArg
- elseif tostring(varArg) ~= nil then
- addCall = addCall.."\""..varArg.."\""
- else
- addCall = addCall.."nil"
- end
- end
- addCall = addCall..") end"
- if cVarValue == "" then
- cVarValue = addCall
- else
- cVarValue = cVarValue.."|"..addCall
- end
- SetCVar("PQREvent", cVarValue)
- end
- function PQR_SendEvents()
- local cVarValue = GetCVar("PQREvent")
- if cVarValue ~= nil and cVarValue ~= "" then
- local tblEvents = { strsplit("|", cVarValue) }
- for k,v in pairs(tblEvents) do
- loadstring(v)()
- end
- SetCVar("PQREvent", "")
- end
- end
- function PQR_EnableEvents()
- local eventsEnabled = GetCVar("PQREventsEnabled")
- if eventsEnabled == "1" then
- eventsEnabled = true
- end
- if eventsEnabled == true then
- PQR_EventSend:Show()
- PQR_EventsEnabled = true
- else
- PQR_EventSend:Hide()
- PQR_EventsEnabled = false
- end
- end
- function PQR_CastSpellByID(...)
- if PQR_CurrentAbilityName ~= nil then
- local spellID = select(1, ...)
- PQR_Event("PQR_ExecutingAbility", PQR_CurrentAbilityName, spellID, PQR_CurrentRotationNumber)
- end
- end
- function PQR_CastSpellByName(...)
- if PQR_CurrentAbilityName ~= nil then
- local spellID = PQR_GetSpellID(select(1, ...))
- if spellID ~= nil and spellID ~= 0 then
- PQR_Event("PQR_ExecutingAbility", PQR_CurrentAbilityName, spellID, PQR_CurrentRotationNumber)
- end
- end
- end
- function PQR_GetSpellID(spellName, target)
- local spellID = 0;
- local i = 1
- if target == nil then
- target = "player"
- end
- while true do
- local sbSpellName, sbSpellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
- if sbSpellName == nil then
- break
- end
- if sbSpellSubName == nil then
- sbSpellSubName = ""
- end
- if spellName == sbSpellName or spellName == sbSpellName..sbSpellSubName or spellName == sbSpellName.." "..sbSpellSubName then
- _, spellID = GetSpellBookItemInfo(i, target)
- break
- end
- i = i + 1
- end
- return spellID
- end
- --create our CVars
- --Do not change values of CVars, their length is necessary because writing to WoW will cause
- --us to overwrite the end of the variable and start writing into the address space of other variables.
- --We define a big chunck so we have room to work with.
- local cVarTest = GetCVar("PQRCvarsLoaded")
- if cVarTest == nil then
- RegisterCVar("PQRCvarsLoaded", "true")
- local sETX = strchar(33)
- local cVarPlaceholderValue = " "..sETX
- local PQRCVars = { "BehindTarget", "FacingTarget", "DistanceTarget", "PQR_TargetX", "PQR_TargetY", "PQR_TargetZ"}
- for _,v in ipairs(PQRCVars) do RegisterCVar(v, sETX..cVarPlaceholderValue..v) end
- local value = " " for i=1,20 do value=value..value end
- local objMgrValue = sETX..value
- RegisterCVar("PQR_ObjectManager", objMgrValue)
- RegisterCVar("PQR_TargetClick", "0")
- end
- function PQR_DistanceTarget()
- local distance = PQR_GetCVar("DistanceTarget")
- if distance == nil or distance == "" then
- return 0
- else
- return tonumber(distance)
- end
- end
- function PQR_PulseObjectManager(overrideTime)
- local timeOverride = tonumber(overrideTime)
- if timeOverride == nil then
- timeOverride = PQR_ObjMgrPulseTimer
- end
- if PQR_LastObjectManagerPulse < GetTime() - timeOverride then
- PQR_LastObjectManagerPulse = GetTime()
- local objMgr = PQR_GetCVar("PQR_ObjectManager")
- if objMgr == nil or objMgr == "" then
- return nil
- else
- loadstring(objMgr)()
- end
- end
- end
- function PQR_GUIDInfo(GUID)
- if PQR_LastObjectManagerPulse < GetTime() - PQR_ObjMgrPulseTimer then
- PQR_LastObjectManagerPulse = GetTime()
- local objMgr = PQR_GetCVar("PQR_ObjectManager")
- if objMgr == nil or objMgr == "" then
- return nil
- else
- loadstring(objMgr)()
- end
- end
- if pom ~= nil then
- if pom[GUID] == nil then
- return nil
- else
- return pom[GUID][1], pom[GUID][2], pom[GUID][3], pom[GUID][4], pom[GUID][5], pom[GUID][6]
- end
- end
- return nil
- end
- function PQR_UnitInfo(unit)
- if UnitExists(unit) then
- return PQR_GUIDInfo(UnitGUID(unit))
- else
- return PQR_GUIDInfo(unit)
- end
- end
- function atan2custom(Y,X)
- local pi = 3.14159265358979
- local product = 0
- if tonumber(Y) == nil or tonumber(X) == nil then
- return 0
- end
- if X == 0 and Y == 0 then
- return 0
- end
- if X == 0 then
- product = pi / 2
- if Y < 0 then
- product = product * 3
- end
- else
- product = atancustom(Y / X)
- if X < 0 then
- product = product + pi
- end
- end
- return product
- end
- function atancustom(r)
- return r/(1+(r*r/(3+(4*r*r)/(5+(9*r*r)/(7+(16*r*r)/(9+(25*r*r)/(11+(36*r*r)/(13+(49*r*r)/(15+(64*r*r)/(17+(81*r*r)))))))))))
- end
- PQRUNIT = 3
- PQRPLAYER = 4
- function PQR_UnitFacing(unitCheck, unitTarget, degrees)
- local degreeCheck = tonumber(degrees)
- local checkX,checkY,_,_, unitCheckType, unitCheckTarget = PQR_UnitInfo(unitCheck)
- local targetX,targetY,_,_, unitTargetType, unitTargetTarget = PQR_UnitInfo(unitTarget)
- local pi = 3.14159265358979
- if unitCheckType == PQRUNIT and (unitTargetType == PQRPLAYER or unitTargetType == PQRUNIT) then
- local playerGUID = UnitGUID("player")
- local facingTarget = PQR_CalculateYaw(unitCheck, unitTarget)
- if unitCheckTarget == UnitGUID("player") and (unitTarget == "player" or unitTarget == playerGUID) then
- --the thing we are checking is targetting the player, which we are comparing to...
- facingTarget = 0
- else
- --we need to correct the angle
- --we need to get the angle of the CHECK to the TARGET OF CHECK
- local tocX, tocY = PQR_UnitInfo(unitCheckTarget)
- if tocX ~= nil then
- --we have a target of check.
- --we need to get the angle between the 2.
- --local angle = atan2((tocY - checkY),(tocX - checkX))
- local angle = atan2((checkY - tocY),(checkX - tocX))
- angle = angle + 180
- --convert degrees to radians
- angle = angle * 0.0174532925
- --fix the rotation of the check unit.
- if UnitExists(unitCheck) then
- --unit exists by ref.
- pom[UnitGUID(unitCheck)][4] = angle
- else
- --a GUID was used.
- pom[unitCheck][4] = angle
- end
- facingTarget = PQR_CalculateYaw(unitCheck, unitTarget)
- end
- end
- if facingTarget == nil then
- facingTarget = 180
- end
- if degrees == true then
- return facingTarget
- elseif degreeCheck ~= nil then
- --custom number check
- if degreeCheck > 360 then
- degreeCheck = 360
- elseif degreeCheck < 0 then
- degreeCheck = 0
- end
- else
- degreeCheck = 180
- end
- local facingNumber = tonumber(facingTarget)
- if facingNumber < degreeCheck / 2 or facingNumber > 360 - (degreeCheck / 2) then
- return true
- else
- return false
- end
- else
- local facingTarget = PQR_CalculateYaw(unitCheck, unitTarget)
- if facingTarget == nil then
- facingTarget = 180
- end
- if degrees == true then
- return facingTarget
- elseif degreeCheck ~= nil then
- --custom number check
- if degreeCheck > 360 then
- degreeCheck = 360
- elseif degreeCheck < 0 then
- degreeCheck = 0
- end
- else
- degreeCheck = 180
- end
- local facingNumber = tonumber(facingTarget)
- if facingNumber < degreeCheck / 2 or facingNumber > 360 - (degreeCheck / 2) then
- return true
- else
- return false
- end
- end
- return false
- end
- function PQR_CalculateYaw(unit1, unit2)
- local unit1X, unit1Y, unit1Z, unit1R = PQR_UnitInfo(unit1)
- local unit2X, unit2Y, unit2Z, unit2R = PQR_UnitInfo(unit2)
- if unit1X == nil or unit2X == nil then
- return nil
- else
- local pi = 3.14159265358979
- local yaw = (180 / pi) * (atan2custom((unit2Y - unit1Y), (unit2X - unit1X)));
- local rotation = unit1R * (180 / pi)
- if yaw < 0 then
- yaw = yaw + 360;
- end
- yaw = yaw - rotation
- if yaw < 0 then
- yaw = yaw + 360
- end
- if yaw >= 360 then
- yaw = 0
- end
- return yaw
- end
- end
- function PQR_UnitDistance(unit1, unit2)
- local unit1X, unit1Y, unit1Z = PQR_UnitInfo(unit1)
- local unit2X, unit2Y, unit2Z = PQR_UnitInfo(unit2)
- if unit1X == nil or unit2X == nil then
- return nil
- else
- return sqrt((unit1X - unit2X) * (unit1X - unit2X) + (unit1Y - unit2Y) * (unit1Y - unit2Y) + (unit1Z - unit2Z) * (unit1Z - unit2Z))
- end
- end
- function PQR_CheckUIError(msg, seconds)
- local errorTime = PQR_LastUIError[msg]
- if seconds == nil then
- seconds = 1
- end
- if errorTime and GetTime() < errorTime + seconds then
- return true
- end
- return false
- end
- function PQR_TargetArea(unit)
- local uX, uY, uZ = PQR_UnitInfo(unit)
- if uX ~= nil and uX ~= 0 then
- SetCVar("PQR_TargetX", uX)
- SetCVar("PQR_TargetY", uY)
- SetCVar("PQR_TargetZ", uZ)
- SetCVar("PQR_TargetClick", "1")
- end
- end
- function PQR_GetCVar(cVarName)
- if cVarName == nil then
- return nil
- end
- local cVarValue = GetCVar(cVarName)
- local sETX = strchar(33)
- if cVarValue == nil then
- return nil
- end
- local sETX = strchar(33)
- local findETX = strfind(cVarValue, sETX)
- if findETX == nil then
- return nil
- end
- findETX = tonumber(findETX)
- if findETX == 1 then
- return ""
- else
- cVarValue = strsub(cVarValue, 1, findETX - 1)
- end
- local cVarNumber = tonumber(cVarValue)
- if cVarNumber == nil then
- --string
- return cVarValue
- else
- return cVarNumber
- end
- end
- function PQR_SetCVar(cVarName, cVarValue)
- if cVarName == nil then
- return
- end
- local cVarValueTest = GetCVar(cVarName)
- if cVarValueTest == nil then
- return
- end
- local sETX = strchar(33)
- SetCVar(cVarName, cVarValue..sETX)
- end
- --Setup our global variables and activate our event frame.
- if PQR_EventFrame == nil then
- --Setup our data table.
- PQR = {}
- for i=0,4 do
- PQR[i] = {}
- end
- PQR_RotationTable = {}
- PQR_SetupTables()
- PQR_SetupInterruptTable()
- --General global variables.
- PQR_ShowChat = true
- PQR_RequireCombat = true
- PQR_CustomTarget = ""
- hooksecurefunc("CastSpellByID", PQR_CastSpellByID)
- hooksecurefunc("CastSpellByName", PQR_CastSpellByName)
- PQR_CurrentRotationNumber = nil
- PQR_CurrentAbilityName = nil
- PQR_LuaLoadedTable = {}
- PQR_Rotation1 = ""
- PQR_Rotation2 = ""
- PQR_Rotation3 = ""
- PQR_Rotation4 = ""
- PQR_InterruptSelected = ""
- PQR_EventsEnabled = true
- PQR_LegacyMode = false
- PQR_LastObjectManagerPulse = 0
- PQR_RotationEnabled = false
- PQR_InterruptEnabled = false
- PQR_ChangeInterrupt = false
- PQR_InterruptName = ""
- PQR_RunningInterruptName = ""
- PQR_InterruptStarted = false
- PQR_RotationStarted = false
- PQR_RotationName = ""
- PQR_RunningRotationName = ""
- PQR_ChangeRotation = false
- PQR_ManualLoaded = false
- PQR_BehindTime = 0
- PQR_InterruptAll = false
- PQR_MonkGCD = 0
- PQR_LastTarget = ""
- PQR_LastCastTime = 0
- PQR_SpellAvailableTime = 0.125
- PQR_AverageTable = {}
- PQR_soundStartRotation = ""
- PQR_soundChangeRotation = ""
- PQR_soundStopRotation = ""
- PQR_soundStartInterrupt = ""
- PQR_soundStopInterrupt = ""
- PQR_ObjMgrPulseTimer = 0.2
- PQR_LastUIError = { }
- --Movement tracking
- PQR_CurrentStationaryTime = 0
- PQR_CurrentMovingTime = 0
- PQR_ResetMovementTime = 0.5
- PQR_Rotation = -1
- PQR_totalElapsed1 = 0.0
- PQR_totalElapsed2 = 0.0
- PQR_UpdateInterval1 = 0.05
- PQR_UpdateInterval2 = 0.05
- PQR_EventSendElapsed = 0.0
- PQR_BaseRotation = nil
- PQR_DebugLevel = "Disabled"
- PQR_LastSpellcast = 0
- PQR_LastCastCount = 0
- PQR_SwappedRotation = false
- PQR_EventFrame = CreateFrame("Frame")
- PQR_EventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
- PQR_EventFrame:RegisterEvent("PLAYER_LOGOUT")
- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_START")
- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_FAILED")
- PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET")
- PQR_EventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- PQR_EventFrame:RegisterEvent("UI_ERROR_MESSAGE")
- PQR_EventFrame:SetScript("OnUpdate", PQR_EventFrame_OnUpdate)
- PQR_EventFrame:SetScript("OnEvent", PQR_EventFrame_OnEvent)
- PQR_EventFrame:Show()
- local cVarValue = GetCVar("PQREvent")
- if cVarValue ~= nil then
- SetCVar("PQREvent", "")
- end
- PQR_EventSend = CreateFrame("Frame")
- PQR_EventSend:SetScript("OnUpdate", PQR_EventSend_OnUpdate)
- PQR_EventSend:Show()
- PQR_Loaded = true
- PQR_Event("PQR_BotLoaded")
- PQR_LoadLua("PQR_PQI.lua")
- local cVarValue = GetCVar("PQR_TargetsAroundTarget")
- if cVarValue ~= nil then
- SetCVar("PQR_TargetsAroundTarget", "PQR_000_VALUE")
- else
- RegisterCVar("PQR_TargetsAroundTarget", "PQR_000_VALUE")
- end
- end
- end
- --DO NOT CHANGE, This is for firing the PQR_BotLoaded event for PQInterface
- if PQR_Loaded == false then
- PQR_Loaded = true
- local cVarValue = GetCVar("PQREvent")
- if cVarValue ~= nil then
- SetCVar("PQREvent", "")
- end
- PQR_Event("PQR_BotLoaded")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement