rpg-engine 0.19.0 → 0.19.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.
@@ -1,4 +1,4 @@
1
- import type { World } from "../../../pages/index.ts";
1
+ import { type World } from "../../../pages/index.ts";
2
2
  import type { GameSystem, Recipe } from "../../../systems/index.ts";
3
3
  import { type GameDate } from "../../../time/index.ts";
4
4
  /** The type of the log's line that says a recipe gave a page something (RST-1). */
@@ -1,9 +1,12 @@
1
1
  // What comes back at dawn (D-571, RST-2): when time passes through the system's dawn, what the party carries below its maximum, which its text brings back, and
2
2
  // who of the party had no rest of a night in its time, which the master gives if they slept. The engine gives nothing by itself.
3
3
  import { readLog } from "../../../core/log.js";
4
- import { comparableText } from "../../../core/text.js";
4
+ import { comparableText, valueNamed } from "../../../core/text.js";
5
+ import { readCounter } from "../../../counters/index.js";
6
+ import { isInParty } from "../../../pages/index.js";
5
7
  import { formatGameDate, minutesBetween, readDuration, readGameDate } from "../../../time/index.js";
6
- import { carriedCounters, partyPages } from "./recipes.js";
8
+ import { effectiveFields } from "../sheet/effect-layer.js";
9
+ import { carriedCounters, recipeTargets } from "./recipes.js";
7
10
  /** The type of the log's line that says a recipe gave a page something (RST-1). */
8
11
  export const recipeAppliedType = "recipe-applied";
9
12
  /** The lines of a dawn this passing of time went through, the last when it went through more; none without one, or when nothing is to say. */
@@ -12,9 +15,10 @@ export function dawnLines(root, world, system, from, to) {
12
15
  if (system === undefined || dawn === undefined) {
13
16
  return [];
14
17
  }
15
- const members = partyPages(world);
18
+ // Dawn comes for the whole living party, wherever each one is.
19
+ const members = world.pages.filter(isInParty);
16
20
  const carried = members.flatMap((member) => carriedCounters(world, member).map((counter) => `${counter} (${member.name})`));
17
- const unrested = system.recipes.filter((recipe) => recipe.oncePer !== undefined && recipe.lasts !== undefined).flatMap((recipe) => unrestedLine(root, recipe, members, to));
21
+ const unrested = system.recipes.filter((recipe) => recipe.oncePer !== undefined && recipe.lasts !== undefined).flatMap((recipe) => unrestedLine(root, world, recipe, members, to));
18
22
  const counters = carried.length === 0 ? "" : ` Below their maximum, what the party carries: ${carried.join(" · ")}; what comes back at dawn, its text says: give it with change.`;
19
23
  return counters === "" && unrested.length === 0 ? [] : [`Dawn came at ${formatGameDate(dawn)}.${counters}`, ...unrested];
20
24
  }
@@ -29,12 +33,20 @@ function lastDawn(from, to, minute) {
29
33
  const dawn = { day, minute };
30
34
  return day >= 1 && minutesBetween(from, dawn) > 0 ? dawn : undefined;
31
35
  }
32
- /** "No long rest in the last 24h: …", for those of the party who had none in its time (RST-1); none when all had one. */
33
- function unrestedLine(root, recipe, members, now) {
36
+ /** "No long rest in the last 24h: …", for those of the party it would give something to who had none in its time (RST-1); none when no one is left. */
37
+ function unrestedLine(root, world, recipe, members, now) {
34
38
  const every = readDuration(recipe.oncePer ?? "") ?? 0;
35
- const missing = members.flatMap((member) => {
39
+ const missing = members.filter((member) => gainsFrom(world, recipe, member)).flatMap((member) => {
36
40
  const last = lastApplied(root, recipe, member.name);
37
41
  return last === undefined ? [`${member.name} (none yet)`] : minutesBetween(last, now) >= every ? [`${member.name} (last at ${formatGameDate(last)})`] : [];
38
42
  });
39
43
  return missing.length === 0 ? [] : [`No ${recipe.name} in the last ${recipe.oncePer}: ${missing.join(", ")}. If they slept, give it with change and the recipe ${recipe.name}.`];
40
44
  }
45
+ /** Whether a recipe would change something on a page now: a counter it brings back that is not there yet. */
46
+ function gainsFrom(world, recipe, page) {
47
+ const fields = effectiveFields(world, page);
48
+ return recipeTargets(world, recipe, page).some(({ field, target }) => {
49
+ const counter = readCounter(valueNamed(fields, field));
50
+ return counter !== undefined && counter.value !== (target === "max" ? counter.max : target);
51
+ });
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpg-engine",
3
- "version": "0.19.0",
3
+ "version": "0.19.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": {