From dbfcca95c095bbe13439e815ce4c0fcb6b327c7c Mon Sep 17 00:00:00 2001 From: shagu Date: Wed, 10 Jan 2018 23:36:47 +0100 Subject: [PATCH] rangecheck: restore autoattack race condition --- modules/rangecheck.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/rangecheck.lua b/modules/rangecheck.lua index a4d6f071..5f0d8860 100644 --- a/modules/rangecheck.lua +++ b/modules/rangecheck.lua @@ -52,8 +52,19 @@ pfUI:RegisterModule("rangecheck", function () pfUI.rangecheck.id = 1 pfUI.rangecheck:RegisterEvent("ACTIONBAR_SLOT_CHANGED") pfUI.rangecheck:RegisterEvent("PLAYER_ENTERING_WORLD") + pfUI.rangecheck:RegisterEvent("PLAYER_ENTER_COMBAT") + pfUI.rangecheck:RegisterEvent("PLAYER_LEAVE_COMBAT") pfUI.rangecheck:SetScript("OnEvent", function() - pfUI.rangecheck.slot = this:GetRangeSlot() + if event == "ACTIONBAR_SLOT_CHANGED" or event == "PLAYER_ENTERING_WORLD" then + pfUI.rangecheck.slot = this:GetRangeSlot() + elseif event == "PLAYER_ENTER_COMBAT" then + this.lastattack = GetTime() + this:Hide() + elseif event == "PLAYER_LEAVE_COMBAT" then + if not this:ReAttack() then + this:Show() + end + end end) pfUI.rangecheck:SetScript("OnUpdate", function() @@ -76,15 +87,13 @@ pfUI:RegisterModule("rangecheck", function () if LootFrame and LootFrame:IsShown() then return nil end if InspectFrame and InspectFrame:IsShown() then return nil end if TradeFrame and TradeFrame:IsShown() then return nil end - if PlayerFrame.inCombat and UnitCanAttack("player", "target") then - return nil - end pfScanActive = true TargetUnit(unit) unitdata[unit] = IsActionInRange(pfUI.rangecheck.slot) TargetLastTarget() pfScanActive = false + this:ReAttack() end this.id = this.id + 1 @@ -93,6 +102,16 @@ pfUI:RegisterModule("rangecheck", function () end end) + function pfUI.rangecheck:ReAttack() + -- we accidentally broke the autoattack... restoring the old state + if this.lastattack and this.lastattack + interval > GetTime() and UnitCanAttack("player", "target") then + AttackTarget() + return true + else + return nil + end + end + function pfUI.rangecheck:NeedRangeScan(unit) if not UnitExists(unit) then return nil end if not UnitIsVisible(unit) then return nil end