-- texlua zonecount.lua 1 casual -- The Casual route heading "Zone: X/N quests" counts hand-ins the addon's Complete hook did not see: another addon -- handing in through its own copy of GetQuestReward (seen by the reward window), a complete quest leaving the log, and -- quests in pfQuest's history. An abandoned quest is not counted. local here = arg[0]:match("^(.*)/") or "." dofile(here .. "/lib.lua") local W, ER, S, P = H.W, H.ER, H.S, H.P local fails = 0 local function check(ok, what) if not ok then fails = fails + 1; P("FAIL " .. what) else P("ok " .. what) end end local function count() local _, _, tail = ER.RouteShort() local d, n = L53.match(tail or "", "(%d+)/(%d+) quests") return tonumber(d), tonumber(n), tail end local function settle() W.Fire("QUEST_LOG_UPDATE"); W.Tick(0.4, 4); W.Tick(3, 1) end local function logIdx(title) for i, q in ipairs(W.log) do if q.title == title then return i, q end end end check(S.Info() and S.Info().route, "the Casual route is running: " .. tostring(S.Info() and S.Info().name)) W.Tick(3, 3) local d0, n0, tail0 = count() check(tail0 and L53.match(tail0, "quests$"), "the heading says what it counts: \"" .. tostring(tail0) .. "\"") -- play the first steps, handing quests in past the hook: the reward window opens (QUEST_COMPLETE), then the quest leaves local bypass, completeGone = 0, 0 local guard = 0 while guard < 40 and (bypass + completeGone) < 4 do local st = S.Current() if not st then break end for _, e in ipairs(st.elements) do local id = tonumber(e.id) local title = id and S.QuestTitle(id) if e.kind == "A" and title and not logIdx(title) then table.insert(W.log, { id = id, title = title, level = S.QuestLevel(id) or 1, objs = { { text = "thing: 0/1", done = false } } }) settle() elseif e.kind == "C" and title then local _, q = logIdx(title) if q then q.complete = true; q.objs[1].done = true; q.objs[1].text = "thing: 1/1"; settle() end elseif e.kind == "T" and title then local i, q = logIdx(title) if i then if (bypass + completeGone) % 2 == 0 then W_TITLE = title; W.Fire("QUEST_COMPLETE"); W.Tick(0.2, 1) q.complete = false -- even when the log did not show it complete table.remove(W.log, i); settle(); bypass = bypass + 1 else q.complete = true; settle() table.remove(W.log, i); settle(); completeGone = completeGone + 1 end end end end if S.Current() == st then S.Next() end guard = guard + 1 end local d1 = count() P("note at step " .. S.Position() .. ": " .. ER.RouteShort()) check(bypass >= 1 and completeGone >= 1 and d1 == d0 + bypass + completeGone, "hand-ins the hook missed are counted (" .. bypass .. " via the reward window, " .. completeGone .. " complete when they left; " .. d0 .. " -> " .. tostring(d1) .. ")") -- abandoning a quest is not a hand-in, even a complete one local ab for _, it in ipairs(S.All()) do if it.step.n > S.Position() then for _, e in ipairs(it.step.elements) do if e.kind == "A" and tonumber(e.id) and not S.TurnedIn(e.id) and not ab then ab = tonumber(e.id) end end end end if ab then local title = S.QuestTitle(ab) table.insert(W.log, { id = ab, title = title, level = S.QuestLevel(ab) or 1, complete = true, objs = { { text = "thing: 1/1", done = true } } }) settle() GetAbandonQuestName = function() return title end SetAbandonQuest() table.remove(W.log, (logIdx(title))); settle() check(not S.TurnedIn(ab) and count() == d1, "an abandoned quest is not counted as handed in") end -- pfQuest's history: a quest handed in before the addon was installed counts at once local later for _, it in ipairs(S.All()) do if it.step.n > S.Position() + 3 then for _, e in ipairs(it.step.elements) do if e.kind == "T" and tonumber(e.id) and not S.TurnedIn(e.id) and tonumber(e.id) ~= ab then later = later or tonumber(e.id) end end end end if later then pfQuest_history = pfQuest_history or {} local c0 = count() pfQuest_history[later] = { 0, 1 } W.Tick(3, 2) check(S.TurnedIn(later) and count() == c0 + 1, "a quest in pfQuest's history counts as handed in (" .. c0 .. " -> " .. tostring(count()) .. ")") end P(fails == 0 and "ALL PASSED" or (fails .. " FAILED")) REPORT()