rpg-engine 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/commands/change/recipe.d.ts +2 -0
  2. package/dist/commands/change/recipe.js +4 -2
  3. package/dist/commands/reveal.d.ts +2 -0
  4. package/dist/commands/reveal.js +22 -3
  5. package/dist/commands/scene/close.js +3 -1
  6. package/dist/commands/scene/open.js +1 -1
  7. package/dist/commands/scene/scene.js +3 -2
  8. package/dist/commands/shared/packages/updates.d.ts +6 -0
  9. package/dist/commands/shared/packages/updates.js +114 -0
  10. package/dist/commands/shared/scene/scene.js +4 -0
  11. package/dist/commands/shared/time/recipes.d.ts +5 -0
  12. package/dist/commands/shared/time/recipes.js +19 -1
  13. package/dist/commands/status.d.ts +1 -0
  14. package/dist/commands/status.js +5 -0
  15. package/dist/commands/travel/travel.js +1 -0
  16. package/dist/commands/view/layers.d.ts +4 -2
  17. package/dist/commands/view/layers.js +15 -6
  18. package/dist/commands/view/place.d.ts +6 -0
  19. package/dist/commands/view/place.js +37 -13
  20. package/dist/commands/view/result.d.ts +2 -0
  21. package/dist/commands/view/view.d.ts +1 -0
  22. package/dist/commands/view/view.js +35 -12
  23. package/dist/core/context.d.ts +5 -0
  24. package/dist/core/length.d.ts +4 -1
  25. package/dist/core/length.js +13 -2
  26. package/dist/dashboard/app.js +1 -1
  27. package/dist/dashboard/dice/tray.js +7 -5
  28. package/dist/dashboard/parts/labels.js +26 -4
  29. package/dist/dashboard/parts/widgets.js +1 -1
  30. package/dist/dashboard/play/rolls.js +3 -3
  31. package/dist/dashboard/settings/setup.js +30 -13
  32. package/dist/dashboard/shell/table.js +7 -3
  33. package/dist/packages/npm.js +32 -7
  34. package/dist/pages/index.d.ts +2 -2
  35. package/dist/pages/index.js +2 -2
  36. package/dist/pages/load.d.ts +2 -0
  37. package/dist/pages/load.js +16 -3
  38. package/dist/scene/scene.d.ts +4 -1
  39. package/instructions/combat.md +2 -2
  40. package/instructions/core.md +2 -2
  41. package/instructions/play.md +3 -3
  42. package/package.json +1 -1
