BlueGit

timfa questward

Files

questward / scripts / content-manifest.mjs

content-manifest.mjs

content-manifest.mjs 16.2 KiB Download Raw
1/**
2 * Generate docs/content-manifest.generated.md from shared definitions.
3 * Output is gitignored — run: npm run content-manifest
4 */
5import { mkdirSync, writeFileSync } from "node:fs";
6import { dirname, join } from "node:path";
7import { fileURLToPath } from "node:url";
8
9import
10{
11 MATERIAL_TIER_ORDER,
12 WOOD_TIER_ORDER,
13 CLOTH_TIER_ORDER,
14 LEATHER_TIER_ORDER,
15 GEM_TIER_ORDER,
16 ORE_BEARING_MATERIALS,
17 GatherMaterialId,
18 MaterialTier,
19 ClothTier,
20 LeatherTier,
21 MATERIAL_DISPLAY_NAME,
22 CLOTH_DISPLAY_NAME,
23 LEATHER_DISPLAY_NAME,
24 tierMinSkillLevel,
25 tierMineSkillLevel,
26 associatedBarTier,
27 isGemstoneMaterial,
28 metalTierForCloth,
29 metalTierForHerbTier
30} from "../shared/definitions/materialTiers.js";
31import
32{
33 toolTierMeetsResource,
34 toolTierMeetsGemstone
35} from "../shared/definitions/gathering.js";
36import { HERB_DEFINITIONS, HERB_ORDER, herbGatherSkillLevel } from "../shared/definitions/herbs.js";
37import { CRAFT_RECIPES } from "../shared/crafting/stationRecipes.js";
38import { ALCHEMY_POTION_DEFINITIONS } from "../shared/definitions/alchemy.js";
39import { formatAlchemyStep, alchemyItemLabel } from "../shared/alchemy/recipes.js";
40import { MOB_DEFINITIONS, defaultSpawnerConfig } from "../shared/definitions/mobs.js";
41import { ITEM_DEFINITIONS, itemDefinition } from "../shared/definitions/items.js";
42import { ARMOUR_CRAFT_PIECES } from "../shared/definitions/armourItems.js";
43import { LEATHER_ARMOUR_PIECES } from "../shared/definitions/leatherArmourItems.js";
44import { WIZARD_PIECES } from "../shared/definitions/wizardItems.js";
45import { fishingRodItemIdForWood } from "../shared/definitions/fishItems.js";
46import { leatherMaterialItemId } from "../shared/definitions/leatherItems.js";
47import { SkillId } from "../shared/definitions/skills.js";
48
49const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
50const OUT = join(ROOT, "docs/content-manifest.generated.md");
51
52const EQUIP_LEVELS = MATERIAL_TIER_ORDER.map((tier) => tierMinSkillLevel(tier));
53
54function esc (text)
55{
56 return String(text ?? "").replace(/\|/g, "\\|").replace(/\n/g, " ");
57}
58
59function mdTable (headers, rows)
60{
61 const head = `| ${headers.map(esc).join(" | ")} |`;
62 const sep = `| ${headers.map(() => "---").join(" | ")} |`;
63 const body = rows.map((row) => `| ${row.map(esc).join(" | ")} |`).join("\n");
64 return `${head}\n${sep}\n${body}`;
65}
66
67function materialLabel (materialId)
68{
69 const name = MATERIAL_DISPLAY_NAME[materialId] ?? materialId;
70 if (materialId === GatherMaterialId.coal)
71 { return "Coal"; }
72 if (materialId === GatherMaterialId.salt)
73 { return "Rock salt"; }
74 if (isGemstoneMaterial(materialId))
75 { return name; }
76 return `${name} ore`;
77}
78
79/** Lowest metal tool tier that can gather this resource (ores / wood). */
80function minMetalToolTier (resourceTier, { gem = false } = {})
81{
82 const gate = associatedBarTier(resourceTier);
83 for (const metal of MATERIAL_TIER_ORDER)
84 {
85 const ok = gem
86 ? toolTierMeetsGemstone(metal, gate)
87 : toolTierMeetsResource(metal, gate);
88 if (ok)
89 { return metal; }
90 }
91 return MaterialTier.bronze;
92}
93
94function toolLabel (metalTier, kind)
95{
96 const name = MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier;
97 return `${name} ${kind}`;
98}
99
100function clothGatherRows ()
101{
102 const rows = [];
103 for (const cloth of CLOTH_TIER_ORDER)
104 {
105 const name = CLOTH_DISPLAY_NAME[cloth] ?? cloth;
106 const metal = metalTierForCloth(cloth);
107 if (cloth === ClothTier.cotton)
108 {
109 rows.push([name, "1 (Herbalism)", "None (pick cotton plant)", "Plant node"]);
110 continue;
111 }
112 if (cloth === ClothTier.linen)
113 {
114 rows.push([
115 name,
116 String(tierMinSkillLevel(metal)),
117 `${toolLabel(metal, "plant clippers")} or better`,
118 "Flax plant (clippers)"
119 ]);
120 continue;
121 }
122 if (cloth === ClothTier.silk)
123 {
124 rows.push([
125 name,
126 String(tierMinSkillLevel(metal)),
127 `${toolLabel(metal, "plant clippers")} or better`,
128 "Silk cocoon (clippers)"
129 ]);
130 continue;
131 }
132 if (cloth === ClothTier.wool)
133 {
134 rows.push([
135 name,
136 String(tierMinSkillLevel(metal)),
137 `${toolLabel(metal, "shears")} or better`,
138 "Shear sheep"
139 ]);
140 continue;
141 }
142 if (cloth === ClothTier.cashmere)
143 {
144 rows.push([
145 name,
146 String(tierMinSkillLevel(metal)),
147 `${toolLabel(metal, "shears")} or better`,
148 "Shear goat"
149 ]);
150 continue;
151 }
152 if (cloth === ClothTier.fairySilk)
153 {
154 rows.push([name, "—", "—", "Fairy death drop (~70%)"]);
155 continue;
156 }
157 if (cloth === ClothTier.dragonweave)
158 {
159 rows.push([name, "—", "—", "No gather path yet"]);
160 continue;
161 }
162 rows.push([name, "—", "—", "Unknown"]);
163 }
164 return rows;
165}
166
167function leatherSourceRows ()
168{
169 const materialIds = new Set(
170 LEATHER_TIER_ORDER.map((tier) => leatherMaterialItemId(tier)).filter((id) => id != null)
171 );
172 const craftByOutputId = new Map();
173 for (const recipe of CRAFT_RECIPES)
174 {
175 const outId = recipe.output?.itemId;
176 if (outId == null || !materialIds.has(outId))
177 { continue; }
178 const inputs = (recipe.inputs ?? []).map((row) =>
179 {
180 const name = itemDefinition(row.itemId)?.displayName ?? String(row.itemId);
181 return `${row.quantity}× ${name}`;
182 }).join(" + ");
183 let extra = "";
184 if (recipe.consumePotionKey)
185 {
186 const potion = ALCHEMY_POTION_DEFINITIONS[recipe.consumePotionKey];
187 extra = ` + 1 fill of ${potion?.displayName ?? recipe.consumePotionKey}`;
188 }
189 const skill = recipe.skillId
190 ? `${recipe.skillId} ${recipe.minSkillLevel ?? "?"}`
191 : "";
192 craftByOutputId.set(outId, `Craft: ${inputs}${extra}${skill ? ` (${skill})` : ""}`);
193 }
194
195 const dropSources = softLeatherDropSources();
196 return LEATHER_TIER_ORDER.map((tier) =>
197 {
198 const name = LEATHER_DISPLAY_NAME[tier] ?? tier;
199 if (tier === LeatherTier.softLeather)
200 {
201 return [name, dropSources || "Mob drops", "—"];
202 }
203 const craft = craftByOutputId.get(leatherMaterialItemId(tier));
204 if (craft)
205 { return [name, craft, "—"]; }
206 return [name, "No craft/drop path in definitions yet", "—"];
207 });
208}
209
210function softLeatherDropSources ()
211{
212 const parts = [];
213 for (const mob of Object.values(MOB_DEFINITIONS))
214 {
215 for (const drop of mob.drops ?? [])
216 {
217 const def = itemDefinition(drop.itemId);
218 if (def?.tier === LeatherTier.softLeather || def?.key === "leather" || def?.key === "soft-leather")
219 {
220 const pct = Math.round((drop.chance ?? 0) * 100);
221 parts.push(`${mob.displayName} (${pct}%)`);
222 }
223 }
224 }
225 return parts.length ? `Drop: ${parts.join(", ")}` : "";
226}
227
228function formatDrop (drop)
229{
230 const name = itemDefinition(drop.itemId)?.displayName ?? `item#${drop.itemId}`;
231 const pct = Math.round((drop.chance ?? 0) * 100);
232 let qty = "";
233 if (drop.quantityMin != null && drop.quantityMax != null)
234 { qty = `${drop.quantityMin}-${drop.quantityMax} `; }
235 else if (drop.quantity != null && drop.quantity !== 1)
236 { qty = `${drop.quantity} `; }
237 return `${pct}% ${qty}${name}`;
238}
239
240function potionRecipeCell (potion)
241{
242 const ingredients = (potion.ingredients ?? []).map((row) =>
243 {
244 if (row.potionKey)
245 { return `${row.quantity}× ${ALCHEMY_POTION_DEFINITIONS[row.potionKey]?.displayName ?? row.potionKey}`; }
246 return `${row.quantity}× ${alchemyItemLabel({ key: row.key, itemId: row.itemId })}`;
247 }).join(", ");
248 const steps = (potion.steps ?? []).map((step) => formatAlchemyStep(step)).join(" → ");
249 return `Ingredients: ${ingredients}. Steps: ${steps}`;
250}
251
252function equipLevelHeaders ()
253{
254 return ["Kind", ...EQUIP_LEVELS.map((level) => `Lv ${level}`)];
255}
256
257function metalTierCells (labelForTier)
258{
259 return MATERIAL_TIER_ORDER.map((tier) => labelForTier(tier));
260}
261
262function woodTierCells (labelForTier)
263{
264 return WOOD_TIER_ORDER.map((tier) => labelForTier(tier));
265}
266
267function clothTierCells (labelForTier)
268{
269 return CLOTH_TIER_ORDER.map((tier) => labelForTier(tier));
270}
271
272function leatherTierCells (labelForTier)
273{
274 return LEATHER_TIER_ORDER.map((tier) => labelForTier(tier));
275}
276
277function buildMarkdown ()
278{
279 const lines = [];
280 const generatedAt = new Date().toISOString();
281 lines.push("# Content manifest");
282 lines.push("");
283 lines.push(`_Generated ${generatedAt} by \`scripts/content-manifest.mjs\`. Do not edit by hand._`);
284 lines.push("");
285 lines.push("Skill gates follow shared rules: gather ≈ ceil(equip/2); tool may be **one metal tier below** the resource (gemstones require **equal or better** pickaxe).");
286 lines.push("");
287
288 // --- Ores ---
289 lines.push("## Ores");
290 lines.push("");
291 {
292 const rows = [];
293 for (const material of ORE_BEARING_MATERIALS)
294 {
295 if (material === GatherMaterialId.bronze || material === GatherMaterialId.steel)
296 { continue; }
297 if (isGemstoneMaterial(material))
298 { continue; }
299 const gate = associatedBarTier(material);
300 const mineLv = tierMineSkillLevel(material);
301 const gem = false;
302 const minTool = minMetalToolTier(gate, { gem });
303 rows.push([
304 materialLabel(material),
305 String(mineLv),
306 `${toolLabel(minTool, "pickaxe")} or better`,
307 `Gate tier: ${MATERIAL_DISPLAY_NAME[gate] ?? gate}`
308 ]);
309 }
310 lines.push(mdTable(["Ore", "Mining level", "Min pickaxe", "Notes"], rows));
311 }
312 lines.push("");
313
314 // --- Wood ---
315 lines.push("## Wood");
316 lines.push("");
317 {
318 const rows = WOOD_TIER_ORDER.map((wood) =>
319 {
320 const name = MATERIAL_DISPLAY_NAME[wood] ?? wood;
321 const chopLv = tierMineSkillLevel(wood);
322 const minTool = minMetalToolTier(wood, { gem: false });
323 return [
324 name,
325 String(chopLv),
326 `${toolLabel(minTool, "axe")} or better`
327 ];
328 });
329 lines.push(mdTable(["Wood", "Woodcutting level", "Min axe"], rows));
330 }
331 lines.push("");
332
333 // --- Cloth / wool fibre ---
334 lines.push("## Cloth fibre (wool & plants)");
335 lines.push("");
336 lines.push("Shears / clippers must be equippable (Herbalism = tier equip gate). Plants without clippers have no skill gate.");
337 lines.push("");
338 lines.push(mdTable(
339 ["Fibre", "Level", "Tool", "How"],
340 clothGatherRows()
341 ));
342 lines.push("");
343
344 // --- Herbs ---
345 lines.push("## Herbs");
346 lines.push("");
347 {
348 const rows = HERB_ORDER.map((herbId) =>
349 {
350 const herb = HERB_DEFINITIONS[herbId];
351 const metal = metalTierForHerbTier(herb.tier);
352 return [
353 herb.displayName,
354 String(herb.tier),
355 String(herbGatherSkillLevel(herb.tier)),
356 `${toolLabel(metal, "plant clippers")} or better`
357 ];
358 });
359 lines.push(mdTable(["Herb", "Herb tier", "Herbalism level", "Tool"], rows));
360 }
361 lines.push("");
362
363 // --- Gemstones ---
364 lines.push("## Gemstones");
365 lines.push("");
366 {
367 const rows = GEM_TIER_ORDER.map((gem) =>
368 {
369 const name = MATERIAL_DISPLAY_NAME[gem] ?? gem;
370 const mineLv = tierMineSkillLevel(gem);
371 const minTool = minMetalToolTier(gem, { gem: true });
372 return [
373 name,
374 String(mineLv),
375 `${toolLabel(minTool, "pickaxe")} or better (equal tier+)`
376 ];
377 });
378 lines.push(mdTable(["Gemstone", "Mining level", "Min pickaxe"], rows));
379 }
380 lines.push("");
381
382 // --- Leather ---
383 lines.push("## Leather");
384 lines.push("");
385 lines.push(mdTable(
386 ["Leather", "How obtained", "Tool"],
387 leatherSourceRows()
388 ));
389 lines.push("");
390
391 // --- Tool equip table ---
392 lines.push("## Tool equip levels");
393 lines.push("");
394 lines.push(`Columns are equip skill levels (${SkillId.woodcutting} / ${SkillId.mining} / ${SkillId.herbalism} / ${SkillId.fishing} as appropriate).`);
395 lines.push("");
396 {
397 const rows = [
398 ["Axe", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
399 ["Pickaxe", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
400 ["Plant clippers", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
401 ["Shears", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
402 [
403 "Fishing rod",
404 ...woodTierCells((w) => (fishingRodItemIdForWood(w)
405 ? MATERIAL_DISPLAY_NAME[w]
406 : "—"))
407 ]
408 ];
409 lines.push(mdTable(equipLevelHeaders(), rows));
410 }
411 lines.push("");
412
413 // --- Metal armour ---
414 lines.push("## Metal armour equip levels");
415 lines.push("");
416 lines.push("Defence skill. Full helms require equip level **+1** vs other pieces of the same tier.");
417 lines.push("");
418 {
419 const rows = ARMOUR_CRAFT_PIECES.map((piece) =>
420 {
421 const cells = MATERIAL_TIER_ORDER.map((tier) =>
422 {
423 const base = tierMinSkillLevel(tier);
424 const level = piece.fullHelm ? base + 1 : base;
425 return `${MATERIAL_DISPLAY_NAME[tier]} (Lv ${level})`;
426 });
427 return [piece.label, ...cells];
428 });
429 lines.push(mdTable(equipLevelHeaders(), rows));
430 }
431 lines.push("");
432
433 // --- Leather armour ---
434 lines.push("## Leather armour equip levels");
435 lines.push("");
436 lines.push("Defence skill.");
437 lines.push("");
438 {
439 const rows = LEATHER_ARMOUR_PIECES.map((piece) =>
440 [piece.label, ...leatherTierCells((t) => LEATHER_DISPLAY_NAME[t])]
441 );
442 lines.push(mdTable(
443 ["Kind", ...LEATHER_TIER_ORDER.map((t) => `Lv ${tierMinSkillLevel(t)}`)],
444 rows
445 ));
446 }
447 lines.push("");
448
449 // --- Cloth armour ---
450 lines.push("## Cloth armour equip levels");
451 lines.push("");
452 lines.push("Defence skill. Pieces: shirt, shorts, trousers, skirt, sweater.");
453 lines.push("");
454 {
455 const pieces = ["shirt", "shorts", "trousers", "skirt", "sweater"];
456 const rows = pieces.map((piece) =>
457 [piece, ...clothTierCells((t) => CLOTH_DISPLAY_NAME[t])]
458 );
459 lines.push(mdTable(
460 ["Kind", ...CLOTH_TIER_ORDER.map((t) => `Lv ${tierMinSkillLevel(t)}`)],
461 rows
462 ));
463 }
464 lines.push("");
465
466 // --- Wizard ---
467 lines.push("## Wizard armour equip levels");
468 lines.push("");
469 lines.push("Magic skill. Cloth-tier gated.");
470 lines.push("");
471 {
472 const rows = WIZARD_PIECES.map((piece) =>
473 [piece.label, ...clothTierCells((t) => CLOTH_DISPLAY_NAME[t])]
474 );
475 lines.push(mdTable(
476 ["Kind", ...CLOTH_TIER_ORDER.map((t) => `Lv ${tierMinSkillLevel(t)}`)],
477 rows
478 ));
479 }
480 lines.push("");
481
482 // --- Melee ---
483 lines.push("## Melee weapons equip levels");
484 lines.push("");
485 {
486 const rows = [
487 ["Sword (swordfighting)", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
488 ["War axe (axefighting)", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
489 ["Quarterstaff (clubfighting)", ...woodTierCells((t) => MATERIAL_DISPLAY_NAME[t])]
490 ];
491 lines.push(mdTable(equipLevelHeaders(), rows));
492 }
493 lines.push("");
494
495 // --- Ranged ---
496 lines.push("## Ranged weapons equip levels");
497 lines.push("");
498 lines.push("Archery skill. Bows are wood-tier; arrows are metal-tier.");
499 lines.push("");
500 {
501 const rows = [
502 ["Bow", ...woodTierCells((t) => MATERIAL_DISPLAY_NAME[t])],
503 ["Arrow", ...metalTierCells((t) => MATERIAL_DISPLAY_NAME[t])]
504 ];
505 lines.push(mdTable(equipLevelHeaders(), rows));
506 }
507 lines.push("");
508
509 // --- Magic ---
510 lines.push("## Magic weapons equip levels");
511 lines.push("");
512 lines.push("Magic skill. Staves are wood-tier (with matching gem).");
513 lines.push("");
514 {
515 const rows = [
516 ["Staff", ...woodTierCells((t) => MATERIAL_DISPLAY_NAME[t])]
517 ];
518 lines.push(mdTable(equipLevelHeaders(), rows));
519 }
520 lines.push("");
521
522 // --- Potions ---
523 lines.push("## Potions");
524 lines.push("");
525 {
526 const potions = Object.values(ALCHEMY_POTION_DEFINITIONS)
527 .slice()
528 .sort((a, b) => (a.minAlchemyLevel | 0) - (b.minAlchemyLevel | 0)
529 || String(a.displayName).localeCompare(String(b.displayName)));
530 const rows = potions.map((p) => [
531 p.displayName,
532 String(p.minAlchemyLevel | 0 || 1),
533 potionRecipeCell(p),
534 p.description ?? ""
535 ]);
536 lines.push(mdTable(["Potion", "Alchemy level", "Recipe", "Description"], rows));
537 }
538 lines.push("");
539
540 // --- Mobs ---
541 lines.push("## Mobs");
542 lines.push("");
543 {
544 const rows = Object.values(MOB_DEFINITIONS).map((mob) =>
545 {
546 const level = defaultSpawnerConfig(`manifest-${mob.mobTypeId}`, mob.mobTypeId).level;
547 const drops = (mob.drops ?? []).map(formatDrop).join(", ") || "—";
548 return [
549 mob.displayName || mob.mobTypeId,
550 mob.mobTypeId,
551 String(level),
552 mob.aggressive ? "yes" : "no",
553 drops
554 ];
555 });
556 lines.push(mdTable(
557 ["Name", "Id", "Default level", "Aggressive", "Drops"],
558 rows
559 ));
560 }
561 lines.push("");
562
563 // --- All items ---
564 lines.push("## All items");
565 lines.push("");
566 {
567 const rows = Object.values(ITEM_DEFINITIONS)
568 .filter((def) => def?.itemId != null)
569 .slice()
570 .sort((a, b) => String(a.displayName ?? "").localeCompare(String(b.displayName ?? ""))
571 || ((a.itemId | 0) - (b.itemId | 0)))
572 .map((def) => [
573 def.displayName ?? String(def.itemId),
574 String(def.itemId),
575 def.key ?? "—",
576 def.description ?? "—"
577 ]);
578 lines.push(mdTable(["Name", "Id", "Key", "Description"], rows));
579 }
580 lines.push("");
581
582 return `${lines.join("\n")}\n`;
583}
584
585mkdirSync(dirname(OUT), { recursive: true });
586const markdown = buildMarkdown();
587writeFileSync(OUT, markdown, "utf8");
588console.log(`Wrote ${OUT} (${markdown.length} bytes)`);