A leveling guide for WoW 1.12 players of pfQuest, based on Easy Route by stealthzi (MIT). See README.md and CHANGES.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfR1apt9f3R7SxBKB2FF2D
243 lines
13 KiB
Lua
243 lines
13 KiB
Lua
-- texlua play.lua <addon> <race> <class> <level> <mode> [maxIter]
|
|
-- Plays the running guide like a player would: accepts, completes, hands in, travels, levels.
|
|
local here = arg[0]:match("^(.*)/") or "."
|
|
W_TITLE = ""
|
|
if os.getenv("SA") then
|
|
-- the lightblade pfQuest on a plain 1.12 client (no world coordinates): its arrow sees nodes on the current zone's map,
|
|
-- through pfQuest.route.coords. Then the real pfQuest SmartArrow is loaded before Easy Route, from $SA.
|
|
local SA = os.getenv("SA")
|
|
local ZID, ZNAME = {}, {}
|
|
local zf = io.open(SA .. "/data/zones.lua"):read("a")
|
|
for id, name in string.gmatch(zf, "%[(%d+)%] = {[^}]*}, %-%- ([^\n]+)") do
|
|
name = string.gsub(name, "%s+$", ""); name = string.gsub(name, " %(.*%)$", "")
|
|
ZID[name] = tonumber(id); ZNAME[tonumber(id)] = name
|
|
end
|
|
ZID["Stormwind City"] = ZID["Stormwind City"] or ZID["Stormwind"]
|
|
SA_ZID = ZID
|
|
pfQuest_config = { arrow = "1", trackingmethod = 1 }
|
|
pfDB = { units = { data = {}, loc = {} }, objects = { data = {}, loc = {} }, items = { data = {}, loc = {} },
|
|
quests = { data = {}, loc = setmetatable({}, { __index = function(t, id) local tt = pfQuest_xpGuide and pfQuest_xpGuide.Steps and pfQuest_xpGuide.Steps.QuestTitle(id) if tt then return { T = tt, O = "Kill $N things." } end end }) },
|
|
meta = { flight = {} }, zones = { data = {}, loc = {} } }
|
|
pfDatabase = { GetQuestIDs = function(self, i) local q = W and W.log[i] if q and q.id then return { q.id } end return {} end }
|
|
pfQuestCompat = { GetPlayerFacing = function() return 1.5 end }
|
|
pfMap = { nodes = {}, queue_update = 0 }
|
|
function pfMap:GetMapIDByName(z) return ZID[z] end
|
|
function pfMap:GetMapNameByID(id) return ZNAME[id] end
|
|
function pfMap:GetMapID(cont, zi) return W and ZID[W.zone] end
|
|
function pfMap:AddNode(m)
|
|
if not m or not m.zone or not m.title then return end
|
|
local a, map, coords = m.addon or "PFDB", m.zone, m.x .. "|" .. m.y
|
|
self.nodes[a] = self.nodes[a] or {}; self.nodes[a][map] = self.nodes[a][map] or {}; self.nodes[a][map][coords] = self.nodes[a][map][coords] or {}
|
|
local copy = {} for k, v in pairs(m) do copy[k] = v end
|
|
self.nodes[a][map][coords][m.title] = copy
|
|
end
|
|
function pfMap:DeleteNode(a) if a then self.nodes[a] = nil else self.nodes = {} end end
|
|
function pfMap:GetNodes(a, title)
|
|
local out = {}
|
|
for map, cl in pairs(self.nodes[a] or {}) do for c, node in pairs(cl) do if node[title] then table.insert(out, node[title]) end end end
|
|
return out
|
|
end
|
|
function pfMap:UpdateNodes()
|
|
local list = pfQuest.route.coords
|
|
for i = #list, 1, -1 do list[i] = nil end
|
|
local here = ZID[W.zone]
|
|
for a, maps in pairs(self.nodes) do for map, cl in pairs(maps) do if map == here then for c, node in pairs(cl) do
|
|
for _, tab in pairs(node) do tab.layer = 1; tab.zone = map
|
|
if tab.arrow == true or a == "PFQUEST" then table.insert(list, { tab.x, tab.y, tab, 0 }) end end
|
|
end end end end
|
|
for i = 2, #list do if pfQuest.route.IsTarget(list[i][3]) then table.insert(list, 1, table.remove(list, i)) break end end
|
|
end
|
|
local tT, tC, tL, tX
|
|
pfQuest = { route = { coords = {} } }
|
|
pfQuest.route.SetTarget = function(node) tT, tC, tL, tX = node and node.title, node and node.cluster, node and node.layer, node and node.texture end
|
|
pfQuest.route.IsTarget = function(n) if n and tT and tT == n.title and tC == n.cluster and tL == n.layer and tX == n.texture then return true end end
|
|
function PF_TARGET() return tT end
|
|
function PRE_ADDONS()
|
|
local a = CreateFrame("Frame", "pfQuestRouteArrow", UIParent)
|
|
a.model = CreateFrame("Model", nil, a); a.texture = a:CreateTexture(); a.title = a:CreateFontString(); a.description = a:CreateFontString()
|
|
a.distance = a:CreateFontString(); a._shown = true
|
|
pfQuest.route.arrow = a
|
|
local toc = io.open(SA .. "/pfQuest-SmartArrow.toc"):read("a")
|
|
for line in L53.gmatch(toc, "[^\r\n]+") do
|
|
if not L53.match(line, "^##") and L53.match(line, "%S") then
|
|
local path = SA .. "/" .. L53.gsub(L53.gsub(line, "\\", "/"), "%s+$", "")
|
|
local chunk, err = loadfile(path)
|
|
if not chunk then error("load " .. path .. ": " .. err) end
|
|
local ok, e = L53.xpcall(chunk, debug.traceback)
|
|
if not ok then table.insert(W.errors, "[load SmartArrow " .. line .. "] " .. tostring(e)) end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
if os.getenv("PFUI") then
|
|
-- pfUI (brues-code fork) as far as Easy Route's theme touches it
|
|
pfUI_config = { appearance = { border = { background = "0.1,0.1,0.12,0.9", color = "0.3,0.3,0.35,1", force_blizz = "0" } },
|
|
global = { font_size = 12 }, disabled = {} }
|
|
pfUI = { font_default = "Interface\\AddOns\\pfUI\\fonts\\Myriad-Pro.ttf", api = {}, calls = { backdrop = 0, check = 0, scroll = 0, strip = 0 } }
|
|
function pfUI.api.CreateBackdrop(f, inset, legacy, transp)
|
|
pfUI.calls.backdrop = pfUI.calls.backdrop + 1
|
|
if not f.backdrop then
|
|
if f:GetBackdrop() then f:SetBackdrop(nil) end
|
|
local b = CreateFrame("Frame", nil, f); f.backdrop = b
|
|
local level = f:GetFrameLevel(); b:SetFrameLevel(level < 1 and level or level - 1)
|
|
end
|
|
f.backdrop:SetBackdrop({ pf = true })
|
|
f.backdrop:SetBackdropColor(.1, .1, .12, transp or .9)
|
|
f.backdrop:SetBackdropBorderColor(.3, .3, .35, 1)
|
|
end
|
|
function pfUI.api.SkinCheckbox(f) pfUI.calls.check = pfUI.calls.check + 1 f:SetNormalTexture("") pfUI.api.CreateBackdrop(f) end
|
|
function pfUI.api.StripTextures(f) pfUI.calls.strip = pfUI.calls.strip + 1 for _, r in ipairs({ f:GetRegions() }) do if r.SetTexture then r:SetTexture(nil) end end end
|
|
function pfUI.api.SkinScrollbar(f) pfUI.calls.scroll = pfUI.calls.scroll + 1 end
|
|
end
|
|
if os.getenv("PFQ") == "brues" then
|
|
-- the brues-code fork: world-space arrow, nodes with arrow = true, SetTarget/IsTarget as in route.lua
|
|
pfQuest_config = { arrow = "1" }
|
|
pfDatabase = { GetQuestIDs = function(self, i) local q = W and W.log[i] if q and q.id then return { q.id } end return {} end }
|
|
pfMap = { nodes = {}, queue_update = 0, updates = 0 }
|
|
function pfMap:GetMapIDByName(z) return "map:" .. z end
|
|
function pfMap:AddNode(m)
|
|
if not m or not m.zone or not m.title then return end
|
|
if m.description == nil then error("AddNode would call pfDatabase:BuildQuestDescription") end
|
|
local a, map, coords = m.addon or "PFDB", m.zone, m.x .. "|" .. m.y
|
|
self.nodes[a] = self.nodes[a] or {}; self.nodes[a][map] = self.nodes[a][map] or {}; self.nodes[a][map][coords] = self.nodes[a][map][coords] or {}
|
|
local copy = {} for k, v in pairs(m) do copy[k] = v end
|
|
self.nodes[a][map][coords][m.title] = copy
|
|
end
|
|
function pfMap:DeleteNode(a) if a then self.nodes[a] = nil else self.nodes = {} end end
|
|
function pfMap:GetNodes(a, title)
|
|
local out = {}
|
|
for map, cl in pairs(self.nodes[a] or {}) do for c, node in pairs(cl) do if node[title] then table.insert(out, node[title]) end end end
|
|
return out
|
|
end
|
|
function pfMap:UpdateNodes()
|
|
self.updates = self.updates + 1
|
|
local list = pfQuest.route.worldcoords
|
|
for i = #list, 1, -1 do list[i] = nil end
|
|
for a, maps in pairs(self.nodes) do for map, cl in pairs(maps) do for c, node in pairs(cl) do
|
|
for _, tab in pairs(node) do tab.layer = 1; if tab.arrow == true or a == "PFQUEST" then table.insert(list, { 0, 0, tab, 0, nil, nil, 1 }) end end
|
|
end end end
|
|
-- explicit target first, as UpdateWorldTarget does
|
|
for i = 2, #list do if pfQuest.route.IsTarget(list[i][3]) then table.insert(list, 1, table.remove(list, i)) break end end
|
|
end
|
|
local tT, tC, tL, tX
|
|
pfQuest = { route = { worldcoords = {} } }
|
|
pfQuest.route.SetTarget = function(node) if node then pfMap.queue_update = GetTime() end
|
|
tT, tC, tL, tX = node and node.title, node and node.cluster, node and node.layer, node and node.texture end
|
|
pfQuest.route.IsTarget = function(n) if n and tT and tT == n.title and tC == n.cluster and tL == n.layer and tX == n.texture then return true end end
|
|
pfQuest.route.arrow = { shown = false, Show = function(s) s.shown = true end, Hide = function(s) s.shown = false end, IsShown = function(s) return s.shown end }
|
|
function PF_TARGET() return tT end
|
|
elseif os.getenv("PFQ") then
|
|
pfDatabase = { GetQuestIDs = function(self, i) local q = W and W.log[i] if q and q.id then return { q.id } end return {} end }
|
|
pfQuest = {}
|
|
pfMap = { nodes = {}, AddNode = function(self, n) self.nodes[n.addon] = n end, DeleteNode = function(self, a) self.nodes[a] = nil end,
|
|
GetMapIDByName = function(self, z) return 1 end, UpdateNodes = function() end, queue_update = false }
|
|
pfQuestCompat = { GetPlayerFacing = function() return 1.5 end }
|
|
pfDB = { quests = { loc = setmetatable({}, { __index = function(t, id) local tt = pfQuest_xpGuide and pfQuest_xpGuide.Steps and pfQuest_xpGuide.Steps.QuestTitle(id) if tt then return { T = tt, O = "Kill $N things." } end end }),
|
|
data = {} }, zones = { data = {}, loc = {} }, units = { data = {}, loc = {} }, objects = { data = {}, loc = {} }, items = { data = {}, loc = {} } }
|
|
end
|
|
local W = dofile(here .. "/wow.lua")
|
|
GetTitleText = function() return W_TITLE end
|
|
local ER = W.ER
|
|
local S = ER.Steps
|
|
local out = {}
|
|
local function P(s) table.insert(out, s) if os.getenv("ECHO") then print(s) end end
|
|
local function try(label, fn, ...)
|
|
local ok, err = L53.xpcall(fn, debug.traceback, ...)
|
|
if not ok then table.insert(W.errors, "[" .. label .. "] " .. tostring(err)) end
|
|
return ok, err
|
|
end
|
|
local function settle(n) W.Fire("QUEST_LOG_UPDATE"); W.Tick(0.4, n or 4) end
|
|
|
|
local function inLog(title) for i, q in ipairs(W.log) do if q.title == title then return i, q end end end
|
|
turnins = 0
|
|
local function accept(id)
|
|
local title = S.QuestTitle(id)
|
|
if not title or inLog(title) or #W.log >= 20 then return end
|
|
table.insert(W.log, { id = tonumber(id), title = title, level = S.QuestLevel(id) or W.level, objs = { { text = "thing: 0/1", done = false } } })
|
|
settle()
|
|
end
|
|
local function complete(id)
|
|
local _, q = inLog(S.QuestTitle(id) or "?")
|
|
if q then q.complete = true; q.objs[1].done = true; q.objs[1].text = "thing: 1/1"; settle() end
|
|
end
|
|
local function turnin(id)
|
|
local title = S.QuestTitle(id)
|
|
local i = inLog(title or "?")
|
|
if not i then return end
|
|
W_TITLE = title
|
|
GetQuestReward(0)
|
|
table.remove(W.log, i)
|
|
turnins = turnins + 1
|
|
settle()
|
|
end
|
|
|
|
|
|
function PLAY(MAXIT, stopWhen)
|
|
local lastKey, same, iter = nil, 0, 0
|
|
local startLevelByVisit = {}
|
|
while iter < MAXIT and not (stopWhen and stopWhen()) do
|
|
iter = iter + 1
|
|
local info = S.Info()
|
|
if not info then P("no guide running at iter " .. iter); break end
|
|
if not visits[info.name] then visits[info.name] = true; table.insert(visits, info.name .. "@" .. W.level) end
|
|
local step = S.Current()
|
|
if not step then
|
|
-- finished: AutoNextGuide should have moved on
|
|
try("AutoNextGuide", function() if ER.AutoNextGuide then ER.AutoNextGuide() end end)
|
|
settle()
|
|
if not S.Current() then P("route finished at level " .. W.level .. " in " .. info.name); break end
|
|
step = S.Current()
|
|
end
|
|
local key = info.name .. "#" .. S.Position()
|
|
if key == lastKey then same = same + 1 else same = 0 end
|
|
lastKey = key
|
|
-- exercise the display code
|
|
try("Title", function() S.Title(step) end)
|
|
try("Target", function() S.Target() end)
|
|
try("Lines", function() for _, e in ipairs(step.elements or {}) do S.Line(step, e) end end)
|
|
try("Warnings", function() S.Warnings() end)
|
|
try("QuestList", function() S.QuestList(10) end)
|
|
if ER.RouteNextLine then try("RouteNextLine", function() ER.RouteNextLine() end) end
|
|
if ER.NeedLevelLine then try("NeedLevelLine", function() ER.NeedLevelLine(step) end) end
|
|
-- travel to the target
|
|
local t = S.Target()
|
|
if t and t.zone then W.zone = t.zone; W.x = (t.x or 50) / 100; W.y = (t.y or 50) / 100; W.Fire("ZONE_CHANGED_NEW_AREA") end
|
|
-- do what the step says
|
|
for _, e in ipairs(step.elements or {}) do
|
|
local k = e.kind
|
|
if k == "A" and e.id then accept(e.id)
|
|
elseif k == "C" and e.id then complete(e.id)
|
|
elseif k == "K" and e.id then complete(e.id)
|
|
elseif k == "T" and e.id then turnin(e.id)
|
|
elseif k == "Z" and e.zone then W.zone = e.zone; W.Fire("ZONE_CHANGED_NEW_AREA")
|
|
elseif k == "X" and e.level then if tonumber(e.level) and tonumber(e.level) > W.level then W.level = math.min(60, math.floor(tonumber(e.level))); W.Fire("PLAYER_LEVEL_UP", W.level) end
|
|
elseif k == "F" then W.Fire("TAXIMAP_OPENED")
|
|
elseif k == "P" then W.Fire("TAXIMAP_OPENED")
|
|
elseif k == "H" then W.Fire("SPELLCAST_START", "Hearthstone"); W.Fire("SPELLCAST_STOP")
|
|
elseif k == "V" then W.Fire("MERCHANT_CLOSED"); W.Fire("TRAINER_CLOSED")
|
|
end
|
|
end
|
|
-- level from hand-ins: roughly the visit's pace
|
|
local want = math.min(60, 1 + math.floor(turnins / 4))
|
|
if info.lo and want < info.lo then want = math.floor(info.lo) end
|
|
if want > W.level then W.level = want; W.Fire("PLAYER_LEVEL_UP", W.level) end
|
|
settle(3)
|
|
if same >= 3 then try("Next (stuck)", function() S.Next() end); settle(2) end
|
|
end
|
|
|
|
return iter
|
|
end
|
|
visits = {}
|
|
H = { W = W, ER = ER, S = S, P = P, try = try, settle = settle, out = out, accept = accept, complete = complete, turnin = turnin }
|
|
function REPORT()
|
|
P("visits: " .. table.concat(visits, ", "))
|
|
P("hand-ins " .. turnins .. ", level " .. W.level)
|
|
local seen, n = {}, 0
|
|
for _, e in ipairs(W.errors) do
|
|
local key = L53.match((L53.gsub(e, "^%[[^%]]*%] ", "")), "^[^\n]*")
|
|
if not seen[key] then seen[key] = true; n = n + 1; P("ERROR " .. e:sub(1, 1800)) end
|
|
end
|
|
P("errors: " .. #W.errors .. " (" .. n .. " unique)")
|
|
print(table.concat(out, "\n"))
|
|
end
|