rpg-engine 0.5.0 → 0.6.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 (218) hide show
  1. package/dist/campaign/settings.d.ts +1 -0
  2. package/dist/campaign/settings.js +6 -5
  3. package/dist/command-line.js +12 -5
  4. package/dist/commands/advance.js +1 -1
  5. package/dist/commands/ask.d.ts +1 -1
  6. package/dist/commands/ask.js +66 -24
  7. package/dist/commands/change.js +28 -17
  8. package/dist/commands/config.d.ts +1 -1
  9. package/dist/commands/config.js +67 -21
  10. package/dist/commands/effect.js +42 -23
  11. package/dist/commands/find.js +1 -1
  12. package/dist/commands/game-adventures.js +2 -2
  13. package/dist/commands/game-catalog.d.ts +13 -0
  14. package/dist/commands/game-catalog.js +26 -2
  15. package/dist/commands/game-checks.js +23 -21
  16. package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
  17. package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
  18. package/dist/commands/game-effects.d.ts +12 -4
  19. package/dist/commands/game-effects.js +21 -13
  20. package/dist/commands/game-examples.d.ts +22 -0
  21. package/dist/commands/game-examples.js +72 -0
  22. package/dist/commands/game-extension-list.d.ts +31 -3
  23. package/dist/commands/game-extension-list.js +83 -7
  24. package/dist/commands/game-images.d.ts +1 -1
  25. package/dist/commands/game-images.js +3 -2
  26. package/dist/commands/game-library.d.ts +3 -0
  27. package/dist/commands/game-library.js +2 -2
  28. package/dist/commands/game-mode.js +1 -1
  29. package/dist/commands/game-package-code.d.ts +87 -0
  30. package/dist/commands/game-package-code.js +648 -0
  31. package/dist/commands/game-package-hooks.d.ts +37 -0
  32. package/dist/commands/game-package-hooks.js +116 -0
  33. package/dist/commands/game-recipes.js +2 -2
  34. package/dist/commands/game-reminders.d.ts +5 -2
  35. package/dist/commands/game-reminders.js +7 -4
  36. package/dist/commands/game-rules.d.ts +4 -1
  37. package/dist/commands/game-rules.js +7 -1
  38. package/dist/commands/game-upkeep.js +3 -3
  39. package/dist/commands/game-view-place.d.ts +8 -20
  40. package/dist/commands/game-view-place.js +16 -35
  41. package/dist/commands/game-widgets.d.ts +39 -10
  42. package/dist/commands/game-widgets.js +138 -35
  43. package/dist/commands/game-world.d.ts +17 -0
  44. package/dist/commands/game-world.js +70 -12
  45. package/dist/commands/image.js +1 -1
  46. package/dist/commands/init.js +2 -2
  47. package/dist/commands/mode.d.ts +1 -1
  48. package/dist/commands/package.d.ts +8 -0
  49. package/dist/commands/package.js +81 -24
  50. package/dist/commands/progression.d.ts +2 -0
  51. package/dist/commands/progression.js +7 -2
  52. package/dist/commands/roll.d.ts +2 -0
  53. package/dist/commands/roll.js +50 -24
  54. package/dist/commands/rules.js +6 -4
  55. package/dist/commands/scene.d.ts +1 -1
  56. package/dist/commands/scene.js +13 -10
  57. package/dist/commands/sheet.js +10 -1
  58. package/dist/commands/status.d.ts +1 -0
  59. package/dist/commands/status.js +14 -4
  60. package/dist/commands/trade.js +6 -4
  61. package/dist/commands/translate.js +2 -2
  62. package/dist/commands/travel.js +1 -1
  63. package/dist/commands/validate.js +2 -2
  64. package/dist/commands/view.d.ts +8 -4
  65. package/dist/commands/view.js +7 -6
  66. package/dist/commands/worked-out.js +11 -5
  67. package/dist/commands/write.d.ts +8 -1
  68. package/dist/commands/write.js +84 -25
  69. package/dist/core/command-reference.js +3 -2
  70. package/dist/core/consents.d.ts +18 -0
  71. package/dist/core/consents.js +93 -0
  72. package/dist/core/context.d.ts +51 -29
  73. package/dist/core/context.js +3 -1
  74. package/dist/core/examples.d.ts +25 -0
  75. package/dist/core/examples.js +19 -0
  76. package/dist/{extensions/api.d.ts → core/package-api.d.ts} +134 -32
  77. package/dist/core/package-declarations.d.ts +102 -0
  78. package/dist/core/package-declarations.js +81 -0
  79. package/dist/core/registry.d.ts +2 -0
  80. package/dist/core/text.d.ts +5 -0
  81. package/dist/core/text.js +12 -0
  82. package/dist/dashboard/acts.js +31 -24
  83. package/dist/dashboard/address.js +4 -1
  84. package/dist/dashboard/api.js +54 -0
  85. package/dist/dashboard/app.js +140 -96
  86. package/dist/dashboard/ask-card.js +76 -25
  87. package/dist/dashboard/asked-dice.js +57 -0
  88. package/dist/dashboard/dice/tray.js +3 -3
  89. package/dist/dashboard/extension-widgets.js +104 -10
  90. package/dist/dashboard/i18n/ar.json +25 -29
  91. package/dist/dashboard/i18n/cs.json +25 -29
  92. package/dist/dashboard/i18n/da.json +25 -29
  93. package/dist/dashboard/i18n/de.json +25 -29
  94. package/dist/dashboard/i18n/el.json +25 -29
  95. package/dist/dashboard/i18n/es.json +25 -29
  96. package/dist/dashboard/i18n/fi.json +25 -29
  97. package/dist/dashboard/i18n/fr.json +25 -29
  98. package/dist/dashboard/i18n/he.json +25 -29
  99. package/dist/dashboard/i18n/hi.json +25 -29
  100. package/dist/dashboard/i18n/hu.json +25 -29
  101. package/dist/dashboard/i18n/is.json +25 -29
  102. package/dist/dashboard/i18n/it.json +25 -29
  103. package/dist/dashboard/i18n/ja.json +25 -29
  104. package/dist/dashboard/i18n/ko.json +25 -29
  105. package/dist/dashboard/i18n/nb.json +25 -29
  106. package/dist/dashboard/i18n/nl.json +25 -29
  107. package/dist/dashboard/i18n/pl.json +25 -29
  108. package/dist/dashboard/i18n/pt.json +25 -29
  109. package/dist/dashboard/i18n/ro.json +25 -29
  110. package/dist/dashboard/i18n/ru.json +25 -29
  111. package/dist/dashboard/i18n/sv.json +25 -29
  112. package/dist/dashboard/i18n/tr.json +25 -29
  113. package/dist/dashboard/i18n/uk.json +25 -29
  114. package/dist/dashboard/i18n/zh.json +25 -29
  115. package/dist/dashboard/icons.js +4 -1
  116. package/dist/dashboard/kit.js +35 -0
  117. package/dist/dashboard/labels.js +1 -0
  118. package/dist/dashboard/pack-card.js +7 -2
  119. package/dist/dashboard/package-page.js +50 -0
  120. package/dist/dashboard/packages.js +172 -23
  121. package/dist/dashboard/page-code.js +248 -0
  122. package/dist/dashboard/party.js +13 -14
  123. package/dist/dashboard/people.js +4 -0
  124. package/dist/dashboard/person-panel.js +110 -0
  125. package/dist/dashboard/place-map-view.js +11 -6
  126. package/dist/dashboard/scene.js +12 -9
  127. package/dist/dashboard/settings.js +55 -9
  128. package/dist/dashboard/sheet.js +21 -13
  129. package/dist/dashboard/status.js +69 -15
  130. package/dist/dashboard/style.css +592 -825
  131. package/dist/dashboard/top.js +75 -25
  132. package/dist/dashboard/turns.js +34 -13
  133. package/dist/dashboard/widgets.js +9 -2
  134. package/dist/dashboard-server.js +189 -10
  135. package/dist/dice/roll-dice.js +1 -1
  136. package/dist/effects/effect.d.ts +7 -4
  137. package/dist/effects/effect.js +12 -9
  138. package/dist/extensions/engine.d.ts +4 -0
  139. package/dist/extensions/engine.js +74 -0
  140. package/dist/extensions/extension.d.ts +25 -37
  141. package/dist/extensions/extension.js +26 -48
  142. package/dist/extensions/index.d.ts +3 -2
  143. package/dist/extensions/index.js +4 -1
  144. package/dist/extensions/packages.d.ts +6 -0
  145. package/dist/extensions/packages.js +100 -11
  146. package/dist/index.d.ts +1 -3
  147. package/dist/mcp-server.js +51 -14
  148. package/dist/page-words.d.ts +4 -0
  149. package/dist/page-words.js +4 -4
  150. package/dist/page.d.ts +218 -0
  151. package/dist/page.js +2 -0
  152. package/dist/pages/load.d.ts +7 -1
  153. package/dist/pages/load.js +10 -5
  154. package/dist/pages/page-file.js +1 -1
  155. package/dist/pages/stack-writes.js +5 -4
  156. package/dist/pages/world.d.ts +8 -0
  157. package/dist/pages/world.js +9 -2
  158. package/dist/systems/game-system.d.ts +52 -26
  159. package/dist/systems/game-system.js +141 -42
  160. package/dist/systems/index.d.ts +3 -3
  161. package/dist/systems/index.js +3 -3
  162. package/dist/systems/system-code.d.ts +29 -88
  163. package/dist/systems/system-code.js +68 -23
  164. package/dist/systems/words.d.ts +2 -0
  165. package/dist/systems/words.js +11 -0
  166. package/dist/testing.d.ts +20 -5
  167. package/dist/testing.js +49 -14
  168. package/instructions/combat.md +2 -2
  169. package/instructions/core.md +2 -2
  170. package/instructions/dashboard.md +1 -1
  171. package/instructions/mentor-tutorial.md +1 -1
  172. package/instructions/play.md +2 -2
  173. package/instructions/setup.md +1 -1
  174. package/package.json +9 -1
  175. package/systems/5e/LICENSE.md +13 -3
  176. package/systems/5e/dist/dying.js +83 -16
  177. package/systems/5e/dist/index.js +2 -2
  178. package/systems/5e/dist/page-style.js +634 -0
  179. package/systems/5e/dist/page.js +166 -0
  180. package/systems/5e/dist/shown.js +23 -0
  181. package/systems/5e/instructions/combat.md +1 -0
  182. package/systems/5e/package.json +4 -2
  183. package/systems/5e/system.yaml +35 -7
  184. package/systems/5e/versions/srd-5.1/system.yaml +2 -0
  185. package/systems/5e/words/ar.yaml +30 -0
  186. package/systems/5e/words/cs.yaml +30 -0
  187. package/systems/5e/words/da.yaml +30 -0
  188. package/systems/5e/words/de.yaml +30 -0
  189. package/systems/5e/words/el.yaml +30 -0
  190. package/systems/5e/words/es.yaml +30 -0
  191. package/systems/5e/words/fi.yaml +30 -0
  192. package/systems/5e/words/fr.yaml +30 -0
  193. package/systems/5e/words/he.yaml +30 -0
  194. package/systems/5e/words/hi.yaml +30 -0
  195. package/systems/5e/words/hu.yaml +30 -0
  196. package/systems/5e/words/is.yaml +30 -0
  197. package/systems/5e/words/it.yaml +30 -0
  198. package/systems/5e/words/ja.yaml +30 -0
  199. package/systems/5e/words/ko.yaml +30 -0
  200. package/systems/5e/words/nb.yaml +30 -0
  201. package/systems/5e/words/nl.yaml +30 -0
  202. package/systems/5e/words/pl.yaml +30 -0
  203. package/systems/5e/words/pt.yaml +30 -0
  204. package/systems/5e/words/ro.yaml +30 -0
  205. package/systems/5e/words/ru.yaml +30 -0
  206. package/systems/5e/words/sv.yaml +30 -0
  207. package/systems/5e/words/tr.yaml +30 -0
  208. package/systems/5e/words/uk.yaml +30 -0
  209. package/systems/5e/words/zh.yaml +30 -0
  210. package/dist/commands/game-extensions.d.ts +0 -34
  211. package/dist/commands/game-extensions.js +0 -407
  212. package/dist/commands/game-system-code.d.ts +0 -33
  213. package/dist/commands/game-system-code.js +0 -188
  214. package/dist/dashboard/death-save.js +0 -67
  215. package/dist/dashboard/dying.js +0 -46
  216. package/dist/dashboard/save-outcome.js +0 -42
  217. package/dist/dashboard/spend.js +0 -115
  218. /package/dist/{extensions/api.js → core/package-api.js} +0 -0
