rpg-engine 0.18.1 → 0.19.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/dist/commands/change/recipe-pace.js +3 -5
- package/dist/commands/shared/time/advance.d.ts +2 -0
- package/dist/commands/shared/time/advance.js +4 -1
- package/dist/commands/shared/time/dawn.d.ts +9 -0
- package/dist/commands/shared/time/dawn.js +40 -0
- package/dist/commands/travel/travel.js +2 -0
- package/dist/core/packages/declarations.d.ts +2 -2
- package/dist/core/packages/declarations.js +2 -2
- package/dist/systems/game-system.d.ts +2 -0
- package/dist/systems/read.js +6 -0
- package/dist/systems/schema.d.ts +1 -0
- package/dist/systems/schema.js +1 -0
- package/package.json +2 -2
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { appendLogEntry, readLog } from "../../core/log.js";
|
|
2
|
-
import { comparableText } from "../../core/text.js";
|
|
3
2
|
import { addDuration, formatDuration, formatGameDate, minutesBetween, readDuration, readGameDate } from "../../time/index.js";
|
|
3
|
+
import { lastApplied, recipeAppliedType } from "../shared/time/dawn.js";
|
|
4
4
|
import { newDatedLogEntry, readPresent } from "../shared/time/time.js";
|
|
5
|
-
const appliedType = "recipe-applied";
|
|
6
5
|
/** 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. */
|
|
7
6
|
export function tooSoonNote(root, recipe, page) {
|
|
8
7
|
const every = recipe.oncePer === undefined ? undefined : readDuration(recipe.oncePer);
|
|
@@ -10,8 +9,7 @@ export function tooSoonNote(root, recipe, page) {
|
|
|
10
9
|
if (every === undefined || now === undefined) {
|
|
11
10
|
return undefined;
|
|
12
11
|
}
|
|
13
|
-
const
|
|
14
|
-
const then = last === undefined ? undefined : readGameDate(last.date);
|
|
12
|
+
const then = lastApplied(root, recipe, page);
|
|
15
13
|
if (then === undefined || minutesBetween(then, now) >= every) {
|
|
16
14
|
return undefined;
|
|
17
15
|
}
|
|
@@ -39,6 +37,6 @@ export function shortRestNote(root, recipe) {
|
|
|
39
37
|
/** Writes in the log that a recipe gave a page something, when the system counts how often it may (RST-1). */
|
|
40
38
|
export function logRecipeApplied(root, context, recipe, page, visibility) {
|
|
41
39
|
if (recipe.oncePer !== undefined) {
|
|
42
|
-
appendLogEntry(root, newDatedLogEntry(root, context,
|
|
40
|
+
appendLogEntry(root, newDatedLogEntry(root, context, recipeAppliedType, visibility, { page, recipe: recipe.name }));
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -32,6 +32,8 @@ export interface TimePassed {
|
|
|
32
32
|
diary?: string;
|
|
33
33
|
/** What the party used up at each midnight passed, under the rigor «rules» (UPK-1, UPK-2). */
|
|
34
34
|
upkeep?: string[];
|
|
35
|
+
/** What comes back at the dawn it went through, and who had no rest of a night (D-571, RST-2). */
|
|
36
|
+
dawn?: string[];
|
|
35
37
|
/** The day of the calendar reached, when the campaign has one (TIM-8): 15 April, spring. */
|
|
36
38
|
calendar?: string;
|
|
37
39
|
/** What the campaign's extensions said of the time passed, such as the weather of a new morning (D-436). */
|
|
@@ -10,6 +10,7 @@ import { shortList, skippedPagesNote } from "../notes.js";
|
|
|
10
10
|
import { surroundings, surroundingsText } from "../places/environment.js";
|
|
11
11
|
import { endedByDate, endEffects } from "../scene/effects.js";
|
|
12
12
|
import { readOpenScene } from "../scene/scene.js";
|
|
13
|
+
import { dawnLines } from "./dawn.js";
|
|
13
14
|
import { clocksToMove, dueAdvice, dueEvents, dueText, isDated, plannedEvents, plannedText } from "./events.js";
|
|
14
15
|
import { calendarDayOf, newDatedLogEntry } from "./time.js";
|
|
15
16
|
import { dailyUpkeep } from "./upkeep.js";
|
|
@@ -50,7 +51,8 @@ export function passTime(root, context, world, now, wanted, why, requested) {
|
|
|
50
51
|
const newDayPart = result.clocks.length === 0 ? "" : situationPart("new-day", context, campaignSystem(root, context));
|
|
51
52
|
const upkeep = passed > 0 ? dailyUpkeep(root, context, campaignSystem(root, context), result.newDays) : [];
|
|
52
53
|
const diary = result.newDays > 0 ? diaryDueLine(root, context, world) : "";
|
|
53
|
-
|
|
54
|
+
const dawn = passed > 0 ? dawnLines(root, world, campaignSystem(root, context), now, reached) : [];
|
|
55
|
+
return { ...result, ended, around, newDayPart, ...(upkeep.length === 0 ? {} : { upkeep }), ...(dawn.length === 0 ? {} : { dawn }), ...(diary === "" ? {} : { diary }) };
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
56
58
|
* What outputs say after time passed, line by line: the effects ended, the events due with how to play them and `then`, what to do after them, those still due,
|
|
@@ -67,6 +69,7 @@ export function passedLines(result, then) {
|
|
|
67
69
|
clocksLine(result.newDays, result.to, result.clocks),
|
|
68
70
|
result.newDayPart,
|
|
69
71
|
...(result.upkeep ?? []),
|
|
72
|
+
...(result.dawn ?? []),
|
|
70
73
|
result.diary ?? "",
|
|
71
74
|
...(result.extensionLines ?? []),
|
|
72
75
|
result.unreadable.length === 0 ? "" : `Time does not stop at these planned events, whose date is not a game date: ${result.unreadable.join(" · ")}. Give each one a game date with write.`,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { World } from "../../../pages/index.ts";
|
|
2
|
+
import type { GameSystem, Recipe } from "../../../systems/index.ts";
|
|
3
|
+
import { type GameDate } from "../../../time/index.ts";
|
|
4
|
+
/** The type of the log's line that says a recipe gave a page something (RST-1). */
|
|
5
|
+
export declare const recipeAppliedType = "recipe-applied";
|
|
6
|
+
/** 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. */
|
|
7
|
+
export declare function dawnLines(root: string, world: World, system: GameSystem | undefined, from: GameDate, to: GameDate): string[];
|
|
8
|
+
/** When a page last had a recipe that gave it something (RST-1); undefined when never. */
|
|
9
|
+
export declare function lastApplied(root: string, recipe: Recipe, page: string): GameDate | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
// 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
|
+
import { readLog } from "../../../core/log.js";
|
|
4
|
+
import { comparableText } from "../../../core/text.js";
|
|
5
|
+
import { formatGameDate, minutesBetween, readDuration, readGameDate } from "../../../time/index.js";
|
|
6
|
+
import { carriedCounters, partyPages } from "./recipes.js";
|
|
7
|
+
/** The type of the log's line that says a recipe gave a page something (RST-1). */
|
|
8
|
+
export const recipeAppliedType = "recipe-applied";
|
|
9
|
+
/** 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. */
|
|
10
|
+
export function dawnLines(root, world, system, from, to) {
|
|
11
|
+
const dawn = system?.dawn === undefined ? undefined : lastDawn(from, to, system.dawn);
|
|
12
|
+
if (system === undefined || dawn === undefined) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const members = partyPages(world);
|
|
16
|
+
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));
|
|
18
|
+
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
|
+
return counters === "" && unrested.length === 0 ? [] : [`Dawn came at ${formatGameDate(dawn)}.${counters}`, ...unrested];
|
|
20
|
+
}
|
|
21
|
+
/** When a page last had a recipe that gave it something (RST-1); undefined when never. */
|
|
22
|
+
export function lastApplied(root, recipe, page) {
|
|
23
|
+
const last = readLog(root).filter((entry) => entry.type === recipeAppliedType && comparableText(String(entry.data.page)) === comparableText(page) && entry.data.recipe === recipe.name).at(-1);
|
|
24
|
+
return last === undefined ? undefined : readGameDate(last.date);
|
|
25
|
+
}
|
|
26
|
+
/** The last dawn after `from` and up to `to`; undefined when none falls there. */
|
|
27
|
+
function lastDawn(from, to, minute) {
|
|
28
|
+
const day = (to.minute ?? 0) >= minute ? to.day : to.day - 1;
|
|
29
|
+
const dawn = { day, minute };
|
|
30
|
+
return day >= 1 && minutesBetween(from, dawn) > 0 ? dawn : undefined;
|
|
31
|
+
}
|
|
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) {
|
|
34
|
+
const every = readDuration(recipe.oncePer ?? "") ?? 0;
|
|
35
|
+
const missing = members.flatMap((member) => {
|
|
36
|
+
const last = lastApplied(root, recipe, member.name);
|
|
37
|
+
return last === undefined ? [`${member.name} (none yet)`] : minutesBetween(last, now) >= every ? [`${member.name} (last at ${formatGameDate(last)})`] : [];
|
|
38
|
+
});
|
|
39
|
+
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
|
+
}
|
|
@@ -476,6 +476,8 @@ function mergedTimes(times) {
|
|
|
476
476
|
newDayPart: times.map((time) => time.newDayPart).find((part) => part !== "") ?? "",
|
|
477
477
|
// What the party used up at every midnight of every leg (UPK-1).
|
|
478
478
|
upkeep: times.flatMap((time) => time.upkeep ?? []),
|
|
479
|
+
// The last dawn of the journey, as an advance through more than one says it (RST-2).
|
|
480
|
+
dawn: times.map((time) => time.dawn ?? []).findLast((lines) => lines.length > 0) ?? [],
|
|
479
481
|
};
|
|
480
482
|
}
|
|
481
483
|
function namesText(pages) {
|
|
@@ -5,9 +5,9 @@ export type { CardPage, FigureSize };
|
|
|
5
5
|
* The version of the API a package is made for, which its package.json names as rpg-engine.api: the contract its code is given and what its extension.yaml or
|
|
6
6
|
* system.yaml may declare. It goes up with every addition an older engine would refuse or misread, and the engine reads a range (D-515, D-549): 2 added the widgets, 3 an extension's
|
|
7
7
|
* additions to the game system and asking the player, 4 the code in the dashboard's page, 5 one contract for every kind of package, 6 the fields of
|
|
8
|
-
* knowledge of a game system (sheet-knowledge), 7 what a page carries and the pictures of the dashboard's states, 8 where a game system's oracle says yes.
|
|
8
|
+
* knowledge of a game system (sheet-knowledge), 7 what a page carries and the pictures of the dashboard's states, 8 where a game system's oracle says yes, 9 a game system's dawn.
|
|
9
9
|
*/
|
|
10
|
-
export declare const packageApi =
|
|
10
|
+
export declare const packageApi = 9;
|
|
11
11
|
/**
|
|
12
12
|
* Our game systems (D-513): the name a campaign gives each, which package install takes alone, its package, and what it is; the setup offers them even when
|
|
13
13
|
* npm does not answer. A list of names, as our scope is, never a game's code; Ironsworn joins it once it is playable.
|
|
@@ -6,9 +6,9 @@ import { cardPages } from "./api.js";
|
|
|
6
6
|
* The version of the API a package is made for, which its package.json names as rpg-engine.api: the contract its code is given and what its extension.yaml or
|
|
7
7
|
* system.yaml may declare. It goes up with every addition an older engine would refuse or misread, and the engine reads a range (D-515, D-549): 2 added the widgets, 3 an extension's
|
|
8
8
|
* additions to the game system and asking the player, 4 the code in the dashboard's page, 5 one contract for every kind of package, 6 the fields of
|
|
9
|
-
* knowledge of a game system (sheet-knowledge), 7 what a page carries and the pictures of the dashboard's states, 8 where a game system's oracle says yes.
|
|
9
|
+
* knowledge of a game system (sheet-knowledge), 7 what a page carries and the pictures of the dashboard's states, 8 where a game system's oracle says yes, 9 a game system's dawn.
|
|
10
10
|
*/
|
|
11
|
-
export const packageApi =
|
|
11
|
+
export const packageApi = 9;
|
|
12
12
|
/**
|
|
13
13
|
* Our game systems (D-513): the name a campaign gives each, which package install takes alone, its package, and what it is; the setup offers them even when
|
|
14
14
|
* npm does not answer. A list of names, as our scope is, never a game's code; Ironsworn joins it once it is playable.
|
|
@@ -233,6 +233,8 @@ export interface GameSystem {
|
|
|
233
233
|
coinMetals: Record<string, string>;
|
|
234
234
|
/** How long a round lasts, in seconds (D-187, DAT-7). */
|
|
235
235
|
roundSeconds?: number;
|
|
236
|
+
/** The minute of the day dawn comes at, as 360 for 06:00, when the system has one (D-571, RST-2): what comes back at dawn, an advance through it names. */
|
|
237
|
+
dawn?: number;
|
|
236
238
|
/** How many metres its mile and foot are worth, when it has its own (D-262): outputs in imperial use them. */
|
|
237
239
|
imperial?: ImperialUnits;
|
|
238
240
|
/**
|
package/dist/systems/read.js
CHANGED
|
@@ -187,6 +187,7 @@ export function readSystem(folder, name, layers = [], ruleset) {
|
|
|
187
187
|
coins: data.coins,
|
|
188
188
|
coinMetals: data["coin-metals"] ?? {},
|
|
189
189
|
roundSeconds: data.round === undefined ? undefined : Number.parseInt(data.round, 10),
|
|
190
|
+
...(data.dawn === undefined ? {} : { dawn: minuteOfDay(data.dawn) }),
|
|
190
191
|
...(data.imperial === undefined ? {} : { imperial: { mile: readLength(data.imperial.mile) ?? 0, foot: readLength(data.imperial.foot) ?? 0 } }),
|
|
191
192
|
...(data.imperial?.pound === undefined ? {} : { pound: Number.parseFloat(data.imperial.pound) }),
|
|
192
193
|
...(data["length-unit"] === undefined ? {} : { lengthUnit: data["length-unit"] }),
|
|
@@ -469,3 +470,8 @@ function downRule(at) {
|
|
|
469
470
|
const [field, value] = at.split(" ");
|
|
470
471
|
return { field, value: Number(value) };
|
|
471
472
|
}
|
|
473
|
+
/** An hour as the schema took it, as 06:00, in minutes since midnight. */
|
|
474
|
+
function minuteOfDay(hour) {
|
|
475
|
+
const [hours, minutes] = hour.split(":").map(Number);
|
|
476
|
+
return (hours ?? 0) * 60 + (minutes ?? 0);
|
|
477
|
+
}
|
package/dist/systems/schema.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export declare const systemSchema: z.ZodObject<{
|
|
|
72
72
|
coins: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
73
73
|
"coin-metals": z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
74
74
|
round: z.ZodOptional<z.ZodString>;
|
|
75
|
+
dawn: z.ZodOptional<z.ZodString>;
|
|
75
76
|
imperial: z.ZodOptional<z.ZodObject<{
|
|
76
77
|
mile: z.ZodString;
|
|
77
78
|
foot: z.ZodString;
|
package/dist/systems/schema.js
CHANGED
|
@@ -99,6 +99,7 @@ export const systemSchema = z.object({
|
|
|
99
99
|
coins: z.union([z.string().min(1), z.record(z.string(), z.unknown())]).optional(),
|
|
100
100
|
"coin-metals": z.record(z.string().min(1), z.string().min(1), { error: "write it as a map, each coin with its metal, such as {gp: gold, sp: silver}" }).optional(),
|
|
101
101
|
round: z.string().regex(/^[1-9]\d* seconds?$/, 'write it as "6 seconds"').optional(),
|
|
102
|
+
dawn: z.string().regex(/^([01]?\d|2[0-3]):[0-5]\d$/, 'write it as the hour, such as "06:00"').optional(),
|
|
102
103
|
imperial: z.object({ mile: lengthSchema, foot: lengthSchema, pound: z.string().regex(/^\d+(\.\d+)? kg$/, { error: "write it in kilograms, such as 0.5 kg" }).optional() }).strict().optional(),
|
|
103
104
|
"length-unit": z.string().min(1).optional(),
|
|
104
105
|
"bonus-lists": z.array(z.string().min(1)).optional(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpg-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
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": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"rpg-engine": {
|
|
12
12
|
"kind": "engine",
|
|
13
|
-
"api":
|
|
13
|
+
"api": 9
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|