rpg-engine 0.4.1 → 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 (231) hide show
  1. package/README.md +1 -1
  2. package/dist/campaign/settings.d.ts +1 -0
  3. package/dist/campaign/settings.js +6 -5
  4. package/dist/command-line.js +12 -5
  5. package/dist/commands/advance.js +1 -1
  6. package/dist/commands/ask.d.ts +37 -2
  7. package/dist/commands/ask.js +106 -35
  8. package/dist/commands/change.js +28 -17
  9. package/dist/commands/config.d.ts +1 -1
  10. package/dist/commands/config.js +69 -21
  11. package/dist/commands/effect.js +42 -23
  12. package/dist/commands/find.js +1 -1
  13. package/dist/commands/game-adventures.js +2 -2
  14. package/dist/commands/game-catalog.d.ts +13 -0
  15. package/dist/commands/game-catalog.js +26 -2
  16. package/dist/commands/game-checks.js +23 -21
  17. package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
  18. package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
  19. package/dist/commands/game-effects.d.ts +12 -4
  20. package/dist/commands/game-effects.js +21 -13
  21. package/dist/commands/game-examples.d.ts +22 -0
  22. package/dist/commands/game-examples.js +72 -0
  23. package/dist/commands/game-extension-list.d.ts +31 -3
  24. package/dist/commands/game-extension-list.js +94 -6
  25. package/dist/commands/game-images.d.ts +1 -1
  26. package/dist/commands/game-images.js +3 -2
  27. package/dist/commands/game-library.d.ts +3 -0
  28. package/dist/commands/game-library.js +2 -2
  29. package/dist/commands/game-mode.js +1 -1
  30. package/dist/commands/game-package-code.d.ts +87 -0
  31. package/dist/commands/game-package-code.js +648 -0
  32. package/dist/commands/game-package-hooks.d.ts +37 -0
  33. package/dist/commands/game-package-hooks.js +116 -0
  34. package/dist/commands/game-recipes.js +2 -2
  35. package/dist/commands/game-reminders.d.ts +5 -2
  36. package/dist/commands/game-reminders.js +7 -4
  37. package/dist/commands/game-rules.d.ts +4 -1
  38. package/dist/commands/game-rules.js +7 -1
  39. package/dist/commands/game-upkeep.js +3 -3
  40. package/dist/commands/game-view-place.d.ts +8 -20
  41. package/dist/commands/game-view-place.js +16 -35
  42. package/dist/commands/game-widgets.d.ts +42 -8
  43. package/dist/commands/game-widgets.js +182 -31
  44. package/dist/commands/game-world.d.ts +32 -3
  45. package/dist/commands/game-world.js +113 -24
  46. package/dist/commands/image.js +1 -1
  47. package/dist/commands/init.js +2 -2
  48. package/dist/commands/mode.d.ts +1 -1
  49. package/dist/commands/package.d.ts +15 -1
  50. package/dist/commands/package.js +96 -24
  51. package/dist/commands/progression.d.ts +2 -0
  52. package/dist/commands/progression.js +7 -2
  53. package/dist/commands/roll.d.ts +2 -0
  54. package/dist/commands/roll.js +50 -24
  55. package/dist/commands/rules.js +6 -4
  56. package/dist/commands/scene.d.ts +2 -2
  57. package/dist/commands/scene.js +13 -10
  58. package/dist/commands/sheet.js +10 -1
  59. package/dist/commands/status.d.ts +1 -0
  60. package/dist/commands/status.js +14 -4
  61. package/dist/commands/trade.js +6 -4
  62. package/dist/commands/translate.js +2 -2
  63. package/dist/commands/travel.js +1 -1
  64. package/dist/commands/validate.js +2 -2
  65. package/dist/commands/view.d.ts +12 -4
  66. package/dist/commands/view.js +11 -8
  67. package/dist/commands/worked-out.js +11 -5
  68. package/dist/commands/write.d.ts +8 -1
  69. package/dist/commands/write.js +84 -25
  70. package/dist/core/command-reference.js +3 -2
  71. package/dist/core/consents.d.ts +18 -0
  72. package/dist/core/consents.js +93 -0
  73. package/dist/core/context.d.ts +68 -27
  74. package/dist/core/context.js +3 -1
  75. package/dist/core/examples.d.ts +25 -0
  76. package/dist/core/examples.js +19 -0
  77. package/dist/core/files.d.ts +2 -0
  78. package/dist/core/files.js +10 -1
  79. package/dist/core/package-api.d.ts +388 -0
  80. package/dist/core/package-declarations.d.ts +102 -0
  81. package/dist/core/package-declarations.js +81 -0
  82. package/dist/core/registry.d.ts +4 -0
  83. package/dist/core/text.d.ts +5 -0
  84. package/dist/core/text.js +12 -0
  85. package/dist/dashboard/acts.js +31 -24
  86. package/dist/dashboard/address.js +4 -1
  87. package/dist/dashboard/api.js +65 -3
  88. package/dist/dashboard/app.js +222 -98
  89. package/dist/dashboard/ask-card.js +169 -0
  90. package/dist/dashboard/asked-dice.js +57 -0
  91. package/dist/dashboard/dice/tray.js +6 -4
  92. package/dist/dashboard/extension-widgets.js +136 -16
  93. package/dist/dashboard/faces.js +6 -4
  94. package/dist/dashboard/help.js +10 -3
  95. package/dist/dashboard/i18n/ar.json +34 -29
  96. package/dist/dashboard/i18n/cs.json +34 -29
  97. package/dist/dashboard/i18n/da.json +34 -29
  98. package/dist/dashboard/i18n/de.json +34 -29
  99. package/dist/dashboard/i18n/el.json +34 -29
  100. package/dist/dashboard/i18n/es.json +34 -29
  101. package/dist/dashboard/i18n/fi.json +34 -29
  102. package/dist/dashboard/i18n/fr.json +34 -29
  103. package/dist/dashboard/i18n/he.json +34 -29
  104. package/dist/dashboard/i18n/hi.json +34 -29
  105. package/dist/dashboard/i18n/hu.json +34 -29
  106. package/dist/dashboard/i18n/is.json +34 -29
  107. package/dist/dashboard/i18n/it.json +34 -29
  108. package/dist/dashboard/i18n/ja.json +34 -29
  109. package/dist/dashboard/i18n/ko.json +34 -29
  110. package/dist/dashboard/i18n/nb.json +34 -29
  111. package/dist/dashboard/i18n/nl.json +34 -29
  112. package/dist/dashboard/i18n/pl.json +34 -29
  113. package/dist/dashboard/i18n/pt.json +34 -29
  114. package/dist/dashboard/i18n/ro.json +34 -29
  115. package/dist/dashboard/i18n/ru.json +34 -29
  116. package/dist/dashboard/i18n/sv.json +34 -29
  117. package/dist/dashboard/i18n/tr.json +34 -29
  118. package/dist/dashboard/i18n/uk.json +34 -29
  119. package/dist/dashboard/i18n/zh.json +34 -29
  120. package/dist/dashboard/icons.js +4 -1
  121. package/dist/dashboard/kit.js +35 -0
  122. package/dist/dashboard/labels.js +1 -0
  123. package/dist/dashboard/pack-card.js +97 -0
  124. package/dist/dashboard/package-page.js +50 -0
  125. package/dist/dashboard/packages.js +180 -24
  126. package/dist/dashboard/page-code.js +248 -0
  127. package/dist/dashboard/party.js +13 -14
  128. package/dist/dashboard/people.js +4 -0
  129. package/dist/dashboard/person-panel.js +110 -0
  130. package/dist/dashboard/place-map-view.js +11 -6
  131. package/dist/dashboard/rolls.js +2 -2
  132. package/dist/dashboard/scene.js +12 -9
  133. package/dist/dashboard/settings.js +55 -9
  134. package/dist/dashboard/sheet.js +21 -13
  135. package/dist/dashboard/status.js +69 -15
  136. package/dist/dashboard/style.css +859 -574
  137. package/dist/dashboard/top.js +75 -25
  138. package/dist/dashboard/turns.js +34 -13
  139. package/dist/dashboard/widgets.js +9 -2
  140. package/dist/dashboard-server.js +246 -11
  141. package/dist/dice/roll-dice.js +1 -1
  142. package/dist/effects/effect.d.ts +7 -4
  143. package/dist/effects/effect.js +12 -9
  144. package/dist/extensions/engine.d.ts +4 -0
  145. package/dist/extensions/engine.js +74 -0
  146. package/dist/extensions/extension.d.ts +28 -33
  147. package/dist/extensions/extension.js +37 -46
  148. package/dist/extensions/index.d.ts +4 -3
  149. package/dist/extensions/index.js +5 -2
  150. package/dist/extensions/packages.d.ts +14 -0
  151. package/dist/extensions/packages.js +148 -12
  152. package/dist/extensions/words.d.ts +2 -1
  153. package/dist/extensions/words.js +5 -4
  154. package/dist/index.d.ts +1 -3
  155. package/dist/mcp-server.js +52 -15
  156. package/dist/page-words.d.ts +4 -0
  157. package/dist/page-words.js +4 -4
  158. package/dist/page.d.ts +218 -0
  159. package/dist/page.js +2 -0
  160. package/dist/pages/index.d.ts +1 -1
  161. package/dist/pages/index.js +1 -1
  162. package/dist/pages/load.d.ts +7 -1
  163. package/dist/pages/load.js +10 -5
  164. package/dist/pages/page-file.js +1 -1
  165. package/dist/pages/stack-writes.js +5 -4
  166. package/dist/pages/standard-fields.d.ts +2 -0
  167. package/dist/pages/standard-fields.js +8 -1
  168. package/dist/pages/world.d.ts +8 -0
  169. package/dist/pages/world.js +9 -2
  170. package/dist/systems/game-system.d.ts +61 -30
  171. package/dist/systems/game-system.js +159 -50
  172. package/dist/systems/index.d.ts +3 -3
  173. package/dist/systems/index.js +3 -3
  174. package/dist/systems/system-code.d.ts +29 -88
  175. package/dist/systems/system-code.js +68 -23
  176. package/dist/systems/words.d.ts +2 -0
  177. package/dist/systems/words.js +11 -0
  178. package/dist/testing.d.ts +76 -0
  179. package/dist/testing.js +197 -0
  180. package/instructions/combat.md +2 -2
  181. package/instructions/core.md +2 -2
  182. package/instructions/dashboard.md +1 -1
  183. package/instructions/mentor-tutorial.md +1 -1
  184. package/instructions/play.md +2 -2
  185. package/instructions/setup.md +1 -1
  186. package/package.json +15 -2
  187. package/systems/5e/LICENSE.md +13 -3
  188. package/systems/5e/dist/dying.js +83 -16
  189. package/systems/5e/dist/index.js +2 -2
  190. package/systems/5e/dist/page-style.js +634 -0
  191. package/systems/5e/dist/page.js +166 -0
  192. package/systems/5e/dist/shown.js +23 -0
  193. package/systems/5e/instructions/combat.md +1 -0
  194. package/systems/5e/package.json +4 -2
  195. package/systems/5e/system.yaml +35 -7
  196. package/systems/5e/versions/srd-5.1/system.yaml +2 -0
  197. package/systems/5e/words/ar.yaml +30 -0
  198. package/systems/5e/words/cs.yaml +30 -0
  199. package/systems/5e/words/da.yaml +30 -0
  200. package/systems/5e/words/de.yaml +30 -0
  201. package/systems/5e/words/el.yaml +30 -0
  202. package/systems/5e/words/es.yaml +30 -0
  203. package/systems/5e/words/fi.yaml +30 -0
  204. package/systems/5e/words/fr.yaml +30 -0
  205. package/systems/5e/words/he.yaml +30 -0
  206. package/systems/5e/words/hi.yaml +30 -0
  207. package/systems/5e/words/hu.yaml +30 -0
  208. package/systems/5e/words/is.yaml +30 -0
  209. package/systems/5e/words/it.yaml +30 -0
  210. package/systems/5e/words/ja.yaml +30 -0
  211. package/systems/5e/words/ko.yaml +30 -0
  212. package/systems/5e/words/nb.yaml +30 -0
  213. package/systems/5e/words/nl.yaml +30 -0
  214. package/systems/5e/words/pl.yaml +30 -0
  215. package/systems/5e/words/pt.yaml +30 -0
  216. package/systems/5e/words/ro.yaml +30 -0
  217. package/systems/5e/words/ru.yaml +30 -0
  218. package/systems/5e/words/sv.yaml +30 -0
  219. package/systems/5e/words/tr.yaml +30 -0
  220. package/systems/5e/words/uk.yaml +30 -0
  221. package/systems/5e/words/zh.yaml +30 -0
  222. package/dist/commands/game-extensions.d.ts +0 -34
  223. package/dist/commands/game-extensions.js +0 -182
  224. package/dist/commands/game-system-code.d.ts +0 -25
  225. package/dist/commands/game-system-code.js +0 -172
  226. package/dist/dashboard/death-save.js +0 -67
  227. package/dist/dashboard/dying.js +0 -46
  228. package/dist/dashboard/save-outcome.js +0 -42
  229. package/dist/dashboard/spend.js +0 -115
  230. package/dist/extensions/api.d.ts +0 -155
  231. /package/dist/{extensions/api.js → core/package-api.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpg-engine",
3
- "version": "0.4.1",
3
+ "version": "0.6.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": {
@@ -8,10 +8,22 @@
8
8
  },
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
11
+ "rpg-engine": {
12
+ "kind": "engine",
13
+ "api": 5
14
+ },
11
15
  "exports": {
12
16
  ".": {
13
17
  "types": "./dist/index.d.ts",
14
18
  "default": "./dist/index.js"
19
+ },
20
+ "./page": {
21
+ "types": "./dist/page.d.ts",
22
+ "default": "./dist/page.js"
23
+ },
24
+ "./testing": {
25
+ "types": "./dist/testing.d.ts",
26
+ "default": "./dist/testing.js"
15
27
  }
16
28
  },
17
29
  "files": [
@@ -25,11 +37,12 @@
25
37
  "instructions"
26
38
  ],
27
39
  "scripts": {
28
- "build": "node -e \"for (const folder of ['dist', 'systems/5e/dist', 'extensions/weather/dist']) require('node:fs').rmSync(folder, { recursive: true, force: true })\" && tsc && tsc -p src/dashboard && node -e \"require('node:fs').cpSync('src/dashboard', 'dist/dashboard', { recursive: true, filter: (path) => !/[.](tsx?|py)$|tsconfig[.]json$/.test(path) })\" && tsc -p extensions/weather && tsc -p systems/5e",
40
+ "build": "node -e \"for (const folder of ['dist', 'systems/5e/dist']) require('node:fs').rmSync(folder, { recursive: true, force: true })\" && tsc && tsc -p src/dashboard && node -e \"require('node:fs').cpSync('src/dashboard', 'dist/dashboard', { recursive: true, filter: (path) => !/[.](tsx?|py)$|tsconfig[.]json$/.test(path) })\" && tsc -p systems/5e",
29
41
  "dev": "tsc --watch",
30
42
  "demo": "npm run build && node --experimental-strip-types --no-warnings test/demo/dashboard.ts --ask --port 5760",
31
43
  "betasim": "npm run build && node --experimental-strip-types --no-warnings test/betasim/run.ts",
32
44
  "translate": "node --experimental-strip-types --no-warnings test/i18n/translate.ts",
45
+ "test:downstream": "node --experimental-strip-types --no-warnings test/downstream/run.ts",
33
46
  "test": "vitest run",
34
47
  "format": "eslint --fix . && dprint fmt",
35
48
  "lint": "eslint . && dprint check && tsc -p tsconfig.test.json && tsc -p src/dashboard --noEmit",
@@ -1,6 +1,6 @@
1
1
  # The 5e system: license
2
2
 
3
- The pages in `world/`, the rules in `rules/` and the game's data in `system.yaml` (its coins, conditions, the length of a round, the titles of its rules, its proficiency table, the names of its skills, how its numbers are worked out, and the uses of features with the rests that bring them back), and the Italian words of `words/it.yaml` are material from the System Reference Document 5.1, under the Creative Commons Attribution 4.0 International License (CC-BY-4.0). The rest of rpg-engine is under the MIT license.
3
+ This package holds material under three licenses. The pages in `world/`, the rules in `rules/`, the game's data in `system.yaml` and `versions/` (its coins, conditions, the length of a round, the titles of its rules, its proficiency table, the names of its skills, how its numbers are worked out, and the uses of features with the rests that bring them back), and the words in `words/` are material from the System Reference Document 5.1, changed as said below, under the Creative Commons Attribution 4.0 International License (CC-BY-4.0); our changes to them are under the same license. The icons in `images/` are under the Creative Commons Attribution 3.0 Unported License (CC-BY-3.0). The code (`src/`, built into `dist/`), the instructions in `instructions/`, the scripts in `build/` and the tests are under the MIT license, whose text is below.
4
4
 
5
5
  This work includes material taken from the System Reference Document 5.1 ("SRD 5.1") by Wizards of the Coast LLC and available at https://dnd.wizards.com/resources/systems-reference-document. The SRD 5.1 is licensed under the Creative Commons Attribution 4.0 International License available at https://creativecommons.org/licenses/by/4.0/legalcode.
6
6
 
@@ -10,7 +10,7 @@ The Italian words in `words/it.yaml` are taken from the Italian translation of t
10
10
 
11
11
  Questo lavoro include materiale del System Reference Document 5.1 ("SRD 5.1") di Wizards of the Coast LLC disponibile al sito https://dnd.wizards.com/it/resources/systems-reference-document. L'SRD 5.1 è concesso in licenza sotto l'Attribuzione 4.0 Internazionale di Creative Commons disponibile al sito https://creativecommons.org/licenses/by/4.0/legalcode.it.
12
12
 
13
- Changes: `words/it.yaml` is a table of ours from the English names of this system to the words of the Italian SRD 5.1, for what the dashboard shows; a word that the Italian SRD does not have is ours, and marked as such in the file. Only words are taken from it, never its measures in metres, nor its text. The words in the other languages (`words/<code>.yaml`) are our translations of the same list, following the terms of the SRD 5.1's official translation in that language where there is one.
13
+ Changes: `words/it.yaml` is a table of ours from the English names of this system to the words of the Italian SRD 5.1, for what the dashboard shows; a word that the Italian SRD does not have is ours, and marked as such in the file. Only words are taken from it, never its measures in metres, nor its text. The words in the other languages (`words/<code>.yaml`) are our translations of the same list, following the terms of the SRD 5.1's official translation in that language where there is one; they are material adapted from the SRD 5.1, under CC-BY-4.0 as above.
14
14
 
15
15
  Changes: the material was converted into pages with fields and sections. Names are written in natural order, with the name the SRD gives as an alias when it differs (Leather Armor for "Leather", Hempen Rope for "Rope, hempen (50 feet)", Sledgehammer for "Hammer, sledge", Stone of Good Luck for "Stone of Good Luck (Luckstone)"), a saddle with its kind (Exotic Saddle), and as the stat blocks write them. Units are written without the final period (40 ft, 3 lb). Potion of Healing joins the adventuring gear entry and the magic item, with the gear entry's sentence on drinking it after the magic item's text. A stat block within an item is set off as a quotation.
16
16
 
@@ -20,6 +20,16 @@ The creatures of the Monsters chapter (pages 261–357) and of appendices MM-A a
20
20
 
21
21
  The rules in `rules/` are the text of the SRD 5.1 in markdown, with its headings, tables, bold and italics, and its words unchanged: a heading is one level below the nearest larger one above it in the PDF, and the title of a sidebar is at the level of the headings beside it. Adventuring and Combat are titles of ours: in the SRD their sections follow those of Using Ability Scores without a title of their own. Traps, Diseases, Madness, Objects and Poisons close Spellcasting in the SRD, after its spells, without a chapter of their own (pages 195–205): each is a chapter here, its headings one level up. Some chapters are taken in part: Spellcasting without its spell lists and spells (pages 100–104), and Magic Items without its items, which are pages, and so without the heading Artifacts, which holds only the Orb of Dragonkind. The sidebars Equipment Packs and Self-Sufficiency are sections, and a row that heads a group in a table, in italics in the PDF, is in bold, as in the Armor and Weapons tables. Beyond 1st Level is taken up to its backgrounds (pages 56–60), which the page Acolyte (background) holds; Races, Monsters and Appendix MM-B: Nonplayer Characters without their races and stat blocks, which are pages (pages 3, 254–260, 395), Monsters keeping as a section of its own the Half-Dragon Template that stands among its stat blocks (pages 320–321). In the Travel Pace table, the heading "Distance Traveled per..." is written out in each of its three columns. The tables Proficiency Bonus by Challenge Rating and Experience Points by Challenge Rating, printed in two halves side by side (pages 256, 258), are each one table of two columns, and in Appendix PH-B each table of deities follows its pantheon's text (pages 360–362). The run-in title X/Day (page 259) is not in bold italics, since a title cannot hold a slash. A sidebar that falls among the parts of a section closes it, at the section's level, as Armor, Weapon, and Tool Proficiencies after Senses (page 257). Appendix MM-A's creatures are pages; its two lines of introduction (page 366) are left out.
22
22
 
23
+ The code, the instructions, the scripts and the tests are under the MIT license:
24
+
25
+ Copyright (c) 2026 Stefano Caronia
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
+
23
33
  The icons in `images/` are from game-icons.net (https://game-icons.net), under the Creative Commons Attribution 3.0 Unported License (CC-BY-3.0, https://creativecommons.org/licenses/by/3.0/): icons made by Carl Olsen, Caro Asercion, Cathelineau, DarkZaitzev, Delapouite, Faithtoken, John Redman, Kier Heyl, Lorc, Pierre Leducq, Sbed, Skoll, Sparker, Willdabeast and Zajkonur, available on https://game-icons.net. Changes: none; they are the white icons on a transparent background, named as on game-icons.net, with the author's name after it when two have the same.
24
34
 
25
- rpg-engine is compatible with fifth edition.
35
+ This system is compatible with fifth edition.
@@ -6,13 +6,25 @@ const successes = { field: "death-successes", most: 3 };
6
6
  const failures = { field: "death-failures", most: 3 };
7
7
  const save = { dice: "1d20", sides: 20, atLeast: 10, highest: { field: hp, value: 1 }, lowest: 2 };
8
8
  const rules = { instant: "Instant Death", saves: "Death Saving Throws" };
9
- /** The dying point's hooks. */
10
- export const dyingHooks = {
9
+ // The counters of the hit dice a rest spends, by the die of each class (p. 56).
10
+ const hitDice = "hit-dice-";
11
+ // The words of each state on the dashboard, translated by the 5e's words.
12
+ const stateWords = { dying: "Dying", stable: "Stable", dead: "Dead" };
13
+ /** The dying point's hooks and its widgets, and how its death saves and hit dice are asked on the dashboard. */
14
+ export const dyingCode = {
11
15
  counterChanged: (change, game) => afterHitPoints(change, game),
12
16
  turnStarted: ({ who }, game) => turnOf(who, game),
13
17
  rolled: (roll, game) => playersSave(roll, game),
14
18
  effectAdded: ({ page, effect }, game) => (game.sameName(effect, stableEffect) ? stabilized(page, game) : []),
15
- asking: ({ who, notations }, game) => saveAsked(who, notations, game),
19
+ // A death save is asked in its card, with no button to turn it down (D-460); the hit dice of a rest in theirs (ASK-14).
20
+ asking: ({ who, checks, notations, recipe }, game) => recipe !== undefined
21
+ ? checks.length > 0 && checks.every((field) => field.toLowerCase().startsWith(hitDice)) ? { card: { widget: "hit-dice", key: `${who} ${game.now()?.date ?? ""}` } } : undefined
22
+ : saveAsking(who, notations, game),
23
+ widgets: {
24
+ "dying": (game, asked) => dyingWidget(game, asked?.who),
25
+ "death-save": (game, asked) => (asked?.key === undefined ? undefined : saveWidget(game, asked.who)),
26
+ "hit-dice": (_game, asked) => (asked?.key === undefined ? undefined : { body: "hit-dice", says: "Hit Dice" }),
27
+ },
16
28
  };
17
29
  /** Whether a party member is dying now (DIE-4): at 0 hit points, neither stable by its successes nor dead by its failures. */
18
30
  function isDying(page) {
@@ -35,7 +47,7 @@ function afterHitPoints(change, game) {
35
47
  const failed = counted(page, failures.field);
36
48
  // The dead, at their most failures, are not brought back by hit points: they go back to 0, and only what the rules say brings them back (DIE-7).
37
49
  if (change.after > 0 && change.before <= 0 && failed >= failures.most) {
38
- game.set(name, { [hp]: 0 }, "the dead regain nothing");
50
+ setCounters(game, name, { [hp]: 0 }, "the dead regain nothing");
39
51
  return [
40
52
  `${name} is dead, with ${failures.field} ${failed}: what this change gave is undone, ${hp} back to 0, as ${hp} regained brings no one back. To bring ${name} back as the rules say, as a spell does: `
41
53
  + `first change ${failures.field} to 0, then give the ${hp}.`,
@@ -54,14 +66,14 @@ function afterHitPoints(change, game) {
54
66
  const past = change.lost - Math.max(change.before, 0);
55
67
  // Damage past 0 as large as the maximum kills at once (DIE-2), one stable too (DIE-6).
56
68
  if (change.lost > 0 && change.max !== undefined && past >= change.max) {
57
- game.set(name, { [failures.field]: failures.most, ...(wasStable ? { [successes.field]: 0 } : {}) }, "instant death");
69
+ setCounters(game, name, { [failures.field]: failures.most, ...(wasStable ? { [successes.field]: 0 } : {}) }, "instant death");
58
70
  const unstable = wasStable && game.endEffect(name, stableEffect, "instant death");
59
71
  lines.push(`${name} dies at once: ${past} past 0 is at least the maximum, ${change.max}; ${failures.field} ${failed} → ${failures.most}${unstable ? `, ${stableEffect} ended` : ""}. Read rules ${rules.instant}.`);
60
72
  }
61
73
  else if (change.lost > 0 && change.before <= 0) {
62
74
  // Damage at 0 counts a failure (DIE-2); a critical hit counts two, which only the master knows. One stable is dying again (DIE-6).
63
75
  const after = Math.min(failed + 1, failures.most);
64
- game.set(name, { [failures.field]: after, ...(wasStable ? { [successes.field]: 0 } : {}) }, `damage at 0 ${hp}`);
76
+ setCounters(game, name, { [failures.field]: after, ...(wasStable ? { [successes.field]: 0 } : {}) }, `damage at 0 ${hp}`);
65
77
  const unstable = wasStable && game.endEffect(name, stableEffect, `damage at 0 ${hp}`);
66
78
  const dead = after >= failures.most;
67
79
  const again = wasStable
@@ -84,7 +96,7 @@ function back(page, game) {
84
96
  const name = page.name;
85
97
  const reset = [successes.field, failures.field].filter((field) => counted(page, field) !== 0);
86
98
  const was = Object.fromEntries(reset.map((field) => [field, counted(page, field)]));
87
- game.set(name, Object.fromEntries(reset.map((field) => [field, 0])), `${hp} above 0`);
99
+ setCounters(game, name, Object.fromEntries(reset.map((field) => [field, 0])), `${hp} above 0`);
88
100
  const ended = game.endEffect(name, unconscious, "hit points regained");
89
101
  const stable = game.endEffect(name, stableEffect, "hit points regained");
90
102
  const parts = [...reset.map((field) => `${field} ${was[field]} → 0`), ...(ended ? [`${unconscious} ended`] : []), ...(stable ? [`${stableEffect} ended`] : [])];
@@ -106,7 +118,7 @@ function turnOf(who, game) {
106
118
  return [`${page.name} is dying: the turn starts with their death save, the player's to roll: ask them, with ask, a check of ${save.dice}; the engine writes its outcome.${stabilize}${read}`];
107
119
  }
108
120
  const rolled = game.roll(save.dice, { who: page.name, why: "death save" });
109
- const lines = saved(page, { who: page.name, notation: save.dice, total: rolled.total, dice: rolled.dice }, game);
121
+ const lines = saved(page, { ...rolled, who: page.name }, game);
110
122
  const still = isDying(game.page(page.name)) ? stabilize : "";
111
123
  return [`${page.name} is dying: the engine rolled its death save, ${rolled.text}, so never roll it again. ${lines.join(" ")} ${tellingOf(game.setting("mentor"))}${still}${read}`];
112
124
  }
@@ -127,7 +139,7 @@ function saved(page, roll, game) {
127
139
  const name = page.name;
128
140
  if (natural === save.sides) {
129
141
  const own = page.counter(hp);
130
- game.set(name, { [hp]: save.highest.value }, "death save");
142
+ setCounters(game, name, { [hp]: save.highest.value }, "death save");
131
143
  const shown = (value) => `${value}${own?.max === undefined ? "" : `/${own.max}`}`;
132
144
  return [`${name}'s death save: ${natural}, the highest face: ${hp} ${shown(own?.value ?? 0)} → ${shown(save.highest.value)}.`, ...back(page, game)];
133
145
  }
@@ -136,7 +148,7 @@ function saved(page, roll, game) {
136
148
  const after = Math.min(before + 1, successes.most);
137
149
  const failed = counted(page, failures.field);
138
150
  const stable = after >= successes.most;
139
- game.set(name, { [successes.field]: after, ...(stable && failed > 0 ? { [failures.field]: 0 } : {}) }, "death save");
151
+ setCounters(game, name, { [successes.field]: after, ...(stable && failed > 0 ? { [failures.field]: 0 } : {}) }, "death save");
140
152
  if (stable) {
141
153
  game.addEffect(name, stableEffect, "death save");
142
154
  }
@@ -147,7 +159,7 @@ function saved(page, roll, game) {
147
159
  const before = counted(page, failures.field);
148
160
  const lost = natural === 1 ? save.lowest : 1;
149
161
  const after = Math.min(before + lost, failures.most);
150
- game.set(name, { [failures.field]: after }, "death save");
162
+ setCounters(game, name, { [failures.field]: after }, "death save");
151
163
  const dead = after >= failures.most ? ` ${name} dies: a moment of its own in the story.` : "";
152
164
  return [`${name}'s death save: ${roll.total}, ${lost > 1 ? `the lowest face, ${lost} failures` : "a failure"}; ${failures.field} ${before} → ${after}.${dead}`];
153
165
  }
@@ -159,25 +171,74 @@ function stabilized(name, game) {
159
171
  }
160
172
  const succeeded = counted(page, successes.field);
161
173
  const failed = counted(page, failures.field);
162
- game.set(page.name, { [successes.field]: successes.most, [failures.field]: 0 }, `${stableEffect} given`);
174
+ setCounters(game, page.name, { [successes.field]: successes.most, [failures.field]: 0 }, `${stableEffect} given`);
163
175
  return [
164
176
  `${page.name} is stable: ${successes.field} ${succeeded} → ${successes.most}, ${failures.field} ${failed} → 0; no more death saves, still ${unconscious} until it regains ${hp}.`,
165
177
  ];
166
178
  }
167
- /** The death save a question asks of a dying player character (D-460): every check the save's die, with the counters as they stand, for the page to draw. */
168
- function saveAsked(who, notations, game) {
179
+ /** The death save a question asks of a dying player character (D-460): every check the save's die, asked in its card, forced. */
180
+ function saveAsking(who, notations, game) {
169
181
  const page = game.page(who);
170
182
  if (!isDying(page) || !page.pc || notations.length === 0 || !notations.every(isSaveRoll)) {
171
183
  return undefined;
172
184
  }
185
+ const marks = `${counted(page, successes.field)}/${counted(page, failures.field)}`;
186
+ return { card: { widget: "death-save", key: `${page.name} ${game.now()?.date ?? ""} ${marks}` }, decline: false };
187
+ }
188
+ /** Where one of the party at 0 stands: dying, stable at the last success, dead at the last failure; none above 0, or marked dead. */
189
+ function stateOf(page) {
190
+ const counter = page?.counter(hp);
191
+ if (page === undefined || !page.party || counter === undefined || counter.value > 0 || page.value("status") === "dead") {
192
+ return undefined;
193
+ }
194
+ return counted(page, failures.field) >= failures.most ? "dead" : counted(page, successes.field) >= successes.most ? "stable" : "dying";
195
+ }
196
+ /**
197
+ * One of the party at 0 hit points, on them (D-516): the word of their state, red dying, green stable, dead greyed; the successes on one side and the
198
+ * failures on the other, which leave the line of values; the line of the heart over the word.
199
+ */
200
+ function dyingWidget(game, who) {
201
+ const page = who === undefined ? undefined : game.page(who);
202
+ const state = stateOf(page);
203
+ if (page === undefined || state === undefined) {
204
+ return undefined;
205
+ }
206
+ const [succeeded, failed] = [counted(page, successes.field), counted(page, failures.field)];
207
+ const data = { state };
173
208
  return {
209
+ icon: "heartbeat",
210
+ chip: stateWords[state],
211
+ ...(state === "dead" ? { dead: true } : {}),
212
+ says: { text: "{who}: {state}", values: { who: page.name, state: stateWords[state] } },
213
+ data,
214
+ parts: [
215
+ { track: { label: "Successes", value: succeeded, max: successes.most, tone: "good", stage: "start", field: successes.field } },
216
+ { lead: stateWords[state], ...(state === "dead" ? {} : { tone: state === "stable" ? "good" : "bad" }), figure: "heartbeat" },
217
+ { track: { label: "Failures", value: failed, max: failures.most, tone: "bad", stage: "end", field: failures.field } },
218
+ ],
219
+ };
220
+ }
221
+ /** The card of a death save, for who rolls it, before and after the dice: their counters, whether still at 0 and whether dead, and what the save's faces do. */
222
+ function saveWidget(game, who) {
223
+ const page = who === undefined ? undefined : game.page(who);
224
+ if (page === undefined) {
225
+ return undefined;
226
+ }
227
+ const failed = counted(page, failures.field);
228
+ const data = {
229
+ who: page.name,
230
+ successes: { value: counted(page, successes.field), most: successes.most },
231
+ failures: { value: failed, most: failures.most },
232
+ down: (page.counter(hp)?.value ?? 0) <= 0,
233
+ dead: failed >= failures.most || page.value("status") === "dead",
174
234
  sides: save.sides,
175
235
  atLeast: save.atLeast,
176
- successes: { field: successes.field, value: counted(page, successes.field), most: successes.most },
177
- failures: { field: failures.field, value: counted(page, failures.field), most: failures.most },
178
236
  lowest: save.lowest,
179
237
  highest: save.highest,
180
238
  };
239
+ // The card in the tint of the moment (D-461, D-517): red while dying, green stable, gold back on their feet, grey dead.
240
+ const tint = data.dead ? "muted" : !data.down ? "gold" : data.successes.value >= successes.most ? "ally" : "low";
241
+ return { body: "death-save", says: "Death Saving Throw", tint, data };
181
242
  }
182
243
  /** How the master tells a companion's death save (D-460): with the mentor off, the story alone, never naming it; else the roll in brackets, explained once in the tutorial. */
183
244
  function tellingOf(mentor) {
@@ -191,3 +252,9 @@ function isSaveRoll(notation) {
191
252
  const compact = notation.toLowerCase().replace(/\s+/g, "").replace(/(^|[+-])d/g, "$11d");
192
253
  return compact.startsWith(save.dice) && compact.slice(save.dice.length).split(/(?=[+-])/).filter((term) => term !== "").every((term) => /^[+-]\d*d\d+$/.test(term));
193
254
  }
255
+ /** Counters changed as the change command changes them, one by one, each to its value: the rules watch them, so they are never just written (D-514). */
256
+ function setCounters(game, page, values, why) {
257
+ for (const [field, value] of Object.entries(values)) {
258
+ game.change(page, field, { to: value }, why);
259
+ }
260
+ }
@@ -1,3 +1,3 @@
1
- import { dyingHooks } from "./dying.js";
2
- const fifthEdition = () => dyingHooks;
1
+ import { dyingCode } from "./dying.js";
2
+ const fifthEdition = () => dyingCode;
3
3
  export default fifthEdition;