Fish Key: no wait after a miss

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-11 17:31:07 +00:00
parent 02c88282cf
commit db73c215bb
2 changed files with 93 additions and 18 deletions

View file

@ -7,11 +7,17 @@
-- 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.
--
-- 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.
local FISHING_SPELL = 7620
-- How long to wait for the loot window after the cast ends before treating it
-- as a miss.
local LOOT_WAIT = 1.5
-- 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
local POLL = 0.05
-- Settings changed while fishing, as temp CVars that are never saved, and
@ -39,6 +45,10 @@ local activeKeys = {}
-- release, nil otherwise.
local state
local looting = false
-- 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
-- Bumped on every new cast and restore, so stale timers do nothing.
local generation = 0
@ -172,6 +182,8 @@ local function Restore()
generation = generation + 1
state = nil
looting = false
awaitingLoot = false
lastInteract = nil
if overridden then
if InCombatLockdown() then
clearAfterCombat = true
@ -186,7 +198,7 @@ end
-- Restores once nothing can still turn a press into a new cast.
local function TryFinish(gen)
if gen ~= generation or state ~= "ending" or looting then
if gen ~= generation or state ~= "ending" or looting or awaitingLoot then
return
end
if AnyKeyHeld() then
@ -202,6 +214,8 @@ local function Apply()
end
generation = generation + 1
looting = false
awaitingLoot = false
lastInteract = nil
local keys = FishingKeys()
if #keys == 0 then
return
@ -221,15 +235,34 @@ local function ChannelEnded()
end
state = "ending"
local gen = generation
-- No loot window by then: the cast missed, timed out or was interrupted.
C_Timer.After(LOOT_WAIT, function() TryFinish(gen) end)
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)
end
-- 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)
owner:RegisterEvent("ADDON_LOADED")
owner:RegisterEvent("PLAYER_REGEN_DISABLED")
owner:RegisterEvent("PLAYER_REGEN_ENABLED")
owner:RegisterEvent("LOOT_OPENED")
owner:RegisterEvent("LOOT_CLOSED")
owner:RegisterEvent("UI_ERROR_MESSAGE")
owner:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_START", "player")
owner:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_STOP", "player")
owner:SetScript("OnEvent", function(_, event, arg1, _, spellID)
@ -250,10 +283,21 @@ owner:SetScript("OnEvent", function(_, event, arg1, _, spellID)
-- The loot can arrive just before or just after the channel stops.
if state then
looting = true
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)
end
elseif event == "LOOT_CLOSED" then
if looting then
looting = false
if state == "fishing" then
-- Looted before the channel-stop event arrived: nothing left to wait for.
lastInteract = nil
end
TryFinish(generation)
end
elseif event == "PLAYER_REGEN_DISABLED" then