diff --git a/CoffeyGuide.toc b/CoffeyGuide.toc index 7798993..4cd8c01 100644 --- a/CoffeyGuide.toc +++ b/CoffeyGuide.toc @@ -1,7 +1,7 @@ ## Interface: 16001 ## Title: Coffey's Leveling Guide ## Notes: Leveling guide for WoW Forever: route for every race/class, talents, spec guides, gear & pre-raid BiS, professions, gold and extras. /cguide -## Version: 3.0.0 +## Version: 3.0.1 ## Author: Coffey Labs LLC ## X-Website: https://coffeylabs.org ## X-Copyright: Copyright (c) 2026 Coffey Labs LLC diff --git a/Plans.lua b/Plans.lua index 1bd20f8..b3539f2 100644 --- a/Plans.lua +++ b/Plans.lua @@ -66,22 +66,31 @@ 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 - local out = {} + 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 end + 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 @@ -176,3 +185,187 @@ ns.On("Login", function() 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 +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.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) diff --git a/tools/harness.lua b/tools/harness.lua index 39c08aa..deca7b7 100644 --- a/tools/harness.lua +++ b/tools/harness.lua @@ -266,6 +266,27 @@ if tstep and ns.PlanFor(tstep) and #ns.PlanFor(tstep) >= 4 then local plan = ns.PlanFor(tstep); ns.MarkSub(tstep, plan[4], true); show("go marked") print("tirisfal step state:", ns.StepState(tstep)) end +-- Flight path, hearthstone and travel sub-steps tick off by themselves. +local sp; for _, st in ipairs(ns.route) do if st.id == "h_silverpine" then sp = st end end +if sp and ns.PlanFor(sp) then + local plan = ns.PlanFor(sp) + local fp, hs = plan[1], plan[2] + ns.SetView(nil); for i, st in ipairs(ns.route) do if st == sp then ns.SetView(i) end end + print("silverpine fp/hs before:", ns.SubDone(sp, fp), ns.SubDone(sp, hs)) + function GetBindLocation() return "The Sepulcher" end + fire("HEARTHSTONE_BOUND") + local nodes = { { "Undercity, Tirisfal", "REACHABLE" }, { "The Sepulcher, Silverpine Forest", "CURRENT" } } + function NumTaxiNodes() return #nodes end + function TaxiNodeName(i) return nodes[i][1] end + function TaxiNodeGetType(i) return nodes[i][2] end + fire("TAXIMAP_OPENED") + print("silverpine fp/hs after:", ns.SubDone(sp, fp), ns.SubDone(sp, hs)) + function GetBindLocation() return "Tarren Mill" end + print("silverpine hs after rebinding elsewhere:", ns.SubDone(sp, hs)) + local tl = ns.PlanFor(tstep) + print("tirisfal last go (next step started):", ns.SubDone(tstep, tl[#tl])) + ns.SetView(nil) +end SlashCmdList.COFFEYGUIDE("quests") ns.ShowLink(ns.WEBSITE); print("website:", ns.WEBSITE) print("HARNESS_OK")