2026-11-11 15:46:46 +00:00
|
|
|
-- Fish Key: while Fishing channels, every key bound to Fishing is overridden to
|
2026-11-11 17:27:31 +00:00
|
|
|
-- "Interact with Target", so the same key clicks the bobber. A few settings are
|
|
|
|
|
-- changed for the cast (Interact Key on, longer interact range, press and hold
|
|
|
|
|
-- casting off). Saved keybinds and settings are never touched.
|
|
|
|
|
--
|
|
|
|
|
-- Everything is put back only once the catch is looted (or the cast ended
|
|
|
|
|
-- without loot) AND every Fishing key is released. Restoring earlier lets the
|
|
|
|
|
-- still-held key, a double tap, or the key release cast Fishing again, which
|
|
|
|
|
-- replaces the bobber and loses the fish. Combat start restores at once.
|
2026-11-11 17:31:07 +00:00
|
|
|
--
|
|
|
|
|
-- Loot can only be coming if the interact key was pressed just before the cast
|
|
|
|
|
-- ended. Otherwise (timeout, moving, another spell) there is nothing to wait for.
|
2026-11-11 15:46:46 +00:00
|
|
|
|
|
|
|
|
local FISHING_SPELL = 7620
|
2026-11-11 17:31:07 +00:00
|
|
|
-- An interact this recent counts as the one that ended the cast.
|
|
|
|
|
local PRESS_WINDOW = 1
|
|
|
|
|
-- After a press with neither a loot window nor an error, wait this long plus
|
|
|
|
|
-- two round trips before treating it as a miss.
|
|
|
|
|
local LOOT_WAIT_BASE = 0.25
|
|
|
|
|
local LOOT_WAIT_MAX = 1.5
|
2026-11-11 17:27:31 +00:00
|
|
|
local POLL = 0.05
|
|
|
|
|
|
|
|
|
|
-- Settings changed while fishing, as temp CVars that are never saved, and
|
|
|
|
|
-- removed again afterwards. "min" raises to at least the value, "max" lowers
|
|
|
|
|
-- to at most it; a setting already there is left alone.
|
2026-11-11 17:02:47 +00:00
|
|
|
local FISHING_CVARS = {
|
|
|
|
|
-- Interact Key: 0 off, 1 gamepad, 2 mouse and keyboard, 3 always.
|
2026-11-11 17:27:31 +00:00
|
|
|
{ name = "SoftTargetInteract", value = 3, mode = "min" },
|
2026-11-11 17:02:47 +00:00
|
|
|
-- The default (about 10 yards) is shorter than a cast, so the bobber
|
|
|
|
|
-- would never become the interact target.
|
2026-11-11 17:27:31 +00:00
|
|
|
{ name = "SoftTargetInteractRange", value = 30, mode = "min" },
|
|
|
|
|
-- Press and hold casting repeats the spell while the key is held and
|
|
|
|
|
-- casts again on release.
|
|
|
|
|
{ name = "ActionButtonUseKeyHeldSpell", value = 0, mode = "max" },
|
2026-11-11 17:02:47 +00:00
|
|
|
}
|
2026-11-11 15:46:46 +00:00
|
|
|
|
2026-11-12 15:42:26 +00:00
|
|
|
-- Quiet everything but sound effects so the splash stands out (/fish sound).
|
|
|
|
|
-- There is no per-sound volume, so other effects (spells, footsteps) still play.
|
|
|
|
|
local SOUND_CVARS = {
|
|
|
|
|
{ name = "Sound_EnableMusic", value = 0, mode = "max" },
|
|
|
|
|
{ name = "Sound_EnableAmbience", value = 0, mode = "max" },
|
|
|
|
|
{ name = "Sound_EnableDialog", value = 0, mode = "max" },
|
|
|
|
|
{ name = "Sound_EnablePetSounds", value = 0, mode = "max" },
|
|
|
|
|
{ name = "Sound_EnableErrorSpeech", value = 0, mode = "max" },
|
|
|
|
|
{ name = "Sound_EnableSFX", value = 1, mode = "min" },
|
|
|
|
|
{ name = "Sound_SFXVolume", value = 1, mode = "min" },
|
|
|
|
|
-- Keep hearing it while another window has focus.
|
|
|
|
|
{ name = "Sound_EnableSoundWhenGameIsInBG", value = 1, mode = "min" },
|
|
|
|
|
-- Distant sounds are muffled; the bobber is 15-20 yards out.
|
|
|
|
|
{ name = "Sound_EnablePositionalLowPassFilter", value = 0, mode = "max" },
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-11 15:46:46 +00:00
|
|
|
local owner = CreateFrame("Frame")
|
|
|
|
|
local overridden = false
|
|
|
|
|
local clearAfterCombat = false
|
2026-11-11 17:27:31 +00:00
|
|
|
local changedCVars = {}
|
2026-11-11 17:02:47 +00:00
|
|
|
local warned = false
|
2026-11-11 17:27:31 +00:00
|
|
|
-- Keys currently overridden to interact.
|
|
|
|
|
local activeKeys = {}
|
|
|
|
|
-- "fishing" while the channel runs, "ending" while waiting for loot or key
|
|
|
|
|
-- release, nil otherwise.
|
|
|
|
|
local state
|
|
|
|
|
local looting = false
|
2026-11-11 17:31:07 +00:00
|
|
|
-- Interact was pressed as the cast ended; a loot window may be on its way.
|
|
|
|
|
local awaitingLoot = false
|
|
|
|
|
-- GetTime() of the last interact during the cast.
|
|
|
|
|
local lastInteract
|
2026-11-11 17:27:31 +00:00
|
|
|
-- Bumped on every new cast and restore, so stale timers do nothing.
|
|
|
|
|
local generation = 0
|
2026-11-11 15:46:46 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2026-11-11 17:27:31 +00:00
|
|
|
-- "SHIFT-F" -> "F", "CTRL--" -> "-".
|
|
|
|
|
local function BaseKey(key)
|
|
|
|
|
local base = key
|
|
|
|
|
repeat
|
|
|
|
|
local stripped = base:gsub("^ALT%-(.)", "%1"):gsub("^CTRL%-(.)", "%1")
|
|
|
|
|
:gsub("^SHIFT%-(.)", "%1"):gsub("^META%-(.)", "%1")
|
|
|
|
|
local changed = stripped ~= base
|
|
|
|
|
base = stripped
|
|
|
|
|
until not changed
|
|
|
|
|
return base
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function AnyKeyHeld()
|
|
|
|
|
for _, key in ipairs(activeKeys) do
|
|
|
|
|
if IsKeyDown(BaseKey(key)) then
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2026-11-12 15:42:26 +00:00
|
|
|
local function ChangeList(list)
|
|
|
|
|
for _, cvar in ipairs(list) do
|
2026-11-11 17:02:47 +00:00
|
|
|
local current = tonumber(C_CVar.GetCVar(cvar.name))
|
2026-11-11 17:27:31 +00:00
|
|
|
local wrong = current and (cvar.mode == "min" and current < cvar.value or cvar.mode == "max" and current > cvar.value)
|
|
|
|
|
if wrong and not changedCVars[cvar.name] then
|
2026-11-11 17:02:47 +00:00
|
|
|
if pcall(C_CVar.SetTempCVar, cvar.name, tostring(cvar.value)) then
|
2026-11-11 17:27:31 +00:00
|
|
|
changedCVars[cvar.name] = true
|
2026-11-11 17:02:47 +00:00
|
|
|
elseif not warned then
|
|
|
|
|
warned = true
|
2026-11-11 17:27:31 +00:00
|
|
|
Print("couldn't change " .. cvar.name .. ", set it in Settings")
|
2026-11-11 17:02:47 +00:00
|
|
|
end
|
|
|
|
|
end
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-11-12 15:42:26 +00:00
|
|
|
local function ChangeCVars()
|
|
|
|
|
ChangeList(FISHING_CVARS)
|
|
|
|
|
if FishKeyDB.sound then
|
|
|
|
|
ChangeList(SOUND_CVARS)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-11-11 17:02:47 +00:00
|
|
|
local function RestoreCVars()
|
2026-11-11 17:27:31 +00:00
|
|
|
for name in pairs(changedCVars) do
|
2026-11-11 17:02:47 +00:00
|
|
|
pcall(C_CVar.RemoveTempCVar, name)
|
2026-11-11 17:27:31 +00:00
|
|
|
changedCVars[name] = nil
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-11-11 17:27:31 +00:00
|
|
|
local function Restore()
|
|
|
|
|
generation = generation + 1
|
|
|
|
|
state = nil
|
|
|
|
|
looting = false
|
2026-11-11 17:31:07 +00:00
|
|
|
awaitingLoot = false
|
|
|
|
|
lastInteract = nil
|
2026-11-11 17:27:31 +00:00
|
|
|
if overridden then
|
|
|
|
|
if InCombatLockdown() then
|
|
|
|
|
clearAfterCombat = true
|
|
|
|
|
else
|
|
|
|
|
ClearOverrideBindings(owner)
|
|
|
|
|
overridden = false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
activeKeys = {}
|
|
|
|
|
RestoreCVars()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Restores once nothing can still turn a press into a new cast.
|
|
|
|
|
local function TryFinish(gen)
|
2026-11-11 17:31:07 +00:00
|
|
|
if gen ~= generation or state ~= "ending" or looting or awaitingLoot then
|
2026-11-11 17:27:31 +00:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if AnyKeyHeld() then
|
|
|
|
|
C_Timer.After(POLL, function() TryFinish(gen) end)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
Restore()
|
|
|
|
|
end
|
|
|
|
|
|
2026-11-11 15:46:46 +00:00
|
|
|
local function Apply()
|
|
|
|
|
if not FishKeyDB.enabled or InCombatLockdown() then
|
|
|
|
|
return
|
|
|
|
|
end
|
2026-11-11 17:27:31 +00:00
|
|
|
generation = generation + 1
|
|
|
|
|
looting = false
|
2026-11-11 17:31:07 +00:00
|
|
|
awaitingLoot = false
|
|
|
|
|
lastInteract = nil
|
2026-11-11 15:46:46 +00:00
|
|
|
local keys = FishingKeys()
|
|
|
|
|
if #keys == 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
for _, key in ipairs(keys) do
|
|
|
|
|
SetOverrideBinding(owner, true, key, "INTERACTTARGET")
|
|
|
|
|
end
|
2026-11-11 17:27:31 +00:00
|
|
|
activeKeys = keys
|
2026-11-11 15:46:46 +00:00
|
|
|
overridden = true
|
2026-11-11 17:27:31 +00:00
|
|
|
state = "fishing"
|
|
|
|
|
ChangeCVars()
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|
|
|
|
|
|
2026-11-11 17:27:31 +00:00
|
|
|
local function ChannelEnded()
|
|
|
|
|
if state ~= "fishing" then
|
|
|
|
|
return
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|
2026-11-11 17:27:31 +00:00
|
|
|
state = "ending"
|
|
|
|
|
local gen = generation
|
2026-11-11 17:31:07 +00:00
|
|
|
if not looting and lastInteract and GetTime() - lastInteract <= PRESS_WINDOW then
|
|
|
|
|
awaitingLoot = true
|
|
|
|
|
local _, _, _, latency = GetNetStats()
|
|
|
|
|
local wait = math.min(LOOT_WAIT_MAX, LOOT_WAIT_BASE + 2 * (latency or 0) / 1000)
|
|
|
|
|
C_Timer.After(wait, function()
|
|
|
|
|
if gen == generation and awaitingLoot then
|
|
|
|
|
awaitingLoot = false
|
|
|
|
|
TryFinish(gen)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
TryFinish(gen)
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|
|
|
|
|
|
2026-11-11 17:31:07 +00:00
|
|
|
-- Runs after the binding (or anything else) interacts; only notes the time.
|
|
|
|
|
hooksecurefunc(C_PlayerInteractionManager, "InteractUnit", function()
|
|
|
|
|
if state == "fishing" then
|
|
|
|
|
lastInteract = GetTime()
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
2026-11-11 15:46:46 +00:00
|
|
|
owner:RegisterEvent("ADDON_LOADED")
|
|
|
|
|
owner:RegisterEvent("PLAYER_REGEN_DISABLED")
|
|
|
|
|
owner:RegisterEvent("PLAYER_REGEN_ENABLED")
|
2026-11-11 17:27:31 +00:00
|
|
|
owner:RegisterEvent("LOOT_OPENED")
|
|
|
|
|
owner:RegisterEvent("LOOT_CLOSED")
|
2026-11-11 17:31:07 +00:00
|
|
|
owner:RegisterEvent("UI_ERROR_MESSAGE")
|
2026-11-11 15:46:46 +00:00
|
|
|
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
|
2026-11-12 15:42:26 +00:00
|
|
|
if FishKeyDB.sound == nil then
|
|
|
|
|
FishKeyDB.sound = true
|
|
|
|
|
end
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|
|
|
|
|
elseif event == "UNIT_SPELLCAST_CHANNEL_START" then
|
|
|
|
|
if IsFishing(spellID) then
|
|
|
|
|
Apply()
|
|
|
|
|
end
|
2026-11-11 17:27:31 +00:00
|
|
|
elseif event == "UNIT_SPELLCAST_CHANNEL_STOP" then
|
|
|
|
|
ChannelEnded()
|
|
|
|
|
elseif event == "LOOT_OPENED" then
|
|
|
|
|
-- The loot can arrive just before or just after the channel stops.
|
|
|
|
|
if state then
|
|
|
|
|
looting = true
|
2026-11-11 17:31:07 +00:00
|
|
|
awaitingLoot = false
|
|
|
|
|
end
|
|
|
|
|
elseif event == "UI_ERROR_MESSAGE" then
|
|
|
|
|
-- "No fish are hooked", "Your fish got away" and the like: no loot coming.
|
|
|
|
|
if awaitingLoot then
|
|
|
|
|
awaitingLoot = false
|
|
|
|
|
TryFinish(generation)
|
2026-11-11 17:27:31 +00:00
|
|
|
end
|
|
|
|
|
elseif event == "LOOT_CLOSED" then
|
|
|
|
|
if looting then
|
|
|
|
|
looting = false
|
2026-11-11 17:31:07 +00:00
|
|
|
if state == "fishing" then
|
|
|
|
|
-- Looted before the channel-stop event arrived: nothing left to wait for.
|
|
|
|
|
lastInteract = nil
|
|
|
|
|
end
|
2026-11-11 17:27:31 +00:00
|
|
|
TryFinish(generation)
|
|
|
|
|
end
|
|
|
|
|
elseif event == "PLAYER_REGEN_DISABLED" then
|
2026-11-11 15:46:46 +00:00
|
|
|
-- 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
|
2026-11-12 15:42:26 +00:00
|
|
|
elseif msg == "sound on" or msg == "sound off" then
|
|
|
|
|
-- Takes effect from the next cast.
|
|
|
|
|
FishKeyDB.sound = msg == "sound on"
|
2026-11-11 15:46:46 +00:00
|
|
|
elseif msg ~= "" then
|
2026-11-12 15:42:26 +00:00
|
|
|
Print("/fish shows status, /fish on|off, /fish sound on|off")
|
2026-11-11 15:46:46 +00:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local keys = FishingKeys()
|
|
|
|
|
local where = #keys > 0 and table.concat(keys, ", ") or "no key bound to Fishing"
|
2026-11-12 15:42:26 +00:00
|
|
|
Print((FishKeyDB.enabled and "on" or "off") .. " (" .. where .. "), quiet sound "
|
|
|
|
|
.. (FishKeyDB.sound and "on" or "off"))
|
2026-11-11 15:46:46 +00:00
|
|
|
end
|