@@ -1,19 +1,21 @@
1
1
  import { join } from "node:path";
2
2
  import { z } from "zod";
3
3
  import { changeExtensions, readTextSetting, requireCampaign } from "../campaign/index.js";
4
+ import { engineSystemsFolder } from "../core/context.js";
4
5
  import { installedFromFolder } from "../core/files.js";
5
6
  import { appendLogEntry } from "../core/log.js";
7
+ import { apiProblem, ourSystems, readsApi } from "../core/package-declarations.js";
6
8
  import { defineCommand } from "../core/registry.js";
7
- import { files } from "../core/store.js";
9
+ import { files, isInside } from "../core/store.js";
8
10
  import { comparableText } from "../core/text.js";
9
11
  import { isNewerVersion } from "../core/version.js";
10
- import { extensionApi, findExtension, installedExtensions, isLocalSpec, issuesPage, isTarball, isVerified, readExtension, readsApi, shortName, verifiedScope } from "../extensions/index.js";
12
+ import { dropConsent, findExtension, installedExtensions, isLocalSpec, issuesPage, isTarball, isVerified, readExtension, recordConsent, shortName, verifiedScope } from "../extensions/index.js";
11
13
  import { installedLanguages, languagePackProblems, readLanguagePack } from "../languages/index.js";
12
14
  import { installedSystems, systemFolders, systemHasCode } from "../systems/index.js";
13
15
  import { exportAdventure, installAdventure, installedAdventures, isAdventureSpec, readAdventureSpec, removeAdventure, storyTouching } from "./game-adventures.js";
14
16
  import { listedExtensions, runsCode } from "./game-extension-list.js";
15
- import { extensionCommandNames, packagesInstalled } from "./game-extensions.js";
16
17
  import { campaignMode } from "./game-mode.js";
