Shows the pet's unspent training points, the abilities its family can learn with the rank it could train now, which ranks taming has unlocked and where to tame the next one, plus what the hunter trainer offered on the last visit. Reminders fire on level up and when points go unspent. Pet ability ranks (pet level and training point cost) are generated from Petopia by tools/build-abilities.js.
77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
// Builds PokeHuntLog/Data/Abilities.lua from Petopia Classic's pet abilities page.
|
|
// Each ability gets its ranks as { rank, pet level needed, training point cost }.
|
|
// Usage: node tools/build-abilities.js (page is cached in tools/cache)
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const ROOT = path.resolve(__dirname, "..");
|
|
const CACHE = path.join(__dirname, "cache");
|
|
const OUT = path.join(ROOT, "PokeHuntLog", "Data", "Abilities.lua");
|
|
const URL = "https://www.wow-petopia.com/classic/abilities.php";
|
|
|
|
function decode(s) {
|
|
return s
|
|
.replace(/�*39;|'/g, "'")
|
|
.replace(/"/g, '"')
|
|
.replace(/&/g, "&")
|
|
.replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
|
|
.trim();
|
|
}
|
|
|
|
async function getPage() {
|
|
const file = path.join(CACHE, "abilities.html");
|
|
if (fs.existsSync(file)) return fs.readFileSync(file, "utf8");
|
|
const res = await fetch(URL, { headers: { "User-Agent": "Mozilla/5.0 (PokeHuntLog data build)" } });
|
|
if (!res.ok) throw new Error(`${res.status} fetching ${URL}`);
|
|
const html = await res.text();
|
|
fs.mkdirSync(CACHE, { recursive: true });
|
|
fs.writeFileSync(file, html);
|
|
return html;
|
|
}
|
|
|
|
function luaStr(s) {
|
|
return '"' + String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
|
}
|
|
|
|
async function main() {
|
|
const html = await getPage();
|
|
const abilities = {};
|
|
|
|
// <span class='abilityrankname classic'>Bite 1</span>: Pet Level 1, Cost 1 TP.
|
|
const re = /class='abilityrankname[^']*'>([^<]+)<\/span>:\s*Pet Level\s*(\d+),\s*Cost\s*(\d+)\s*TP/g;
|
|
for (const m of html.matchAll(re)) {
|
|
const full = decode(m[1]);
|
|
const parts = full.match(/^(.*?)\s+(\d+)$/);
|
|
if (!parts) continue;
|
|
const name = parts[1];
|
|
const rank = Number(parts[2]);
|
|
if (!abilities[name]) abilities[name] = [];
|
|
abilities[name].push({ rank, level: Number(m[2]), cost: Number(m[3]) });
|
|
}
|
|
|
|
const names = Object.keys(abilities).sort();
|
|
const lines = [];
|
|
lines.push("-- PokeHuntLog pet ability ranks: what pet level each rank needs and what it costs in training points.");
|
|
lines.push("-- Generated by tools/build-abilities.js from Petopia Classic (https://www.wow-petopia.com/classic/).");
|
|
lines.push("-- Do not edit by hand; rerun the script instead.");
|
|
lines.push("-- Each entry: { rank, pet level, training point cost }.");
|
|
lines.push("");
|
|
lines.push("PokeHuntLog_Abilities = {");
|
|
for (const name of names) {
|
|
const ranks = abilities[name].sort((a, b) => a.rank - b.rank);
|
|
const body = ranks.map((r) => `{ ${r.rank}, ${r.level}, ${r.cost} }`).join(", ");
|
|
lines.push(` [${luaStr(name)}] = { ${body} },`);
|
|
}
|
|
lines.push("}");
|
|
lines.push("");
|
|
fs.writeFileSync(OUT, lines.join("\n"));
|
|
console.log(`Wrote ${names.length} abilities -> ${path.relative(ROOT, OUT)}`);
|
|
names.forEach((n) => console.log(` ${n}: ${abilities[n].length} ranks`));
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|