Fish Key: restore after loot and key release, press and hold off

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

View file

@ -38,7 +38,30 @@ function ClearOverrideBindings() overrides = {} end
local inCombat = false
function InCombatLockdown() return inCombat end
local cvars = { SoftTargetInteract = "0", SoftTargetInteractRange = "10" }
local held = {}
function IsKeyDown(key)
assert(not key:find("^SHIFT%-") and not key:find("^CTRL%-") and not key:find("^ALT%-"), "modifier passed to IsKeyDown: " .. key)
return held[key] or false
end
local clock, timers = 0, {}
C_Timer = { After = function(sec, fn) timers[#timers + 1] = { at = clock + sec, fn = fn } end }
local function advance(sec)
local target = clock + sec
while true do
local nextIndex
for i, t in ipairs(timers) do
if t.at <= target and (not nextIndex or t.at < timers[nextIndex].at) then nextIndex = i end
end
if not nextIndex then break end
local t = table.remove(timers, nextIndex)
clock = t.at
t.fn()
end
clock = target
end
local cvars = { SoftTargetInteract = "0", SoftTargetInteractRange = "10", ActionButtonUseKeyHeldSpell = "1" }
local temp = {}
C_CVar = {
GetCVar = function(n) return temp[n] or cvars[n] end,
@ -64,6 +87,9 @@ local function check(cond, what)
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
local function stop() handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7620) end
-- Cast ends with no loot and every key released: everything back to normal.
local function finish() stop(); advance(2) end
assert(loadfile(arg[1]))("FishKey", {})
handler(nil, "ADDON_LOADED", "FishKey")
@ -80,10 +106,55 @@ check(count(overrides) == 5, "only Fishing keys overridden")
check(C_CVar.GetCVar("SoftTargetInteractRange") == "30", "interact range raised while fishing")
check(C_CVar.GetCVar("SoftTargetInteract") == "3", "Interact Key turned on while fishing")
local function restored()
return count(overrides) == 0 and C_CVar.GetCVar("SoftTargetInteract") == "0"
and C_CVar.GetCVar("SoftTargetInteractRange") == "10" and C_CVar.GetCVar("ActionButtonUseKeyHeldSpell") == "1"
end
check(C_CVar.GetCVar("ActionButtonUseKeyHeldSpell") == "0", "press and hold casting off while fishing")
-- Catch with the key held through the loot (press and hold, slow release).
held["F"] = true
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")
check(C_CVar.GetCVar("SoftTargetInteract") == "0", "Interact Key off again")
check(overrides["F"] == "INTERACTTARGET", "still interact right after the channel ends")
handler(nil, "LOOT_OPENED")
advance(2)
check(overrides["F"] == "INTERACTTARGET", "still interact while the loot window is open")
handler(nil, "LOOT_CLOSED")
advance(0.3)
check(overrides["F"] == "INTERACTTARGET" and C_CVar.GetCVar("ActionButtonUseKeyHeldSpell") == "0", "still interact while the key is held")
held["F"] = nil
advance(0.1)
check(restored(), "key and settings restored once looted and released")
-- Miss: no loot window.
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
stop()
advance(1)
check(overrides["F"] == "INTERACTTARGET", "waits a moment for loot after a miss")
advance(1)
check(restored(), "restored after a miss")
-- Loot arrives before the channel stop, modifier key held.
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
handler(nil, "LOOT_OPENED")
stop()
held["1"] = true
handler(nil, "LOOT_CLOSED")
advance(0.2)
check(overrides["SHIFT-1"] == "INTERACTTARGET", "held SHIFT-1 counts as held")
held["1"] = nil
advance(0.1)
check(restored(), "restored after loot that came first")
-- A stale miss timer must not cut short the next cast.
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
handler(nil, "LOOT_OPENED")
stop()
handler(nil, "LOOT_CLOSED")
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
advance(2)
check(overrides["F"] == "INTERACTTARGET", "old timer leaves the new cast alone")
finish()
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 133)
check(count(overrides) == 0, "other channels ignored")
@ -99,18 +170,18 @@ 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)
finish()
cvars.SoftTargetInteract = "3"
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
check(temp.SoftTargetInteract == nil, "Interact Key already on is left alone")
handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7620)
finish()
cvars.SoftTargetInteract = "0"
C_CVar.SetTempCVar = function() error("secure cvar") end
handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620)
check(overrides["F"] == "INTERACTTARGET" and printed[#printed]:find("Settings", 1, true), "blocked setting warns, key still overridden")
handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7620)
finish()
C_CVar.SetTempCVar = function(n, v) temp[n] = v end
SlashCmdList.FISHKEY("off")