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
223 lines
10 KiB
Python
223 lines
10 KiB
Python
#!/usr/bin/env python3
|
|
"""Converts Bethink's Guidelime guides (Guidelime_Bethink, GPLv3) into pfQuest xpGuide's guide format.
|
|
|
|
Usage: python3 build_bethink.py <Guidelime_Bethink folder> <output Data/Bethink.lua>
|
|
|
|
Each Guidelime line becomes one step (S line). Tags become elements:
|
|
[QA id] / [QT id] / [QC id(,obj)] A / T / C (the quest's title is filled in by the addon at run time)
|
|
[G x,y Zone] [L x,y Zone] G (the last one is the step's place, earlier ones are points on the way)
|
|
[XP n] X (reach level n)
|
|
[H place] [S place] [P place] [F place] H hearth, B set hearth, P flight path, F fly
|
|
[T] / [V] / [R] V trainer / vendor / vendor (repair)
|
|
[CI item,count] [UI item] K have the item / U use the item
|
|
[O] [OC] completewith=next (an optional step, shown "on the way")
|
|
[A ...] the step's condition: classes and races (Guidelime: one of each kind listed)
|
|
Steps for a primary profession (Mining, Skinning, Herbalism, Blacksmithing, Engineering, Enchanting, ...) are left out:
|
|
the player chooses those. Cooking, Fishing and First Aid stay. The sentence itself stays as the step's words, with each
|
|
quest tag written as {q<id>}, which the addon turns into the quest's title.
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
PRIMARY = {"Mining", "Skinning", "Herbalism", "Blacksmithing", "Engineering", "Enchanting", "Alchemy",
|
|
"Tailoring", "Leatherworking"}
|
|
SECONDARY = {"Cooking", "Fishing", "First Aid", "FirstAid"}
|
|
CLASSES = {"Druid", "Hunter", "Mage", "Paladin", "Priest", "Rogue", "Shaman", "Warlock", "Warrior"}
|
|
RACES = {"Human", "Dwarf", "NightElf", "Gnome", "Orc", "Undead", "Tauren", "Troll", "Skyborne", "HighElf", "Goblin"}
|
|
TAG = re.compile(r"\[([A-Z]+)([^\]]*)\]")
|
|
|
|
|
|
def clean(text):
|
|
return text.replace("\t", " ").replace("\\", "/").replace('"', "'").strip()
|
|
|
|
|
|
def esc(s):
|
|
return s.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n").replace("\t", "\\t")
|
|
|
|
|
|
def condition(arg):
|
|
"""[A Hunter,Dwarf] -> "Dwarf Hunter"; None when the step is for a primary profession (left out)."""
|
|
races, classes = [], []
|
|
for p in [x.strip() for x in arg.split(",") if x.strip()]:
|
|
base = re.split(r"[<>]", p)[0].strip()
|
|
if base in PRIMARY:
|
|
return None
|
|
if base in SECONDARY or p.startswith("IT"):
|
|
continue # secondary professions are for everyone here; item checks are not kept
|
|
if base in CLASSES:
|
|
classes.append(base)
|
|
elif base in RACES:
|
|
races.append(base)
|
|
elif base in ("Alliance", "Horde"):
|
|
races.append(base)
|
|
if races and classes:
|
|
return "/".join(r + " " + c for r in races for c in classes)
|
|
return "/".join(races + classes)
|
|
|
|
|
|
def coords(arg):
|
|
m = re.match(r"\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*[\d.]+)?\s+(.+)$", arg)
|
|
if not m:
|
|
return None
|
|
return clean(m.group(3)), float(m.group(1)), float(m.group(2))
|
|
|
|
|
|
TRIVIAL = re.compile(r"^(?:accept|turn in|then|and|or|,|\.|;|:|\s)*$", re.I)
|
|
|
|
|
|
def convert_line(line):
|
|
"""One Guidelime line -> list of element lines (without the S line) and the step's flags; None to leave it out."""
|
|
need = ""
|
|
flags = []
|
|
places, elems = [], []
|
|
for m in TAG.finditer(line):
|
|
tag, arg = m.group(1), m.group(2).strip()
|
|
if tag == "A":
|
|
c = condition(arg)
|
|
if c is None:
|
|
return None
|
|
need = c
|
|
elif tag in ("O", "OC"):
|
|
if "completewith=next" not in flags:
|
|
flags.append("completewith=next")
|
|
elif tag in ("QA", "QT", "QC"):
|
|
parts = arg.split(",")
|
|
qid = parts[0].strip()
|
|
if not qid.isdigit():
|
|
continue
|
|
if tag == "QA":
|
|
elems.append("A\t\t%s\t" % qid)
|
|
elif tag == "QT":
|
|
elems.append("T\t\t%s\t" % qid)
|
|
else:
|
|
obj = parts[1].strip() if len(parts) > 1 and parts[1].strip().isdigit() else ""
|
|
elems.append("C\t\t%s\t%s\t" % (qid, obj))
|
|
elif tag in ("G", "L"):
|
|
c = coords(arg)
|
|
if c:
|
|
places.append(c)
|
|
elif tag == "XP":
|
|
m2 = re.match(r"(\d+)", arg)
|
|
if m2:
|
|
elems.append("X\t\t\t%s\t\t\t" % m2.group(1))
|
|
elif tag == "H":
|
|
elems.append("H\t\t%s" % clean("Hearth to " + arg if arg else "Hearth"))
|
|
elif tag == "S":
|
|
elems.append("B\t\t%s" % clean("Set your hearthstone to " + arg if arg else "Set your hearthstone"))
|
|
elif tag == "P":
|
|
elems.append("P\t\t%s\t" % clean(arg))
|
|
elif tag == "F":
|
|
elems.append("F\t\t%s\t" % clean(arg))
|
|
elif tag == "T":
|
|
elems.append("V\t\ttrainer\t")
|
|
elif tag in ("V", "R"):
|
|
elems.append("V\t\tvendor\t")
|
|
elif tag == "CI":
|
|
parts = arg.split(",")
|
|
if parts[0].strip().isdigit():
|
|
count = parts[1].strip() if len(parts) > 1 and parts[1].strip().isdigit() else "1"
|
|
elems.append("K\t\t%s\t%s\t\t" % (parts[0].strip(), count))
|
|
elif tag == "UI":
|
|
if arg.isdigit():
|
|
elems.append("U\t\t%s\t" % arg)
|
|
# the words: quest tags become {q<id>}, every other tag goes
|
|
text = re.sub(r"\[Q[ATC](\d+)(?:,\d+)?[^\]]*\]", lambda m: "{q%s}" % m.group(1), line)
|
|
text = TAG.sub("", text)
|
|
text = re.sub(r"\s+", " ", text).strip()
|
|
text = re.sub(r"\s+([,.;:])", r"\1", text)
|
|
words = clean(text)
|
|
out = []
|
|
# places first (the last is where the step happens), then the words, then the things to do
|
|
for i, (zone, x, y) in enumerate(places):
|
|
if i < len(places) - 1:
|
|
out.append("G\t\t%s\t%s\t%s\t20\t0\t" % (zone, x, y))
|
|
else:
|
|
out.append("G\t\t%s\t%s\t%s\t\t\t" % (zone, x, y))
|
|
if words and not TRIVIAL.match(re.sub(r"\{q\d+\}", "", words)):
|
|
out.append("I\t\t%s" % words)
|
|
out.extend(elems)
|
|
if not out:
|
|
return None
|
|
return need, ";".join(flags), out
|
|
|
|
|
|
def convert_guide(text):
|
|
head = {}
|
|
for tag in ("N", "D", "GA", "NX"):
|
|
m = re.search(r"\[%s ([^\]]*)\]" % tag, text)
|
|
head[tag] = m.group(1).strip() if m else ""
|
|
body = []
|
|
steps = 0
|
|
for raw in text.split("\n"):
|
|
line = raw.strip()
|
|
if not line or re.match(r"^\[(N|D|GA|NX) ", line):
|
|
continue
|
|
c = convert_line(line)
|
|
if not c:
|
|
continue
|
|
need, flags, elems = c
|
|
body.append("S\t%s\t\t%s" % (need, flags))
|
|
body.extend(elems)
|
|
steps += 1
|
|
m = re.match(r"(\d+)-(\d+) (.+?)(?: \((Alliance|Horde)\))?$", head["N"])
|
|
lo, hi, zone = int(m.group(1)), int(m.group(2)), m.group(3)
|
|
ga = [x.strip() for x in head["GA"].split(",")]
|
|
faction = "Alliance" if "Alliance" in ga else "Horde"
|
|
races = [r for r in ga if r in RACES]
|
|
# names are unique per faction (both have a "39-42 Stranglethorn Vale"); the title is what the menu shows
|
|
nxt = head["NX"] if head["NX"] else ""
|
|
if nxt and not re.search(r"\((Alliance|Horde)\)$", nxt):
|
|
nxt = nxt + " (" + ("Alliance" if "Alliance" in head["GA"] else "Horde") + ")"
|
|
title = "%d-%d %s" % (lo, hi, zone)
|
|
band = "1-20" if lo < 20 else ("20-40" if lo < 40 else "40-60")
|
|
# a guide for a race the game does not have here (Skyborne) is only offered to that race
|
|
cond = faction
|
|
if "Skyborne" in races:
|
|
cond = faction + " Skyborne"
|
|
name = "%s (%s)" % (title, faction)
|
|
return {
|
|
"name": name, "title": title, "group": "Bethink's Guide " + band, "faction": faction, "lo": lo, "hi": hi,
|
|
"next": nxt, "defaultFor": "/".join(r for r in races if r != "Skyborne"), "cond": cond,
|
|
"about": head["D"], "steps": "\n".join(body), "count": steps,
|
|
}
|
|
|
|
|
|
def main():
|
|
src, out = sys.argv[1], sys.argv[2]
|
|
toc = open(os.path.join(src, "Guidelime_Bethink_Camelot.toc"), encoding="utf-8").read()
|
|
version = re.search(r"## Version: (\S+)", toc).group(1)
|
|
files = [l.strip().replace("\\", "/") for l in toc.splitlines() if l.strip().startswith("guides")]
|
|
guides = []
|
|
for f in files:
|
|
text = open(os.path.join(src, f), encoding="utf-8").read()
|
|
m = re.search(r"registerGuide\(\[\[(.*)\]\]", text, re.S)
|
|
guides.append(convert_guide(m.group(1)))
|
|
lines = [
|
|
"-- Generated by build_bethink.py from Bethink's Guidelime guides (Guidelime_Bethink %s). Do not edit by hand." % version,
|
|
"-- The guides are Bethink's: Copyright (c) 2026 Bethink, licensed under the GNU General Public License version 3",
|
|
"-- (LICENSE-Bethink.txt next to this addon). Changed from the original: converted from Guidelime's format into",
|
|
"-- pfQuest xpGuide's guide format (one step per line of the original, its words kept); steps for primary professions",
|
|
"-- left out. The original guides are at the Guidelime_Bethink pack; build_bethink.py (in the test harness) converts them.",
|
|
"-- They join pfQuest_xpGuide_Guides as the \"Bethink's Guide\" groups.",
|
|
"pfQuest_xpGuide_Guides = pfQuest_xpGuide_Guides or {}",
|
|
"pfQuest_xpGuide_Bethink = { version = \"%s\", guides = %d }" % (version, len(guides)),
|
|
"for _, g in ipairs({",
|
|
]
|
|
for g in guides:
|
|
lines.append(' { name = "%s", title = "%s", group = "%s", faction = "%s", lo = %d, hi = %d, next = "%s", defaultFor = "%s", cond = "%s", bethink = true,'
|
|
% (esc(g["name"]), esc(g["title"]), esc(g["group"]), g["faction"], g["lo"], g["hi"], esc(g["next"]),
|
|
esc(g["defaultFor"]), esc(g["cond"])))
|
|
lines.append(' about = "%s",' % esc(g["about"]))
|
|
lines.append(' steps = "%s" },' % esc(g["steps"]))
|
|
lines.append("}) do table.insert(pfQuest_xpGuide_Guides, g) end")
|
|
open(out, "w", encoding="utf-8").write("\n".join(lines) + "\n")
|
|
total = sum(g["count"] for g in guides)
|
|
print("%d guides, %d steps -> %s" % (len(guides), total, out))
|
|
for g in guides[:3]:
|
|
print(" ", g["group"], "|", g["name"], g["faction"], g["lo"], g["hi"], "next:", g["next"], "for:", g["defaultFor"], "cond:", g["cond"], g["count"], "steps")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|