Progress detection: - Quests you passed by (not in the log, not done, three later quests started) no longer hold up a zone's checklist. Only a quest's first row counts, follow-ups of quests in the log are never flagged, and nothing is flagged when it would cover more than 40% of a plan. - When the quest log and current zone show you're further along, the tracker offers to jump there. Earlier steps are skipped, class quests and mounts are put off, and Undo restores both. - Class quests and mounts 8+ levels behind stop blocking the route and stay on a "still open" reminder. - A welcome panel on each new character sums up what was detected. Tracker and guide: - Compact, standard and detailed tracker layouts; real checkboxes on objectives; the panel grows downward and no longer changes height on a timer; optional fading in combat, until mouseover, and in instances. - Flat theme with a class-color or gold accent, line-drawn buttons, slim scrollbars and short fade-ins. - Resizable guide window with search on every tab, Talents and Spec Guide merged into one tab, the Route tab opening at the current step, and grouped settings that are also under Options > AddOns. - Key bindings, a confirmation before resetting progress (which now also clears manual checkmarks), fewer chat messages, a draggable level-up popup, adjustable text size, and a colorblind-friendly palette. Step and plan state is cached per refresh, since one refresh used to work it out several times over for the whole route.
447 lines
17 KiB
Lua
447 lines
17 KiB
Lua
-- Coffey's Leveling Guide quest plans: quest-by-quest checklists attached to route steps, live quest-log
|
|
-- tracking, and optional Questie database lookups for NPC locations (never required).
|
|
local ADDON, ns = ...
|
|
|
|
ns.logComplete = {} -- questID -> true when objectives are complete (ready to turn in)
|
|
|
|
ns.ACT_ICONS = {
|
|
accept = "Interface\\GossipFrame\\AvailableQuestIcon",
|
|
turnin = "Interface\\GossipFrame\\ActiveQuestIcon",
|
|
kill = "Interface\\Icons\\Ability_DualWield",
|
|
collect = "Interface\\Icons\\INV_Misc_Bag_08",
|
|
use = "Interface\\Icons\\INV_Misc_Gear_01",
|
|
go = "Interface\\Icons\\Ability_Tracking",
|
|
fp = "Interface\\Icons\\Ability_Hunter_EagleEye",
|
|
hs = "Interface\\Icons\\INV_Misc_Rune_01",
|
|
note = "Interface\\Icons\\INV_Misc_Note_01",
|
|
}
|
|
local ACT_VERB = { accept = "Accept", turnin = "Turn in", kill = "", collect = "", use = "", go = "", fp = "", hs = "", note = "" }
|
|
|
|
---------------------------------------------------------------------------
|
|
-- Optional Questie lookups
|
|
---------------------------------------------------------------------------
|
|
local function QuestieModules()
|
|
if not QuestieLoader or not QuestieLoader.ImportModule then return end
|
|
local ok, qdb = pcall(QuestieLoader.ImportModule, QuestieLoader, "QuestieDB")
|
|
local ok2, zdb = pcall(QuestieLoader.ImportModule, QuestieLoader, "ZoneDB")
|
|
if ok and qdb and qdb.GetQuest then return qdb, ok2 and zdb or nil end
|
|
end
|
|
|
|
local function NPCWaypoint(qdb, zdb, npcId)
|
|
local npc = qdb.GetNPC and qdb:GetNPC(npcId)
|
|
if not npc or not npc.spawns then return end
|
|
for areaId, list in pairs(npc.spawns) do
|
|
local first = list[1]
|
|
local map = zdb and zdb.GetUiMapIdByAreaId and zdb:GetUiMapIdByAreaId(areaId)
|
|
if first and map then return { map, first[1], first[2], npc.name or "NPC" } end
|
|
end
|
|
end
|
|
|
|
-- which = "finish" | "start"
|
|
local wpCache = {}
|
|
function ns.QuestieWaypoint(questID, which)
|
|
if not questID or not ns.db.useQuestie then return end
|
|
local key = questID .. which
|
|
if wpCache[key] ~= nil then return wpCache[key] or nil end
|
|
local result = false
|
|
local ok = pcall(function()
|
|
local qdb, zdb = QuestieModules()
|
|
if not qdb then return end
|
|
local q = qdb.GetQuest(questID)
|
|
if not q then return end
|
|
local npcs = which == "finish" and (q.Finisher and q.Finisher.NPC) or (q.Starts and q.Starts.NPC)
|
|
if npcs and npcs[1] then result = NPCWaypoint(qdb, zdb, npcs[1]) or false end
|
|
end)
|
|
if not ok then result = false end
|
|
wpCache[key] = result
|
|
return result or nil
|
|
end
|
|
|
|
---------------------------------------------------------------------------
|
|
-- Plan state
|
|
---------------------------------------------------------------------------
|
|
local function QuestID(s) return s.quest and s.quest[2] end
|
|
|
|
local function PlayerMatches(s)
|
|
return not s.races or ns.Contains(s.races, ns.player.race)
|
|
end
|
|
|
|
-- Sub-steps of a route step for this player's race (cached; the race never changes).
|
|
local planCache, planCacheRace = {}, nil
|
|
function ns.PlanFor(step)
|
|
local plan = step and ns.PLANS[step.id]
|
|
if not plan then return nil end
|
|
if planCacheRace ~= ns.player.race then planCache, planCacheRace = {}, ns.player.race end
|
|
local out = planCache[step.id]
|
|
if out then return out end
|
|
out = {}
|
|
for i, s in ipairs(plan) do
|
|
if PlayerMatches(s) then s._i = i; out[#out + 1] = s; s._pos = #out end
|
|
end
|
|
planCache[step.id] = out
|
|
return out
|
|
end
|
|
|
|
local AutoDone -- defined below: flight paths, hearthstone and travel steps
|
|
|
|
function ns.SubDone(step, s)
|
|
local mark = ns.char.plan[step.id]
|
|
if mark and mark[s._i] then return true end
|
|
local q = s.quest
|
|
local id = QuestID(s)
|
|
if s.act == "note" then return true end
|
|
if s.act == "fp" or s.act == "hs" or s.act == "go" then return AutoDone(step, s) end
|
|
if q then
|
|
if ns.IsQuestDone(q) then return true end
|
|
if s.act == "accept" then return ns.IsQuestActive(q) and true or false end
|
|
if s.act == "kill" or s.act == "collect" or s.act == "use" then return id and ns.logComplete[id] or false end
|
|
return false
|
|
end
|
|
return false
|
|
end
|
|
|
|
function ns.MarkSub(step, s, value)
|
|
ns.char.plan[step.id] = ns.char.plan[step.id] or {}
|
|
ns.char.plan[step.id][s._i] = value or nil
|
|
ns.Invalidate()
|
|
ns.Fire("Refresh")
|
|
end
|
|
|
|
-- How many different quests past a sub-step must show progress before an untouched
|
|
-- quest is treated as passed by (never picked up, or abandoned).
|
|
local MISSED_AFTER = 3
|
|
|
|
-- Returns plan list, index of the first open sub-step (nil when finished), done count, and a
|
|
-- set of indexes the player has moved past.
|
|
--
|
|
-- A quest counts as passed by when it is untouched (not in the log, not completed) and at
|
|
-- least MISSED_AFTER other quests whose *first* row comes later in the plan have been picked
|
|
-- up or finished. Only a quest's first row counts: the objectives and turn-ins of quests you
|
|
-- accepted earlier always sit further down the list, and counting those would flag the next
|
|
-- hub's quests while you're simply following the plan. An accept that comes after the turn-in
|
|
-- of a quest still in your log is never flagged either, since it may be that quest's follow-up.
|
|
-- If more than 40% of the plan would be passed by, nothing is: that's a different route
|
|
-- through the zone, not a few skipped quests, so the plan is followed as written.
|
|
-- Passed-by rows stay listed (dimmed) but no longer hold the cursor.
|
|
local memo = {}
|
|
local Compute
|
|
function ns.PlanProgress(step)
|
|
if not step then return nil end
|
|
local key = ns.MemoKey()
|
|
local m = memo[step.id]
|
|
if m and m.key == key then return m.plan, m.first, m.done, m.missed end
|
|
local plan, first, done, missed = Compute(step)
|
|
memo[step.id] = { key = key, plan = plan, first = first, done = done, missed = missed }
|
|
return plan, first, done, missed
|
|
end
|
|
|
|
Compute = function(step)
|
|
local plan = ns.PlanFor(step)
|
|
if not plan then return nil end
|
|
local n = #plan
|
|
local doneAt, keyAt, firstPos, touched = {}, {}, {}, {}
|
|
local done = 0
|
|
for i, s in ipairs(plan) do
|
|
if ns.SubDone(step, s) then doneAt[i] = true; done = done + 1 end
|
|
local k = s.quest and (s.quest[2] or s.quest[1])
|
|
if k then
|
|
keyAt[i] = k
|
|
if not firstPos[k] then
|
|
firstPos[k] = i
|
|
touched[k] = (ns.IsQuestActive(s.quest) or ns.IsQuestDone(s.quest)) and true or false
|
|
end
|
|
end
|
|
end
|
|
-- Open turn-ins of quests in the log, by position: accepts after them may be follow-ups.
|
|
local openTurninBefore, open = {}, false
|
|
for i, s in ipairs(plan) do
|
|
openTurninBefore[i] = open
|
|
if s.act == "turnin" and s.quest and not doneAt[i] and ns.IsQuestActive(s.quest) then open = true end
|
|
end
|
|
local missed, missedKey, ahead = {}, {}, 0
|
|
for i = n, 1, -1 do
|
|
local k = keyAt[i]
|
|
if k and firstPos[k] == i then
|
|
if touched[k] then
|
|
ahead = ahead + 1
|
|
elseif not doneAt[i] and ahead >= MISSED_AFTER and not openTurninBefore[i] then
|
|
missedKey[k] = true
|
|
end
|
|
elseif not k and not doneAt[i] and (plan[i].act == "fp" or plan[i].act == "hs") and ahead >= MISSED_AFTER + 1 then
|
|
missed[i] = true
|
|
end
|
|
end
|
|
-- Every row of a passed-by quest goes together (accept, objectives and turn-in).
|
|
for i = 1, n do
|
|
if keyAt[i] and missedKey[keyAt[i]] and not doneAt[i] then missed[i] = true end
|
|
end
|
|
if ns.MissedCount(missed) > n * 0.4 then missed = {} end
|
|
local first
|
|
for i = 1, n do
|
|
if not doneAt[i] and not missed[i] then first = i; break end
|
|
end
|
|
return plan, first, done, missed
|
|
end
|
|
|
|
function ns.MissedCount(missed)
|
|
local c = 0
|
|
for _ in pairs(missed or {}) do c = c + 1 end
|
|
return c
|
|
end
|
|
|
|
function ns.SubText(s)
|
|
local verb = ACT_VERB[s.act] or ""
|
|
local name = s.quest and s.quest[1]
|
|
if s.text and s.text ~= "" then
|
|
if (s.act == "accept" or s.act == "turnin") and name then
|
|
return verb .. " |cffffd100" .. name .. "|r" .. (s.npc and (" (" .. s.npc .. ")") or "") .. " - " .. s.text
|
|
end
|
|
return s.text
|
|
end
|
|
if name then return verb .. " |cffffd100" .. name .. "|r" .. (s.npc and (" from " .. s.npc) or "") end
|
|
return s.act
|
|
end
|
|
|
|
-- Waypoints for the tracker: the current sub-step's location, or Questie's NPC location.
|
|
function ns.SubWaypoints(s)
|
|
if not s then return nil end
|
|
if s.wp then return { s.wp } end
|
|
local id = QuestID(s)
|
|
if id and s.act == "turnin" then local wp = ns.QuestieWaypoint(id, "finish"); if wp then return { wp } end end
|
|
if id and s.act == "accept" then local wp = ns.QuestieWaypoint(id, "start"); if wp then return { wp } end end
|
|
end
|
|
|
|
---------------------------------------------------------------------------
|
|
-- Quest log snapshot (objectives + completion), used by the Quest Log tab
|
|
---------------------------------------------------------------------------
|
|
function ns.QuestLogSnapshot()
|
|
local groups, header = {}, nil
|
|
local num = (GetNumQuestLogEntries and GetNumQuestLogEntries()) or 0
|
|
for i = 1, num do
|
|
local title, level, _, isHeader, _, isComplete, _, id = GetQuestLogTitle(i)
|
|
if isHeader then
|
|
header = { name = title, quests = {} }
|
|
groups[#groups + 1] = header
|
|
elseif title then
|
|
if not header then header = { name = "Quests", quests = {} }; groups[#groups + 1] = header end
|
|
local objectives = {}
|
|
if id and C_QuestLog and C_QuestLog.GetQuestObjectives then
|
|
for _, o in ipairs(C_QuestLog.GetQuestObjectives(id) or {}) do
|
|
objectives[#objectives + 1] = { text = o.text, done = o.finished }
|
|
end
|
|
elseif GetNumQuestLeaderBoards then
|
|
for j = 1, GetNumQuestLeaderBoards(i) do
|
|
local text, _, finished = GetQuestLogLeaderBoard(j, i)
|
|
objectives[#objectives + 1] = { text = text, done = finished }
|
|
end
|
|
end
|
|
header.quests[#header.quests + 1] = { title = title, level = level, id = id,
|
|
complete = (isComplete == 1 or isComplete == true), failed = (isComplete == -1), objectives = objectives }
|
|
end
|
|
end
|
|
return groups
|
|
end
|
|
|
|
function ns.ScanLogCompletion()
|
|
ns.Invalidate()
|
|
wipe(ns.logComplete)
|
|
local num = (GetNumQuestLogEntries and GetNumQuestLogEntries()) or 0
|
|
for i = 1, num do
|
|
local _, _, _, isHeader, _, isComplete, _, id = GetQuestLogTitle(i)
|
|
if not isHeader and id and (isComplete == 1 or isComplete == true) then ns.logComplete[id] = true end
|
|
end
|
|
end
|
|
|
|
ns.On("Login", function()
|
|
ns.char.plan = ns.char.plan or {}
|
|
if ns.db.useQuestie == nil then ns.db.useQuestie = true end
|
|
ns.ScanLogCompletion()
|
|
end)
|
|
ns.On("QuestLogChanged", ns.ScanLogCompletion)
|
|
|
|
---------------------------------------------------------------------------
|
|
-- Flight paths, hearthstone and travel steps tick off by themselves:
|
|
-- fp: the flight path shows up as known on any flight map you open, or you
|
|
-- open a flight map / discover a path next to the step's flight master.
|
|
-- hs: your hearthstone is bound there (GetBindLocation), or you bind it next
|
|
-- to the step's innkeeper. "Hearth to X" ticks when you use the hearthstone.
|
|
-- go: done once you have done anything later in the same plan (or, for the
|
|
-- last step of a plan, in the next route step that has a plan).
|
|
---------------------------------------------------------------------------
|
|
local HBD = LibStub and LibStub("HereBeDragons-2.0", true)
|
|
local HEARTHSTONE = 8690
|
|
|
|
local function Lower(t) return (t or ""):lower() end
|
|
|
|
-- The part of a step's text that names the place: drop "(...)" and ", then ..."
|
|
local function Place(s)
|
|
local t = Lower(s.text)
|
|
t = t:gsub("%(.*", ""):gsub(", then .*", "")
|
|
return t
|
|
end
|
|
|
|
local function IsHearthTo(s) return s.act == "hs" and Lower(s.text):find("^hearth to") ~= nil end
|
|
|
|
local function Mark(step, s)
|
|
ns.char.plan[step.id] = ns.char.plan[step.id] or {}
|
|
ns.char.plan[step.id][s._i] = true
|
|
ns.Invalidate()
|
|
end
|
|
|
|
local function NodeShort(name) return Lower((name or ""):match("^%s*([^,]+)")):gsub("%s+$", "") end
|
|
|
|
-- Remember every flight path the taxi map lists as known.
|
|
function ns.RecordTaxiNodes()
|
|
ns.Invalidate()
|
|
ns.char.taxi = ns.char.taxi or {}
|
|
local known, n = ns.char.taxi, 0
|
|
if NumTaxiNodes and TaxiNodeName then
|
|
for i = 1, NumTaxiNodes() or 0 do
|
|
local kind = TaxiNodeGetType and TaxiNodeGetType(i)
|
|
local name = TaxiNodeName(i)
|
|
if name and (kind == "CURRENT" or kind == "REACHABLE" or not TaxiNodeGetType) then
|
|
known[NodeShort(name)] = true; n = n + 1
|
|
end
|
|
end
|
|
end
|
|
if n == 0 and C_TaxiMap and C_TaxiMap.GetAllTaxiNodes and GetTaxiMapID then
|
|
local ok, nodes = pcall(C_TaxiMap.GetAllTaxiNodes, GetTaxiMapID())
|
|
for _, node in ipairs(ok and nodes or {}) do
|
|
if node.name and (node.state == 0 or node.state == 1) then known[NodeShort(node.name)] = true; n = n + 1 end
|
|
end
|
|
end
|
|
return n
|
|
end
|
|
|
|
local function KnowsFlightPath(s)
|
|
local place = Place(s)
|
|
for short in pairs(ns.char.taxi or {}) do
|
|
if #short >= 4 and place:find(short, 1, true) then return true end
|
|
end
|
|
return false
|
|
end
|
|
|
|
local function BoundHere(s)
|
|
local bind = GetBindLocation and Lower(GetBindLocation())
|
|
return bind ~= nil and #bind >= 4 and Place(s):find(bind, 1, true) ~= nil
|
|
end
|
|
|
|
local function Near(s, yards)
|
|
if not (HBD and s.wp and s.wp[1]) then return false end
|
|
local px, py, pmap = HBD:GetPlayerZonePosition()
|
|
if not px then return false end
|
|
local d = HBD:GetZoneDistance(pmap, px, py, s.wp[1], s.wp[2] / 100, s.wp[3] / 100)
|
|
return d ~= nil and d <= yards
|
|
end
|
|
|
|
local routeIndex, routeIndexFor = {}, nil
|
|
local function NextStep(step)
|
|
if routeIndexFor ~= ns.route then
|
|
routeIndex, routeIndexFor = {}, ns.route
|
|
for i, st in ipairs(ns.route or {}) do routeIndex[st.id] = i end
|
|
end
|
|
-- The next route step that has a quest plan (class quest and dungeon steps in between have none).
|
|
local i = routeIndex[step.id]
|
|
if not i then return nil end
|
|
for j = i + 1, math.min(i + 6, #ns.route) do
|
|
local st = ns.route[j]
|
|
if ns.PLANS[st.id] and not st.optional then return st end
|
|
end
|
|
end
|
|
|
|
-- Anything after sub-step s (quest steps, flight paths, hearthstone binds) done?
|
|
local function LaterDone(step, s, plan)
|
|
for i = (s._pos or 0) + 1, #plan do
|
|
local o = plan[i]
|
|
if o.act ~= "go" and o.act ~= "note" and not IsHearthTo(o) and ns.SubDone(step, o) then return true end
|
|
end
|
|
return false
|
|
end
|
|
|
|
AutoDone = function(step, s)
|
|
if s.act == "fp" then
|
|
return KnowsFlightPath(s)
|
|
elseif s.act == "hs" and not IsHearthTo(s) then
|
|
return BoundHere(s)
|
|
end
|
|
-- "go" and "Hearth to X": done once you have moved on.
|
|
local plan = ns.PlanFor(step)
|
|
if not plan then return false end
|
|
if LaterDone(step, s, plan) then return true end
|
|
if s._pos == #plan then
|
|
local nxt = NextStep(step)
|
|
local nplan = nxt and ns.PlanFor(nxt)
|
|
if nplan then
|
|
for _, o in ipairs(nplan) do
|
|
if o.act ~= "go" and o.act ~= "note" and not IsHearthTo(o) and ns.SubDone(nxt, o) then return true end
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- Steps the player is working on: the current one and the one being viewed.
|
|
local function ActiveSteps()
|
|
local out = {}
|
|
for _, i in ipairs({ ns.CurrentIndex(), ns.ViewIndex() }) do
|
|
local st = ns.route[i]
|
|
if st and st ~= out[1] then out[#out + 1] = st end
|
|
end
|
|
return out
|
|
end
|
|
|
|
-- Mark undone sub-steps of the active steps that match; true if any changed.
|
|
local function MarkActive(match)
|
|
local hit = false
|
|
for _, step in ipairs(ActiveSteps()) do
|
|
for _, s in ipairs(ns.PlanFor(step) or {}) do
|
|
local marks = ns.char.plan[step.id]
|
|
if not (marks and marks[s._i]) and match(s) then Mark(step, s); hit = true end
|
|
end
|
|
end
|
|
return hit
|
|
end
|
|
|
|
local function FirstHearthTo()
|
|
for _, step in ipairs(ActiveSteps()) do
|
|
for _, s in ipairs(ns.PlanFor(step) or {}) do
|
|
if IsHearthTo(s) and not ns.SubDone(step, s) then Mark(step, s); return true end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- A bind only counts while it lasts, so save it on the steps you are working on;
|
|
-- otherwise moving your hearthstone later would undo them.
|
|
local function SaveBinds()
|
|
if ns.char and ns.char.plan and ns.route then
|
|
MarkActive(function(s) return s.act == "hs" and not IsHearthTo(s) and BoundHere(s) end)
|
|
end
|
|
end
|
|
ns.On("Refresh", SaveBinds)
|
|
|
|
local ev = CreateFrame("Frame")
|
|
for _, e in ipairs({ "TAXIMAP_OPENED", "UI_INFO_MESSAGE", "HEARTHSTONE_BOUND", "UNIT_SPELLCAST_SUCCEEDED" }) do
|
|
pcall(ev.RegisterEvent, ev, e)
|
|
end
|
|
ev:SetScript("OnEvent", function(_, e, a1, a2, a3)
|
|
if not ns.char or not ns.char.plan or not ns.route then return end
|
|
local changed = false
|
|
if e == "TAXIMAP_OPENED" then
|
|
ns.RecordTaxiNodes()
|
|
MarkActive(function(s) return s.act == "fp" and Near(s, 60) end)
|
|
changed = true
|
|
elseif e == "UI_INFO_MESSAGE" then
|
|
if ERR_NEWTAXIPATH and (a1 == ERR_NEWTAXIPATH or a2 == ERR_NEWTAXIPATH) then
|
|
changed = MarkActive(function(s) return s.act == "fp" and Near(s, 100) end) or true
|
|
end
|
|
elseif e == "HEARTHSTONE_BOUND" then
|
|
MarkActive(function(s) return s.act == "hs" and not IsHearthTo(s) and (BoundHere(s) or Near(s, 60)) end)
|
|
changed = true
|
|
elseif e == "UNIT_SPELLCAST_SUCCEEDED" then
|
|
local spell = a3 or a2
|
|
if a1 == "player" and spell == HEARTHSTONE then changed = FirstHearthTo() end
|
|
end
|
|
if changed then ns.Fire("Refresh") end
|
|
end)
|