forked from brues/pfUI
The hunter bar called C_Spell.IsSpellInRange for Wing Clip and Arcane Shot 50 times a second while it had an attackable target. It now turns on C_SwingTimer's range checks for the main hand and the ranged weapon, and reads both again on PLAYER_SWING_RANGE_UPDATE and at login. The ranged check is Auto Shot's: the same range row as Arcane Shot (8-35 yd), with the same Hawk Eye and ranged-weapon bonuses. The melee check is the server's auto-attack reach, which Raptor Strike swings with. It is Wing Clip's reach measured flat, without the height difference, and without the 2.67 yd Wing Clip gets while both units move. Without a ranged weapon the ranged check has no answer, so the bar stays on the melee page.
50 lines
2.0 KiB
Lua
50 lines
2.0 KiB
Lua
pfUI:RegisterModule("hunterbar", function ()
|
|
if UnitClassBase("player") ~= "HUNTER" or C.bars.hunterbar == "0" then return end
|
|
|
|
-- The bar follows the target's range: page 2 (ranged) once the target is
|
|
-- out of melee range and in shot range, page 1 (melee) once it is in melee
|
|
-- range and too close to shoot. In between, in the dead zone, the page
|
|
-- stays as it is, so it doesn't flip back and forth.
|
|
--
|
|
-- ClassicAPI's swing range checks report both ranges as they change. The
|
|
-- ranged check is Auto Shot's: the same range row as Arcane Shot (8-35 yd),
|
|
-- with the same Hawk Eye and ranged-weapon bonuses. The melee check is the
|
|
-- server's auto-attack reach, the one Raptor Strike swings with. It is
|
|
-- Wing Clip's reach, but measured flat, without the height difference,
|
|
-- and without the extra 2.67 yd Wing Clip gets while both units move.
|
|
-- Either check gives no answer (nil) without an attackable target or a
|
|
-- weapon for it, and then the page stays as it is.
|
|
local MELEE = Enum.PlayerSwingType.MainHand
|
|
local RANGED = Enum.PlayerSwingType.Ranged
|
|
|
|
pfUI.hunterbar = CreateFrame("Frame", "pfHunterBar", UIParent)
|
|
|
|
-- the page we last forced, so a range change doesn't force it again
|
|
pfUI.hunterbar.lastPage = nil
|
|
|
|
local function SetPage(page)
|
|
if pfUI.hunterbar.lastPage == page then return end
|
|
pfUI.hunterbar.lastPage = page
|
|
_G.CURRENT_ACTIONBAR_PAGE = page
|
|
ChangeActionBarPage()
|
|
end
|
|
|
|
local function Update()
|
|
local melee = C_SwingTimer.IsTargetWithinSwingRange(MELEE)
|
|
local ranged = C_SwingTimer.IsTargetWithinSwingRange(RANGED)
|
|
|
|
if melee == false and ranged == true then
|
|
SetPage(2)
|
|
elseif melee == true and ranged == false then
|
|
SetPage(1)
|
|
end
|
|
end
|
|
|
|
-- the range event fires only on a change, so the login reads the state once
|
|
C_SwingTimer.EnableRangeCheck(MELEE, true)
|
|
C_SwingTimer.EnableRangeCheck(RANGED, true)
|
|
pfUI.hunterbar:RegisterEvent("PLAYER_SWING_RANGE_UPDATE")
|
|
pfUI.hunterbar:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
pfUI.hunterbar:SetScript("OnEvent", Update)
|
|
end)
|