diff --git a/libs/libpredict.lua b/libs/libpredict.lua index 24f43d74..587c89aa 100644 --- a/libs/libpredict.lua +++ b/libs/libpredict.lua @@ -959,8 +959,6 @@ hooksecurefunc("CastSpellByName", function(effect, target) if not libpredict.sender.enabled then return end local effect, rank = libspell.GetSpellInfo(effect) if not effect then return end - local mouseover = pfUI and pfUI.uf and pfUI.uf.mouseover and pfUI.uf.mouseover.unit - mouseover = mouseover and UnitCanAssist("player", mouseover) and UnitName(mouseover) local default = UnitName("target") and UnitCanAssist("player", "target") and UnitName("target") or UnitName("player") @@ -979,13 +977,13 @@ hooksecurefunc("CastSpellByName", function(effect, target) if not libpredict.sender.current_cast then spell_queue[1] = effect spell_queue[2] = effect.. ( rank or "" ) - spell_queue[3] = target or mouseover or default + spell_queue[3] = target or default end -- Instant HoTs: libdebuff/Nampower via GetHotDuration, hook method as fallback if effect == REJUVENATION then - local hotTarget = target or mouseover or default + local hotTarget = target or default local now = pfUI.uf.now or GetTime() local key = "Reju" .. hotTarget @@ -1002,7 +1000,7 @@ hooksecurefunc("CastSpellByName", function(effect, target) local rankStr = rankNum and tostring(rankNum) or "0" libpredict.sender:SendHealCommMsg("Reju/"..hotTarget.."/"..rejuvDuration.."/"..rankStr.."/") elseif effect == RENEW then - local hotTarget = target or mouseover or default + local hotTarget = target or default local now = pfUI.uf.now or GetTime() local key = "Renew" .. hotTarget diff --git a/modules/mouseover.lua b/modules/mouseover.lua index 5f3eed55..b2f675f1 100644 --- a/modules/mouseover.lua +++ b/modules/mouseover.lua @@ -1,39 +1,6 @@ pfUI:RegisterModule("mouseover", function () - pfUI.uf.mouseover = CreateFrame("Frame", "pfMouseOver", UIParent) - - -- Prepare a list of units that can be used via SpellTargetUnit - local st_units = { [1] = "player", [2] = "target", [3] = "mouseover" } - for i=1, MAX_PARTY_MEMBERS do table.insert(st_units, "party"..i) end - for i=1, MAX_RAID_MEMBERS do table.insert(st_units, "raid"..i) end - - -- Try to find a valid (friendly) unitstring that can be used for - -- SpellTargetUnit(unit) to avoid another target switch - local function GetUnitString(unit) - for index, unitstr in pairs(st_units) do - if UnitIsUnit(unit, unitstr) then - return unitstr - end - end - - return nil - end - - -- Same as CastSpellByName but with disabled AutoSelfCast - local function NoSelfCast(spell, onself) - local cvar_selfcast = GetCVar("AutoSelfCast") - - if cvar_selfcast ~= "0" then - SetCVar("AutoSelfCast", "0") - pcall(CastSpellByName, spell, onself) - SetCVar("AutoSelfCast", cvar_selfcast) - else - CastSpellByName(spell, onself) - end - end - _G.SLASH_PFCAST1, _G.SLASH_PFCAST2 = "/pfcast", "/pfmouse" function SlashCmdList.PFCAST(msg) - local restore_target = true local func = pfUI.api.TryMemoizedFuncLoadstringForSpellCasts(msg) local unit = "mouseover" @@ -50,51 +17,18 @@ pfUI:RegisterModule("mouseover", function () end end - -- Nampower: CastSpellByName supports a second unit parameter directly. - -- unit is already resolved to "mouseover", "target" or "player" at this point. - if not func and GetNampowerVersion then + -- Spell-name path: Nampower's CastSpellByName takes a second unit + -- parameter directly, no target swap dance required. + if not func then CastSpellByName(msg, unit) return end - -- If target and mouseover are friendly units, we can't use spell target as it - -- would cast on the target instead of the mouseover. However, if the mouseover - -- is friendly and the target is not, we can try to obtain the best unitstring - -- for the later SpellTargetUnit() call. - local unitstr = not UnitCanAssist("player", "target") and UnitCanAssist("player", unit) and GetUnitString(unit) - - if UnitIsUnit("target", unit) or (not func and unitstr) then - -- no target change required, we can either use spell target - -- or the unit is already our current target. - restore_target = false - else - -- The spelltarget can't be used here, we need to switch - -- and restore the target during spell cast - TargetUnit(unit) - end - - if func then - func() - else - -- write temporary unit name - pfUI.uf.mouseover.unit = unit - - -- cast without self cast cvar setting - -- to allow spells to use spelltarget - NoSelfCast(msg) - - -- set spell target to unitstring (or selfcast) - if SpellIsTargeting() then SpellTargetUnit(unitstr or "player") end - - -- clean up spell target in error case - if SpellIsTargeting() then SpellStopTargeting() end - - -- remove temporary mouseover unit - pfUI.uf.mouseover.unit = nil - end - - if restore_target then - TargetLastTarget() - end + -- Macro path: switch target so the macro's spell calls land on `unit`, + -- then restore. + local restore_target = not UnitIsUnit("target", unit) + if restore_target then TargetUnit(unit) end + func() + if restore_target then TargetLastTarget() end end end) \ No newline at end of file