Add Fish Key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-11 15:46:46 +00:00
parent 40add57ba9
commit 6ae2b47bb1
4 changed files with 306 additions and 2 deletions

183
FishKey/FishKey.lua Normal file
View file

@ -0,0 +1,183 @@
-- Fish Key: while Fishing channels, every key bound to Fishing is overridden to
-- "Interact with Target", so the same key clicks the bobber. 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
-- Soft interact range while fishing. The default (about 10 yards) is shorter
-- than a cast, so the bobber would never become the interact target.
local FISHING_RANGE = 30
local owner = CreateFrame("Frame")
local overridden = false
local clearAfterCombat = false
local raisedRange = 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 RaiseRange()
local current = tonumber(C_CVar.GetCVar("SoftTargetInteractRange"))
if current and current < FISHING_RANGE then
C_CVar.SetTempCVar("SoftTargetInteractRange", tostring(FISHING_RANGE))
raisedRange = true
end
end
local function RestoreRange()
if raisedRange then
C_CVar.RemoveTempCVar("SoftTargetInteractRange")
raisedRange = false
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
RaiseRange()
end
local function Restore()
if overridden then
if InCombatLockdown() then
clearAfterCombat = true
else
ClearOverrideBindings(owner)
overridden = false
end
end
RestoreRange()
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

7
FishKey/FishKey.toc Normal file
View file

@ -0,0 +1,7 @@
## Interface: 16001
## Title: Fish Key
## Notes: While you fish, your Fishing key clicks the bobber instead.
## Version: 1.0
## SavedVariables: FishKeyDB
FishKey.lua

View file