@@ -14,6 +14,8 @@ export interface RecipeOutcome {
14
14
  /** The dice the recipe lets the page spend that would give something, as hit-dice-d8 2/3, which the player chooses for the player character (ASK-14). */
15
15
  spendable: string[];
16
16
  notBroughtBack: string[];
17
+ /** The counters below their maximum of the items the page carries, as Wand charges 3/7, whose text says what comes back and when. */
18
+ carried: string[];
17
19
  kept: string[];
18
20
  /** The effects without an end still on the page, which a rest may ask something of (EFF-15). */
19
21
  resting: string;
@@ -11,7 +11,7 @@ import { restingEffectsNote } from "../shared/scene/reminders.js";
11
11
  import { keptRolls } from "../shared/sheet/counters.js";
12
12
  import { effectiveFields } from "../shared/sheet/effect-layer.js";
13
13
  import { spendableDice, spendDice } from "../shared/time/dice-pool.js";
14
- import { effectsAtRecipe, notBroughtBack, partyPages, recipeChoices, recipeNamed, recipeTargets } from "../shared/time/recipes.js";
14
+ import { carriedCounters, effectsAtRecipe, notBroughtBack, partyPages, recipeChoices, recipeNamed, recipeTargets } from "../shared/time/recipes.js";
15
15
  import { newDatedLogEntry } from "../shared/time/time.js";
16
16
  import { counterStep } from "./amounts.js";
17
17
  import { applyStep, holderNamed, pageHolder, stepNotes } from "./holder.js";
@@ -93,6 +93,7 @@ function recipeOn(root, context, world, system, recipe, name, why) {
93
93
  choices: recipeChoices(current, recipe, pageCalled(current, name)),
94
94
  spendable: barred ? [] : spendableDice(current, recipe, pageCalled(current, name)),
95
95
  notBroughtBack: notBroughtBack(current, system, recipe, pageCalled(current, name)),
96
+ carried: carriedCounters(current, pageCalled(current, name)),
96
97
  kept: keptRolls(current, pageCalled(current, name)).map(([field, values]) => `${field} ${values.join(", ")}`),
97
98
  barred,
98
99
  resting: [atZero ? `At 0 ${recipe.needs ?? ""} when it began, ${name} gains nothing from it.` : tooSoon ?? "", restingEffectsNote(pageCalled(current, name))].filter((note) => note !== "").join(" "),
@@ -136,13 +137,14 @@ export function recipeText(result) {
136
137
  const lines = result.outcomes.flatMap((outcome) => {
137
138
  const done = [...outcome.ended.map((effect) => `${effect} ended`), ...outcome.steps.map(stepText)];
138
139
  const left = outcome.notBroughtBack.length === 0 ? "" : ` Not brought back: ${outcome.notBroughtBack.join(", ")}.`;
140
+ const carried = outcome.carried.length === 0 ? "" : ` ${outcome.page} carries ${outcome.carried.join(", ")}: ${outcome.carried.length === 1 ? "its page says" : "their pages say"} what comes back and when; give it with change.`;
139
141
  // The player chooses and rolls for the player character, the master for a companion (D-206, D-213).
140
142
  const chosen = [...outcome.choices.map((choice) => ` ${outcome.pc ? "Ask the player" : `Choose for ${outcome.page}`}: ${choice}.`), spendText(outcome, result)].join("");
141
143
  // Rolls kept for later: if this rest brings them back, they are rolled again (KEP-4).
142
144
  const roller = outcome.pc ? "the player rolls" : "roll";
143
145
  const kept = outcome.kept.length === 0 ? "" : ` ${outcome.page} keeps ${outcome.kept.join("; ")}: if this rest brings them back, ${roller} them again, with roll and keep.`;
144
146
  const resting = outcome.resting === "" ? "" : ` ${outcome.resting}`;
145
- return [`${outcome.page}: ${done.length === 0 ? "nothing changed" : done.join("; ")}.${chosen}${left}${kept}${resting}`, ...outcome.steps.flatMap(stepNotes).filter((note) => !note.includes("\n"))];
147
+ return [`${outcome.page}: ${done.length === 0 ? "nothing changed" : done.join("; ")}.${chosen}${left}${carried}${kept}${resting}`, ...outcome.steps.flatMap(stepNotes).filter((note) => !note.includes("\n"))];
146
148
  });
147
149
  const rules = result.rules.length === 0 ? "" : `For the rest, read ${result.rules.map((rule) => `rules "${rule}"`).join(" and ")}.`;
148
150
  const title = `${result.recipe.charAt(0).toUpperCase()}${result.recipe.slice(1)} (a recipe of the system ${result.system}):`;
@@ -13,6 +13,8 @@ interface RevealResult {
13
13
  what: string;
14
14
  page: string;
15
15
  }[];
16
+ /** Those the open scene gave by what the character sees of them, now by name (D-568). */
17
+ named?: string[];
16
18
  unplaced?: {
17
19
  places: string[];
18
20
  from?: string;
@@ -8,12 +8,13 @@ import { campaignWorld } from "./shared/campaign/world.js";
8
8
  import { knownLink, knownLinks } from "./shared/characters/knowledge.js";
9
9
  import { textList, textsOf } from "./shared/inputs.js";
10
10
  import { placedPosition } from "./shared/places/positions.js";
11
- import { copyName, readOpenScene } from "./shared/scene/scene.js";
11
+ import { copyName, readOpenScene, updateScene } from "./shared/scene/scene.js";
12
12
  import { newDatedLogEntry } from "./shared/time/time.js";
13
13
  export const reveal = defineCommand({
14
14
  name: "reveal",
15
15
  description: "Record what characters learn: a secret, as Page#Secret, or a whole page they did not know. "
16
16
  + "It adds the links to their knows and answers without the text: read a secret with show before you tell it. "
17
+ + "A whole page the player's character learns that the open scene gives by seen goes by its name again, known before or not. "
17
18
  + "Example: page [Coppa#Veleno, Varro], to [Ettore, Bruna].",
18
19
  group: "game",
19
20
  positionals: ["page"],
@@ -62,17 +63,35 @@ export const reveal = defineCommand({
62
63
  result.learned.push({ who: learner.name, what: learned.map((item) => (item.asked === undefined ? item.shown : `${item.shown} (as ${item.asked} shows it)`)) });
63
64
  }
64
65
  logLearned(root, context, world, lines);
66
+ const named = learners.some(isPlayerCharacter) ? namedInScene(root, context, scene, known.map((item) => item.link)) : [];
65
67
  const unplaced = unplacedPlaces(world, lines);
66
- return unplaced === undefined ? result : { ...result, unplaced };
68
+ return { ...result, ...(named.length === 0 ? {} : { named }), ...(unplaced === undefined ? {} : { unplaced }) };
67
69
  },
68
70
  format(result) {
69
71
  const learned = result.learned.map((entry) => `${entry.who} now knows ${entry.what.join(", ")}.`);
70
72
  const known = result.known.length === 0 ? "" : `Already known: ${result.known.map((entry) => `${entry.who}: ${entry.what.join(", ")}`).join("; ")}.`;
71
73
  const notSecret = result.notSecret.length === 0 ? "" : `Not secrets, nothing to record: ${result.notSecret.map((entry) => `${entry.what} (whoever knows ${entry.page} knows it)`).join(", ")}.`;
72
74
  const unplaced = result.unplaced === undefined ? "" : placesNote(result.unplaced.places, result.unplaced.from);
73
- return [...(learned.length === 0 ? ["Nothing new to record."] : learned), known, notSecret, unplaced].filter((line) => line !== "").join(" ");
75
+ const named = result.named === undefined ? "" : `The open scene now gives ${result.named.join(", ")} by name: the player sees it, no longer what the character saw.`;
76
+ return [...(learned.length === 0 && named === "" ? ["Nothing new to record."] : learned), known, notSecret, named, unplaced].filter((line) => line !== "").join(" ");
74
77
  },
75
78
  });
79
+ /**
80
+ * Takes out of the open scene's seen the pages the player's character learns whole (D-568): from now the player sees their name; a hidden line of the log
81
+ * says so. The names taken out.
82
+ */
83
+ function namedInScene(root, context, scene, learned) {
84
+ const pages = learned.flatMap((link) => links(link)).filter((link) => link.section === undefined).map((link) => comparableText(link.page));
85
+ const seen = Object.entries(scene?.seen ?? {});
86
+ const named = seen.filter(([name]) => pages.includes(comparableText(name))).map(([name]) => name);
87
+ if (scene === undefined || named.length === 0) {
88
+ return [];
89
+ }
90
+ const kept = seen.filter(([name]) => !named.includes(name));
91
+ updateScene(root, [[["seen"], kept.length === 0 ? undefined : Object.fromEntries(kept)]]);
92
+ appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: scene.title, named }));
93
+ return named;
94
+ }
76
95
  /**
77
96
  * One line in the log for each who learned something (REV-3, D-158): public only for what the player's character knows, theirs and a companion's who learned it
78
97
  * with them; what someone else learned alone stays hidden, since a secret's name may tell too much.
@@ -125,8 +125,10 @@ function rewardLines(world, system, scene) {
125
125
  const calls = party.map((page) => (held(page) ? `change ${page.name}, field ${reward.field}, by ${share}` : `write ${page.name}, set ${reward.field}=${share}`)).join("; ");
126
126
  const kinds = [...new Set(unknown.map((item) => item.kind))];
127
127
  const characters = overcome.filter((item) => item.character).map((item) => item.name);
128
+ // The share is said to the player at once, where a master who divides it right may forget it.
129
+ const tell = `Then tell the player what each got: ${share} ${reward.field}${party.length === 1 ? "" : " each"}.`;
128
130
  const parts = [
129
- total === 0 ? `${reward.field}:` : `${reward.field} of those overcome: ${overcome.map((item) => `${item.name} ${item.worth}`).join(", ")}, ${total} in all; ${to}: ${calls}.`,
131
+ total === 0 ? `${reward.field}:` : `${reward.field} of those overcome: ${overcome.map((item) => `${item.name} ${item.worth}`).join(", ")}, ${total} in all; ${to}: ${calls}. ${tell}`,
130
132
  characters.length === 0 ? "" : `${characters.join(", ")} ${characters.length === 1 ? "is a character" : "are characters"}: leave out any who fought on your side, and share again.`,
131
133
  fled.length === 0 ? "" : `Fled: ${fled.map((item) => `${item.name} ${item.worth}`).join(", ")}, to count if the party overcame them.`,
132
134
  unknown.length === 0
@@ -161,7 +161,7 @@ function copyCreatures(world, copies) {
161
161
  return [...new Set(Object.values(copies).flatMap((copy) => findPage(world, parsePageReference(copy.creature).name) ?? []))];
162
162
  }
163
163
  /**
164
- * What the character sees of those it does not know by name (D-416), by the name of a character in the scene or of a creature with copies in it: Bandito=brigante
164
+ * What the character sees of someone, known by name or not (D-416, D-568), by the name of a character in the scene or of a creature with copies in it: Bandito=brigante
165
165
  * incappucciato on the command line, {"Varro": "il mugnaio"} through MCP; none when not given.
166
166
  */
167
167
  function seenOf(world, seen, characters, copies) {
@@ -36,7 +36,8 @@ export const scene = defineCommand({
36
36
  + "At open, whoever of the party is elsewhere moves to the scene's place, except in a travel scene. "
37
37
  + "order sets who takes turns, after rolling for it if the game does; next passes the turn; use marks what one uses of a turn: the engine counts the uses the game declares and refuses one too many. "
38
38
  + "now is the line the player's dashboard shows: give it at open too, and change it as the scene turns. "
39
- + "hostile marks who attacks the party, calm takes the mark off; seen gives what the character sees of those it does not know by name; the player's dashboard shows both. "
39
+ + "hostile marks who attacks the party, calm takes the mark off; seen gives what the character sees of someone, which the player sees instead of the name, "
40
+ + "even one they know, until the scene closes or reveal names them; the player's dashboard shows both. "
40
41
  + "close ends the scene with a summary the player may read. Change a copy's counters with change, as for a page. "
41
42
  + 'Example: action open, title "Scontro all\'ossario", type combat, creatures {"Annegato": 2}.',
42
43
  group: "game",
@@ -54,7 +55,7 @@ export const scene = defineCommand({
54
55
  order: textList.optional().describe("order: who takes turns, in order; those left out (fallen, fled) take none"),
55
56
  now: z.string().optional().describe('open, now: what is happening now, in one line as the player sees it, such as "The bandits overturn the tables"; never what they cannot see'),
56
57
  summary: z.string().optional().describe("close: what happened, in one or two sentences, as the player saw it"),
57
- seen: z.union([textList, z.record(z.string(), z.string())]).optional().describe("open, add: what the character sees of one it does not know by name, by its page or creature, in two or three words, never its kind when that is a secret: "
58
+ seen: z.union([textList, z.record(z.string(), z.string())]).optional().describe("open, add: what the character sees of someone in the scene, by its page or creature, in two or three words, never its kind when that is a secret; the player sees it instead of the name: "
58
59
  + 'Bandito=brigante incappucciato, or through MCP an object such as {"Varro": "il mugnaio"}'),
59
60
  }),
60
61
  run(given, context) {
@@ -0,0 +1,6 @@
1
+ import { type Context } from "../../../core/context.ts";
2
+ /**
3
+ * "Newer on npm: 5e 0.14.1 (here 0.11.2)…": the campaign's game system and extensions installed from npm that npm has a newer version of, one this engine reads,
4
+ * with the command that updates each; undefined when there is none, without npm, or offline, which is never an error.
5
+ */
6
+ export declare function packageUpdates(root: string, context: Context): Promise<string | undefined>;
@@ -0,0 +1,114 @@
1
+ // Newer versions of the campaign's packages on npm (D-569): asked at most once a day and with a short wait, told to the master, never installed by themselves
2
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { readTextSetting } from "../../../campaign/index.js";
5
+ import { engineSystemsFolder } from "../../../core/context.js";
6
+ import { installedFromFolder } from "../../../core/files.js";
7
+ import { files, isInside } from "../../../core/store.js";
8
+ import { comparableText } from "../../../core/text.js";
9
+ import { isNewerVersion } from "../../../core/version.js";
10
+ import { findExtension, shortName } from "../../../extensions/index.js";
11
+ import { verifiedScope } from "../../../packages/index.js";
12
+ import { systemFolders } from "../../../systems/index.js";
13
+ import { listedExtensions } from "./extensions.js";
14
+ // What npm said, kept in the player's folder on this computer for a day, so that a session starts without asking it again.
15
+ const fileName = "package-updates.json";
16
+ const checkHolds = 24 * 60 * 60 * 1000;
17
+ /**
18
+ * "Newer on npm: 5e 0.14.1 (here 0.11.2)…": the campaign's game system and extensions installed from npm that npm has a newer version of, one this engine reads,
19
+ * with the command that updates each; undefined when there is none, without npm, or offline, which is never an error.
20
+ */
21
+ export async function packageUpdates(root, context) {
22
+ const newest = context.packages?.newest;
23
+ const packages = campaignPackages(root, context);
24
+ if (newest === undefined || packages.length === 0) {
25
+ return undefined;
26
+ }
27
+ const known = await newestVersions(context, packages.map((one) => one.name), newest);
28
+ const newer = packages.flatMap((one) => {
29
+ const version = known[one.name];
30
+ return version !== undefined && isNewerVersion(version, one.version) ? [{ ...one, newer: version }] : [];
31
+ });
32
+ if (newer.length === 0) {
33
+ return undefined;
34
+ }
35
+ const listed = newer.map((one) => `${one.install} ${one.newer} (here ${one.version})`).join(", ");
36
+ const commands = newer.map((one) => `package install ${one.install}`).join(", ");
37
+ return `Newer on npm: ${listed}. Tell the player; update only if they want it, with ${commands}.`;
38
+ }
39
+ /** The newest versions of these packages npm has, by name: those kept from today, else asked now and kept; none for one npm did not answer. */
40
+ async function newestVersions(context, names, newest) {
41
+ const now = context.now().getTime();
42
+ const kept = keptCheck(context.home);
43
+ if (kept !== undefined && now - kept.checked >= 0 && now - kept.checked < checkHolds && names.every((name) => name in kept.newest)) {
44
+ return Object.fromEntries(Object.entries(kept.newest).filter((entry) => entry[1] !== null));
45
+ }
46
+ const asked = await Promise.all(names.map(async (name) => [name, (await newest(name)) ?? null]));
47
+ keepCheck(context.home, now, Object.fromEntries(asked));
48
+ return Object.fromEntries(asked.filter((entry) => entry[1] !== null));
49
+ }
50
+ /** The game system the campaign plays and the extensions it lists, those installed from npm alone: a folder's copy, or a system the engine ships, has no newer version there. */
51
+ function campaignPackages(root, context) {
52
+ const plays = readTextSetting(root, "system");
53
+ const system = plays === undefined ? undefined : systemFolders(context.systemFolders).find((one) => comparableText(one.name) === comparableText(plays));
54
+ const manifest = system === undefined || isInside(engineSystemsFolder, system.folder) || installedFromFolder(system.folder) ? undefined : packageOf(system.folder);
55
+ const systemPackage = manifest === undefined || system === undefined ? [] : [{ ...manifest, install: installName(manifest.name, system.name) }];
56
+ const extensions = Object.keys(listedExtensions(root)).flatMap((name) => {
57
+ try {
58
+ const extension = findExtension(context.extensionFolders ?? [], name);
59
+ return extension === undefined || extension.linked ? [] : [{ name: extension.package, version: extension.version, install: installName(extension.package) }];
60
+ }
61
+ catch {
62
+ return [];
63
+ }
64
+ });
65
+ return [...systemPackage, ...extensions];
66
+ }
67
+ /** The name package install takes for a package: one of ours by its short name, the 5e for @rpgengine/system-5e; another's by its npm name, npm: before one without a scope. */
68
+ function installName(name, system) {
69
+ if (name.startsWith(verifiedScope)) {
70
+ return system !== undefined && name === `${verifiedScope}system-${system}` ? system : shortName(name);
71
+ }
72
+ return name.startsWith("@") ? name : `npm:${name}`;
73
+ }
74
+ /** The name and the version a package.json in this folder gives; undefined when it has none that reads. */
75
+ function packageOf(folder) {
76
+ try {
77
+ const read = JSON.parse(files().text(join(folder, "package.json")) ?? "");
78
+ return typeof read.name === "string" && typeof read.version === "string" ? { name: read.name, version: read.version } : undefined;
79
+ }
80
+ catch {
81
+ return undefined;
82
+ }
83
+ }
84
+ /** The last check, as kept in the player's folder: when, and the newest version of each package, null where npm did not answer; none when it does not read. */
85
+ function keptCheck(home) {
86
+ if (home === undefined) {
87
+ return undefined;
88
+ }
89
+ try {
90
+ const read = JSON.parse(readFileSync(join(home, fileName), "utf8"));
91
+ const checked = typeof read.checked === "string" ? Date.parse(read.checked) : Number.NaN;
92
+ const newest = read.newest !== null && typeof read.newest === "object" ? read.newest : undefined;
93
+ if (Number.isNaN(checked) || newest === undefined) {
94
+ return undefined;
95
+ }
96
+ return { checked, newest: Object.fromEntries(Object.entries(newest).map(([name, version]) => [name, typeof version === "string" ? version : null])) };
97
+ }
98
+ catch {
99
+ return undefined;
100
+ }
101
+ }
102
+ /** Keeps a check in the player's folder; a folder that cannot be written only means npm is asked again next time. */
103
+ function keepCheck(home, now, newest) {
104
+ if (home === undefined) {
105
+ return;
106
+ }
107
+ try {
108
+ mkdirSync(home, { recursive: true });
109
+ writeFileSync(join(home, fileName), `${JSON.stringify({ checked: new Date(now).toISOString(), newest }, null, 2)}\n`);
110
+ }
111
+ catch {
112
+ // Nothing to keep is no reason to stop the session.
113
+ }
114
+ }
@@ -305,6 +305,10 @@ function sceneChangeLine(data) {
305
305
  if (Array.isArray(data.left)) {
306
306
  return `left: ${data.left.map((name) => withNumbers(String(name))).join(", ")}`;
307
307
  }
308
+ // Who reveal gave back their name, no longer seen (D-568).
309
+ if (Array.isArray(data.named)) {
310
+ return `named: ${namesText(data.named)}`;
311
+ }
308
312
  const seen = data.seen !== null && typeof data.seen === "object" ? Object.entries(data.seen).map(([name, said]) => `${name} as ${String(said)}`) : [];
309
313
  const joined = Array.isArray(data.added) && data.added.length > 0 ? [`joined: ${namesText(data.added)}`] : [];
310
314
  if (joined.length > 0 || seen.length > 0) {
@@ -32,3 +32,8 @@ export declare function recipeChoices(world: World, recipe: Recipe, page: Page):
32
32
  * when they are not, such as exhaustion; each with the rule of a threshold it is at, or of one without a value, as in "exhaustion 1/6 (rules "Exhaustion")".
33
33
  */
34
34
  export declare function notBroughtBack(world: World, system: GameSystem, recipe: Recipe, page: Page): string[];
35
+ /**
36
+ * The counters below their maximum of the items a page carries, also inside others, as in "Wand charges 3/7": what comes back to them, and when, only
37
+ * their text says, which a rest never applies by itself.
38
+ */
39
+ export declare function carriedCounters(world: World, page: Page): string[];
@@ -1,7 +1,7 @@
1
1
  // The recipes of a game system (D-185, DAT-4): which pages a rest goes to, the effects it ends, the fields it brings back, and what it leaves to the master.
2
2
  import { comparableText } from "../../../core/text.js";
3
3
  import { readCounter } from "../../../counters/index.js";
4
- import { isDeclaredUncounted, isInParty, locate, playerCharacters } from "../../../pages/index.js";
4
+ import { findPage, heldNames, isDeclaredUncounted, isInParty, locate, playerCharacters } from "../../../pages/index.js";
5
5
  import { effectiveFields, effectsOf } from "../sheet/effect-layer.js";
6
6
  import { formulaValue } from "../sheet/formula-scope.js";
7
7
  import { refillAmount } from "../sheet/worked-out.js";
@@ -81,6 +81,24 @@ export function notBroughtBack(world, system, recipe, page) {
81
81
  return [`${field} ${String(value).trim()}${rule === undefined ? "" : ` (rules "${rule}")`}`];
82
82
  });
83
83
  }
84
+ /**
85
+ * The counters below their maximum of the items a page carries, also inside others, as in "Wand charges 3/7": what comes back to them, and when, only
86
+ * their text says, which a rest never applies by itself.
87
+ */
88
+ export function carriedCounters(world, page) {
89
+ return carriedItems(world, page, new Set([page])).flatMap((item) => Object.entries(effectiveFields(world, item)).flatMap(([field, value]) => {
90
+ const counter = isDeclaredUncounted(world, field) ? undefined : readCounter(value);
91
+ return counter?.max === undefined || counter.value >= counter.max ? [] : [`${item.name} ${field} ${counter.value}/${counter.max}`];
92
+ }));
93
+ }
94
+ /** The items a holder carries, and those inside them, each once. */
95
+ function carriedItems(world, holder, seen) {
96
+ const held = heldNames(holder).flatMap((name) => findPage(world, name) ?? []).filter((item) => item.type === "item" && !seen.has(item));
97
+ for (const item of held) {
98
+ seen.add(item);
99
+ }
100
+ return held.flatMap((item) => [item, ...carriedItems(world, item, seen)]);
101
+ }
84
102
  /**
85
103
  * The regains of a recipe on these fields (DAT-4): for each, the counters it names that are spent and how many come back in all. When all that is spent comes
86
104
  * back, or only one counter is spent, they are targets; otherwise the player chooses.
@@ -25,6 +25,7 @@ export declare const status: import("../core/registry.ts").Command<z.ZodObject<{
25
25
  table: string[];
26
26
  precedents: string[];
27
27
  extensions: string;
28
+ updates: string | undefined;
28
29
  houseRules: string[];
29
30
  players: Member[];
30
31
  companions: Member[];
@@ -23,6 +23,7 @@ import { quotedOrders } from "./shared/characters/orders.js";
23
23
  import { installableSystems } from "./shared/packages/catalog.js";
24
24
  import { packageCodeProblems } from "./shared/packages/code.js";
25
25
  import { extensionsLine } from "./shared/packages/extensions.js";
26
+ import { packageUpdates } from "./shared/packages/updates.js";
26
27
  import { surroundings, surroundingsText } from "./shared/places/environment.js";
27
28
  import { journeyText, readJourney } from "./shared/places/journey.js";
28
29
  import { measuresOf, roadsOf } from "./shared/places/roads.js";
@@ -105,6 +106,8 @@ export const status = defineCommand({
105
106
  const installable = settings.system === undefined ? await installableSystems(context) : [];
106
107
  // The opening of an evening, once in a chat: notes said while the master read the game reached the player (playtests 15, 16).
107
108
  const opening = firstInChat(context, "opening");
109
+ // At the start of a session, the campaign's packages npm has newer (D-569): once in a chat, at every status on the command line.
110
+ const updates = opening || context.told === undefined ? await packageUpdates(root, context) : undefined;
108
111
  return {
109
112
  campaign: [
110
113
  settings.name,
@@ -150,6 +153,7 @@ export const status = defineCommand({
150
153
  precedents: settings.precedents ?? [],
151
154
  // The extensions it uses, each with what it brings (D-28).
152
155
  extensions: extensionsLine(root, context),
156
+ updates,
153
157
  houseRules: bookTitles(readRuleBook(join(root, houseRulesFolderName), "house rules")),
154
158
  players: players.map(member),
155
159
  companions: characters.filter((page) => page.fields.role === "companion").map(member),
@@ -217,6 +221,7 @@ export const status = defineCommand({
217
221
  result.table.length === 0 ? "" : `Table: ${result.table.join("; ")}`,
218
222
  result.precedents.length === 0 ? "" : `Precedents: ${result.precedents.join("; ")}`,
219
223
  result.extensions,
224
+ result.updates ?? "",
220
225
  result.houseRules.length === 0 ? "" : `House rules (rules): ${result.houseRules.join(", ")}`,
221
226
  timeLine(result),
222
227
  result.betweenSessions ?? "",
@@ -19,6 +19,7 @@ import { acrossHint, crossedRoads, openLegs } from "./open.js";
19
19
  export const travel = defineCommand({
20
20
  name: "travel",
21
21
  description: "Make a journey: whenever the party goes somewhere, use it instead of advance and move. "
22
+ + "Before anyone says how long a journey takes, ask route, which tells it without moving anyone. "
22
23
  + "By road it takes the quickest way, in the vehicle the party is in if any; off the roads, across and toward go through the regions and their terrain. "
23
24
  + "It moves the travellers and lets the time pass, stopping on arrival, at an event that comes due and at the end of the day's travel; travel again goes on from there. "
24
25
  + "When others go with the party, name in who everyone who goes, the party too: companions, hirelings, mounts; a vehicle goes with those in it. "
@@ -1,5 +1,7 @@
1
1
  import { type Page, type World } from "../../pages/index.ts";
2
+ import type { GameSystem } from "../../systems/index.ts";
2
3
  import { type Knowledge } from "../shared/characters/knowledge.ts";
4
+ import type { Measures } from "../shared/places/roads.ts";
3
5
  /** A page of the game system the campaign changed with a layer (SYS-11), as the dashboard lists it. */
4
6
  export interface ShownLayer {
5
7
  /** The page's name, by which its layer is taken off. */
@@ -8,7 +10,7 @@ export interface ShownLayer {
8
10
  title?: string;
9
11
  /** Its type, of a page the player may read. */
10
12
  type?: string;
11
- /** The fields the layer changes: each as the system gives it, none for one the layer adds, and as the campaign has it; none of a page the player may not read. */
13
+ /** The fields the layer changes: each as the system gives it, none for one the layer adds, and as the campaign has it, its measures in the story's units; none of a page the player may not read. */
12
14
  fields: {
13
15
  field: string;
14
16
  system?: string;
@@ -24,7 +26,7 @@ export interface ShownLayer {
24
26
  * value of every field; any other, as a creature the character does not know, by its name alone, never a value nor what changed: a layer is a house rule of
25
27
  * the campaign, not a fact of the story (D-565).
26
28
  */
27
- export declare function shownLayers(world: World, knowledge: Knowledge): ShownLayer[];
29
+ export declare function shownLayers(world: World, knowledge: Knowledge, system: GameSystem | undefined, measures: Measures): ShownLayer[];
28
30
  /** The page of the game system with a layer, by its name, as the view lists it and the player takes the layer off; undefined for any other. */
29
31
  export declare function listedLayer(world: World, name: string): Page | undefined;
30
32
  /**
@@ -1,26 +1,35 @@
1
1
  // The pages of the game system the campaign changed with a layer (SYS-11), as the player may see them: what changed, and what the system gave
2
+ import { lengthsInUnits } from "../../core/length.js";
2
3
  import { comparableText, sameName, valueNamed, valueText } from "../../core/text.js";
3
- import { baseChain, partContent, systemOriginal } from "../../pages/index.js";
4
+ import { baseChain, partContent, poundsInKilograms, systemOriginal } from "../../pages/index.js";
4
5
  import { inKnownWords, knowsPage } from "../shared/characters/knowledge.js";
5
6
  /**
6
7
  * The pages of the game system with a layer of the campaign, by name (SYS-11). One the player may read (VIEW-2) with what the layer changes and the system's
7
8
  * value of every field; any other, as a creature the character does not know, by its name alone, never a value nor what changed: a layer is a house rule of
8
9
  * the campaign, not a fact of the story (D-565).
9
10
  */
10
- export function shownLayers(world, knowledge) {
11
- const text = (value) => inKnownWords(world, knowledge, valueText(value));
11
+ export function shownLayers(world, knowledge, system, measures) {
12
+ const pound = measures.units === "metric" ? system?.pound : undefined;
13
+ const weightField = system?.load?.field;
14
+ // Measures in the story's units, as the sheet tells them (D-328, LOAD-2); a layer never holds aliases (INH-8), so no name is told in other units.
15
+ const text = (field, value) => {
16
+ const known = inKnownWords(world, knowledge, valueText(value));
17
+ return pound !== undefined && weightField !== undefined && comparableText(field) === comparableText(weightField)
18
+ ? poundsInKilograms(known, pound)
19
+ : lengthsInUnits(known, measures.units, measures.imperial);
20
+ };
12
21
  return layeredPages(world).map((page) => {
13
22
  const named = { name: page.name, ...(page.title === undefined ? {} : { title: page.title }) };
14
23
  if (!knowsPage(knowledge, page)) {
15
24
  return { ...named, fields: [], sections: [] };
16
25
  }
17
- const system = systemOriginal(page).fields;
26
+ const original = systemOriginal(page).fields;
18
27
  return {
19
28
  ...named,
20
29
  ...(page.type === undefined ? {} : { type: page.type }),
21
30
  fields: (page.layer?.fields ?? []).map((field) => {
22
- const given = valueNamed(system, field);
23
- return { field: sameName(Object.keys(system), field) ?? field, ...(given === undefined ? {} : { system: text(given) }), campaign: text(valueNamed(page.fields, field)) };
31
+ const given = valueNamed(original, field);
32
+ return { field: sameName(Object.keys(original), field) ?? field, ...(given === undefined ? {} : { system: text(field, given) }), campaign: text(field, valueNamed(page.fields, field)) };
24
33
  }),
25
34
  sections: (page.layer?.sections ?? []).filter((section) => partContent(page.body, section)?.secret === false),
26
35
  ...(page.layer?.introduction === true ? { introduction: true } : {}),
@@ -1,6 +1,7 @@
1
1
  import type { Context } from "../../core/context.ts";
2
2
  import type { Effect, EffectEnd } from "../../effects/index.ts";
3
3
  import { type Page, type World } from "../../pages/index.ts";
4
+ import type { Scene } from "../../scene/index.ts";
4
5
  import type { GameSystem } from "../../systems/index.ts";
5
6
  import { type Knowledge } from "../shared/characters/knowledge.ts";
6
7
  import { type SeenEffect } from "../shared/scene/effects.ts";
@@ -167,6 +168,11 @@ export declare function strangerImage(root: string, context: Context, world: Wor
167
168
  file: string;
168
169
  version: number;
169
170
  } | undefined;
171
+ /**
172
+ * Whether the open scene gives someone by what the character sees of them (D-568), by their name, a copy's or its creature's: one in the scene the master gave
173
+ * seen for, known by name or not, while the scene keeps them; never one of the party.
174
+ */
175
+ export declare function seenInScene(world: World, party: Page[], scene: Pick<Scene, "with" | "copies" | "gone" | "seen"> | undefined, name: string): boolean;
170
176
  /**
171
177
  * "Scontro all'ossario (combat), at Ossario, with Ennio, Lena, uomo col coltello, brigante 1 and brigante 2": the open scene as the player sees it, with the words
172
178
  * of the page (D-254, D-416): who the character does not know by what it sees of them, else someone, and two or more of them as others.
@@ -32,8 +32,10 @@ export function shownPlace(sight) {
32
32
  .map(({ entry, place: holder }) => ({ name: entry.name, value: inKnownWords(world, knowledge, entry.value), ...placed(holder) })),
33
33
  ...placesAround(world, place).flatMap((holder) => effectsOf(holder).map((effect) => ({ effect: effect.name, ...(effect.end === undefined ? {} : { end: effect.end }), ...placed(holder) }))),
34
34
  ];
35
+ const scene = readOpenScene(sight.root).scene;
36
+ // One the open scene gives by what the character sees of them is there in the scene alone, as one it does not know (D-568).
35
37
  const present = world.pages.filter((page) => page.type === "character" && page.fields.status !== "dead" && locate(world, page).chain[0] === place
36
- && (sight.party.includes(page) || knowsPage(knowledge, page)));
38
+ && (sight.party.includes(page) || (knowsPage(knowledge, page) && !seenInScene(world, sight.party, scene, page.name))));
37
39
  const image = picture(sight, place);
38
40
  const grid = placeGrid(place)?.grid;
39
41
  const text = knownText(world, knowledge, place);
@@ -49,7 +51,7 @@ export function shownPlace(sight) {
49
51
  // The party first, the player character in the foreground at its head (VIEW-12).
50
52
  here: [...partyFirst(sight).filter((page) => present.includes(page)), ...present.filter((page) => !sight.party.includes(page))].map((page) => ({
51
53
  ...person(sight, page),
52
- ...hostileMark(readOpenScene(sight.root).scene, page.name),
54
+ ...hostileMark(scene, page.name),
53
55
  ...stateOf(sight, page),
54
56
  })),
55
57
  ...(grid === undefined ? {} : { map: shownGrid(sight, place, grid) }),
@@ -64,7 +66,7 @@ export function shownScene(sight) {
64
66
  const place = knownPage(sight, scene.place);
65
67
  const characters = scene.with.map((link) => {
66
68
  const name = parsePageReference(link).name;
67
- const page = knownPage(sight, link);
69
+ const page = knownInScene(sight, scene, link);
68
70
  const hostile = hostileMark(scene, name);
69
71
  const written = pagesWithName(sight.world, name)[0];
70
72
  const state = written === undefined ? {} : strangerState(sight, scene, written);
@@ -75,7 +77,7 @@ export function shownScene(sight) {
75
77
  });
76
78
  const creatures = [...new Set(Object.values(scene.copies).map((copy) => copy.creature))].map((creature) => {
77
79
  const count = Object.values(scene.copies).filter((copy) => copy.creature === creature).length;
78
- const page = knownPage(sight, creature);
80
+ const page = knownInScene(sight, scene, creature);
79
81
  // A kind the character does not know by the letter its copies have in the scene, as creature B, with more kinds (D-331).
80
82
  const first = Object.keys(scene.copies).find((copy) => scene.copies[copy].creature === creature);
81
83
  const name = first === undefined ? "creature" : strangerName(scene, first).replace(/\s*\d+$/, "");
@@ -132,7 +134,7 @@ export function seenEffect(sight, effect) {
132
134
  if (end === undefined || !("turn" in end)) {
133
135
  return effectParts(sight.world, system, effect, sight.words);
134
136
  }
135
- const scene = readOpenScene(sight.root).scene ?? { copies: {} };
137
+ const scene = readOpenScene(sight.root).scene ?? { with: [], copies: {} };
136
138
  return effectParts(sight.world, system, { ...effect, end: { ...end, turn: shownTurn(sight, scene, end.turn) } }, sight.words);
137
139
  }
138
140
  /** The picture of one the character does not know, as strangerPicture gives it, for the scene and for the rolls (D-420, D-421). */
@@ -144,6 +146,21 @@ export function strangerImage(root, context, world, name) {
144
146
  const hidden = file === undefined ? undefined : hiddenImageName(file);
145
147
  return file === undefined || hidden === undefined ? undefined : { file: hidden, version: Math.trunc(files().modified(file) ?? 0) };
146
148
  }
149
+ /**
150
+ * Whether the open scene gives someone by what the character sees of them (D-568), by their name, a copy's or its creature's: one in the scene the master gave
151
+ * seen for, known by name or not, while the scene keeps them; never one of the party.
152
+ */
153
+ export function seenInScene(world, party, scene, name) {
154
+ if (scene === undefined) {
155
+ return false;
156
+ }
157
+ const copies = { ...scene.gone, ...scene.copies };
158
+ const copy = Object.keys(copies).find((copyName) => comparableText(copyName) === comparableText(name));
159
+ const key = parsePageReference(copy === undefined ? name : copies[copy].creature).name;
160
+ const inScene = [...scene.with, ...Object.values(copies).map((one) => one.creature)].some((link) => comparableText(parsePageReference(link).name) === comparableText(key));
161
+ const page = pagesWithName(world, key)[0];
162
+ return inScene && seenOf(scene, key) !== undefined && (page === undefined || !party.includes(page));
163
+ }
147
164
  /**
148
165
  * A place's map as the player sees it (GRD-6): who stands where, the party and the characters the character knows by name, the others of the open scene as
149
166
  * someone, its copies as the scene names them; a character it does not know outside the scene is not shown, as in VIEW-6.
@@ -169,7 +186,7 @@ function shownGrid(sight, place, written) {
169
186
  const measured = { square, ...(system?.grid === undefined ? {} : measuredFrom(sight, system.grid, measures, here, self, one)) };
170
187
  if (one.copy !== undefined && here !== undefined) {
171
188
  const copy = here.copies[one.copy];
172
- const creature = knownPage(sight, copy?.creature);
189
+ const creature = knownInScene(sight, here, copy?.creature);
173
190
  const image = creature === undefined ? strangerPicture(sight, copy?.creature) : picture(sight, creature);
174
191
  const state = copy === undefined ? {} : stateOf(sight, copyPage(one.copy, copy));
175
192
  return [
@@ -182,7 +199,7 @@ function shownGrid(sight, place, written) {
182
199
  if (page === undefined || page.type !== "character" || page.fields.status === "dead") {
183
200
  return [];
184
201
  }
185
- if (sight.party.includes(page) || knowsPage(sight.knowledge, page)) {
202
+ if (sight.party.includes(page) || knownInScene(sight, here, page.name) !== undefined) {
186
203
  return [{ ...person(sight, page), ...hostileMark(here, page.name), ...stateOf(sight, page), ...measured }];
187
204
  }
188
205
  const image = strangerPicture(sight, page.name);
@@ -246,9 +263,9 @@ function fighterOf(sight, scene, name) {
246
263
  return undefined;
247
264
  }
248
265
  const party = sight.party.includes(page);
249
- // A copy is named when the character knows its creature; a character when it knows them.
250
- const creature = copy === undefined ? undefined : knownPage(sight, copy[1].creature);
251
- const stranger = copy === undefined ? !party && !knowsPage(sight.knowledge, page) : creature === undefined;
266
+ // A copy is named when the character knows its creature; a character when it knows them; neither while the scene gives them by what is seen (D-568).
267
+ const creature = copy === undefined ? undefined : knownInScene(sight, scene, copy[1].creature);
268
+ const stranger = copy === undefined ? !party && knownInScene(sight, scene, page.name) === undefined : creature === undefined;
252
269
  const shown = !stranger ? page.name : copy === undefined ? seenName(scene, page.name) : strangerName(scene, copy[0]);
253
270
  const image = stranger ? strangerPicture(sight, copy === undefined ? page.name : copy[1].creature) : picture(sight, creature ?? page);
254
271
  const effects = shownEffects(sight, system, page, party);
@@ -376,13 +393,20 @@ function knownPage(sight, name) {
376
393
  const page = pagesWithName(sight.world, parsePageReference(name).name)[0];
377
394
  return page !== undefined && knowsPage(sight.knowledge, page) ? page : undefined;
378
395
  }
379
- /** Whose turn it is, as the character knows them: a character it knows by name, a copy by its own name when it knows the creature, else creature and its number. */
396
+ /**
397
+ * Whose turn it is, as the character knows them: a character it knows by name, a copy by its own name when it knows the creature, else creature and its number;
398
+ * by what is seen while the scene gives them so (D-568).
399
+ */
380
400
  function shownTurn(sight, scene, name) {
381
401
  const copy = Object.entries(scene.copies).find(([copyName]) => comparableText(copyName) === comparableText(name));
382
402
  if (copy === undefined) {
383
- return knownPage(sight, name)?.name ?? seenName(scene, name);
403
+ return knownInScene(sight, scene, name)?.name ?? seenName(scene, name);
384
404
  }
385
- return knownPage(sight, copy[1].creature) === undefined ? strangerName(scene, copy[0]) : copy[0];
405
+ return knownInScene(sight, scene, copy[1].creature) === undefined ? strangerName(scene, copy[0]) : copy[0];
406
+ }
407
+ /** The page the character knows by a name in the open scene: none while the scene gives them by what is seen (D-568), known or not. */
408
+ function knownInScene(sight, scene, name) {
409
+ return name === undefined || seenInScene(sight.world, sight.party, scene, name) ? undefined : knownPage(sight, name);
386
410
  }
387
411
  /**
388
412
  * The name the player hears for a copy of a creature its character does not know (D-325, D-331, D-416): what the master said the character sees of its kind and
@@ -18,6 +18,8 @@ import type { KnownEntry, ShownCalendar, ShownDocument } from "./world.ts";
18
18
  export type ViewResult = {
19
19
  kind: "none";
20
20
  language?: string;
21
+ /** The game system's words in the campaign's language, as in play: they name the system's own questions of the setup (D-403). */
22
+ words?: SystemWords;
21
23
  importing?: ShownImport;
22
24
  } | {
23
25
  kind: "overview";
@@ -17,6 +17,7 @@ export declare const view: import("../../core/registry.ts").Command<z.ZodObject<
17
17
  }, z.core.$strip>, {
18
18
  kind: "none";
19
19
  language?: string;
20
+ words?: SystemWords;
20
21
  importing?: import("../import/import.ts").ShownImport;
21
22
  } | {
22
23
  kind: "overview";