rpg-engine 0.18.0 → 0.18.1

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.
@@ -15,6 +15,7 @@ export declare const change: import("../../core/registry.ts").Command<z.ZodObjec
15
15
  outcomes: import("./recipe.ts").RecipeOutcome[];
16
16
  rules: string[];
17
17
  lasts?: string;
18
+ short?: string;
18
19
  buttons?: boolean;
19
20
  physical?: boolean;
20
21
  spent?: string;
@@ -2,5 +2,10 @@ import type { Context } from "../../core/context.ts";
2
2
  import type { Recipe } from "../../systems/index.ts";
3
3
  /** Why a page gains nothing from a recipe it had too recently (RST-1), as "Ettore had a long rest at day 2, 08:00: …"; undefined when it may have it. */
4
4
  export declare function tooSoonNote(root: string, recipe: Recipe, page: string): string | undefined;
5
+ /**
6
+ * When the last advance ended now and was shorter than the rest, as a night of 6h10 for a long rest of 8h (D-500): "The last advance covered 6h 10m (day 1,
7
+ * 23:50 → day 2, 06:00) …"; undefined otherwise. A watch split into advances may trip it, hence the "if".
8
+ */
9
+ export declare function shortRestNote(root: string, recipe: Recipe): string | undefined;
5
10
  /** Writes in the log that a recipe gave a page something, when the system counts how often it may (RST-1). */
6
11
  export declare function logRecipeApplied(root: string, context: Context, recipe: Recipe, page: string, visibility: "public" | "hidden"): void;
@@ -1,6 +1,6 @@
1
1
  import { appendLogEntry, readLog } from "../../core/log.js";
2
2
  import { comparableText } from "../../core/text.js";
3
- import { addDuration, formatGameDate, minutesBetween, readDuration, readGameDate } from "../../time/index.js";
3
+ import { addDuration, formatDuration, formatGameDate, minutesBetween, readDuration, readGameDate } from "../../time/index.js";
4
4
  import { newDatedLogEntry, readPresent } from "../shared/time/time.js";
5
5
  const appliedType = "recipe-applied";
6
6
  /** Why a page gains nothing from a recipe it had too recently (RST-1), as "Ettore had a long rest at day 2, 08:00: …"; undefined when it may have it. */
@@ -17,6 +17,25 @@ export function tooSoonNote(root, recipe, page) {
17
17
  }
18
18
  return `${page} had a ${recipe.name} at ${formatGameDate(then)}, and gains nothing from another before ${formatGameDate(addDuration(then, every))}: one in ${recipe.oncePer}.`;
19
19
  }
20
+ /**
21
+ * When the last advance ended now and was shorter than the rest, as a night of 6h10 for a long rest of 8h (D-500): "The last advance covered 6h 10m (day 1,
22
+ * 23:50 → day 2, 06:00) …"; undefined otherwise. A watch split into advances may trip it, hence the "if".
23
+ */
24
+ export function shortRestNote(root, recipe) {
25
+ const lasts = recipe.lasts === undefined ? undefined : readDuration(recipe.lasts);
26
+ const now = readPresent(root).date;
27
+ const last = readLog(root).filter((entry) => entry.type === "time-advanced").at(-1);
28
+ const from = last === undefined ? undefined : readGameDate(String(last.data.from));
29
+ const to = last === undefined ? undefined : readGameDate(String(last.data.to));
30
+ if (lasts === undefined || now === undefined || from === undefined || to === undefined || minutesBetween(to, now) !== 0) {
31
+ return undefined;
32
+ }
33
+ const covered = minutesBetween(from, to);
34
+ if (covered <= 0 || covered >= lasts) {
35
+ return undefined;
36
+ }
37
+ return `The last advance covered ${formatDuration(covered)} (${formatGameDate(from)} → ${formatGameDate(to)}) of the ${recipe.name}'s ${recipe.lasts}: if it began at ${formatGameDate(from)}, it ends at ${formatGameDate(addDuration(from, lasts))}; advance the other ${formatDuration(lasts - covered)} before anyone acts.`;
38
+ }
20
39
  /** Writes in the log that a recipe gave a page something, when the system counts how often it may (RST-1). */
