/er go suggests quests for the area you are in, in stops grouped by giver, with Casual, Medium and Normal moods. It lists chains worth following, suggests a grind spot for a break, and asks where to go when an area is used up. Quest and mob data are generated from pfQuest and pfExtend, with route hints from TourGuideVanilla. Adds /er selftest.
124 lines
4.7 KiB
JavaScript
124 lines
4.7 KiB
JavaScript
// Builds Data/Quests.lua from TourGuideVanilla's route files.
|
|
// Only facts are taken (quest id, title, who gives it and where, the quest it follows, which class or
|
|
// race it is for, and the order the route does them in). The route's own wording is not copied.
|
|
// Usage: node tools/build-quests.js <path to the TourGuideVanilla folder>
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const SRC = process.argv[2];
|
|
if (!SRC || !fs.existsSync(SRC)) {
|
|
console.error("Usage: node tools/build-quests.js <path to the TourGuideVanilla folder>");
|
|
process.exit(1);
|
|
}
|
|
const OUT = path.resolve(__dirname, "..", "Data", "Quests.lua");
|
|
|
|
function luaString(s) {
|
|
return '"' + String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
|
}
|
|
|
|
// "Krang Stonehoof in Bloodhoof Village (49.52, 60.60)" -> { npc, place, x, y }
|
|
function parseNote(note) {
|
|
const out = {};
|
|
if (!note) return out;
|
|
const c = note.match(/\((\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\)/);
|
|
if (c) {
|
|
out.x = parseFloat(c[1]);
|
|
out.y = parseFloat(c[2]);
|
|
}
|
|
const g = note.match(/^(.+?)\s+in\s+(.+?)\s*\(/);
|
|
if (g) {
|
|
out.npc = g[1].trim();
|
|
out.place = g[2].trim();
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function tag(line, name) {
|
|
const m = line.match(new RegExp("\\|" + name + "\\|([^|]*)\\|"));
|
|
return m ? m[1].trim() : null;
|
|
}
|
|
|
|
function parseGuide(text, faction) {
|
|
const head = text.match(/RegisterGuide\(\s*"([^"]+)"\s*,\s*"([^"]*)"\s*,\s*"([^"]+)"/);
|
|
if (!head) return null;
|
|
const name = head[1];
|
|
const next = head[2];
|
|
const lv = name.match(/\((\d+)-(\d+)\)\s*$/);
|
|
const zone = name.replace(/\s*\(\d+-\d+\)\s*$/, "");
|
|
const body = (text.match(/\[\[([\s\S]*?)\]\]/) || [])[1] || "";
|
|
const quests = [];
|
|
const byId = {};
|
|
let order = 0;
|
|
for (const raw of body.split(/\r?\n/)) {
|
|
const line = raw.trim();
|
|
const m = line.match(/^([ACT])\s+([^|]+?)\s*(\|.*)?$/);
|
|
if (!m) continue;
|
|
const action = m[1];
|
|
const title = m[2].trim();
|
|
const qid = parseInt(tag(line, "QID") || "0", 10);
|
|
if (!qid) continue;
|
|
const note = parseNote(tag(line, "N"));
|
|
let q = byId[qid];
|
|
if (!q) {
|
|
q = { id: qid, name: title, order: ++order };
|
|
byId[qid] = q;
|
|
quests.push(q);
|
|
}
|
|
const cls = tag(line, "C");
|
|
const race = tag(line, "R");
|
|
if (cls) q.class = cls;
|
|
if (race) q.race = race;
|
|
if (action === "A") {
|
|
q.giver = q.giver || note.npc;
|
|
q.gplace = q.gplace || note.place;
|
|
if (note.x !== undefined && q.x === undefined) { q.x = note.x; q.y = note.y; }
|
|
const pre = tag(line, "PRE");
|
|
if (pre) q.pre = parseInt(pre, 10);
|
|
const z = tag(line, "Z");
|
|
if (z) q.zone = z;
|
|
} else if (action === "T") {
|
|
q.taker = q.taker || note.npc;
|
|
if (note.x !== undefined && q.tx === undefined) { q.tx = note.x; q.ty = note.y; }
|
|
if (tag(line, "Z") && !q.zone) q.zone = tag(line, "Z");
|
|
}
|
|
}
|
|
return { name, zone, lo: lv ? +lv[1] : 1, hi: lv ? +lv[2] : 60, next, faction, quests };
|
|
}
|
|
|
|
const lua = ["-- Generated by tools/build-quests.js from TourGuideVanilla route files (credits: cralor, Tekkub).",
|
|
"-- Facts only: quest ids, titles, givers, places and chains. Do not edit by hand.",
|
|
"EasyRoute_Quests = {"];
|
|
let total = 0;
|
|
for (const faction of ["Alliance", "Horde"]) {
|
|
const dir = path.join(SRC, "TourGuide_" + faction);
|
|
const files = fs.readdirSync(dir).filter((f) => f.endsWith(".lua")).sort();
|
|
lua.push(" [" + luaString(faction) + "] = {");
|
|
for (const f of files) {
|
|
const g = parseGuide(fs.readFileSync(path.join(dir, f), "utf8"), faction);
|
|
if (!g) { console.warn("skipped (no header): " + f); continue; }
|
|
lua.push(" { name = " + luaString(g.name) + ", zone = " + luaString(g.zone) + ", lo = " + g.lo + ", hi = " + g.hi +
|
|
", next = " + luaString(g.next) + ", quests = {");
|
|
for (const q of g.quests) {
|
|
const parts = ["id = " + q.id, "name = " + luaString(q.name), "order = " + q.order];
|
|
if (q.giver) parts.push("giver = " + luaString(q.giver));
|
|
if (q.gplace) parts.push("place = " + luaString(q.gplace));
|
|
if (q.x !== undefined) parts.push("x = " + q.x, "y = " + q.y);
|
|
if (q.taker) parts.push("taker = " + luaString(q.taker));
|
|
if (q.tx !== undefined) parts.push("tx = " + q.tx, "ty = " + q.ty);
|
|
if (q.pre) parts.push("pre = " + q.pre);
|
|
if (q.zone) parts.push("zone = " + luaString(q.zone));
|
|
if (q.class) parts.push("class = " + luaString(q.class));
|
|
if (q.race) parts.push("race = " + luaString(q.race));
|
|
lua.push(" { " + parts.join(", ") + " },");
|
|
total++;
|
|
}
|
|
lua.push(" } },");
|
|
}
|
|
lua.push(" },");
|
|
}
|
|
lua.push("}", "");
|
|
fs.mkdirSync(path.dirname(OUT), { recursive: true });
|
|
fs.writeFileSync(OUT, lua.join("\n"));
|
|
console.log("Wrote " + OUT + " (" + total + " quest entries)");
|