rpg-engine 0.3.0 → 0.4.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.
- package/README.md +1 -1
- package/dist/campaign/index.d.ts +1 -1
- package/dist/campaign/index.js +1 -1
- package/dist/campaign/settings.d.ts +10 -1
- package/dist/campaign/settings.js +9 -2
- package/dist/command-line.js +6 -1
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +41 -7
- package/dist/commands/game-master-rolls.d.ts +15 -0
- package/dist/commands/game-master-rolls.js +34 -0
- package/dist/commands/game-mode.js +2 -1
- package/dist/commands/game-system-code.js +8 -1
- package/dist/commands/game-tables.d.ts +7 -0
- package/dist/commands/game-tables.js +40 -0
- package/dist/commands/game-upkeep.js +1 -1
- package/dist/commands/package.js +5 -3
- package/dist/commands/roll.d.ts +4 -0
- package/dist/commands/roll.js +73 -18
- package/dist/dashboard/i18n/ar.json +6 -0
- package/dist/dashboard/i18n/cs.json +6 -0
- package/dist/dashboard/i18n/da.json +6 -0
- package/dist/dashboard/i18n/de.json +6 -0
- package/dist/dashboard/i18n/el.json +6 -0
- package/dist/dashboard/i18n/es.json +6 -0
- package/dist/dashboard/i18n/fi.json +6 -0
- package/dist/dashboard/i18n/fr.json +6 -0
- package/dist/dashboard/i18n/he.json +6 -0
- package/dist/dashboard/i18n/hi.json +6 -0
- package/dist/dashboard/i18n/hu.json +6 -0
- package/dist/dashboard/i18n/is.json +6 -0
- package/dist/dashboard/i18n/it.json +6 -0
- package/dist/dashboard/i18n/ja.json +6 -0
- package/dist/dashboard/i18n/ko.json +6 -0
- package/dist/dashboard/i18n/nb.json +6 -0
- package/dist/dashboard/i18n/nl.json +6 -0
- package/dist/dashboard/i18n/pl.json +6 -0
- package/dist/dashboard/i18n/pt.json +6 -0
- package/dist/dashboard/i18n/ro.json +6 -0
- package/dist/dashboard/i18n/ru.json +6 -0
- package/dist/dashboard/i18n/sv.json +6 -0
- package/dist/dashboard/i18n/tr.json +6 -0
- package/dist/dashboard/i18n/uk.json +6 -0
- package/dist/dashboard/i18n/zh.json +6 -0
- package/dist/dashboard/labels.js +3 -0
- package/dist/dashboard/settings.js +3 -3
- package/dist/dice/index.d.ts +2 -0
- package/dist/dice/index.js +3 -1
- package/dist/dice/oracle.d.ts +19 -0
- package/dist/dice/oracle.js +22 -0
- package/dist/dice/tables.d.ts +29 -0
- package/dist/dice/tables.js +123 -0
- package/dist/pages/index.d.ts +1 -1
- package/dist/pages/index.js +1 -1
- package/dist/pages/markdown.d.ts +8 -0
- package/dist/pages/markdown.js +27 -0
- package/dist/systems/system-code.d.ts +1 -1
- package/instructions/combat.md +1 -1
- package/instructions/core.md +1 -1
- package/instructions/play.md +1 -1
- package/package.json +2 -2
- package/systems/5e/instructions/play.md +1 -0
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ Today RPG Engine plays **fifth edition**, from the free System Reference Documen
|
|
|
42
42
|
|
|
43
43
|
## What you need
|
|
44
44
|
|
|
45
|
-
**Node.js 22** or newer, a web browser, and an AI agent to be the master: an AI app that can work with the files on your computer, such as Claude Code or Codex. A plain chat such as claude.ai or ChatGPT, or a phone app, is not enough: the master needs to reach the campaign's files on your computer.
|
|
45
|
+
**Node.js 22.4** or newer, a web browser, and an AI agent to be the master: an AI app that can work with the files on your computer, such as Claude Code or Codex. A plain chat such as claude.ai or ChatGPT, or a phone app, is not enough: the master needs to reach the campaign's files on your computer.
|
|
46
46
|
|
|
47
47
|
RPG Engine is tied to no AI company: any agent that supports MCP tools can be the master, local ones included. We play and test it with **Claude Code**; **Codex** is connected and checked, but no whole campaign has been played with it yet; [the guide](https://github.com/stefanocaronia/rpg-engine/blob/main/src/dashboard/guide/en.md#24-connect-your-ai) says how to connect any other agent. Give the master the largest model you have: a small one is easier to talk into revealing secrets or bending the rules.
|
|
48
48
|
|
package/dist/campaign/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createCampaign } from "./create-campaign.ts";
|
|
2
2
|
export { campaignFileName, findCampaign, houseRulesFolderName, requireCampaign } from "./find-campaign.ts";
|
|
3
3
|
export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.ts";
|
|
4
|
-
export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, companionWays, type CountedByGame, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readCoinsSetting, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingMeaning, type SettingName, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.ts";
|
|
4
|
+
export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, companionWays, type CountedByGame, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readCoinsSetting, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingMeaning, type SettingName, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.ts";
|
|
5
5
|
export { type CampaignState, changeState, changeStateAt, readState, readStateValues } from "./state.ts";
|
package/dist/campaign/index.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
export { createCampaign } from "./create-campaign.js";
|
|
3
3
|
export { campaignFileName, findCampaign, houseRulesFolderName, requireCampaign } from "./find-campaign.js";
|
|
4
4
|
export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.js";
|
|
5
|
-
export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readCoinsSetting, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.js";
|
|
5
|
+
export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readCoinsSetting, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.js";
|
|
6
6
|
export { changeState, changeStateAt, readState, readStateValues } from "./state.js";
|
|
@@ -29,6 +29,8 @@ export declare const mentorMeanings: Record<(typeof mentorWays)[number], string>
|
|
|
29
29
|
export declare function settingMeaning(name: string, value: unknown, counted?: CountedByGame): string | undefined;
|
|
30
30
|
/** Who rolls the player character's dice (D-241): rpg, or the player with their own, telling the values; the master's are always rolled by rpg. */
|
|
31
31
|
export declare const diceWays: readonly ["digital", "physical"];
|
|
32
|
+
/** Whether the master's rolls for anyone outside the party are hidden (D-287): behind the screen, unset too, or in view; the party's are always shown. */
|
|
33
|
+
export declare const masterRollWays: readonly ["behind the screen", "in view"];
|
|
32
34
|
/**
|
|
33
35
|
* Who voices the characters (D-490), where the AI app has subagents: a character as a subagent of its own at key moments, the master chooses (auto); the master
|
|
34
36
|
* always; always for the companions and the main characters; always for everyone.
|
|
@@ -107,6 +109,10 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
107
109
|
digital: "digital";
|
|
108
110
|
physical: "physical";
|
|
109
111
|
}>>;
|
|
112
|
+
"master-rolls": z.ZodOptional<z.ZodEnum<{
|
|
113
|
+
"behind the screen": "behind the screen";
|
|
114
|
+
"in view": "in view";
|
|
115
|
+
}>>;
|
|
110
116
|
units: z.ZodOptional<z.ZodEnum<{
|
|
111
117
|
metric: "metric";
|
|
112
118
|
imperial: "imperial";
|
|
@@ -162,7 +168,10 @@ export declare const listSettingNames: SettingName[];
|
|
|
162
168
|
export declare const mapSettingNames: SettingName[];
|
|
163
169
|
/** The settings that hold entries by name: what the campaign adds to its game system, and where the dashboard shows the extensions' widgets (D-502). */
|
|
164
170
|
export declare const entrySettingNames: SettingName[];
|
|
165
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* What only the setup asks (D-241, MOD-3, D-347, D-287): how much the master teaches the game, whether the master's rolls are shown, how the companions come,
|
|
173
|
+
* when the story starts, and the lines and veils, which "none" answers too.
|
|
174
|
+
*/
|
|
166
175
|
export declare const setupSettingNames: SettingName[];
|
|
167
176
|
/** What the setup asks only of a campaign without a written world (D-79, D-80, MOD-3). */
|
|
168
177
|
export declare const premiseSettingNames: SettingName[];
|
|
@@ -68,6 +68,8 @@ export function settingMeaning(name, value, counted) {
|
|
|
68
68
|
}
|
|
69
69
|
/** Who rolls the player character's dice (D-241): rpg, or the player with their own, telling the values; the master's are always rolled by rpg. */
|
|
70
70
|
export const diceWays = ["digital", "physical"];
|
|
71
|
+
/** Whether the master's rolls for anyone outside the party are hidden (D-287): behind the screen, unset too, or in view; the party's are always shown. */
|
|
72
|
+
export const masterRollWays = ["behind the screen", "in view"];
|
|
71
73
|
/**
|
|
72
74
|
* Who voices the characters (D-490), where the AI app has subagents: a character as a subagent of its own at key moments, the master chooses (auto); the master
|
|
73
75
|
* always; always for the companions and the main characters; always for everyone.
|
|
@@ -128,6 +130,8 @@ export const settingsSchema = z.object({
|
|
|
128
130
|
saves: z.enum(saveModes).optional().describe("when the game may go back: permadeath (never, but to the start, the campaign starting over), checkpoint (to the last end of a scene, once the player character dies) or free (to any save, and saves when the player asks)"),
|
|
129
131
|
rigor: z.enum(rigors).optional().describe("how closely travel, fatigue, food and the like follow the rules: smooth (the master glosses over them), rules (as written) or simulation (beyond them)"),
|
|
130
132
|
dice: z.enum(diceWays).optional().describe("the player character's dice: digital (rpg rolls them) or physical (the player rolls their own and tells the values)"),
|
|
133
|
+
"master-rolls": z.enum(masterRollWays).optional().describe("the master's rolls for foes and anyone else outside the party: behind the screen (roll hides them, the master telling only the outcome) or in view (roll shows them); "
|
|
134
|
+
+ "the party's rolls are always shown; unset, behind the screen"),
|
|
131
135
|
units: z.enum(unitSystems).optional().describe("the units of measure of the story: metric or imperial"),
|
|
132
136
|
voices: z.enum(voiceWays).optional().describe("who voices the characters, where the AI app has subagents, from the master to the characters: master (the master, always), auto (at key moments, as the master chooses, "
|
|
133
137
|
+ "a character answers as a subagent of its own, knowing only what it knows), important (always a subagent for the companions and the characters with kind main), "
|
|
@@ -171,8 +175,11 @@ export const listSettingNames = ["lines", "veils", "table", "precedents", "learn
|
|
|
171
175
|
export const mapSettingNames = ["fields", "tables", "computed", "counters", "recipes", "travel", "values"];
|
|
172
176
|
/** The settings that hold entries by name: what the campaign adds to its game system, and where the dashboard shows the extensions' widgets (D-502). */
|
|
173
177
|
export const entrySettingNames = [...mapSettingNames, "widgets"];
|
|
174
|
-
/**
|
|
175
|
-
|
|
178
|
+
/**
|
|
179
|
+
* What only the setup asks (D-241, MOD-3, D-347, D-287): how much the master teaches the game, whether the master's rolls are shown, how the companions come,
|
|
180
|
+
* when the story starts, and the lines and veils, which "none" answers too.
|
|
181
|
+
*/
|
|
182
|
+
export const setupSettingNames = ["mentor", "master-rolls", "companions", "calendar-start", "lines", "veils"];
|
|
176
183
|
/** What the setup asks only of a campaign without a written world (D-79, D-80, MOD-3). */
|
|
177
184
|
export const premiseSettingNames = ["premise", "preparation"];
|
|
178
185
|
// Settings that only some games have, or that only the setup asks: never asked for in play when missing.
|
package/dist/command-line.js
CHANGED
|
@@ -73,11 +73,16 @@ function readArguments(command, args) {
|
|
|
73
73
|
const positionals = command.positionals ?? [];
|
|
74
74
|
const options = { json: { type: "boolean" } };
|
|
75
75
|
for (const [name, field] of inputFields(command)) {
|
|
76
|
+
// --no-x turns x off: a field named no-x would be lost, as an extension's might be (review of 25 October).
|
|
77
|
+
if (name.startsWith("no-")) {
|
|
78
|
+
throw new Error(`${command.name} has a field named ${name}, and none may start with no-, which the command line reads as turning ${name.slice(3)} off: rename it.`);
|
|
79
|
+
}
|
|
76
80
|
if (!positionals.includes(name)) {
|
|
77
81
|
options[name] = { type: isBoolean(field) ? "boolean" : "string", multiple: isList(field) };
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
|
|
84
|
+
// A flag is turned off as --no-hidden, where a setting would turn it on, as the MCP server takes hidden: false.
|
|
85
|
+
const parsed = parseArgs({ args, options, allowPositionals: true, allowNegative: true, strict: true, tokens: true });
|
|
81
86
|
// The last positional, when it is a list, takes the arguments left before the first option, as in rpg move Ettore Lena --to Ossario.
|
|
82
87
|
const last = positionals.at(-1);
|
|
83
88
|
const takesRest = last !== undefined && isList(command.input.shape[last]);
|
|
@@ -14,7 +14,7 @@ interface ConfigResult {
|
|
|
14
14
|
part?: string;
|
|
15
15
|
}
|
|
16
16
|
/** The settings the player changes on the dashboard (D-341): how the game plays for them; the master's own, as house rules, coins and precedents, stay in the chat. */
|
|
17
|
-
export declare const playerSettingNames: readonly ["difficulty", "lethality", "saves", "rigor", "mentor", "learned", "prose", "story", "author", "style", "dice", "units", "voices", "pictures", "effort", "lines", "veils", "language"];
|
|
17
|
+
export declare const playerSettingNames: readonly ["difficulty", "lethality", "saves", "rigor", "mentor", "learned", "prose", "story", "author", "style", "dice", "master-rolls", "units", "voices", "pictures", "effort", "lines", "veils", "language"];
|
|
18
18
|
/** A setting of the player's as the dashboard shows it (D-341): what it is, its value or a list's items, and its values with what each means to the player. */
|
|
19
19
|
export interface PlayerSetting {
|
|
20
20
|
name: string;
|
package/dist/commands/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { parse, stringify } from "yaml";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, clearSetting, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, mentorWays, pictureWays, preparations, proseWays, readCampaignData, readSettings, readTextSetting, refreshHostFiles, requireCampaign, rigors, saveModes, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unitSystems, voiceWays, writeEffortFiles, } from "../campaign/index.js";
|
|
4
|
+
import { changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, clearSetting, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, pictureWays, preparations, proseWays, readCampaignData, readSettings, readTextSetting, refreshHostFiles, requireCampaign, rigors, saveModes, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unitSystems, voiceWays, writeEffortFiles, } from "../campaign/index.js";
|
|
5
5
|
import { appendLogEntry } from "../core/log.js";
|
|
6
6
|
import { defineCommand } from "../core/registry.js";
|
|
7
7
|
import { comparableText } from "../core/text.js";
|
|
@@ -33,6 +33,7 @@ export const config = defineCommand({
|
|
|
33
33
|
+ "saves, when the game may go back: permadeath (never, only to the start, the campaign starting over), checkpoint (to the last end of a scene, once the player character dies), free (to any save, and saves when the player asks). "
|
|
34
34
|
+ "rigor, how closely travel, fatigue, food and the like follow the rules: smooth (you gloss over them), rules (as written), simulation (beyond them). "
|
|
35
35
|
+ "dice, who rolls the player character's dice: digital (rpg) or physical (the player, who tells you the values). units: metric or imperial. "
|
|
36
|
+
+ "master-rolls, your rolls for foes and NPCs: behind the screen (roll hides them, unset too: tell only the outcome) or in view; the party's are always shown. "
|
|
36
37
|
+ "voices, who voices the characters where your app has subagents: master (you, always), auto (a subagent at key moments, as you choose), "
|
|
37
38
|
+ "important (always a subagent for the companions and the characters with kind main), always (always a subagent); unset, auto. "
|
|
38
39
|
+ "companions: none, made with the player or made by the master in session zero, or met in play. "
|
|
@@ -202,7 +203,27 @@ function configure(input, context) {
|
|
|
202
203
|
const freeSettingNames = ["author", "style", "calendar"];
|
|
203
204
|
const styleSettingNames = ["prose", "story", "author", "style"];
|
|
204
205
|
/** The settings the player changes on the dashboard (D-341): how the game plays for them; the master's own, as house rules, coins and precedents, stay in the chat. */
|
|
205
|
-
export const playerSettingNames = [
|
|
206
|
+
export const playerSettingNames = [
|
|
207
|
+
"difficulty",
|
|
208
|
+
"lethality",
|
|
209
|
+
"saves",
|
|
210
|
+
"rigor",
|
|
211
|
+
"mentor",
|
|
212
|
+
"learned",
|
|
213
|
+
"prose",
|
|
214
|
+
"story",
|
|
215
|
+
"author",
|
|
216
|
+
"style",
|
|
217
|
+
"dice",
|
|
218
|
+
"master-rolls",
|
|
219
|
+
"units",
|
|
220
|
+
"voices",
|
|
221
|
+
"pictures",
|
|
222
|
+
"effort",
|
|
223
|
+
"lines",
|
|
224
|
+
"veils",
|
|
225
|
+
"language",
|
|
226
|
+
];
|
|
206
227
|
// What each of the player's settings is, and what its values mean to the player, in their words rather than the master's.
|
|
207
228
|
const playerWords = {
|
|
208
229
|
difficulty: {
|
|
@@ -278,6 +299,12 @@ const playerWords = {
|
|
|
278
299
|
cleared: "their own words on how you write no longer hold",
|
|
279
300
|
},
|
|
280
301
|
dice: { about: "who rolls your character's dice", values: diceWays, means: { digital: "the engine rolls them", physical: "you roll your own and tell the values" } },
|
|
302
|
+
"master-rolls": {
|
|
303
|
+
about: "the master's rolls for foes and the characters you meet; yours and your companions' are always in view",
|
|
304
|
+
values: masterRollWays,
|
|
305
|
+
means: { "behind the screen": "hidden: the master tells you only what comes of them", "in view": "shown among the rolls, beside yours" },
|
|
306
|
+
unset: "behind the screen",
|
|
307
|
+
},
|
|
281
308
|
units: { about: "the units of the story", values: unitSystems, means: { metric: "metres and kilometres", imperial: "feet and miles" } },
|
|
282
309
|
voices: {
|
|
283
310
|
about: "who speaks for the characters you meet",
|
|
@@ -326,11 +353,11 @@ const setupWords = {
|
|
|
326
353
|
};
|
|
327
354
|
// The setup's questions, in the order the player meets them on the dashboard: how well they know the game, how it plays, how it is rolled, who comes along,
|
|
328
355
|
// then the limits.
|
|
329
|
-
const setupOrder = ["mentor", "difficulty", "lethality", "saves", "rigor", "dice", "units", "companions", "preparation"];
|
|
356
|
+
const setupOrder = ["mentor", "difficulty", "lethality", "saves", "rigor", "dice", "master-rolls", "units", "companions", "preparation"];
|
|
330
357
|
// The mentor as the setup asks it (D-347): how well the player knows the game, each answer a way of the mentor, from the newest player's.
|
|
331
358
|
const mentorAnswers = { tutorial: "never played it", hints: "a little", off: "I know it" };
|
|
332
359
|
// The values the game suggests in the setup, as the design has them by default (D-370): never chosen for the player.
|
|
333
|
-
const suggestedValues = { saves: "checkpoint", rigor: "smooth", preparation: "on the fly" };
|
|
360
|
+
const suggestedValues = { saves: "checkpoint", rigor: "smooth", "master-rolls": "behind the screen", preparation: "on the fly" };
|
|
334
361
|
// The lethality the difficulty suggests (D-141).
|
|
335
362
|
const suggestedLethality = { story: "narrative", easy: "epic" };
|
|
336
363
|
/**
|
|
@@ -344,13 +371,19 @@ export function setupQuestions(root, context, writtenWorld) {
|
|
|
344
371
|
return setting === undefined ? [] : [setting];
|
|
345
372
|
};
|
|
346
373
|
const system = (campaignSystem(root, context)?.settings ?? []).map((setting) => setting.name);
|
|
347
|
-
const
|
|
374
|
+
const settings = readSettings(root);
|
|
375
|
+
const difficulty = settings.difficulty;
|
|
348
376
|
const suggested = { ...suggestedValues, ...(difficulty === undefined ? {} : { lethality: suggestedLethality[difficulty] ?? "dice" }) };
|
|
349
377
|
return [...setupOrder.filter((name) => name !== "preparation" || !writtenWorld), ...system, "lines", "veils"].flatMap(named).map((question) => ({
|
|
350
|
-
...(question.name === "mentor" ? mentorQuestion(question) : question),
|
|
378
|
+
...(question.name === "mentor" ? mentorQuestion(question) : unsetUnanswered(question, settings)),
|
|
351
379
|
...(suggested[question.name] === undefined ? {} : { suggested: suggested[question.name] }),
|
|
352
380
|
}));
|
|
353
381
|
}
|
|
382
|
+
/** A question whose value is only the one shown while it is unset, as master-rolls behind the screen (D-287): still unanswered in the setup. */
|
|
383
|
+
function unsetUnanswered(question, settings) {
|
|
384
|
+
const { value, ...unanswered } = question;
|
|
385
|
+
return value !== undefined && wordsOf(question.name)?.unset === value && settings[question.name] === undefined ? unanswered : question;
|
|
386
|
+
}
|
|
354
387
|
/** The mentor as the setup asks it (D-347): how well the player knows the game, never played it first. */
|
|
355
388
|
function mentorQuestion(question) {
|
|
356
389
|
const order = Object.keys(mentorAnswers);
|
|
@@ -507,7 +540,7 @@ function shownValue(root, context, settings, name) {
|
|
|
507
540
|
return settings[name] ?? {};
|
|
508
541
|
}
|
|
509
542
|
// How the master writes, unset: the core's own ways, never missing (D-395).
|
|
510
|
-
// And the master's effort, unset: each app's own, the player's to choose (D-462); who voices the characters, unset: auto (D-490).
|
|
543
|
+
// And the master's effort, unset: each app's own, the player's to choose (D-462); who voices the characters, unset: auto (D-490); the master's rolls, behind the screen (D-287).
|
|
511
544
|
const own = {
|
|
512
545
|
prose: "plain (as your instructions write)",
|
|
513
546
|
story: "situations (as your instructions write)",
|
|
@@ -515,6 +548,7 @@ function shownValue(root, context, settings, name) {
|
|
|
515
548
|
style: "(none)",
|
|
516
549
|
effort: "(the app's own: the player's to choose)",
|
|
517
550
|
voices: "auto (a subagent at key moments, as you choose, where the app has them)",
|
|
551
|
+
"master-rolls": "behind the screen (unset: roll hides your rolls for foes and NPCs)",
|
|
518
552
|
};
|
|
519
553
|
if (settings[name] === undefined && Object.hasOwn(own, name)) {
|
|
520
554
|
return own[name];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Context } from "../core/context.ts";
|
|
2
|
+
import type { LogEntry } from "../core/log.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the master-rolls setting hides a roll of who: one for anyone the party does not hold, by name or alias, as a foe's copy in the scene or a name of
|
|
5
|
+
* no page; never a roll of no one, as an oracle's.
|
|
6
|
+
*/
|
|
7
|
+
export declare function behindTheScreen(root: string, context: Context, who: string | undefined): boolean;
|
|
8
|
+
/** Whether who is the player character or a companion, by name or alias, dead ones too. */
|
|
9
|
+
export declare function ofTheParty(root: string, context: Context, who: string): boolean;
|
|
10
|
+
/** Whether the campaign keeps the master's own rolls, as a table's or the oracle's, behind the screen: unless master-rolls says in view. */
|
|
11
|
+
export declare function screenUp(root: string): boolean;
|
|
12
|
+
/** Whether who names no page and no copy in the open scene: a stranger named in words, or a party member named wrongly. */
|
|
13
|
+
export declare function namesNoOne(root: string, context: Context, who: string): boolean;
|
|
14
|
+
/** Seals a hidden roll's line with its proof, kept for a reveal, and gives the fingerprint the player may ask for. */
|
|
15
|
+
export declare function sealHiddenRoll(entry: LogEntry, text: string, context: Context): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The master's rolls for anyone outside the party (D-287): hidden behind the screen, as the master-rolls setting has them when unset too, or in view.
|
|
2
|
+
import { readTextSetting } from "../campaign/index.js";
|
|
3
|
+
import { sameName } from "../core/text.js";
|
|
4
|
+
import { createProof, fingerprint } from "../dice/index.js";
|
|
5
|
+
import { isPartyMember, pagesWithNameOrAlias } from "../pages/index.js";
|
|
6
|
+
import { readOpenScene } from "./game-scene.js";
|
|
7
|
+
import { campaignWorld } from "./game-world.js";
|
|
8
|
+
/**
|
|
9
|
+
* Whether the master-rolls setting hides a roll of who: one for anyone the party does not hold, by name or alias, as a foe's copy in the scene or a name of
|
|
10
|
+
* no page; never a roll of no one, as an oracle's.
|
|
11
|
+
*/
|
|
12
|
+
export function behindTheScreen(root, context, who) {
|
|
13
|
+
return who !== undefined && screenUp(root) && !ofTheParty(root, context, who);
|
|
14
|
+
}
|
|
15
|
+
/** Whether who is the player character or a companion, by name or alias, dead ones too. */
|
|
16
|
+
export function ofTheParty(root, context, who) {
|
|
17
|
+
return pagesWithNameOrAlias(campaignWorld(root, context), who).some(isPartyMember);
|
|
18
|
+
}
|
|
19
|
+
/** Whether the campaign keeps the master's own rolls, as a table's or the oracle's, behind the screen: unless master-rolls says in view. */
|
|
20
|
+
export function screenUp(root) {
|
|
21
|
+
return readTextSetting(root, "master-rolls") !== "in view";
|
|
22
|
+
}
|
|
23
|
+
/** Whether who names no page and no copy in the open scene: a stranger named in words, or a party member named wrongly. */
|
|
24
|
+
export function namesNoOne(root, context, who) {
|
|
25
|
+
const copies = Object.keys(readOpenScene(root).scene?.copies ?? {});
|
|
26
|
+
return pagesWithNameOrAlias(campaignWorld(root, context), who).length === 0 && sameName(copies, who) === undefined;
|
|
27
|
+
}
|
|
28
|
+
/** Seals a hidden roll's line with its proof, kept for a reveal, and gives the fingerprint the player may ask for. */
|
|
29
|
+
export function sealHiddenRoll(entry, text, context) {
|
|
30
|
+
const proof = createProof(entry.id, text, context.newSalt());
|
|
31
|
+
const shown = fingerprint(proof);
|
|
32
|
+
Object.assign(entry.data, { proof, fingerprint: shown });
|
|
33
|
+
return shown;
|
|
34
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The mode of the campaign, the main state of the game (D-77): setup, session zero or play, each opened by the checklist of the one before (D-221, D-241; MOD-1–MOD-7).
|
|
2
2
|
import { basename } from "node:path";
|
|
3
|
-
import { companionWays, diceWays, difficulties, lethalities, missingSettings, preparations, readSettings, readStateValues, rigors, saveModes, unansweredSettings, unitSystems } from "../campaign/index.js";
|
|
3
|
+
import { companionWays, diceWays, difficulties, lethalities, masterRollWays, missingSettings, preparations, readSettings, readStateValues, rigors, saveModes, unansweredSettings, unitSystems } from "../campaign/index.js";
|
|
4
4
|
import { readLog } from "../core/log.js";
|
|
5
5
|
import { comparableText } from "../core/text.js";
|
|
6
6
|
import { isInParty, playerCharacters } from "../pages/index.js";
|
|
@@ -21,6 +21,7 @@ const settingLabels = {
|
|
|
21
21
|
saves: `saves (${saveModes.join(", ")})`,
|
|
22
22
|
rigor: `rigor (${rigors.join(", ")})`,
|
|
23
23
|
dice: `dice (${diceWays.join(", ")})`,
|
|
24
|
+
"master-rolls": `master-rolls (your rolls for foes and NPCs: ${masterRollWays.join(", ")}; suggest behind the screen)`,
|
|
24
25
|
units: `units (${unitSystems.join(", ")})`,
|
|
25
26
|
companions: `companions (${companionWays.join(", ")})`,
|
|
26
27
|
"calendar-start": "calendar-start (when the story starts: day 1 to count only the days, or a day of the world, such as 14 April 1491)",
|
|
@@ -9,6 +9,7 @@ import { withEffect } from "../effects/index.js";
|
|
|
9
9
|
import { concernsPlayer, isPartyMember, isPlayerCharacter, pagesWithName, writePage } from "../pages/index.js";
|
|
10
10
|
import { effectiveFields, effectsOf } from "./effect-layer.js";
|
|
11
11
|
import { saveEffects } from "./game-effects.js";
|
|
12
|
+
import { behindTheScreen, sealHiddenRoll } from "./game-master-rolls.js";
|
|
12
13
|
import { keepingConditionNote } from "./game-reminders.js";
|
|
13
14
|
import { readOpenScene } from "./game-scene.js";
|
|
14
15
|
import { newDatedLogEntry } from "./game-time.js";
|
|
@@ -95,7 +96,13 @@ function game(root, context) {
|
|
|
95
96
|
endEffect: (name, effect, why) => endEffect(root, context, name, effect, why),
|
|
96
97
|
roll: (notation, by) => {
|
|
97
98
|
const rolled = rollDice(notation, { random: context.random });
|
|
98
|
-
|
|
99
|
+
// For anyone outside the party, hidden as the master-rolls setting says (D-287).
|
|
100
|
+
const hidden = behindTheScreen(root, context, by.who);
|
|
101
|
+
const entry = newDatedLogEntry(root, context, "roll", hidden ? "hidden" : "public", { notation: rolled.notation, total: rolled.total, result: rolled.text, why: by.why, who: by.who, physical: false, dice: rolled.dice });
|
|
102
|
+
if (hidden) {
|
|
103
|
+
sealHiddenRoll(entry, rolled.text, context);
|
|
104
|
+
}
|
|
105
|
+
appendLogEntry(root, entry);
|
|
99
106
|
return { total: rolled.total, dice: rolled.dice, text: rolled.text };
|
|
100
107
|
},
|
|
101
108
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context } from "../core/context.ts";
|
|
2
|
+
import { type FaceSource, type TableRoll } from "../dice/index.ts";
|
|
3
|
+
/** A roll on the table of a page's section, given as Page#Section; refused, saying what to fix, before anything is rolled. */
|
|
4
|
+
export declare function rollPageTable(root: string, context: Context, reference: string, source: FaceSource): TableRoll & {
|
|
5
|
+
table: string;
|
|
6
|
+
secret: boolean;
|
|
7
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { comparableText } from "../core/text.js";
|
|
2
|
+
import { DiceError, readRandomTable, rollOnTable } from "../dice/index.js";
|
|
3
|
+
import { baseChain, findPage, firstTable, pageNamed, parsePageReference, readSection, secretNames, sectionTitles } from "../pages/index.js";
|
|
4
|
+
import { campaignWorld, missingSystemHint } from "./game-world.js";
|
|
5
|
+
/** A roll on the table of a page's section, given as Page#Section; refused, saying what to fix, before anything is rolled. */
|
|
6
|
+
export function rollPageTable(root, context, reference, source) {
|
|
7
|
+
const { name, section } = parsePageReference(reference);
|
|
8
|
+
if (name.trim() === "") {
|
|
9
|
+
throw new Error(`Give the page before #, such as Colli di Vallerana#${section ?? "Incontri"}. Nothing rolled.`);
|
|
10
|
+
}
|
|
11
|
+
if (section === undefined || section === "") {
|
|
12
|
+
throw new Error(`Give the section that holds the table after #, such as ${name || "Colli di Vallerana"}#Incontri. Nothing rolled.`);
|
|
13
|
+
}
|
|
14
|
+
const world = campaignWorld(root, context);
|
|
15
|
+
const page = findPage(world, name) ?? pageNamed(world, name);
|
|
16
|
+
if (page === undefined) {
|
|
17
|
+
throw new Error(`There is no page named ${name}: give the page and the section of its table, such as Colli di Vallerana#Incontri; look for the page with the find command.${missingSystemHint(world)} Nothing rolled.`);
|
|
18
|
+
}
|
|
19
|
+
// The page's own section, or its nearest base's (INH-13).
|
|
20
|
+
const text = [page, ...baseChain(world, page)].map((holder) => readSection(holder.body, section)).find((found) => found !== undefined);
|
|
21
|
+
if (text === undefined) {
|
|
22
|
+
const titles = sectionTitles(page.body);
|
|
23
|
+
throw new Error(`${page.name} has no section "${section}". ${titles.length === 0 ? "It has no sections." : `Its sections are: ${titles.join(", ")}.`} Nothing rolled.`);
|
|
24
|
+
}
|
|
25
|
+
const table = firstTable(text);
|
|
26
|
+
if (table === undefined) {
|
|
27
|
+
throw new Error(`${page.name}#${section} holds no table: write one under its heading, the die in the first header cell and each row's numbers in the first column, such as | d8 | Encounter |, |---|---|, | 1–2 | Wolves |. Nothing rolled.`);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// A table in a secret, or a secret named after #, is the master's alone.
|
|
31
|
+
const secret = table.secret || secretNames(page.body).some((one) => comparableText(one) === comparableText(section));
|
|
32
|
+
return { ...rollOnTable(readRandomTable(table.rows), source), table: `${page.name}#${section}`, secret };
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error instanceof DiceError) {
|
|
36
|
+
throw new Error(`The table of ${page.name}#${section}: ${error.message} Nothing rolled.`);
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -94,7 +94,7 @@ function lifestylePaid(root, context, world, member, lifestyle) {
|
|
|
94
94
|
// A lifestyle of the campaign's has no price the system knows: the master charges it.
|
|
95
95
|
return typeof chosen === "string" && chosen.trim() !== ""
|
|
96
96
|
? `${member.name}'s ${lifestyle.field} ${chosen} has no price here: charge the day with change ${member.name} money, or set one of ${names.join(", ")}. Read ${lifestyle.rules}.`
|
|
97
|
-
: `${member.name} has no ${lifestyle.field} to pay a day in a settlement: ${who}set ${lifestyle.field}=${example}, one of ${names.join(", ")}. Read ${lifestyle.rules}.`;
|
|
97
|
+
: `${member.name} has no ${lifestyle.field} to pay a day in a settlement: ${who}set ${lifestyle.field}=${example}, one of ${names.join(", ")}; or, for a night paid on its own or board earned by work, charge it with change ${member.name} money, if not yet charged. Read ${lifestyle.rules}.`;
|
|
98
98
|
}
|
|
99
99
|
const price = coins === undefined ? undefined : readAmount(lifestyle.costs[named], coins);
|
|
100
100
|
if (coins === undefined || price === undefined || totalOf(price, coins) === 0) {
|
package/dist/commands/package.js
CHANGED
|
@@ -187,11 +187,13 @@ async function installed(root, context, name) {
|
|
|
187
187
|
throw new Error("Packages are installed only by the game's server or the command line, which reach npm.");
|
|
188
188
|
}
|
|
189
189
|
// A name alone is one of ours: weather is @rpgengine/weather, never a stranger's of that name, which is given as npm:weather.
|
|
190
|
-
const
|
|
191
|
-
const described = await packages.describe(
|
|
190
|
+
const asked = name.startsWith("npm:") ? name.slice(4) : isLocalSpec(name) || name.startsWith("@") ? name : `${verifiedScope}${name}`;
|
|
191
|
+
const described = await packages.describe(asked);
|
|
192
192
|
if ("failed" in described) {
|
|
193
|
-
throw new Error(`${described.failed}. Nothing changed${
|
|
193
|
+
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`}.`);
|
|
194
194
|
}
|
|
195
|
+
// npm is given the version described, which the player's yes was for: by its name alone, npm would keep the exact version it saved before.
|
|
196
|
+
const spec = isLocalSpec(asked) ? asked : `${described.name}@${described.version}`;
|
|
195
197
|
if (described.kind === "system") {
|
|
196
198
|
return await systemInstalled(root, context, spec, name, described);
|
|
197
199
|
}
|
package/dist/commands/roll.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare const roll: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
15
15
|
use: z.ZodOptional<z.ZodString>;
|
|
16
16
|
from: z.ZodOptional<z.ZodString>;
|
|
17
17
|
double: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
table: z.ZodOptional<z.ZodString>;
|
|
19
|
+
oracle: z.ZodOptional<z.ZodString>;
|
|
18
20
|
}, z.core.$strip>, {
|
|
19
21
|
kind: "roll";
|
|
20
22
|
id: string;
|
|
@@ -25,6 +27,8 @@ export declare const roll: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
25
27
|
check?: string;
|
|
26
28
|
physical: boolean;
|
|
27
29
|
hidden: boolean;
|
|
30
|
+
screened?: true;
|
|
31
|
+
stranger?: true;
|
|
28
32
|
fingerprint?: string;
|
|
29
33
|
note?: string;
|
|
30
34
|
kept?: string;
|
package/dist/commands/roll.js
CHANGED
|
@@ -5,11 +5,13 @@ import { appendLogEntry, readLog } from "../core/log.js";
|
|
|
5
5
|
import { defineCommand } from "../core/registry.js";
|
|
6
6
|
import { comparableText, sameName, valueNamed } from "../core/text.js";
|
|
7
7
|
import { readCounter } from "../counters/index.js";
|
|
8
|
-
import {
|
|
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 { behindTheScreen, namesNoOne, ofTheParty, screenUp, sealHiddenRoll } from "./game-master-rolls.js";
|
|
11
12
|
import { copyPage, readOpenScene } from "./game-scene.js";
|
|
12
13
|
import { systemRolled } from "./game-system-code.js";
|
|
14
|
+
import { rollPageTable } from "./game-tables.js";
|
|
13
15
|
import { newDatedLogEntry } from "./game-time.js";
|
|
14
16
|
import { campaignSystem, campaignWorld, missingSystemHint } from "./game-world.js";
|
|
15
17
|
import { itemList, signedText, workedFields } from "./worked-out.js";
|
|
@@ -23,10 +25,12 @@ export const roll = defineCommand({
|
|
|
23
25
|
name: "roll",
|
|
24
26
|
description: "Roll dice and log the roll. "
|
|
25
27
|
+ "Give why and, if it belongs to someone, who; for a roll the player sees, check names it for them, while why stays yours. "
|
|
26
|
-
+ "When the player rolls physical dice, pass their faces as values. Make it hidden when the player must not see the result
|
|
28
|
+
+ "When the player rolls physical dice, pass their faces as values. Make it hidden when the player must not see the result; "
|
|
29
|
+
+ "left out, a roll for a foe or anyone outside the party is hidden or shown as the master-rolls setting says. "
|
|
27
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; "
|
|
28
31
|
+ "use takes one of those instead of the die and logs which roll it replaced. "
|
|
29
|
-
+
|
|
32
|
+
+ "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?".',
|
|
30
34
|
group: "game",
|
|
31
35
|
positionals: ["notation"],
|
|
32
36
|
input: z.object({
|
|
@@ -36,31 +40,42 @@ export const roll = defineCommand({
|
|
|
36
40
|
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"),
|
|
37
41
|
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"),
|
|
38
42
|
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"),
|
|
39
|
-
hidden: z.boolean().optional().describe("only the master sees the result; its fingerprint goes to the player only if they ask for it"),
|
|
43
|
+
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"),
|
|
40
44
|
reveal: z.string().optional().describe("id of a hidden roll whose proof to show, later"),
|
|
41
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"),
|
|
42
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"),
|
|
43
47
|
from: z.string().optional().describe("who keeps the roll that use takes, when it is not who rolls"),
|
|
44
48
|
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
|
+
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"),
|
|
50
|
+
oracle: z.string().optional().describe("odds of a yes/no question, on a d100: almost certain, likely, 50/50, unlikely or small chance; why is the question asked; a double makes the answer extreme"),
|
|
45
51
|
}),
|
|
46
52
|
run(input, context) {
|
|
47
53
|
const root = requireCampaign(context.folder);
|
|
48
54
|
if (input.reveal !== undefined) {
|
|
49
|
-
if (input.notation !== undefined) {
|
|
50
|
-
throw new Error("Give either the dice to roll or the id of a hidden roll to reveal, not both.");
|
|
55
|
+
if (input.notation !== undefined || input.table !== undefined || input.oracle !== undefined) {
|
|
56
|
+
throw new Error("Give either the dice to roll, a table or the oracle, or the id of a hidden roll to reveal, not both.");
|
|
51
57
|
}
|
|
52
58
|
return revealHiddenRoll(input.reveal, root, context);
|
|
53
59
|
}
|
|
54
|
-
if (input.notation
|
|
55
|
-
throw new Error("Give the dice to roll,
|
|
60
|
+
if ([input.notation, input.table, input.oracle].filter((given) => given !== undefined).length > 1) {
|
|
61
|
+
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
|
+
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.");
|
|
56
65
|
}
|
|
57
66
|
if (input.values && input.hidden) {
|
|
58
67
|
throw new Error("Physical dice are rolled by the player, so they cannot be hidden.");
|
|
59
68
|
}
|
|
69
|
+
if (input.notation === undefined) {
|
|
70
|
+
return answerRoll(input, root, context);
|
|
71
|
+
}
|
|
60
72
|
if (input.use !== undefined && (input.keep !== undefined || input.values !== undefined || input.hidden === true)) {
|
|
61
73
|
throw new Error("A kept roll takes the place of the die: give use without keep or values, and not hidden.");
|
|
62
74
|
}
|
|
63
75
|
const physical = input.values !== undefined;
|
|
76
|
+
// Left out, hidden follows the master-rolls setting for anyone outside the party (D-287); never for the player's dice, nor a kept roll used.
|
|
77
|
+
const screened = input.hidden === undefined && !physical && input.use === undefined && behindTheScreen(root, context, input.who);
|
|
78
|
+
const hidden = input.hidden === true || screened;
|
|
64
79
|
const system = campaignSystem(root, context);
|
|
65
80
|
const roller = rollerOf(root, context, input.who, hasNames(input.notation));
|
|
66
81
|
// The notation as it is rolled, twice the dice for a critical hit (D-449).
|
|
@@ -77,22 +92,20 @@ export const roll = defineCommand({
|
|
|
77
92
|
const using = used === undefined ? {} : { used: { from: used.page.name, field: used.field, value: used.value } };
|
|
78
93
|
const checked = input.check === undefined ? {} : { check: input.check };
|
|
79
94
|
const data = { notation: input.notation, total: diceRoll.total, result: text, ...sheet, why: input.why, who: input.who, ...checked, physical, ...keeping, ...using, dice: diceRoll.dice };
|
|
80
|
-
const entry = newDatedLogEntry(root, context, "roll",
|
|
81
|
-
|
|
82
|
-
if (input.hidden) {
|
|
83
|
-
const proof = createProof(entry.id, text, context.newSalt());
|
|
84
|
-
shownFingerprint = fingerprint(proof);
|
|
85
|
-
Object.assign(entry.data, { proof, fingerprint: shownFingerprint });
|
|
86
|
-
}
|
|
95
|
+
const entry = newDatedLogEntry(root, context, "roll", hidden ? "hidden" : "public", data);
|
|
96
|
+
const shownFingerprint = hidden ? sealHiddenRoll(entry, text, context) : undefined;
|
|
87
97
|
// The page first: a page that cannot be written leaves no line in the log saying it was (KEP-2, KEP-3).
|
|
88
98
|
const kept = keeper !== undefined ? keepFaces(keeper, diceRoll.faces) : used !== undefined ? takeKept(used) : undefined;
|
|
89
99
|
appendLogEntry(root, entry);
|
|
90
100
|
// A roll of a dying party member is their death save, which the engine writes (DIE-4, D-460).
|
|
91
101
|
// A hidden roll writes nothing the player would see (review of 17 October).
|
|
92
|
-
const said = input.who === undefined ||
|
|
102
|
+
const said = input.who === undefined || hidden ? { lines: [] } : systemRolled(root, context, { who: input.who, notation: diceRoll.notation, total: diceRoll.total, dice: diceRoll.dice });
|
|
93
103
|
const own = said.lines.length > 0 ? said.lines.join("\n") : roller === undefined ? undefined : rollerNote(roller.world, system, roller.page);
|
|
94
104
|
const note = [own, said.problem].filter((line) => line !== undefined && line !== "").join("\n") || undefined;
|
|
95
|
-
|
|
105
|
+
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
|
+
// 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
|
+
const stranger = screened && input.who !== undefined && namesNoOne(root, context, input.who) ? { stranger: true } : {};
|
|
108
|
+
return screened ? { ...shown, screened: true, ...stranger } : shown;
|
|
96
109
|
},
|
|
97
110
|
format(output) {
|
|
98
111
|
if (output.kind === "reveal") {
|
|
@@ -101,12 +114,54 @@ export const roll = defineCommand({
|
|
|
101
114
|
}
|
|
102
115
|
const note = [output.kept, output.note].filter((line) => line !== undefined).map((line) => `\n${line}`).join("");
|
|
103
116
|
if (output.hidden) {
|
|
104
|
-
|
|
117
|
+
const screen = output.screened === true ? ". Behind the screen, as master-rolls says: tell only the outcome, in the story." : "";
|
|
118
|
+
const stranger = output.stranger === true
|
|
119
|
+
? `\n${output.who} names no page nor copy in the scene: hidden as a stranger's. If ${output.who} is of the party, roll --reveal ${output.id}, and give who as their page's name.`
|
|
120
|
+
: "";
|
|
121
|
+
return `Hidden roll ${output.id}, only for the master: ${output.text}${screen}${stranger}\nIts fingerprint, only if the player asks for it: ${output.fingerprint}${note}`;
|
|
105
122
|
}
|
|
106
123
|
const label = [output.who, output.check, output.why].filter(Boolean).join(", ");
|
|
107
124
|
return `${output.id} ${label ? label + ": " : ""}${output.text}${output.physical ? " (physical dice)" : ""}${note}`;
|
|
108
125
|
},
|
|
109
126
|
});
|
|
127
|
+
/** A roll on a page's random table or of the oracle (D-503): logged as any roll, hidden or shown as any roll; the row or the answer is for the master to tell. */
|
|
128
|
+
function answerRoll(input, root, context) {
|
|
129
|
+
if (input.keep !== undefined || input.use !== undefined || input.double === true) {
|
|
130
|
+
throw new Error("keep, use and double go with dice to roll, not with a table or the oracle. Nothing rolled.");
|
|
131
|
+
}
|
|
132
|
+
if (input.oracle !== undefined && (input.why === undefined || input.why.trim() === "")) {
|
|
133
|
+
throw new Error('Give the question asked as why, such as oracle likely, why "is the ferryman awake?". Nothing rolled.');
|
|
134
|
+
}
|
|
135
|
+
const physical = input.values !== undefined;
|
|
136
|
+
const source = input.values ? { values: input.values } : { random: context.random };
|
|
137
|
+
const answer = input.table !== undefined ? tableAnswer(root, context, input.table, source) : oracleAnswer(input.oracle ?? "", source);
|
|
138
|
+
// A table or the oracle is the master's own roll, behind the screen as master-rolls says, but for a party member's (D-287); a secret's table is never shown.
|
|
139
|
+
const masters = input.who === undefined || !ofTheParty(root, context, input.who);
|
|
140
|
+
const screened = answer.secret || (input.hidden === undefined && !physical && masters && screenUp(root));
|
|
141
|
+
const hidden = input.hidden === true || screened;
|
|
142
|
+
const checked = input.check === undefined ? {} : { check: input.check };
|
|
143
|
+
const data = { notation: answer.notation, total: answer.total, result: answer.text, ...answer.data, why: input.why, who: input.who, ...checked, physical, dice: answer.dice };
|
|
144
|
+
const entry = newDatedLogEntry(root, context, "roll", hidden ? "hidden" : "public", data);
|
|
145
|
+
const shownFingerprint = hidden ? sealHiddenRoll(entry, answer.text, context) : undefined;
|
|
146
|
+
appendLogEntry(root, entry);
|
|
147
|
+
const shown = { kind: "roll", id: entry.id, text: answer.text, total: answer.total, why: input.why, who: input.who, check: input.check, physical, hidden, fingerprint: shownFingerprint };
|
|
148
|
+
return screened ? { ...shown, screened: true } : shown;
|
|
149
|
+
}
|
|
150
|
+
/** The row of a page's table that the roll lands on, with the table and the row for the log. */
|
|
151
|
+
function tableAnswer(root, context, table, source) {
|
|
152
|
+
const rolled = rollPageTable(root, context, table, source);
|
|
153
|
+
return { secret: rolled.secret, notation: rolled.die, total: rolled.result, text: rolled.text, dice: rolled.roll.dice, data: { table: rolled.table, row: rolled.row.label } };
|
|
154
|
+
}
|
|
155
|
+
/** The oracle's answer, with its odds and the answer for the log. */
|
|
156
|
+
function oracleAnswer(odds, source) {
|
|
157
|
+
try {
|
|
158
|
+
const asked = askOracle(odds, source);
|
|
159
|
+
return { secret: false, notation: "d100", total: asked.roll.total, text: asked.text, dice: asked.roll.dice, data: { oracle: asked.odds, odds: asked.chance, answer: `${asked.extreme ? "extreme " : ""}${asked.yes ? "yes" : "no"}` } };
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw error instanceof DiceError ? new Error(`${error.message} Nothing rolled.`) : error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
110
165
|
/** A notation with twice its dice and the same numbers, as a critical hit's damage (D-449): 1d8+3 is 2d8+3, d6+1d4 is 2d6+2d4. */
|
|
111
166
|
function doubledDice(notation) {
|
|
112
167
|
// Any case, as the dice read: 1D8 is 1d8.
|