@ -1,6 +1,6 @@
# WoW Forever addons
Six small quality-of-life addons for WoW Forever (client 1.60.1, Interface 16001).
Seven small quality-of-life addons for WoW Forever (client 1.60.1, Interface 16001).
| Addon | What it does | Check command |
| --- | --- | --- |
@ -10,10 +10,11 @@ Six small quality-of-life addons for WoW Forever (client 1.60.1, Interface 16001
| Quest Shopping List | A panel beside the auction house listing items your quests still need, with cost against the quest's reward. Click to search. Requires [Auctionator](https://www.curseforge.com/wow/addons/auctionator). | `/qsl` |
| Dungeon Pre-Quest | Marks dungeon quests and quests whose chain leads to one, in the quest log, NPC quest lists and the quest offer window, with a purple "!" on the minimap for ones you can pick up now. | `/dpq <questID>` |
| Ship Routes | Draws every boat, zeppelin and airship route on the world map, coloured by faction. Hover a dock marker to see where it sails and light up its route, click it to open the destination's map. On a continent or zone map, a route that sails off it ends in a marker at the edge naming where it goes. | `/routes`, `/routes mine`, `/routes all` |
| Fish Key | While you fish, the key you cast Fishing with clicks the bobber instead. It casts Fishing again once the cast ends. Needs the Interact Key soft targeting setting on. | `/fish`, `/fish on`, `/fish off` |
## Install
Copy the six addon folders into `World of Warcraft/_forever_/Interface/AddOns/`, then type `/reload` in game.
Copy the seven addon folders into `World of Warcraft/_forever_/Interface/AddOns/`, then type `/reload` in game.
Each addon works on its own, so copy only the ones you want. Vendor Flag and Quest Shopping List stay disabled unless Auctionator is installed.
## Known limits
@ -25,6 +26,7 @@ Each addon works on its own, so copy only the ones you want. Vendor Flag and Que
- Its minimap markers skip quests started by an item, and quests with profession or reputation requirements.
- Quest Shopping List's prices are Auctionator's last-seen prices, so run "Search all" for current ones. Rewards count gold plus item value, not XP.
- Ship Routes' dock names and the list of which paths are transports are curated by hand in `ShipRoutes/tools/generate.py`, because the client doesn't record which ship sails which path. Lanes between continents follow hand-placed sea waypoints there too, since the ships teleport mid-ocean. The Zephras Isle airships have no line, since the island isn't on the world map, and they have no known faction, so they show in neutral gold.
- Fish Key finds Fishing on Blizzard's action bars, `CLICK` bindings to addon buttons, and spell or macro bindings. It doesn't see bar addons that bind keys through their own override bindings, such as Bartender. While you fish it raises the interact range to 30 yards, so a closer NPC or object can be picked over the bobber.
## Tests
@ -38,6 +40,7 @@ lua tests/test_dpq.lua DungeonPreQuest/DungeonPreQuest.lua
lua tests/test_dpq_minimap.lua DungeonPreQuest/Minimap.lua
lua tests/test_qsl.lua QuestShoppingList/QuestShoppingList.lua
lua tests/test_sr.lua ShipRoutes
lua tests/test_fk.lua FishKey/FishKey.lua
```
## Regenerating Dungeon Pre-Quest's data

111
tests/test_fk.lua Normal file
View file

@ -0,0 +1,111 @@
-- Runs FishKey.lua against a mock of the WoW API.
-- arg[1] = addon file
local spells = { [7620] = "Fishing", [7731] = "Fishing", [133] = "Fireball" }
C_Spell = { GetSpellName = function(id) return spells[id] end }
local actions = { [9] = { "spell", 7731 }, [30] = { "macro", 4 }, [40] = { "spell", 133 } }
function GetActionInfo(slot)
local a = actions[slot]
if a then return a[1], a[2] end
end
local macros = { [4] = 7620, [5] = 133 }
function GetMacroSpell(i) return macros[i] end
local macroNames = { ["FishMacro"] = 4, ["Nuke"] = 5 }
function GetMacroIndexByName(n) return macroNames[n] or 0 end
ActionButton9 = { bindingAction = "ACTIONBUTTON9", action = 9 }
ActionButton10 = { bindingAction = "ACTIONBUTTON10", action = 40 }
MultiBarBottomLeftButton6 = { bindingAction = "MULTIACTIONBAR1BUTTON6", action = 30 }
SomeAddonButton = { GetAttribute = function(_, k) if k == "action" then return 9 end end }
local bindings = {
{ "ACTIONBUTTON9", "ACTIONBAR", "F", "SHIFT-1" },
{ "ACTIONBUTTON10", "ACTIONBAR", "G" },
{ "MULTIACTIONBAR1BUTTON6", "ACTIONBAR" },
{ "SPELL Fishing", "SPELLS", "CTRL-F" },
{ "MACRO FishMacro", "MACROS", "ALT-F" },
{ "MACRO Nuke", "MACROS", "N" },
{ "CLICK SomeAddonButton:LeftButton", "ADDONS", "BUTTON4" },
{ "INTERACTTARGET", "TARGETING", "SHIFT-F" },
}
function GetNumBindings() return #bindings end
function GetBinding(i) return unpack(bindings[i]) end
local overrides = {}
function SetOverrideBinding(_, priority, key, command) overrides[key] = command end
function ClearOverrideBindings() overrides = {} end
local inCombat = false
function InCombatLockdown() return inCombat end
local cvars = { SoftTargetInteractRange = "10" }
local temp = {}
C_CVar = {
GetCVar = function(n) return temp[n] or cvars[n] end,
SetTempCVar = function(n, v) temp[n] = v end,
RemoveTempCVar = function(n) temp[n] = nil end,
}
local handler
CreateFrame = function()
return {
RegisterEvent = function() end,
RegisterUnitEvent = function() end,
SetScript = function(_, _, fn) handler = fn end,
}
end
SlashCmdList = {}
local printed = {}
DEFAULT_CHAT_FRAME = { AddMessage = function(_, m) printed[#printed + 1] = m end }
local failures = 0
local function check(cond, what)
if not cond then failures = failures + 1 end
print((cond and "ok " or "FAIL ") .. what)
end
local function count(t) local n = 0 for _ in pairs(t) do n = n + 1 end return n end
assert(loadfile(arg[1]))("FishKey", {})
handler(nil, "ADDON_LOADED", "FishKey")
check(FishKeyDB.enabled == true, "enabled by default")
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7731)
check(overrides["F"] == "INTERACTTARGET", "action bar key becomes interact")
check(overrides["SHIFT-1"] == "INTERACTTARGET", "second key on the same button too")
check(overrides["CTRL-F"] == "INTERACTTARGET", "SPELL binding")
check(overrides["ALT-F"] == "INTERACTTARGET", "macro binding casting Fishing")
check(overrides["BUTTON4"] == "INTERACTTARGET", "CLICK binding to an addon button")
check(overrides["G"] == nil and overrides["N"] == nil, "other spells untouched")
check(count(overrides) == 5, "only Fishing keys overridden")
check(C_CVar.GetCVar("SoftTargetInteractRange") == "30", "interact range raised while fishing")
handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7731)
check(count(overrides) == 0, "keys back to Fishing when the channel ends")
check(C_CVar.GetCVar("SoftTargetInteractRange") == "10", "range restored")
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 133)
check(count(overrides) == 0, "other channels ignored")
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
handler(nil, "PLAYER_REGEN_DISABLED")
check(count(overrides) == 0, "cleared when combat starts")
inCombat = true
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
check(count(overrides) == 0, "no override in combat")
inCombat = false
cvars.SoftTargetInteractRange = "40"
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
check(temp.SoftTargetInteractRange == nil, "longer range left alone")
handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7620)
SlashCmdList.FISHKEY("off")
check(FishKeyDB.enabled == false, "/fish off")
check(printed[#printed]:find("off", 1, true) and printed[#printed]:find("F, SHIFT-1", 1, true), "status lists keys")
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
check(count(overrides) == 0, "nothing when off")
SlashCmdList.FISHKEY("on")
check(FishKeyDB.enabled == true, "/fish on")
print(failures == 0 and "all passed" or (failures .. " failed"))
os.exit(failures == 0 and 0 or 1)