- Quests that really are inside a dungeon are marked; ones that only mention a dungeon (Westfall Stew, cauldron and Scourgestone quests) no longer are. - Group quests are marked from the game's own quest facts and the guides' group steps. - Dungeon quests are now left out on every difficulty; group quests on Casual and Medium. - Escort quests also come from a short checked list.
105 lines
4.4 KiB
JavaScript
105 lines
4.4 KiB
JavaScript
// Builds tools/data/quest-kinds.tsv: for every quest of the classic-db quest_template table, its quest type, the number of
|
|
// players it suggests, its quest flags and its zone (or sort). Only these facts are kept; no text of any quest.
|
|
// Sources:
|
|
// CMaNGOS classic-db (GPL-3.0, github.com/cmangos/classic-db): the quest_template table of the Full_DB dump, read as plain text.
|
|
// The route builder (tools/build-route.js) uses the facts to tell group quests (type 1 or 62, or 2 or more suggested players),
|
|
// dungeon quests (type 81, or a dungeon zone) and escort quests (the party-accept flag) apart. The dump is never run and never
|
|
// copied into this repo: it is data, read with a text parser that looks at the quest_template INSERT lines only.
|
|
// Usage: node --max-old-space-size=4096 tools/build-quest-kinds.js [classicdb.sql]
|
|
// (default: ../_data/classic-db/classicdb.sql next to the repo folder)
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const REPO = path.resolve(__dirname, "..");
|
|
const OUT_FILE = path.join(REPO, "tools", "data", "quest-kinds.tsv");
|
|
const DEFAULT_SQL = path.resolve(REPO, "..", "_data", "classic-db", "classicdb.sql");
|
|
const MIN_ROWS = 4000;
|
|
|
|
function die(msg) {
|
|
console.error(msg);
|
|
process.exit(1);
|
|
}
|
|
|
|
// The column names of the CREATE TABLE of quest_template, in order. Returns null when the table is not in the text.
|
|
function readColumns(sql) {
|
|
const m = /CREATE TABLE `quest_template` \(([\s\S]*?)\) ENGINE/.exec(sql);
|
|
if (!m) return null;
|
|
const cols = [];
|
|
for (const line of m[1].split("\n")) {
|
|
const t = line.trim();
|
|
if (t.charAt(0) === "`") cols.push(t.split("`")[1]);
|
|
}
|
|
return cols;
|
|
}
|
|
|
|
// Every tuple of every INSERT INTO `quest_template` statement, as an array of strings. Nothing is run: the text between the
|
|
// quotes is read character by character (a backslash keeps the next character as it is).
|
|
function readTuples(sql) {
|
|
const tuples = [];
|
|
const marker = "INSERT INTO `quest_template` VALUES ";
|
|
let pos = 0;
|
|
while ((pos = sql.indexOf(marker, pos)) >= 0) {
|
|
pos += marker.length;
|
|
while (sql.charAt(pos) === "(") {
|
|
pos++;
|
|
const vals = [];
|
|
let cur = "", inQuote = false;
|
|
for (;;) {
|
|
if (pos >= sql.length) return tuples;
|
|
const ch = sql.charAt(pos++);
|
|
if (inQuote) {
|
|
if (ch === "\\") { cur += sql.charAt(pos++); continue; }
|
|
if (ch === "'") { inQuote = false; continue; }
|
|
cur += ch;
|
|
continue;
|
|
}
|
|
if (ch === "'") { inQuote = true; continue; }
|
|
if (ch === ",") { vals.push(cur); cur = ""; continue; }
|
|
if (ch === ")") { vals.push(cur); break; }
|
|
cur += ch;
|
|
}
|
|
tuples.push(vals);
|
|
if (sql.charAt(pos) === ",") pos++;
|
|
}
|
|
}
|
|
return tuples;
|
|
}
|
|
|
|
const sqlPath = process.argv[2] || DEFAULT_SQL;
|
|
if (!fs.existsSync(sqlPath)) die("classic-db dump not found: " + sqlPath + " (usage: node --max-old-space-size=4096 tools/build-quest-kinds.js [classicdb.sql])");
|
|
const sql = fs.readFileSync(sqlPath, "utf8");
|
|
const cols = readColumns(sql);
|
|
if (!cols) die("no quest_template table in " + sqlPath);
|
|
const want = ["entry", "Type", "SuggestedPlayers", "QuestFlags", "ZoneOrSort"];
|
|
const at = {};
|
|
for (const w of want) {
|
|
at[w] = cols.indexOf(w);
|
|
if (at[w] < 0) die("quest_template has no column " + w);
|
|
}
|
|
|
|
const rows = new Map();
|
|
for (const t of readTuples(sql)) {
|
|
const n = {};
|
|
for (const w of want) n[w] = parseInt(t[at[w]], 10);
|
|
if (isNaN(n.entry)) continue;
|
|
for (const w of want) if (isNaN(n[w])) n[w] = 0;
|
|
rows.set(n.entry, n);
|
|
}
|
|
if (rows.size < MIN_ROWS) die("only " + rows.size + " quests came out of " + sqlPath + " (need more than " + MIN_ROWS + "); nothing written");
|
|
|
|
const ids = Array.from(rows.keys()).sort((a, b) => a - b);
|
|
const out = [
|
|
"# Generated by tools/build-quest-kinds.js from CMaNGOS classic-db (GPL-3.0, github.com/cmangos/classic-db) quest_template. Only facts are kept. Do not edit by hand.",
|
|
"# id <TAB> type <TAB> suggested players <TAB> quest flags <TAB> zone or sort (above 0: a zone id; below 0: a sort)",
|
|
];
|
|
const typeCount = {};
|
|
for (const id of ids) {
|
|
const r = rows.get(id);
|
|
out.push([id, r.Type, r.SuggestedPlayers, r.QuestFlags, r.ZoneOrSort].join("\t"));
|
|
typeCount[r.Type] = (typeCount[r.Type] || 0) + 1;
|
|
}
|
|
fs.writeFileSync(OUT_FILE, out.join("\n") + "\n");
|
|
console.log("quest-kinds.tsv: " + ids.length + " quests");
|
|
console.log("types: " + Object.keys(typeCount).sort((a, b) => a - b).map((k) => k + "=" + typeCount[k]).join(" "));
|