18
+ import { loadCampaignCode, packageCommandNames, packagesInstalled } from "./game-package-code.js";
17
19
  import { newDatedLogEntry } from "./game-time.js";
18
20
  import { campaignWorld } from "./game-world.js";
19
21
  /** The player's yes to a package not ours, not given (D-478): they said no or closed the question, or no window could be shown here. */
@@ -89,8 +91,13 @@ export const packageCommand = defineCommand({
89
91
  const { system } = result;
90
92
  return [
91
93
  `Installed the game system ${system.name}${system.version === undefined ? "" : ` ${system.version}`}, ${system.title}${system.verified ? "" : ", not verified: at the player's risk"}.`,
92
- system.used ? "The campaign plays it." : `It is for a new campaign, chosen in its setup: this one plays ${result.plays ?? "none yet"}.`,
93
- system.code ? "Its code runs from the next start of the game's server." : "",
94
+ // In a setup with no system yet, the one just installed is chosen next (D-513 (1)).
95
+ system.used
96
+ ? "The campaign plays it."
97
+ : result.plays === undefined
98
+ ? `The campaign has no system yet: if the player chose this one, set it with config, setting system, value ${system.name}.`
99
+ : `It is for a new campaign, chosen in its setup: this one plays ${result.plays}.`,
100
+ !system.code ? "" : result.plays === undefined ? "Its code runs once config sets it." : "Its code runs from the next start of the game's server.",
94
101
  ].filter((line) => line !== "").join(" ");
95
102
  }
96
103
  if (result.kind === "removed") {
@@ -106,7 +113,7 @@ export const packageCommand = defineCommand({
106
113
  const what = `${extension.name} ${extension.version}${result.verified ? ", verified" : ", not verified: at the player's risk"}`;
107
114
  const said = [
108
115
  `${result.already ? `The campaign already uses ${what}` : `Installed ${what}, and the campaign uses it`}: ${extension.about}.`,
109
- result.codeLeftOut ? "Its code is not used: for now RPG Engine runs only its own packages' code, and its texts bring the rest." : "",
116
+ result.codeLeftOut ? "Its code is not used: the player's yes holds for another version or other files; install it again for their yes." : "",
110
117
  result.commands.length === 0 ? "" : `Its commands: ${result.commands.join(", ")}.${result.tools === "" ? "" : ` ${result.tools}`}`,
111
118
  Object.keys(extension.parts).length === 0 ? "" : `Its parts of your instructions are given when they apply: ${Object.keys(extension.parts).join(", ")}.`,
112
119
  ].filter((line) => line !== "").join(" ");
@@ -119,7 +126,8 @@ export const packageCommand = defineCommand({
119
126
  const lines = result.packages.map((one) => {
120
127
  const here = one.installed === undefined ? "" : one.update ? `, installed ${one.installed}: an update` : ", installed";
121
128
  const by = one.author === undefined ? "" : ` by ${one.author}`;
122
- return `${one.name} ${one.version}${one.verified ? "" : " (not verified)"}${by}${here}${one.description === undefined ? "" : `: ${one.description.replace(/\.$/, "")}`}`;
129
+ const newer = one.newer === undefined ? "" : ` (its ${one.newer.version} needs ${one.newer.engine === undefined ? "a newer rpg-engine" : `rpg-engine ${one.newer.engine}`})`;
130
+ return `${one.name} ${one.version}${one.verified ? "" : " (not verified)"}${by}${here}${newer}${one.description === undefined ? "" : `: ${one.description.replace(/\.$/, "")}`}`;
123
131
  });
124
132
  return `On npm: ${lines.length === 0 ? "none" : lines.join("; ")}.`;
125
133
  }
@@ -164,7 +172,7 @@ async function available(context) {
164
172
  return { kind: "available", packages: [], failed: searched.failed };
165
173
  }
166
174
  const here = installedExtensions(context.extensionFolders ?? []);
167
- const packages = searched.filter((one) => one.kind === "extension" && readsApi(one.api)).map((one) => {
175
+ const packages = searched.filter((one) => one.kind === "extension" && readsApi(one.api, "extension")).map((one) => {
168
176
  const installed = here.find((found) => found.package === one.name);
169
177
  const copy = installed === undefined ? undefined : usable(context, one.name);
170
178
  const version = copy?.version;
@@ -178,19 +186,29 @@ async function available(context) {
178
186
  verified: isVerified(one.name, copy?.linked ?? false),
179
187
  ...(installed === undefined ? {} : { installed: version ?? "broken" }),
180
188
  update: version !== undefined && isNewerVersion(one.version, version),
189
+ ...(one.newer === undefined ? {} : { newer: one.newer }),
181
190
  };
182
191
  });
183
192
  return { kind: "available", packages: packages.sort((first, second) => Number(second.verified) - Number(first.verified) || first.name.localeCompare(second.name)) };
184
193
  }
194
+ /** The npm names of ours a name alone may be, with its version if given: an extension's, then a game system's; a system of the engine's list first (D-513). */
195
+ function ourNames(name) {
196
+ const names = [`${verifiedScope}${name}`, `${verifiedScope}system-${name}`];
197
+ const bare = name.replace(/(?<=.)@[^@/]*$/, "");
198
+ return ourSystems.some((system) => comparableText(system.name) === comparableText(bare)) ? [names[1], names[0]] : names;
199
+ }
185
200
  /** Installs a package on this computer and adds it to the campaign (D-27, D-428, D-441): ours, or another once the player wants it; an extension, for this game. */
186
201
  async function installed(root, context, name) {
187
202
  const packages = context.packages;
188
203
  if (packages === undefined) {
189
204
  throw new Error("Packages are installed only by the game's server or the command line, which reach npm.");
190
205
  }
191
- // A name alone is one of ours: weather is @rpgengine/weather, never a stranger's of that name, which is given as npm:weather.
192
- const asked = name.startsWith("npm:") ? name.slice(4) : isLocalSpec(name) || name.startsWith("@") ? name : `${verifiedScope}${name}`;
193
- const described = await packages.describe(asked);
206
+ // A name alone is one of ours: weather is @rpgengine/weather, never a stranger's of that name, which is given as npm:weather; or our game system's, as 5e
207
+ // is @rpgengine/system-5e (D-513).
208
+ const [first, second] = name.startsWith("npm:") ? [name.slice(4)] : isLocalSpec(name) || name.startsWith("@") ? [name] : ourNames(name);
209
+ const tried = await packages.describe(first);
210
+ const other = second !== undefined && "failed" in tried && tried.missing === true ? await packages.describe(second) : undefined;
211
+ const [asked, described] = second !== undefined && other !== undefined && !("failed" in other && other.missing === true) ? [second, other] : [first, tried];
194
212
  if ("failed" in described) {
195
213
  throw new Error(`${described.failed}. Nothing changed${asked === name ? "" : `: ${name} alone means ${asked}, one of RPG Engine's; another's is named with its scope, or as npm:${name} without one`}.`);
196
214
  }
@@ -204,11 +222,12 @@ async function installed(root, context, name) {
204
222
  }
205
223
  if (described.kind !== "extension") {
206
224
  throw new Error(described.kind === undefined
207
- ? `${described.name} is not a package for RPG Engine: its package.json does not say "rpg-engine": {"kind": "extension"}. Nothing changed.`
225
+ ? `${described.name} is not a package for RPG Engine: its package.json does not say "rpg-engine": {"kind": "extension"}, or {"kind": "system"} for a game system. Nothing changed.`
208
226
  : `${described.name} is a package of kind ${described.kind}: for now extensions, game systems and adventures are installed this way. Nothing changed.`);
209
227
  }
210
- if (!readsApi(described.api)) {
211
- throw new Error(`${described.name} ${described.version} is made for the extension API ${described.api ?? "none"}, and this RPG Engine reads the API 1 to ${extensionApi}: install a version made for these. Nothing changed.`);
228
+ const unread = apiProblem(described.api, "extension");
229
+ if (unread !== undefined) {
230
+ throw new Error(`${described.name} ${described.version} cannot be used, because ${unread}. Nothing changed.`);
212
231
  }
213
232
  const local = isLocalSpec(spec);
214
233
  const before = usable(context, described.name);
@@ -216,10 +235,11 @@ async function installed(root, context, name) {
216
235
  // A file or a folder says what it holds, and when it takes the place of a copy from npm, which is one for the whole computer (D-452).
217
236
  const holds = local ? ` (${described.name} ${described.version}${described.author === undefined ? "" : `, by ${described.author}`})` : "";
218
237
  const replaces = local && before !== undefined && !before.linked ? ` It takes the place of ${before.package} ${before.version} from npm, in every campaign on this computer.` : "";
219
- await playerYes(context, local ? name : described.name, local, holds, replaces);
238
+ await playerYes(context, local ? name : `${described.name} ${described.version}`, described.name, local, holds, replaces);
220
239
  }
221
240
  // A copy from a file or a folder never stands for the one npm has: asked by its name, npm's comes back.
222
- const reinstall = before === undefined || before.version !== described.version || local || before.linked;
241
+ // Another's whose code may not run is installed again before its yes is kept: the yes goes to npm's files, never to files changed since (D-478, D-510).
242
+ const reinstall = before === undefined || before.version !== described.version || local || before.linked || (!isVerified(described.name, local) && !runsCode(before));
223
243
  if (reinstall) {
224
244
  const why = await packages.install(spec);
225
245
  if (why !== undefined) {
@@ -233,17 +253,25 @@ async function installed(root, context, name) {
233
253
  if (extension === undefined) {
234
254
  throw new Error(`${described.name} was installed, but RPG Engine cannot use it as an extension. Nothing changed in the campaign.`);
235
255
  }
256
+ // The player's yes holds for this version and these files, on this computer: its code runs on the server and in the page (D-478, D-510).
257
+ if (!isVerified(described.name, local) && !extension.linked) {
258
+ recordConsent(extension.folder, extension.package, extension.version);
259
+ }
236
260
  const system = readTextSetting(root, "system");
237
261
  if (extension.needs.system !== undefined && comparableText(extension.needs.system) !== comparableText(system ?? "")) {
238
262
  throw new Error(`${extension.name} is installed on this computer, but it is for the game system ${extension.needs.system}, and the campaign plays ${system ?? "none"}: the campaign does not use it.`);
239
263
  }
264
+ // Its state, widgets and pictures go by its name, which the system's would share (D-514).
265
+ if (comparableText(extension.name) === comparableText(system ?? "")) {
266
+ throw new Error(`${extension.name} is installed on this computer, but it has the name of the game system the campaign plays: the campaign does not use it. Nothing changed in the campaign.`);
267
+ }
240
268
  const others = Object.keys(listedExtensions(root)).filter((other) => other !== extension.package && shortName(other) === extension.name);
241
269
  if (others.length > 0) {
242
270
  throw new Error(`The campaign uses ${others[0]}, with the same name, ${extension.name}: take it away with package remove ${others[0]} first. Nothing changed in the campaign.`);
243
271
  }
244
272
  // Its code is checked before the campaign lists it: a package that would not work is never added.
245
273
  const commands = runsCode(extension)
246
- ? await extensionCommandNames(extension, []).catch((error) => {
274
+ ? await packageCommandNames(extension, context, []).catch((error) => {
247
275
  throw new Error(`The code of ${extension.package} cannot be used: ${error instanceof Error ? error.message : String(error)}. Nothing changed in the campaign.`);
248
276
  })
249
277
  : [];
@@ -254,12 +282,14 @@ async function installed(root, context, name) {
254
282
  changeExtensions(root, { ...listedBefore, [extension.package]: extension.version });
255
283
  appendLogEntry(root, newDatedLogEntry(root, context, "package-installed", "public", { package: extension.package, version: extension.version, verified }));
256
284
  }
285
+ // The campaign's code anew, the new one's included: their hooks are called at the next change, never skipped (D-514).
286
+ await loadCampaignCode(context);
257
287
  return {
258
288
  kind: "installed",
259
289
  extension,
260
290
  verified,
261
291
  commands,
262
- codeLeftOut: extension.code !== undefined && !runsCode(extension),
292
+ codeLeftOut: (extension.code !== undefined || extension.page !== undefined) && !runsCode(extension),
263
293
  already,
264
294
  ...modePart(root, context, extension),
265
295
  tools: toolsNote(context),
@@ -272,18 +302,27 @@ async function installed(root, context, name) {
272
302
  async function systemInstalled(root, context, spec, name, described) {
273
303
  const local = isLocalSpec(spec);
274
304
  const named = shortName(described.name).replace(/^system-/, "");
305
+ const unread = apiProblem(described.api, "system");
306
+ if (unread !== undefined) {
307
+ throw new Error(`${described.name} ${described.version} cannot be used, because ${unread}. Nothing changed.`);
308
+ }
275
309
  const taken = systemsHere(root, context).find((one) => comparableText(one.name) === comparableText(named) && one.package !== described.name);
276
310
  if (taken !== undefined) {
277
311
  throw new Error(`There is already a game system named ${taken.name} on this computer${taken.package === undefined ? ", the engine's own" : `, from ${taken.package}`}: ${described.name} would take its name. Nothing changed.`);
278
312
  }
279
313
  if (!isVerified(described.name, local)) {
280
- await playerYes(context, local ? name : described.name, local, local ? ` (${described.name} ${described.version})` : "");
314
+ await playerYes(context, local ? name : `${described.name} ${described.version}`, described.name, local, local ? ` (${described.name} ${described.version})` : "");
281
315
  }
282
316
  const why = await context.packages.install(spec);
283
317
  if (why !== undefined) {
284
318
  throw new Error(`${described.name} could not be installed: ${why}. Nothing changed.`);
285
319
  }
286
320
  [...context.systemFolders, ...(context.extensionFolders ?? [])].forEach((folder) => files().refresh(folder));
321
+ const installed = installedExtensionFolder(context, described.name);
322
+ // The player's yes holds for this version and these files: its code runs at the next start of the game's server (D-478, D-511).
323
+ if (!isVerified(described.name, local) && !local && installed !== undefined) {
324
+ recordConsent(installed, described.name, described.version);
325
+ }
287
326
  let system;
288
327
  try {
289
328
  system = systemsHere(root, context).find((one) => one.package === described.name);
@@ -305,7 +344,7 @@ function systemsHere(root, context) {
305
344
  return installedSystems(context.systemFolders).map((system) => {
306
345
  const manifest = packageOf(folders.find((one) => one.name === system.name)?.folder ?? system.folder);
307
346
  // The engine's own have no package of their own here; one npm installed is ours only by our scope, and never from a folder (D-441).
308
- const shipped = system.folder.startsWith(context.systemFolders[0]);
347
+ const shipped = isInside(engineSystemsFolder, system.folder);
309
348
  const linked = installedFromFolder(system.folder);
310
349
  return {
311
350
  name: system.name,
@@ -316,7 +355,7 @@ function systemsHere(root, context) {
316
355
  used: comparableText(system.name) === comparableText(plays),
317
356
  code: systemHasCode(system.folder),
318
357
  // The engine's own are reported where the engine is: its package.json is in the folder above its systems.
319
- ...issuesOf(shipped ? join(context.systemFolders[0], "..") : system.folder),
358
+ ...issuesOf(shipped ? join(engineSystemsFolder, "..") : system.folder),
320
359
  };
321
360
  });
322
361
  }
@@ -395,6 +434,11 @@ function languagesHere(context) {
395
434
  ...issuesOf(pack.folder),
396
435
  }));
397
436
  }
437
+ /** Whether a package is on this computer, by its name as package takes it: an extension, a game system or a language npm installed (D-510). */
438
+ export function isInstalledPackage(context, name) {
439
+ const asked = name.startsWith("npm:") ? name.slice(4) : name.startsWith("@") ? name : `${verifiedScope}${name}`;
440
+ return [asked, name].some((one) => installedExtensionFolder(context, one) !== undefined);
441
+ }
398
442
  /** The folder npm installed a package in, among the extensions' folders; undefined when it is not there. */
399
443
  function installedExtensionFolder(context, name) {
400
444
  return (context.extensionFolders ?? []).map((folder) => join(folder, ...name.split("/"))).find((folder) => files().exists(join(folder, "package.json")));
@@ -412,10 +456,17 @@ function pagePhrases(context) {
412
456
  * The player's own yes to a package not ours (D-441, D-478), where the master cannot give it with its own tools: the host's form first, never the dashboard's
413
457
  * page, whose click a local program can forge; else a window of their operating system; else none, and it throws.
414
458
  */
415
- async function playerYes(context, name, local, holds = "", replaces = "") {
459
+ async function playerYes(context, name, pack, local, holds = "", replaces = "") {
460
+ // A no in a window holds for the package npm describes, however it was written, until the server starts again (D-510).
461
+ if (context.declined?.has(pack) === true) {
462
+ throw new YesRefused(`The player said no to ${pack} in this session: it is not asked again until the game's server starts again. Nothing changed.`, "declined");
463
+ }
464
+ // Said in plain words, the fixed text before the name its author chose; and where the request comes from (D-510).
465
+ const from = context.actor === "player" ? "the dashboard" : context.host === undefined ? "the command line" : "the chat";
466
+ const can = "Its code runs on this computer with your permissions, and in the dashboard, where it can see the whole campaign, its secrets included, and press buttons and speak to the master for you.";
416
467
  const warning = local
417
- ? `${name}${holds} is ${isTarball(name) ? "a file" : "a folder"} of this computer, not a package published by RPG Engine: its code runs, it is never verified, and RPG Engine takes no responsibility for it.${replaces}`
418
- : `${name} is not published by RPG Engine: its texts are someone else's, and RPG Engine takes no responsibility for it.`;
468
+ ? `Not verified by RPG Engine: ${name}${holds}, ${isTarball(name) ? "a file" : "a folder"} of this computer, asked from ${from}. ${can} RPG Engine takes no responsibility for it.${replaces}`
469
+ : `Not verified by RPG Engine: ${name}, asked from ${from}. ${can} Install it only if you trust who made it.`;
419
470
  const question = `Install ${name}? ${warning}`;
420
471
  const title = "A package not ours";
421
472
  const answer = context.player === undefined ? "unavailable" : await context.player.choose(question, title, ["Install it, at my risk", "Do not install it"], context.signal);
@@ -434,6 +485,7 @@ async function playerYes(context, name, local, holds = "", replaces = "") {
434
485
  return;
435
486
  }
436
487
  if (window === "no") {
488
+ context.declined?.add(pack);
437
489
  throw new YesRefused(`The player did not want ${name}. Nothing changed.`, "declined");
438
490
  }
439
491
  throw new YesRefused(`${warning} Only the player can say yes to it, in the host's form or in a window of their computer, and neither can be shown here (no desktop, as over SSH; `
@@ -499,10 +551,15 @@ async function uninstalled(root, context, name) {
499
551
  if (packages === undefined) {
500
552
  throw new Error("Packages are uninstalled only by the game's server or the command line, which reach npm.");
501
553
  }
554
+ const folder = installedExtensionFolder(context, found.package);
502
555
  const why = await packages.uninstall(found.package);
503
556
  if (why !== undefined) {
504
557
  throw new Error(`${found.package} could not be uninstalled: ${why}. Nothing changed.`);
505
558
  }
559
+ // Off this computer, its yes goes with it: installed again, it is asked again.
560
+ if (folder !== undefined) {
561
+ dropConsent(folder, found.package);
562
+ }
506
563
  [...context.systemFolders, ...(context.extensionFolders ?? [])].forEach((folder) => files().refresh(folder));
507
564
  const listed = listedExtensions(root);
508
565
  const wasUsed = Object.hasOwn(listed, found.package);
@@ -25,6 +25,8 @@ export interface Progression {
25
25
  name: string;
26
26
  pages: Page[];
27
27
  }[];
28
+ /** The features written on the character by hand, as what a feat or the story gives, that no row or part gives: counted with them (PRO-3). */
29
+ written: string[];
28
30
  /** Each feature as a row or a part gives it, before they are merged, with its level and page: what a new level adds, even a feature gained again. */
29
31
  gains: {
30
32
  name: string;
@@ -41,11 +41,15 @@ export function progressionOf(world, fields) {
41
41
  }
42
42
  // Item by item, then level by level; at the same level, a class's own features before its subclass's.
43
43
  features.sort((first, second) => first.order - second.order || first.level - second.level || first.part - second.part);
44
+ const merged = mergedFeatures(features);
45
+ const gainedNames = new Set(merged.map(({ name }) => comparableText(featureParts(name).name)));
46
+ const handWritten = listItems(valueNamed(fields, featuresField)).map((item) => item.name).filter((name) => !gainedNames.has(comparableText(featureParts(name).name)));
44
47
  return {
45
48
  lists: rule.parts === undefined ? [rule.list] : [rule.list, rule.parts.list],
46
49
  values: [...values.values()],
47
50
  featuresField,
48
- features: mergedFeatures(features).map(({ name }) => ({ name, pages: pagesGiving(features, name) })),
51
+ features: merged.map(({ name }) => ({ name, pages: pagesGiving(features, name) })),
52
+ written: [...new Set(handWritten)],
49
53
  gains: features.map(({ name, level, page }) => ({ name, level, page })),
50
54
  given,
51
55
  from: [...entries.map((entry) => ({ list: rule.list, name: entry.page.name, level: entry.level })), ...parts.map((part) => ({ list: rule.parts?.list ?? "", name: part.page.name }))],
@@ -60,8 +64,9 @@ export function progressionValue(progression, field) {
60
64
  if (progression === undefined) {
61
65
  return undefined;
62
66
  }
67
+ // Those of the rows and the parts, then those written by hand (PRO-3).
63
68
  if (comparableText(field) === comparableText(progression.featuresField)) {
64
- return progression.features.map((feature) => feature.name);
69
+ return [...progression.features.map((feature) => feature.name), ...progression.written];
65
70
  }
66
71
  return progression.values.find((value) => comparableText(value.field) === comparableText(field))?.value;
67
72
  }
@@ -40,6 +40,8 @@ export declare const roll: import("../core/registry.ts").Command<z.ZodObject<{
40
40
  sha256: string;
41
41
  fingerprint: string;
42
42
  }>;
43
+ /** The dice a game system rolls a number of its sheet with, for an example: that field's, else its first; 2d6 without them (D-280, D-514). */
44
+ export declare function sheetDiceOf(system: GameSystem | undefined, field?: string): string;
43
45
  /**
44
46
  * The page of who rolls, a character or a copy in the open scene, with its world; undefined when who names neither, as a free label does. Without names to
45
47
  * read, a name two pages share is a label too: the roll needs no sheet.
@@ -8,12 +8,13 @@ import { readCounter } from "../counters/index.js";
8
8
  import { askOracle, DiceError, rollDice, sha256 } from "../dice/index.js";
9
9
  import { declaredKind, findPage, pagesWithName, writePage } from "../pages/index.js";
10
10
  import { effectiveFields, effectsOf } from "./effect-layer.js";
11
+ import { systemNamed } from "./game-effects.js";
11
12
  import { behindTheScreen, namesNoOne, ofTheParty, screenNote, screenUp, sealHiddenRoll } from "./game-master-rolls.js";
13
+ import { packagesRolled } from "./game-package-hooks.js";
12
14
  import { copyPage, readOpenScene } from "./game-scene.js";
13
- import { systemRolled } from "./game-system-code.js";
14
15
  import { rollPageTable } from "./game-tables.js";
15
16
  import { newDatedLogEntry } from "./game-time.js";
16
- import { campaignSystem, campaignWorld, missingSystemHint } from "./game-world.js";
17
+ import { campaignSystem, campaignSystemWords, campaignWorld, missingSystemHint } from "./game-world.js";
17
18
  import { itemList, signedText, workedFields } from "./worked-out.js";
18
19
  // Faces arrive as "14,7" or "14 7" from a shell (PowerShell turns 14,7 into "14 7"), or as an array.
19
20
  export const faceValues = z.preprocess((value) => (typeof value === "string" ? value.split(/[\s,;]+/).filter(Boolean).map(Number) : value), z.array(z.number()));
@@ -27,23 +28,23 @@ export const roll = defineCommand({
27
28
  + "Give why and, if it belongs to someone, who; for a roll the player sees, check names it for them, while why stays yours. "
28
29
  + "When the player rolls physical dice, pass their faces as values. Make it hidden when the player must not see the result; "
29
30
  + "left out, a roll for a foe or anyone outside the party is hidden or shown as the master-rolls setting says. "
30
- + "keep stores the dice rolled for later, such as the two d20 of a diviner's Portent, rolled by the player for the player character, by you for a companion; "
31
+ + "keep stores the dice rolled for later, as a power of foresight does, rolled by the player for the player character, by you for a companion; "
31
32
  + "use takes one of those instead of the die and logs which roll it replaced. "
32
33
  + "Instead of a notation, table rolls on a random table of a page and gives its row, for you to tell; oracle answers a yes/no question with its odds. "
33
- + 'Example: notation 1d20+perception, why "notice the trap", who Lena; table "Colli di Vallerana#Incontri", why "a night on the hills"; oracle likely, why "is the ferryman awake?".',
34
+ + 'Example: notation {{roll}}, why "notice the trap", who Lena; table "Colli di Vallerana#Incontri", why "a night on the hills"; oracle likely, why "is the ferryman awake?".',
34
35
  group: "game",
35
36
  positionals: ["notation"],
36
37
  input: z.object({
37
38
  notation: z.string().optional().describe("dice to roll: 1d20+5, 2d20kh1 (keep the highest), 4d6dl1 (drop the lowest), 2d6ro<=2 (reroll once), 1d6! (exploding), 6d10>=8 (count successes), 4dF, d%; "
38
- + "with who, a field of their sheet stands for its value, such as 1d20+athletics"),
39
+ + "with who, a field of their sheet stands for its value, such as {{roll}}"),
39
40
  why: z.string().optional().describe("what the roll is for"),
40
41
  check: z.string().optional().describe("what the roll is, as the player sees it in the dashboard's rolls, such as Bite or Stealth: never what only you know"),
41
42
  who: z.string().optional().describe("character the roll belongs to, or a copy in the open scene, the damage and heals they deal too, never who takes them; leave it out only for a roll that is no one's, such as an oracle"),
42
43
  values: faceValues.optional().describe("faces rolled by the player with physical dice, separated by commas; on the command line write --values=-1,0,1 for negative faces"),
43
44
  hidden: z.boolean().optional().describe("only the master sees the result; its fingerprint goes to the player only if they ask for it; left out, the master-rolls setting decides for who outside the party"),
44
45
  reveal: z.string().optional().describe("id of a hidden roll whose proof to show, later"),
45
- keep: z.string().optional().describe("a field of who that keeps rolls for later, such as portent: the dice rolled go there, in place of what it held"),
46
- use: z.string().optional().describe("a kept roll to use instead of the die, as field=value, such as portent=3: the notation has one die"),
46
+ keep: z.string().optional().describe("a field of who that keeps rolls for later, such as omens: the dice rolled go there, in place of what it held"),
47
+ use: z.string().optional().describe("a kept roll to use instead of the die, as field=value, such as omens=3: the notation has one die"),
47
48
  from: z.string().optional().describe("who keeps the roll that use takes, when it is not who rolls"),
48
49
  double: z.boolean().optional().describe("roll twice the dice, never the numbers added, as a critical hit's damage: 1d8+3 rolls 2d8+3"),
49
50
  table: z.string().optional().describe("a random table to roll on, as Page#Section: the first table under that heading, its die in the first header cell (d8, 2d6, d100, d66) or as big as its highest row"),
@@ -61,7 +62,7 @@ export const roll = defineCommand({
61
62
  throw new Error("Give one of the dice to roll, table or oracle, not more: each is a roll of its own. Nothing rolled.");
62
63
  }
63
64
  if (input.notation === undefined && input.table === undefined && input.oracle === undefined) {
64
- throw new Error("Give the dice to roll, for example 1d20+5; or table, for a random table, or oracle, for a yes/no question.");
65
+ throw new Error(`Give the dice to roll, for example ${sheetDiceOf(campaignSystem(root, context))}+2; or table, for a random table, or oracle, for a yes/no question.`);
65
66
  }
66
67
  if (input.values && input.hidden) {
67
68
  throw new Error("Physical dice are rolled by the player, so they cannot be hidden.");
@@ -99,9 +100,12 @@ export const roll = defineCommand({
99
100
  appendLogEntry(root, entry);
100
101
  // A roll of a dying party member is their death save, which the engine writes (DIE-4, D-460).
101
102
  // A hidden roll writes nothing the player would see (review of 17 October).
102
- const said = input.who === undefined || hidden ? { lines: [] } : systemRolled(root, context, { who: input.who, notation: diceRoll.notation, total: diceRoll.total, dice: diceRoll.dice });
103
- const own = said.lines.length > 0 ? said.lines.join("\n") : roller === undefined ? undefined : rollerNote(roller.world, system, roller.page);
104
- const note = [own, said.problem].filter((line) => line !== undefined && line !== "").join("\n") || undefined;
103
+ const said = input.who === undefined || hidden
104
+ ? { lines: [], added: [] }
105
+ : packagesRolled(root, context, { who: input.who, notation: diceRoll.notation, total: diceRoll.total, faces: diceRoll.faces, dice: diceRoll.dice, text, id: entry.id });
106
+ const own = said.lines.length > 0 ? said.lines.join("\n") : roller === undefined ? undefined : rollerNote(roller.world, system, roller.page, campaignSystemWords(root, context));
107
+ // The system's lines take the place of the engine's note, as a death save does; the extensions' come after it (D-514).
108
+ const note = [own, ...said.added, said.problem].filter((line) => line !== undefined && line !== "").join("\n") || undefined;
105
109
  const shown = { kind: "roll", id: entry.id, text, total: diceRoll.total, why: input.why, who: input.who, check: input.check, physical, hidden, fingerprint: shownFingerprint, note, kept };
106
110
  // A who of no page may be a party member named wrongly: the master is told how to undo the screen (review of 25 October).
107
111
  const stranger = screened && input.who !== undefined && namesNoOne(root, context, input.who) ? { stranger: true } : {};
@@ -178,7 +182,7 @@ function keptField(root, context, who, field) {
178
182
  function keptRoll(root, context, holder, use) {
179
183
  const match = /^\s*([^=]+?)\s*=\s*([+-]?\d+)\s*$/.exec(use);
180
184
  if (match === null) {
181
- throw new Error(`Give use as the field and the kept number, such as portent=3, not "${use}". Nothing rolled.`);
185
+ throw new Error(`Give use as the field and the kept number, such as ${keptExample(campaignWorld(root, context))}=3, not "${use}". Nothing rolled.`);
182
186
  }
183
187
  if (holder === undefined) {
184
188
  throw new Error(`Give who keeps the roll, with from or who, such as from Elara. Nothing rolled.`);
@@ -219,7 +223,25 @@ function notRollsText(world, field, value) {
219
223
  const kind = declaredKind(world, field) ?? (readCounter(value) === undefined ? undefined : "counter");
220
224
  return kind === undefined
221
225
  ? `${field} keeps no rolls: declare it so first, such as config, setting fields, value "${field}: rolls".`
222
- : `${field} is ${kind === "counter" ? "a counter" : `a field of kind ${kind}`}, not kept rolls: keep and use take a field declared as rolls, such as portent.`;
226
+ : `${field} is ${kind === "counter" ? "a counter" : `a field of kind ${kind}`}, not kept rolls: keep and use take a field declared as rolls${rollsExample(world)}.`;
227
+ }
228
+ /** ", such as omen": a field the system or the campaign declares as kept rolls; how to declare one when none is. */
229
+ function rollsExample(world) {
230
+ const declared = declaredRolls(world);
231
+ return declared === undefined ? ', which config declares, such as setting fields, value "luck: rolls"' : `, such as ${declared}`;
232
+ }
233
+ /** A field of kept rolls for an example: one the system or the campaign declares, else a neutral name (D-514). */
234
+ function keptExample(world) {
235
+ return declaredRolls(world) ?? "omens";
236
+ }
237
+ function declaredRolls(world) {
238
+ return Object.keys(world.system?.fields ?? {}).find((name) => declaredKind(world, name) === "rolls");
239
+ }
240
+ /** The dice a game system rolls a number of its sheet with, for an example: that field's, else its first; 2d6 without them (D-280, D-514). */
241
+ export function sheetDiceOf(system, field) {
242
+ const dice = Object.entries(system?.sheetDice ?? {});
243
+ const own = field === undefined ? undefined : dice.find(([listed]) => comparableText(listed) === comparableText(field))?.[1];
244
+ return own ?? dice[0]?.[1] ?? "2d6";
223
245
  }
224
246
  /** " Elara keeps 3, 4 in portent: give from Elara.": the characters whose field holds the number use asked for, when the page asked does not (KEP-3). */
225
247
  function otherKeepers(world, kept, value) {
@@ -241,7 +263,9 @@ function rollWith(notation, used, source) {
241
263
  catch (error) {
242
264
  // A kept number is not a face rolled now: there is nothing to roll again.
243
265
  const why = (error instanceof DiceError ? error.message : String(error)).replace(/: ask the player to roll it again\.$/, "");
244
- throw new Error(`A kept roll takes the place of one die, of the kind it was rolled with: give a notation with that one die, such as 1d20+2 (${why}). Nothing rolled.`);
266
+ // The example with the notation's own die, as 1d6+2 for 2d6+2.
267
+ const die = /d(\d+|%|F)/i.exec(notation)?.[1] ?? "6";
268
+ throw new Error(`A kept roll takes the place of one die, of the kind it was rolled with: give a notation with that one die, such as 1d${die}+2 (${why}). Nothing rolled.`);
245
269
  }
246
270
  }
247
271
  /** Writes the dice rolled in the field of kept rolls, in place of what it held (KEP-2), and says so. */
@@ -293,7 +317,7 @@ export function withSheetValues(notation, roller, who, system) {
293
317
  // "sleight of hand": a name of several words, which a notation cannot hold.
294
318
  const words = /^\s+[A-Za-z]/.test(notation.slice(offset + whole.length));
295
319
  checkNotScore(roller, system, fields, name);
296
- const value = sheetValue(roller, fields, name, who, words);
320
+ const value = sheetValue(roller, fields, name, who, words, system);
297
321
  taken[name] = value;
298
322
  const negative = (sign === "-") !== (value < 0);
299
323
  return `${negative ? "-" : sign === "" ? "" : "+"}${Math.abs(value)}`;
@@ -308,15 +332,15 @@ function checkNotScore(roller, system, fields, name) {
308
332
  const modifier = entry?.beside === undefined ? undefined : numberOf(read(entry.beside));
309
333
  if (roller !== undefined && entry?.beside !== undefined && modifier !== undefined) {
310
334
  const worked = `${entry.beside} ${signedText(roller.world, entry.beside, modifier)}`;
311
- throw new Error(`${name} ${String(read(name))} is a score: the system ${system?.name ?? ""} works out ${worked} from it, which is what a roll adds, such as 1d20+${entry.beside}. Nothing rolled.`);
335
+ throw new Error(`${name} ${String(read(name))} is a score: the system ${system?.name ?? ""} works out ${worked} from it, which is what a roll adds, such as ${sheetDiceOf(system, entry.beside)}+${entry.beside}. Nothing rolled.`);
312
336
  }
313
337
  }
314
338
  /** The whole number a field holds on the sheet of who rolls; refused, with the numbers it has, when there is no sheet or it holds none. */
315
- function sheetValue(roller, fields, name, who, words) {
339
+ function sheetValue(roller, fields, name, who, words, system) {
316
340
  const page = roller?.page;
317
341
  if (roller === undefined || fields === undefined || page === undefined) {
318
342
  throw new Error(who === undefined
319
- ? `"${name}" is no die: to take it from a sheet, give who rolls, such as who Bruna; or give the number, such as 1d20+5.`
343
+ ? `"${name}" is no die: to take it from a sheet, give who rolls, such as who Bruna; or give the number, such as ${sheetDiceOf(system)}+2.`
320
344
  : `There is no page named ${who}, nor a copy of that name in the open scene, to take ${name} from: give who as the name of a character, or the number in the notation.`);
321
345
  }
322
346
  const value = valueNamed(fields, name);
@@ -325,15 +349,17 @@ function sheetValue(roller, fields, name, who, words) {
325
349
  // Only numbers: a class's martial-arts 1d6 or its features are no bonus (PRO-2).
326
350
  const numbers = workedFields(roller.world, fields).filter((worked) => numberOf(worked.value) !== undefined).map((worked) => `${worked.field} ${signedText(roller.world, worked.field, worked.value)}`);
327
351
  const has = numbers.length === 0 ? "" : ` Its numbers: ${numbers.join(", ")}.`;
328
- const subtraction = /-\d+$/.test(name) ? " To subtract, put spaces around the minus, such as 1d20+athletics - 1." : "";
352
+ // The master's own field in the example, as athletics - 1 for athletics-1.
353
+ const subtracted = /^(.+)-(\d+)$/.exec(name);
354
+ const subtraction = subtracted === null ? "" : ` To subtract, put spaces around the minus, such as ${sheetDiceOf(system, subtracted[1])}+${subtracted[1]} - ${subtracted[2]}.`;
329
355
  const hyphens = words ? " A name of several words is written with hyphens, such as sleight-of-hand." : "";
330
- throw new Error(`${page.name} has no ${name}.${has} Give one of them, or the number, such as 1d20+5.${subtraction}${hyphens}${missingSystemHint(roller.world)}`);
356
+ throw new Error(`${page.name} has no ${name}.${has} Give one of them, or the number, such as ${sheetDiceOf(system)}+2.${subtraction}${hyphens}${missingSystemHint(roller.world)}`);
331
357
  }
332
358
  // One value for each item of a list, as the attacks of two weapons (PRO-5): the roll takes the number of the one used.
333
359
  const list = itemList(roller.world, name);
334
360
  const first = typeof value === "string" ? /[+-]\d+/.exec(value)?.[0] : undefined;
335
361
  if (number === undefined && list !== undefined && first !== undefined) {
336
- throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}, one for each item in its ${list}: give the number of the one used, such as 1d20${first}.`);
362
+ throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}, one for each item in its ${list}: give the number of the one used, such as ${sheetDiceOf(system, name)}${first}.`);
337
363
  }
338
364
  if (number === undefined || !Number.isInteger(number)) {
339
365
  throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}, not a whole number: give the number in the notation.`);
@@ -342,11 +368,11 @@ function sheetValue(roller, fields, name, who, words) {
342
368
  }
343
369
  /**
344
370
  * "Lena has Poisoned, Bless, exhaustion 1: see whether they change this roll.": the effects on who rolls that are not already in their numbers, being no more
345
- * than a name, and the conditions (DAT-6); then the fields of their line written with ?, when they are not at zero (DAT-8).
371
+ * than a name, and the conditions, maybe in the campaign's language (DAT-6, D-403); then the fields of their line written with ?, when they are not at zero (DAT-8).
346
372
  */
347
- function rollerNote(world, system, page) {
373
+ function rollerNote(world, system, page, words) {
348
374
  const fields = effectiveFields(world, page);
349
- const effects = effectsOf(page).filter((effect) => effect.values.length === 0 || sameName(system?.conditions ?? [], effect.name) !== undefined);
375
+ const effects = effectsOf(page).filter((effect) => effect.values.length === 0 || systemNamed(system?.conditions ?? [], effect.name, words) !== undefined);
350
376
  // Kept rolls are no number that changes a roll: use takes them.
351
377
  const marked = (system?.statusLine ?? []).filter((entry) => entry.whenSet && declaredKind(world, entry.field) !== "rolls").flatMap((entry) => {
352
378
  const value = valueNamed(fields, entry.field);
@@ -5,8 +5,9 @@ import { defineCommand } from "../core/registry.js";
5
5
  import { comparableText } from "../core/text.js";
6
6
  import { findPage, pageFileNamed, pageNamed as pageWithName, sectionTitles } from "../pages/index.js";
7
7
  import { bookTitles, findRules, hasAllWords, readRuleBook, shownRules } from "../rules/index.js";
8
+ import { systemContentFolders } from "../systems/index.js";
8
9
  import { libraryAnswer, libraryLines, systemWordsNamed } from "./game-library.js";
9
- import { disagreementAdvice, houseRules, precedentRule } from "./game-rules.js";
10
+ import { disagreementAdvice, houseRules, precedentRule, systemRuleBook } from "./game-rules.js";
10
11
  import { campaignSystem, campaignWorld, foreignLanguage } from "./game-world.js";
11
12
  // About how many words an answer shows: a section of the system has about 80 words in the middle (D-178).
12
13
  const answerWords = 800;
@@ -18,7 +19,7 @@ export const rules = defineCommand({
18
19
  name: "rules",
19
20
  description: "Find the exact text of a rule: the campaign's house rules first, then the game system's rules, then the table's precedents. "
20
21
  + "Use it whenever you are unsure how a rule works, before you rule and say what is at stake, and when the player questions a ruling. "
21
- + "Give the book's words, such as grappled, opportunity attack or long rest; a heading, or headings joined by ›, reads that section. "
22
+ + "Give the book's words, such as grappled, cover or falling; a heading, or headings joined by ›, reads that section. "
22
23
  + "It searches the player's own books too, after the system, each excerpt with its book and page: Book › p. 194 reads that page.",
23
24
  group: "game",
24
25
  readOnly: true,
@@ -33,7 +34,7 @@ export const rules = defineCommand({
33
34
  // Read one by one, as the system is (SYS-1): a mistake elsewhere in campaign.yaml does not stop the rules.
34
35
  const precedents = readListSetting(root, "precedents");
35
36
  const house = readRuleBook(join(root, houseRulesFolderName), houseRules);
36
- const book = system === undefined ? [] : readRuleBook(join(system.folder, "rules"), system.name);
37
+ const book = system === undefined ? [] : systemRuleBook(system);
37
38
  const text = input.text?.trim() ?? "";
38
39
  const common = {
39
40
  text,
@@ -114,7 +115,8 @@ function isAboutAny(precedent, text, titles) {
114
115
  */
115
116
  function pageNamed(root, context, system, text) {
116
117
  const page = pageFileNamed(root, text);
117
- const systemPage = page === undefined && system !== undefined ? pageFileNamed(system.folder, text) : undefined;
118
+ // The version's page first, which takes the place of a common one (VER-3).
119
+ const systemPage = page === undefined && system !== undefined ? [...systemContentFolders(system)].reverse().map((folder) => pageFileNamed(folder, text)).find((found) => found !== undefined) : undefined;
118
120
  if (page !== undefined) {
119
121
  return page;
120
122
  }
@@ -32,8 +32,8 @@ export declare const scene: import("../core/registry.ts").Command<z.ZodObject<{
32
32
  hostile: "hostile";
33
33
  add: "add";
34
34
  close: "close";
35
- use: "use";
36
35
  order: "order";
36
+ use: "use";
37
37
  now: "now";
38
38
  leave: "leave";
39
39
  calm: "calm";