-- Fish Key: while Fishing channels, every key bound to Fishing is overridden to -- "Interact with Target", so the same key clicks the bobber, and the Interact -- Key setting is switched on for the cast. The override is -- dropped the moment the channel ends (catch, miss, timeout, move) or combat -- starts. Saved keybinds are never touched. local FISHING_SPELL = 7620 -- Settings raised while fishing, as temp CVars that are never saved, and -- dropped again when the cast ends. Each is only raised if it is below the value. local FISHING_CVARS = { -- Interact Key: 0 off, 1 gamepad, 2 mouse and keyboard, 3 always. { name = "SoftTargetInteract", value = 3 }, -- The default (about 10 yards) is shorter than a cast, so the bobber -- would never become the interact target. { name = "SoftTargetInteractRange", value = 30 }, } local owner = CreateFrame("Frame") local overridden = false local clearAfterCombat = false local raisedCVars = {} local warned = false local function Print(msg) DEFAULT_CHAT_FRAME:AddMessage("|cff4fc3f7Fish Key|r: " .. msg) end local fishingName local function FishingName() fishingName = fishingName or C_Spell.GetSpellName(FISHING_SPELL) return fishingName end local function IsFishing(spellID) return spellID ~= nil and FishingName() ~= nil and C_Spell.GetSpellName(spellID) == FishingName() end local function ActionIsFishing(slot) if type(slot) ~= "number" then return false end local kind, id = GetActionInfo(slot) if kind == "macro" then return IsFishing(GetMacroSpell(id)) end return kind == "spell" and IsFishing(id) end -- Blizzard bar buttons by their binding command (ACTIONBUTTON1, MULTIACTIONBAR1BUTTON3, ...). local BAR_BUTTONS = { "ActionButton", "MultiBarBottomLeftButton", "MultiBarBottomRightButton", "MultiBarRightButton", "MultiBarLeftButton", "MultiBar5Button", "MultiBar6Button", "MultiBar7Button", } local function ButtonsByCommand() local map = {} for _, prefix in ipairs(BAR_BUTTONS) do for i = 1, 12 do local button = _G[prefix .. i] if button and button.bindingAction then map[button.bindingAction] = button end end end return map end local function CommandIsFishing(command, buttons) local spell = command:match("^SPELL (.+)$") if spell then local name = FishingName() return name ~= nil and (spell == name or spell:sub(1, #name + 1) == name .. "(") end local macro = command:match("^MACRO (.+)$") if macro then local index = GetMacroIndexByName and GetMacroIndexByName(macro) return index ~= nil and index > 0 and IsFishing(GetMacroSpell(index)) end local frameName = command:match("^CLICK ([^:]+)") local button = frameName and _G[frameName] or buttons[command] if type(button) ~= "table" then return false end local slot = button.action if slot == nil and button.GetAttribute then slot = button:GetAttribute("action") end return ActionIsFishing(tonumber(slot)) end -- Every key whose binding casts Fishing, with modifiers (e.g. "SHIFT-F"). local function FishingKeys() local keys = {} local buttons = ButtonsByCommand() for i = 1, GetNumBindings() do local binding = { GetBinding(i) } local command = binding[1] if command and CommandIsFishing(command, buttons) then for k = 3, #binding do keys[#keys + 1] = binding[k] end end end return keys end local function RaiseCVars() for _, cvar in ipairs(FISHING_CVARS) do local current = tonumber(C_CVar.GetCVar(cvar.name)) if current and current < cvar.value and not raisedCVars[cvar.name] then if pcall(C_CVar.SetTempCVar, cvar.name, tostring(cvar.value)) then raisedCVars[cvar.name] = true elseif not warned then warned = true Print("couldn't change " .. cvar.name .. ", turn Interact Key on in Settings") end end end end local function RestoreCVars() for name in pairs(raisedCVars) do pcall(C_CVar.RemoveTempCVar, name) raisedCVars[name] = nil end end local function Apply() if not FishKeyDB.enabled or InCombatLockdown() then return end local keys = FishingKeys() if #keys == 0 then return end for _, key in ipairs(keys) do SetOverrideBinding(owner, true, key, "INTERACTTARGET") end overridden = true RaiseCVars() end local function Restore() if overridden then if InCombatLockdown() then clearAfterCombat = true else ClearOverrideBindings(owner) overridden = false end end RestoreCVars() end owner:RegisterEvent("ADDON_LOADED") owner:RegisterEvent("PLAYER_REGEN_DISABLED") owner:RegisterEvent("PLAYER_REGEN_ENABLED") owner:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_START", "player") owner:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_STOP", "player") owner:SetScript("OnEvent", function(_, event, arg1, _, spellID) if event == "ADDON_LOADED" then if arg1 == "FishKey" then FishKeyDB = FishKeyDB or {} if FishKeyDB.enabled == nil then FishKeyDB.enabled = true end end elseif event == "UNIT_SPELLCAST_CHANNEL_START" then if IsFishing(spellID) then Apply() end elseif event == "UNIT_SPELLCAST_CHANNEL_STOP" or event == "PLAYER_REGEN_DISABLED" then -- Bindings still change inside PLAYER_REGEN_DISABLED; lockdown starts after it. Restore() elseif event == "PLAYER_REGEN_ENABLED" and clearAfterCombat then clearAfterCombat = false ClearOverrideBindings(owner) overridden = false end end) SLASH_FISHKEY1 = "/fish" SlashCmdList.FISHKEY = function(msg) msg = (msg or ""):lower():match("^%s*(.-)%s*$") if msg == "on" or msg == "off" then FishKeyDB.enabled = msg == "on" if not FishKeyDB.enabled then Restore() end elseif msg ~= "" then Print("/fish shows status, /fish on, /fish off") return end local keys = FishingKeys() local where = #keys > 0 and table.concat(keys, ", ") or "no key bound to Fishing" Print((FishKeyDB.enabled and "on" or "off") .. " (" .. where .. ")") end