21
40
  export function logRecipeApplied(root, context, recipe, page, visibility) {
22
41
  if (recipe.oncePer !== undefined) {
@@ -41,6 +41,7 @@ export declare function recipeResult(root: string, context: Context, world: Worl
41
41
  outcomes: RecipeOutcome[];
42
42
  rules: string[];
43
43
  lasts?: string;
44
+ short?: string;
44
45
  buttons?: boolean;
45
46
  physical?: boolean;
46
47
  spent?: string;
@@ -55,6 +56,7 @@ export declare function recipeText(result: {
55
56
  outcomes: RecipeOutcome[];
56
57
  rules: string[];
57
58
  lasts?: string;
59
+ short?: string;
58
60
  buttons?: boolean;
59
61
  physical?: boolean;
60
62
  }): string;
@@ -15,7 +15,7 @@ import { carriedCounters, effectsAtRecipe, notBroughtBack, partyPages, recipeCho
15
15
  import { newDatedLogEntry } from "../shared/time/time.js";
16
16
  import { counterStep } from "./amounts.js";
17
17
  import { applyStep, holderNamed, pageHolder, stepNotes } from "./holder.js";
18
- import { logRecipeApplied, tooSoonNote } from "./recipe-pace.js";
18
+ import { logRecipeApplied, shortRestNote, tooSoonNote } from "./recipe-pace.js";
19
19
  /**
20
20
  * A recipe of the game system applied to a page, or to the living player characters and the companions with them (DAT-4). Every page is checked before any
21
21
  * is written.
@@ -52,7 +52,9 @@ export function recipeResult(root, context, world, input) {
52
52
  });
53
53
  // Where the dashboard serves a page, the player spends their dice there with ask (ASK-14); with physical dice, they roll their own (ASK-8).
54
54
  const physical = readSettings(root).dice === "physical";
55
- return { recipe: recipe.name, system: system.name, outcomes, rules: recipe.rules, lasts: recipe.lasts, buttons: context.page?.spendDice !== undefined, physical };
55
+ // A night advanced shorter than the rest, as 6h10 for a long rest of 8h (D-500): said, not refused, since the rest may have begun earlier.
56
+ const short = shortRestNote(root, recipe);
57
+ return { recipe: recipe.name, system: system.name, outcomes, rules: recipe.rules, lasts: recipe.lasts, short, buttons: context.page?.spendDice !== undefined, physical };
56
58
  }
57
59
  /**
58
60
  * A recipe applied to one page (DAT-4): the effects that last until one of its occasions end first (DAT-5), then each field it names goes to its maximum or to
@@ -151,7 +153,7 @@ export function recipeText(result) {
151
153
  // A refused rest has no hours to advance (D-500).
152
154
  const hours = result.outcomes.every((outcome) => outcome.barred)
153
155
  ? ""
154
- : `The game date did not move: apply a rest once its hours${result.lasts === undefined ? "" : ` (${result.lasts})`} have passed; if they have not yet, advance them now.`;
156
+ : result.short ?? `The game date did not move: apply a rest once its hours${result.lasts === undefined ? "" : ` (${result.lasts})`} have passed; if they have not yet, advance them now.`;
155
157
  const text = [title, ...lines, rules, hours].filter((line) => line !== "").join("\n");
156
158
  return [text, ...notes.filter((note) => note.includes("\n"))].join("\n\n");
157
159
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  The story is on. Besides the tools above:
4
4
 
5
- - `move`: whenever someone or something goes somewhere, before you narrate it: the party (a journey: `travel`), a person who leaves, whoever climbs into a cart or gets out of it to act, an item given or taken.
5
+ - `move`: whenever someone or something goes somewhere, before you narrate it: the party (a journey: `travel`, and how long it takes: `route`, before anyone says it), a person who leaves, whoever climbs into a cart or gets out of it to act, an item given or taken.
6
6
  - `advance`: whenever time passes in the story, in a scene too, before you narrate it: once for a stretch of the story, not for each gesture. When it stops at an event, do as it says, and write the traces where they will be found. A rest the game system has a recipe for, whenever the characters take it: its hours with `advance`, then `change` with the recipe.
7
7
  - `scene`: open one when a scene of any kind starts, not only a fight, with the type it is, and close it when it ends: a chase, a heist, a ritual or a race is a challenge; a deal that matters, social. Whoever the character does not know or recognize comes in with `seen`, two or three words of what they see, until `reveal` gives the name.
8
8
  - `effect`: every condition or effect on someone (frightened, a curse, a form), how long it lasts and who keeps it alive; it ends by itself.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpg-engine",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Play a tabletop role-playing game with an AI as your game master: the AI tells the story; RPG Engine remembers the world, rolls the dice and keeps the accounts.",
5
5
  "type": "module",
6
6
  "bin": {