rpg-engine 0.15.0 → 0.17.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 (503) hide show
  1. package/dist/adventures/source.d.ts +3 -1
  2. package/dist/adventures/source.js +31 -1
  3. package/dist/campaign/find-campaign.js +8 -4
  4. package/dist/campaign/index.d.ts +1 -1
  5. package/dist/campaign/index.js +1 -1
  6. package/dist/campaign/settings.d.ts +6 -0
  7. package/dist/campaign/settings.js +22 -1
  8. package/dist/cli/cli.js +1 -1
  9. package/dist/cli/command-line.js +1 -1
  10. package/dist/commands/advance.d.ts +1 -1
  11. package/dist/commands/advance.js +6 -6
  12. package/dist/commands/ask.js +7 -7
  13. package/dist/commands/change/amounts.d.ts +32 -0
  14. package/dist/commands/change/amounts.js +150 -0
  15. package/dist/commands/change/change.d.ts +4 -54
  16. package/dist/commands/change/change.js +19 -749
  17. package/dist/commands/change/damage.d.ts +30 -0
  18. package/dist/commands/change/damage.js +73 -2
  19. package/dist/commands/change/dice.d.ts +34 -0
  20. package/dist/commands/change/dice.js +59 -0
  21. package/dist/commands/change/fields.d.ts +37 -0
  22. package/dist/commands/change/fields.js +156 -0
  23. package/dist/commands/change/holder.d.ts +48 -0
  24. package/dist/commands/change/holder.js +162 -0
  25. package/dist/commands/change/recipe-pace.js +1 -1
  26. package/dist/commands/change/recipe.d.ts +58 -0
  27. package/dist/commands/change/recipe.js +179 -0
  28. package/dist/commands/choices.js +3 -3
  29. package/dist/commands/config/config.d.ts +15 -0
  30. package/dist/commands/config/config.js +355 -0
  31. package/dist/commands/config/custom-levels.d.ts +7 -0
  32. package/dist/commands/config/custom-levels.js +32 -0
  33. package/dist/commands/{config.d.ts → config/dashboard.d.ts} +2 -24
  34. package/dist/commands/config/dashboard.js +171 -0
  35. package/dist/commands/config/entries.d.ts +17 -0
  36. package/dist/commands/config/entries.js +76 -0
  37. package/dist/commands/config/news.d.ts +7 -0
  38. package/dist/commands/config/news.js +88 -0
  39. package/dist/commands/config/shown.d.ts +9 -0
  40. package/dist/commands/config/shown.js +80 -0
  41. package/dist/commands/config/words.d.ts +27 -0
  42. package/dist/commands/config/words.js +204 -0
  43. package/dist/commands/effect.js +9 -9
  44. package/dist/commands/find.js +1 -1
  45. package/dist/commands/image.js +6 -6
  46. package/dist/commands/import/import.d.ts +0 -2
  47. package/dist/commands/import/import.js +68 -45
  48. package/dist/commands/import/run.js +1 -1
  49. package/dist/commands/index.js +3 -3
  50. package/dist/commands/init.js +2 -2
  51. package/dist/commands/install.js +1 -1
  52. package/dist/commands/instructions.js +6 -6
  53. package/dist/commands/mode.d.ts +2 -2
  54. package/dist/commands/mode.js +8 -8
  55. package/dist/commands/mood.js +4 -4
  56. package/dist/commands/move.js +10 -10
  57. package/dist/commands/package/consent.d.ts +11 -0
  58. package/dist/commands/package/consent.js +52 -0
  59. package/dist/commands/package/here.d.ts +51 -0
  60. package/dist/commands/package/here.js +128 -0
  61. package/dist/commands/package/install.d.ts +10 -0
  62. package/dist/commands/package/install.js +337 -0
  63. package/dist/commands/package/package.d.ts +18 -0
  64. package/dist/commands/package/package.js +270 -0
  65. package/dist/commands/package/result.d.ts +89 -0
  66. package/dist/commands/package/result.js +1 -0
  67. package/dist/commands/package/uninstall.d.ts +6 -0
  68. package/dist/commands/package/uninstall.js +70 -0
  69. package/dist/commands/rename.js +3 -3
  70. package/dist/commands/reveal.js +5 -5
  71. package/dist/commands/roll/roll.js +11 -9
  72. package/dist/commands/roll/tables.js +1 -1
  73. package/dist/commands/rules.d.ts +2 -2
  74. package/dist/commands/rules.js +3 -3
  75. package/dist/commands/save.d.ts +2 -2
  76. package/dist/commands/save.js +2 -2
  77. package/dist/commands/scene/close.d.ts +18 -0
  78. package/dist/commands/scene/close.js +179 -0
  79. package/dist/commands/scene/members.d.ts +14 -0
  80. package/dist/commands/scene/members.js +32 -0
  81. package/dist/commands/scene/open.d.ts +6 -0
  82. package/dist/commands/scene/open.js +298 -0
  83. package/dist/commands/scene/result.d.ts +98 -0
  84. package/dist/commands/scene/result.js +2 -0
  85. package/dist/commands/{scene.d.ts → scene/scene.d.ts} +10 -36
  86. package/dist/commands/scene/scene.js +210 -0
  87. package/dist/commands/scene/turns.d.ts +18 -0
  88. package/dist/commands/scene/turns.js +229 -0
  89. package/dist/commands/shared/books/adventure-layers.d.ts +89 -0
  90. package/dist/commands/shared/books/adventure-layers.js +201 -0
  91. package/dist/commands/shared/{adventures.d.ts → books/adventures.d.ts} +28 -9
  92. package/dist/commands/shared/{adventures.js → books/adventures.js} +77 -35
  93. package/dist/commands/shared/{library-reader.js → books/library-reader.js} +3 -3
  94. package/dist/commands/shared/{library.d.ts → books/library.d.ts} +2 -2
  95. package/dist/commands/shared/{library.js → books/library.js} +9 -9
  96. package/dist/commands/shared/{rules.d.ts → books/rules.d.ts} +2 -2
  97. package/dist/commands/shared/{rules.js → books/rules.js} +5 -5
  98. package/dist/commands/shared/{system-texts.d.ts → books/system-texts.d.ts} +2 -2
  99. package/dist/commands/shared/{system-texts.js → books/system-texts.js} +9 -8
  100. package/dist/commands/shared/{page-words.d.ts → books/words.d.ts} +2 -2
  101. package/dist/commands/shared/{page-words.js → books/words.js} +4 -4
  102. package/dist/commands/shared/{checks.d.ts → campaign/checks.d.ts} +3 -3
  103. package/dist/commands/shared/{checks.js → campaign/checks.js} +7 -7
  104. package/dist/commands/shared/{images.d.ts → campaign/images.d.ts} +3 -3
  105. package/dist/commands/shared/{images.js → campaign/images.js} +5 -5
  106. package/dist/commands/shared/{mode.d.ts → campaign/mode.d.ts} +4 -4
  107. package/dist/commands/shared/{mode.js → campaign/mode.js} +24 -13
  108. package/dist/commands/shared/{money.d.ts → campaign/money.d.ts} +3 -3
  109. package/dist/commands/shared/{money.js → campaign/money.js} +2 -2
  110. package/dist/commands/shared/{offers.d.ts → campaign/offers.d.ts} +3 -3
  111. package/dist/commands/shared/{offers.js → campaign/offers.js} +3 -3
  112. package/dist/commands/shared/{outside.d.ts → campaign/outside.d.ts} +3 -3
  113. package/dist/commands/shared/{outside.js → campaign/outside.js} +7 -7
  114. package/dist/commands/shared/{parts.d.ts → campaign/parts.d.ts} +3 -3
  115. package/dist/commands/shared/{parts.js → campaign/parts.js} +3 -3
  116. package/dist/commands/shared/{problems.d.ts → campaign/problems.d.ts} +3 -3
  117. package/dist/commands/shared/{problems.js → campaign/problems.js} +17 -17
  118. package/dist/commands/shared/{quests.d.ts → campaign/quests.d.ts} +4 -4
  119. package/dist/commands/shared/{quests.js → campaign/quests.js} +6 -6
  120. package/dist/commands/shared/{saves.d.ts → campaign/saves.d.ts} +4 -4
  121. package/dist/commands/shared/{saves.js → campaign/saves.js} +10 -10
  122. package/dist/commands/shared/{theme.d.ts → campaign/theme.d.ts} +3 -3
  123. package/dist/commands/shared/{theme.js → campaign/theme.js} +1 -1
  124. package/dist/commands/shared/{world.d.ts → campaign/world.d.ts} +5 -5
  125. package/dist/commands/shared/{world.js → campaign/world.js} +17 -14
  126. package/dist/commands/shared/{knowledge.d.ts → characters/knowledge.d.ts} +3 -3
  127. package/dist/commands/shared/{knowledge.js → characters/knowledge.js} +4 -4
  128. package/dist/commands/shared/{moods.d.ts → characters/moods.d.ts} +3 -3
  129. package/dist/commands/shared/{moods.js → characters/moods.js} +3 -3
  130. package/dist/commands/shared/characters/orders.d.ts +4 -0
  131. package/dist/commands/shared/characters/orders.js +10 -0
  132. package/dist/commands/shared/{thoughts.d.ts → characters/thoughts.d.ts} +9 -6
  133. package/dist/commands/shared/{thoughts.js → characters/thoughts.js} +17 -7
  134. package/dist/commands/shared/{voices.d.ts → characters/voices.d.ts} +1 -1
  135. package/dist/commands/shared/{voices.js → characters/voices.js} +2 -2
  136. package/dist/commands/shared/examples.js +2 -2
  137. package/dist/commands/shared/packages/catalog.js +2 -2
  138. package/dist/commands/shared/packages/code.d.ts +1 -1
  139. package/dist/commands/shared/packages/code.js +8 -8
  140. package/dist/commands/shared/packages/extensions.d.ts +1 -1
  141. package/dist/commands/shared/packages/extensions.js +1 -1
  142. package/dist/commands/shared/packages/hooks.d.ts +1 -1
  143. package/dist/commands/shared/packages/hooks.js +1 -1
  144. package/dist/commands/shared/packages/widgets.d.ts +3 -3
  145. package/dist/commands/shared/packages/widgets.js +3 -3
  146. package/dist/commands/shared/{environment.d.ts → places/environment.d.ts} +1 -1
  147. package/dist/commands/shared/{environment.js → places/environment.js} +4 -4
  148. package/dist/commands/shared/{grid-moves.d.ts → places/grid-moves.d.ts} +4 -4
  149. package/dist/commands/shared/{grid-moves.js → places/grid-moves.js} +8 -7
  150. package/dist/commands/shared/{grids.d.ts → places/grids.d.ts} +4 -4
  151. package/dist/commands/shared/{grids.js → places/grids.js} +6 -6
  152. package/dist/commands/shared/{journey.d.ts → places/journey.d.ts} +3 -3
  153. package/dist/commands/shared/{journey.js → places/journey.js} +6 -6
  154. package/dist/commands/shared/{moves.d.ts → places/moves.d.ts} +2 -2
  155. package/dist/commands/shared/{moves.js → places/moves.js} +4 -4
  156. package/dist/commands/shared/{positions.d.ts → places/positions.d.ts} +2 -2
  157. package/dist/commands/shared/{positions.js → places/positions.js} +4 -4
  158. package/dist/commands/shared/{roads.d.ts → places/roads.d.ts} +5 -5
  159. package/dist/commands/shared/{roads.js → places/roads.js} +6 -6
  160. package/dist/commands/shared/{effects.d.ts → scene/effects.d.ts} +7 -7
  161. package/dist/commands/shared/{effects.js → scene/effects.js} +10 -10
  162. package/dist/commands/shared/{loot.d.ts → scene/loot.d.ts} +2 -2
  163. package/dist/commands/shared/{loot.js → scene/loot.js} +3 -3
  164. package/dist/commands/shared/{master-rolls.d.ts → scene/master-rolls.d.ts} +2 -2
  165. package/dist/commands/shared/{master-rolls.js → scene/master-rolls.js} +5 -5
  166. package/dist/commands/shared/{reminders.d.ts → scene/reminders.d.ts} +4 -4
  167. package/dist/commands/shared/{reminders.js → scene/reminders.js} +4 -4
  168. package/dist/commands/shared/{scene.d.ts → scene/scene.d.ts} +3 -3
  169. package/dist/commands/shared/{scene.js → scene/scene.js} +10 -8
  170. package/dist/commands/shared/{bonds.d.ts → sheet/bonds.d.ts} +3 -3
  171. package/dist/commands/shared/{bonds.js → sheet/bonds.js} +2 -2
  172. package/dist/commands/shared/{page-counters.d.ts → sheet/counters.d.ts} +3 -3
  173. package/dist/commands/shared/{page-counters.js → sheet/counters.js} +5 -5
  174. package/dist/commands/shared/{effect-layer.d.ts → sheet/effect-layer.d.ts} +2 -2
  175. package/dist/commands/shared/{effect-layer.js → sheet/effect-layer.js} +9 -6
  176. package/dist/commands/shared/sheet/effect-values.d.ts +9 -0
  177. package/dist/commands/shared/sheet/effect-values.js +69 -0
  178. package/dist/commands/shared/{experience.d.ts → sheet/experience.d.ts} +3 -3
  179. package/dist/commands/shared/{experience.js → sheet/experience.js} +5 -5
  180. package/dist/commands/shared/sheet/formula-problems.d.ts +8 -0
  181. package/dist/commands/shared/sheet/formula-problems.js +140 -0
  182. package/dist/commands/shared/sheet/formula-scope.d.ts +32 -0
  183. package/dist/commands/shared/sheet/formula-scope.js +235 -0
  184. package/dist/commands/shared/{limits.d.ts → sheet/limits.d.ts} +3 -3
  185. package/dist/commands/shared/{limits.js → sheet/limits.js} +5 -4
  186. package/dist/commands/shared/{progression.d.ts → sheet/progression.d.ts} +2 -2
  187. package/dist/commands/shared/{progression.js → sheet/progression.js} +4 -4
  188. package/dist/commands/shared/{sheet.d.ts → sheet/sheet.d.ts} +7 -5
  189. package/dist/commands/shared/{sheet.js → sheet/sheet.js} +11 -7
  190. package/dist/commands/shared/{stacks.d.ts → sheet/stacks.d.ts} +2 -2
  191. package/dist/commands/shared/{stacks.js → sheet/stacks.js} +4 -4
  192. package/dist/commands/shared/sheet/system-fields.d.ts +21 -0
  193. package/dist/commands/shared/sheet/system-fields.js +45 -0
  194. package/dist/commands/shared/{thresholds.d.ts → sheet/thresholds.d.ts} +1 -1
  195. package/dist/commands/shared/{thresholds.js → sheet/thresholds.js} +4 -4
  196. package/dist/commands/shared/{turn-uses.d.ts → sheet/turn-uses.d.ts} +3 -3
  197. package/dist/commands/shared/{turn-uses.js → sheet/turn-uses.js} +4 -3
  198. package/dist/commands/shared/{worked-out.d.ts → sheet/worked-out.d.ts} +11 -46
  199. package/dist/commands/shared/sheet/worked-out.js +291 -0
  200. package/dist/commands/shared/sheet/worked-text.d.ts +14 -0
  201. package/dist/commands/shared/sheet/worked-text.js +55 -0
  202. package/dist/commands/shared/{advance.d.ts → time/advance.d.ts} +3 -3
  203. package/dist/commands/shared/{advance.js → time/advance.js} +11 -11
  204. package/dist/commands/shared/{dice-pool.d.ts → time/dice-pool.d.ts} +3 -3
  205. package/dist/commands/shared/{dice-pool.js → time/dice-pool.js} +11 -11
  206. package/dist/commands/shared/{events.d.ts → time/events.d.ts} +5 -5
  207. package/dist/commands/shared/{events.js → time/events.js} +10 -13
  208. package/dist/commands/shared/{recipes.d.ts → time/recipes.d.ts} +3 -3
  209. package/dist/commands/shared/{recipes.js → time/recipes.js} +6 -5
  210. package/dist/commands/shared/{time.d.ts → time/time.d.ts} +4 -4
  211. package/dist/commands/shared/{time.js → time/time.js} +6 -6
  212. package/dist/commands/shared/{upkeep.d.ts → time/upkeep.d.ts} +3 -3
  213. package/dist/commands/shared/{upkeep.js → time/upkeep.js} +14 -13
  214. package/dist/commands/show.d.ts +9 -0
  215. package/dist/commands/show.js +43 -10
  216. package/dist/commands/status.d.ts +2 -1
  217. package/dist/commands/status.js +28 -22
  218. package/dist/commands/thoughts.d.ts +1 -0
  219. package/dist/commands/thoughts.js +26 -18
  220. package/dist/commands/trade.js +8 -8
  221. package/dist/commands/translate.d.ts +1 -1
  222. package/dist/commands/translate.js +3 -3
  223. package/dist/commands/travel/open.d.ts +1 -1
  224. package/dist/commands/travel/open.js +2 -2
  225. package/dist/commands/travel/route.js +7 -6
  226. package/dist/commands/travel/travel.d.ts +1 -1
  227. package/dist/commands/travel/travel.js +8 -8
  228. package/dist/commands/validate.js +3 -3
  229. package/dist/commands/view/journal.d.ts +2 -2
  230. package/dist/commands/view/journal.js +2 -2
  231. package/dist/commands/view/layers.d.ts +34 -0
  232. package/dist/commands/view/layers.js +44 -0
  233. package/dist/commands/view/map.d.ts +1 -1
  234. package/dist/commands/view/map.js +6 -6
  235. package/dist/commands/view/memory.d.ts +16 -0
  236. package/dist/commands/view/memory.js +96 -0
  237. package/dist/commands/view/page.d.ts +32 -0
  238. package/dist/commands/view/page.js +166 -0
  239. package/dist/commands/view/place.d.ts +7 -2
  240. package/dist/commands/view/place.js +30 -12
  241. package/dist/commands/view/result.d.ts +252 -0
  242. package/dist/commands/view/result.js +1 -0
  243. package/dist/commands/view/saves.d.ts +6 -0
  244. package/dist/commands/view/saves.js +53 -0
  245. package/dist/commands/view/story.d.ts +32 -0
  246. package/dist/commands/view/story.js +227 -0
  247. package/dist/commands/view/view.d.ts +29 -292
  248. package/dist/commands/view/view.js +31 -536
  249. package/dist/commands/view/world.d.ts +1 -1
  250. package/dist/commands/view/world.js +3 -3
  251. package/dist/commands/write/checks.d.ts +42 -0
  252. package/dist/commands/write/checks.js +291 -0
  253. package/dist/commands/write/here.d.ts +1 -1
  254. package/dist/commands/write/here.js +5 -5
  255. package/dist/commands/write/inheritance.d.ts +40 -0
  256. package/dist/commands/write/inheritance.js +185 -0
  257. package/dist/commands/write/input.d.ts +29 -0
  258. package/dist/commands/write/input.js +124 -0
  259. package/dist/commands/write/layer.d.ts +44 -0
  260. package/dist/commands/write/layer.js +68 -0
  261. package/dist/commands/write/notes.d.ts +22 -0
  262. package/dist/commands/write/notes.js +76 -0
  263. package/dist/commands/write/progression.d.ts +27 -0
  264. package/dist/commands/write/progression.js +175 -0
  265. package/dist/commands/write/write.d.ts +2 -0
  266. package/dist/commands/write/write.js +36 -816
  267. package/dist/core/files.d.ts +2 -0
  268. package/dist/core/files.js +7 -0
  269. package/dist/core/{package-declarations.d.ts → packages/declarations.d.ts} +1 -1
  270. package/dist/core/{package-declarations.js → packages/declarations.js} +1 -1
  271. package/dist/core/session-store.js +3 -3
  272. package/dist/core/store.d.ts +2 -2
  273. package/dist/core/store.js +18 -4
  274. package/dist/core/text.d.ts +2 -0
  275. package/dist/core/text.js +4 -0
  276. package/dist/dashboard/acts/acts.js +1 -1
  277. package/dist/dashboard/acts/sending.js +110 -0
  278. package/dist/dashboard/acts/sheet.js +2 -2
  279. package/dist/dashboard/acts/strip.js +1 -1
  280. package/dist/dashboard/address.js +6 -0
  281. package/dist/dashboard/api.js +19 -1
  282. package/dist/dashboard/app.js +51 -171
  283. package/dist/dashboard/dice/roller.js +1 -1
  284. package/dist/dashboard/dice/sets.js +2 -2
  285. package/dist/dashboard/dice/stage.js +1 -1
  286. package/dist/dashboard/dice/tray.js +6 -6
  287. package/dist/dashboard/guide/ar.md +7 -3
  288. package/dist/dashboard/guide/cs.md +9 -5
  289. package/dist/dashboard/guide/da.md +9 -5
  290. package/dist/dashboard/guide/de.md +7 -3
  291. package/dist/dashboard/guide/el.md +9 -5
  292. package/dist/dashboard/guide/en.md +4 -0
  293. package/dist/dashboard/guide/es.md +8 -4
  294. package/dist/dashboard/guide/fi.md +9 -5
  295. package/dist/dashboard/guide/fr.md +8 -4
  296. package/dist/dashboard/guide/he.md +7 -3
  297. package/dist/dashboard/guide/hi.md +10 -6
  298. package/dist/dashboard/guide/hu.md +8 -4
  299. package/dist/dashboard/guide/is.md +9 -5
  300. package/dist/dashboard/guide/it.md +5 -1
  301. package/dist/dashboard/guide/ja.md +9 -5
  302. package/dist/dashboard/guide/ko.md +8 -4
  303. package/dist/dashboard/guide/nb.md +8 -4
  304. package/dist/dashboard/guide/nl.md +8 -4
  305. package/dist/dashboard/guide/pl.md +8 -4
  306. package/dist/dashboard/guide/pt.md +7 -3
  307. package/dist/dashboard/guide/ro.md +9 -5
  308. package/dist/dashboard/guide/ru.md +8 -4
  309. package/dist/dashboard/guide/sv.md +9 -5
  310. package/dist/dashboard/guide/tr.md +9 -5
  311. package/dist/dashboard/guide/uk.md +8 -4
  312. package/dist/dashboard/guide/zh.md +8 -4
  313. package/dist/dashboard/help/help.js +3 -3
  314. package/dist/dashboard/i18n/ar.json +29 -0
  315. package/dist/dashboard/i18n/cs.json +29 -0
  316. package/dist/dashboard/i18n/da.json +29 -0
  317. package/dist/dashboard/i18n/de.json +29 -0
  318. package/dist/dashboard/i18n/el.json +29 -0
  319. package/dist/dashboard/i18n/es.json +29 -0
  320. package/dist/dashboard/i18n/fi.json +29 -0
  321. package/dist/dashboard/i18n/fr.json +29 -0
  322. package/dist/dashboard/i18n/he.json +29 -0
  323. package/dist/dashboard/i18n/hi.json +29 -0
  324. package/dist/dashboard/i18n/hu.json +29 -0
  325. package/dist/dashboard/i18n/is.json +29 -0
  326. package/dist/dashboard/i18n/it.json +29 -0
  327. package/dist/dashboard/i18n/ja.json +30 -1
  328. package/dist/dashboard/i18n/ko.json +29 -0
  329. package/dist/dashboard/i18n/nb.json +29 -0
  330. package/dist/dashboard/i18n/nl.json +29 -0
  331. package/dist/dashboard/i18n/pl.json +29 -0
  332. package/dist/dashboard/i18n/pt.json +29 -0
  333. package/dist/dashboard/i18n/ro.json +29 -0
  334. package/dist/dashboard/i18n/ru.json +29 -0
  335. package/dist/dashboard/i18n/sv.json +29 -0
  336. package/dist/dashboard/i18n/tr.json +29 -0
  337. package/dist/dashboard/i18n/uk.json +29 -0
  338. package/dist/dashboard/i18n/zh.json +29 -0
  339. package/dist/dashboard/{journal.js → journal/journal.js} +16 -16
  340. package/dist/dashboard/{notes.js → journal/notes.js} +4 -4
  341. package/dist/dashboard/kit.js +3 -3
  342. package/dist/dashboard/packages/ask-card.js +3 -3
  343. package/dist/dashboard/packages/catalog.js +196 -0
  344. package/dist/dashboard/packages/changes.js +111 -0
  345. package/dist/dashboard/packages/engine.js +87 -0
  346. package/dist/dashboard/packages/installed.js +53 -0
  347. package/dist/dashboard/packages/library.js +97 -0
  348. package/dist/dashboard/packages/outcomes.js +45 -0
  349. package/dist/dashboard/packages/packages.js +27 -578
  350. package/dist/dashboard/packages/page-code.js +15 -2
  351. package/dist/dashboard/packages/{package-page.js → page.js} +12 -5
  352. package/dist/dashboard/packages/rows.js +84 -0
  353. package/dist/dashboard/packages/share.js +44 -0
  354. package/dist/dashboard/packages/widgets.js +3 -3
  355. package/dist/dashboard/{card.js → parts/card.js} +1 -1
  356. package/dist/dashboard/parts/changed.js +37 -0
  357. package/dist/dashboard/{faces.js → parts/faces.js} +5 -5
  358. package/dist/dashboard/{game-words.js → parts/game-words.js} +1 -1
  359. package/dist/dashboard/{icons.js → parts/icons.js} +1 -1
  360. package/dist/dashboard/{labels.js → parts/labels.js} +2 -1
  361. package/dist/dashboard/{map-symbols.js → parts/map-symbols.js} +1 -1
  362. package/dist/dashboard/{markdown.js → parts/markdown.js} +2 -2
  363. package/dist/dashboard/{mood.js → parts/mood.js} +1 -1
  364. package/dist/dashboard/{refusals.js → parts/refusals.js} +5 -1
  365. package/dist/dashboard/{status.js → parts/status.js} +4 -4
  366. package/dist/dashboard/{widgets.js → parts/widgets.js} +5 -3
  367. package/dist/dashboard/place/key.js +24 -0
  368. package/dist/dashboard/place/paper.js +67 -0
  369. package/dist/dashboard/place/{map-sheet.js → sheet.js} +2 -2
  370. package/dist/dashboard/place/things.js +129 -0
  371. package/dist/dashboard/place/tokens.js +93 -0
  372. package/dist/dashboard/place/view.js +124 -0
  373. package/dist/dashboard/{asked-dice.js → play/asked-dice.js} +3 -3
  374. package/dist/dashboard/{asked.js → play/asked.js} +10 -10
  375. package/dist/dashboard/{choices.js → play/choices.js} +11 -10
  376. package/dist/dashboard/{requested.js → play/requested.js} +1 -1
  377. package/dist/dashboard/{rolls.js → play/rolls.js} +9 -9
  378. package/dist/dashboard/{scene.js → play/scene.js} +14 -14
  379. package/dist/dashboard/{turns.js → play/turns.js} +12 -12
  380. package/dist/dashboard/{language-choice.js → settings/language-choice.js} +1 -1
  381. package/dist/dashboard/{languages.js → settings/languages.js} +1 -1
  382. package/dist/dashboard/{saves.js → settings/saves.js} +8 -8
  383. package/dist/dashboard/{settings.js → settings/settings.js} +17 -15
  384. package/dist/dashboard/{setup.js → settings/setup.js} +5 -5
  385. package/dist/dashboard/{party.js → sheet/party.js} +8 -8
  386. package/dist/dashboard/{person-panel.js → sheet/person-panel.js} +4 -4
  387. package/dist/dashboard/{sheet.js → sheet/sheet.js} +27 -24
  388. package/dist/dashboard/{story.js → sheet/story.js} +3 -3
  389. package/dist/dashboard/{columns.js → shell/columns.js} +1 -1
  390. package/dist/dashboard/{footer.js → shell/footer.js} +3 -3
  391. package/dist/dashboard/{master.js → shell/master.js} +2 -2
  392. package/dist/dashboard/{notices.js → shell/notices.js} +3 -3
  393. package/dist/dashboard/{pages.js → shell/pages.js} +5 -5
  394. package/dist/dashboard/shell/shown.js +38 -0
  395. package/dist/dashboard/{table.js → shell/table.js} +2 -2
  396. package/dist/dashboard/{tabs.js → shell/tabs.js} +2 -2
  397. package/dist/dashboard/{top.js → shell/top.js} +7 -7
  398. package/dist/dashboard/style.css +288 -4
  399. package/dist/dashboard/world/calendar.js +4 -4
  400. package/dist/dashboard/world/drawing.js +92 -0
  401. package/dist/dashboard/world/key.js +21 -0
  402. package/dist/dashboard/world/lore.js +10 -6
  403. package/dist/dashboard/world/map-card.js +186 -0
  404. package/dist/dashboard/world/place-card.js +39 -0
  405. package/dist/dashboard/world/places.js +29 -0
  406. package/dist/dashboard/world/world.js +9 -341
  407. package/dist/extensions/extension.d.ts +1 -1
  408. package/dist/extensions/extension.js +1 -1
  409. package/dist/images/images.js +12 -9
  410. package/dist/index.d.ts +1 -1
  411. package/dist/languages/index.d.ts +1 -1
  412. package/dist/languages/index.js +1 -1
  413. package/dist/packages/npm.js +1 -1
  414. package/dist/page.d.ts +2 -2
  415. package/dist/page.js +1 -1
  416. package/dist/pages/check.js +23 -1
  417. package/dist/pages/containers.d.ts +1 -1
  418. package/dist/pages/containers.js +1 -1
  419. package/dist/pages/index.d.ts +4 -2
  420. package/dist/pages/index.js +4 -2
  421. package/dist/pages/inheritance.d.ts +2 -2
  422. package/dist/pages/layers.d.ts +52 -0
  423. package/dist/pages/layers.js +105 -0
  424. package/dist/pages/markdown.d.ts +5 -1
  425. package/dist/pages/markdown.js +13 -1
  426. package/dist/pages/rename-page.js +1 -1
  427. package/dist/pages/stacks/writes.js +48 -22
  428. package/dist/pages/standard-fields.d.ts +1 -1
  429. package/dist/pages/system-pages.d.ts +5 -3
  430. package/dist/pages/system-pages.js +16 -7
  431. package/dist/pages/world.d.ts +8 -1
  432. package/dist/pages/world.js +16 -4
  433. package/dist/pages/write-layer.d.ts +23 -0
  434. package/dist/pages/write-layer.js +162 -0
  435. package/dist/pages/write-page.d.ts +2 -2
  436. package/dist/pages/write-page.js +2 -2
  437. package/dist/rules/index.d.ts +1 -1
  438. package/dist/rules/index.js +1 -1
  439. package/dist/rules/search.d.ts +1 -1
  440. package/dist/rules/shown.d.ts +1 -1
  441. package/dist/server/dashboard/choices.d.ts +2 -0
  442. package/dist/server/dashboard/choices.js +6 -4
  443. package/dist/server/dashboard/files.js +5 -5
  444. package/dist/server/dashboard/index.d.ts +2 -2
  445. package/dist/server/dashboard/index.js +7 -3
  446. package/dist/server/dashboard/news.js +4 -3
  447. package/dist/server/dashboard/player.js +1 -1
  448. package/dist/server/dashboard/writes.d.ts +7 -0
  449. package/dist/server/dashboard/writes.js +48 -7
  450. package/dist/server/mcp.js +28 -13
  451. package/dist/systems/campaign-data.d.ts +15 -0
  452. package/dist/systems/campaign-data.js +85 -0
  453. package/dist/systems/{system-code.d.ts → code.d.ts} +1 -1
  454. package/dist/systems/{system-code.js → code.js} +2 -2
  455. package/dist/systems/game-system.d.ts +7 -61
  456. package/dist/systems/game-system.js +1 -984
  457. package/dist/systems/index.d.ts +6 -3
  458. package/dist/systems/index.js +6 -3
  459. package/dist/systems/installed.d.ts +31 -0
  460. package/dist/systems/installed.js +89 -0
  461. package/dist/systems/maps.d.ts +3 -0
  462. package/dist/systems/maps.js +9 -0
  463. package/dist/systems/read.d.ts +3 -0
  464. package/dist/systems/read.js +471 -0
  465. package/dist/systems/schema.d.ts +289 -0
  466. package/dist/systems/schema.js +243 -0
  467. package/dist/systems/settings.d.ts +19 -0
  468. package/dist/systems/settings.js +78 -0
  469. package/dist/systems/versions.d.ts +12 -0
  470. package/dist/systems/versions.js +52 -0
  471. package/dist/testing/index.js +1 -1
  472. package/instructions/import.md +1 -1
  473. package/instructions/play.md +1 -1
  474. package/instructions/voices.md +1 -1
  475. package/package.json +1 -1
  476. package/dist/commands/config.js +0 -948
  477. package/dist/commands/package.d.ts +0 -143
  478. package/dist/commands/package.js +0 -785
  479. package/dist/commands/scene.js +0 -894
  480. package/dist/commands/shared/worked-out.js +0 -805
  481. package/dist/dashboard/place/map-view.js +0 -417
  482. /package/dist/commands/shared/{library-reader.d.ts → books/library-reader.d.ts} +0 -0
  483. /package/dist/core/{package-api.d.ts → packages/api.d.ts} +0 -0
  484. /package/dist/core/{package-api.js → packages/api.js} +0 -0
  485. /package/dist/dashboard/{coins.js → parts/coins.js} +0 -0
  486. /package/dist/dashboard/{glass.js → parts/glass.js} +0 -0
  487. /package/dist/dashboard/{layout.js → parts/layout.js} +0 -0
  488. /package/dist/dashboard/{mood-faces.js → parts/mood-faces.js} +0 -0
  489. /package/dist/dashboard/{free-rolls.js → play/free-rolls.js} +0 -0
  490. /package/dist/dashboard/{reactions.js → play/reactions.js} +0 -0
  491. /package/dist/dashboard/{prefs.js → shell/prefs.js} +0 -0
  492. /package/dist/dashboard/{system-style.js → shell/system-style.js} +0 -0
  493. /package/dist/dashboard/{theme.js → shell/theme.js} +0 -0
  494. /package/dist/languages/{language-pack.d.ts → pack.d.ts} +0 -0
  495. /package/dist/languages/{language-pack.js → pack.js} +0 -0
  496. /package/dist/pages/{page-file.d.ts → file.d.ts} +0 -0
  497. /package/dist/pages/{page-file.js → file.js} +0 -0
  498. /package/dist/pages/{page-types.d.ts → types.d.ts} +0 -0
  499. /package/dist/pages/{page-types.js → types.js} +0 -0
  500. /package/dist/rules/{rule-book.d.ts → book.d.ts} +0 -0
  501. /package/dist/rules/{rule-book.js → book.js} +0 -0
  502. /package/dist/systems/{system-folders.d.ts → folders.d.ts} +0 -0
  503. /package/dist/systems/{system-folders.js → folders.js} +0 -0
@@ -1,37 +1,27 @@
1
+ // The change command
1
2
  import { z } from "zod";
2
- import { readSettings, requireCampaign } from "../../campaign/index.js";
3
- import { fieldsRead } from "../../core/formula.js";
4
- import { appendLogEntry } from "../../core/log.js";
3
+ import { requireCampaign } from "../../campaign/index.js";
5
4
  import { defineCommand } from "../../core/registry.js";
6
- import { comparableText, valueNamed, withArticle } from "../../core/text.js";
7
- import { canSpend, changeCounter, counterLimit, formatCounter, isSafeCounter, readCounter, readCounterText } from "../../counters/index.js";
8
- import { diceProblem, rollDice } from "../../dice/index.js";
9
- import { addCoins, formatAmount, formatTotal, isSafePurse, namesCoins, payCoins, readAmount, readSignedAmount, totalOf } from "../../money/index.js";
10
- import { baseChain, baseFieldOf, baseValue, concernsPlayer, declaredKind, findPage, followersOf, goodsNamed, inheritedFields, isCounterField, isDeclaredUncounted, isPartyMember, isPlayerCharacter, isStandardField, keepersOf, kindNamed, ownField, stackName, stacksOf, systemPageNamed, textsIn, withPage, writePage, } from "../../pages/index.js";
5
+ import { comparableText, valueNamed } from "../../core/text.js";
6
+ import { readCounter, readCounterText } from "../../counters/index.js";
7
+ import { readAmount } from "../../money/index.js";
8
+ import { declaredKind, isCounterField, kindNamed } from "../../pages/index.js";
11
9
  import { faceValues } from "../roll/roll.js";
12
- import { spendableDice, spendDice } from "../shared/dice-pool.js";
13
- import { effectGiving, effectiveFields, effectsOf, withValue } from "../shared/effect-layer.js";
14
- import { checkEffectsReadable, saveEffects } from "../shared/effects.js";
15
- import { fireEvents, nowDueNote } from "../shared/events.js";
16
- import { coinExamples, poolExample, restExample } from "../shared/examples.js";
17
- import { experienceOf, levelWay, newLevelNotes, settleChoices } from "../shared/experience.js";
10
+ import { campaignCoins } from "../shared/campaign/money.js";
11
+ import { campaignSystem, campaignWorld } from "../shared/campaign/world.js";
12
+ import { poolExample, restExample } from "../shared/examples.js";
18
13
  import { wholeNumber } from "../shared/inputs.js";
19
- import { screenNote, screenUp, sealHiddenRoll } from "../shared/master-rolls.js";
20
- import { campaignCoins } from "../shared/money.js";
21
- import { followersNote, keepersNote, skippedPagesNote } from "../shared/notes.js";
14
+ import { skippedPagesNote } from "../shared/notes.js";
22
15
  import { allSaid, packagesCounterChanged } from "../shared/packages/hooks.js";
23
- import { keptRolls } from "../shared/page-counters.js";
24
- import { situationPart } from "../shared/parts.js";
25
- import { effectsAtRecipe, notBroughtBack, partyPages, recipeChoices, recipeNamed, recipeTargets } from "../shared/recipes.js";
26
- import { keepingLossNote, restingEffectsNote, shieldNotes } from "../shared/reminders.js";
27
- import { checkNotCopied, checkNotSystemPage, pageOrCopy, readOpenScene, updateScene } from "../shared/scene.js";
28
- import { changeStack } from "../shared/stacks.js";
29
- import { fallNotes, thresholdNotes } from "../shared/thresholds.js";
30
- import { newDatedLogEntry, readPresent } from "../shared/time.js";
31
- import { computedField, computedMessage, counterLimits, hasSheet, maximumHint, maximumSources, startingAtZero } from "../shared/worked-out.js";
32
- import { campaignSystem, campaignWorld, missingSystemHint } from "../shared/world.js";
33
- import { damageLists, damageTaken } from "./damage.js";
34
- import { logRecipeApplied, tooSoonNote } from "./recipe-pace.js";
16
+ import { effectiveFields } from "../shared/sheet/effect-layer.js";
17
+ import { changeStack } from "../shared/sheet/stacks.js";
18
+ import { counterLimits, maximumHint } from "../shared/sheet/worked-out.js";
19
+ import { counterStep, moneyStep } from "./amounts.js";
20
+ import { damageLists, damageSteps, shieldOf, typedDamage, untypedDamageNote } from "./damage.js";
21
+ import { diceBy, diceHiding, logDiceBy, rolledText } from "./dice.js";
22
+ import { countable, exampleValue, fieldName, holdsField, suggestedNumber, usuallyZero, withDeclaredStart, withoutMaximum } from "./fields.js";
23
+ import { applyStep, holderNamed, stepNotes } from "./holder.js";
24
+ import { recipeResult, recipeText } from "./recipe.js";
35
25
  export const change = defineCommand({
36
26
  name: "change",
37
27
  description: "Change a counter, money or a stack of goods on a page: hit points, uses, a progress track, an event's clock, coins, torches. "
@@ -133,125 +123,6 @@ function changeField(root, context, world, input) {
133
123
  const lost = Number.isFinite(by) && by < 0 ? Math.max(-by - shielded, 0) : 0;
134
124
  return { ...told, ...counterChangeOf({ holder, field, fields }, told, lost), problems: world.problems };
135
125
  }
136
- /**
137
- * Dice given as by, such as -(2d6+3), rolled with the engine's dice (D-459): the sign in front is the roll's, so -(2d6+3) takes away 2d6+3, never less than 0;
138
- * undefined for a number, coins or any other text.
139
- */
140
- function diceBy(by, context) {
141
- const text = typeof by === "string" ? by.replace(/\s+/g, "") : "";
142
- const body = text.replace(/^[+-]/, "");
143
- const bracketed = /^\((.*)\)$/.exec(body)?.[1];
144
- const notation = bracketed ?? body;
145
- if (!/\d*d(\d+|%|F)/i.test(notation)) {
146
- return undefined;
147
- }
148
- // Dice that do not read as a roll: as -(2d6)+3, with brackets around a part, the whole roll goes in them; in brackets already, what the dice say is wrong.
149
- const problem = diceProblem(notation);
150
- if (problem !== undefined) {
151
- throw new Error(bracketed === undefined
152
- ? `by ${String(by)} does not read as a roll: put the whole roll in brackets after the sign, such as by -(2d6+3), which takes away 2d6+3. Nothing changed.`
153
- : `by ${String(by)} does not read as a roll: ${problem} Nothing changed.`);
154
- }
155
- // -1d8-2 reads as 1d8+2 taken away or as 1d8-2 taken away: a minus before more than one term asks for brackets (playtest 08).
156
- if (text.startsWith("-") && bracketed === undefined && /[+-]/.test(notation)) {
157
- throw new Error(`by ${String(by)} reads two ways: put the roll in brackets after the minus, such as by -(1d8+2), which takes away 1d8+2. Nothing changed.`);
158
- }
159
- const rolled = rollDice(notation, { random: context.random });
160
- const total = Math.max(0, rolled.total);
161
- return { by: text.startsWith("-") ? -total : total, taking: text.startsWith("-"), data: { notation, total: rolled.total, result: rolled.text, physical: false, dice: rolled.dice } };
162
- }
163
- /**
164
- * Why the dice in by are hidden, or undefined when shown (D-287): with their change, on a page that does not concern the player, whatever master-rolls says;
165
- * behind the screen, taking away from the player character or a companion, as a foe's or a trap's do. Healing them, or dice on a copy in the scene, are shown.
166
- */
167
- function diceHiding(root, world, name, taking) {
168
- const holder = holderNamed(root, world, name);
169
- if (holder.kind === "copy") {
170
- return undefined;
171
- }
172
- if (holder.visibility === "hidden") {
173
- return "secret";
174
- }
175
- return taking && screenUp(root) && isPartyMember(holder.page) ? "screen" : undefined;
176
- }
177
- /** Logs the roll of the dice in by, sealed when hidden as roll seals one; what the master is told of it when hidden. */
178
- function logDiceBy(root, context, data, hiding) {
179
- const entry = newDatedLogEntry(root, context, "roll", hiding === undefined ? "public" : "hidden", data);
180
- const fingerprint = hiding === undefined ? undefined : sealHiddenRoll(entry, data.result, context);
181
- appendLogEntry(root, entry);
182
- return fingerprint === undefined ? undefined : { id: entry.id, fingerprint, screened: hiding === "screen" };
183
- }
184
- /** "Rolled 2d6+3 = 11 [5, 3] + 3.", or the hidden roll as roll tells it, only for the master. */
185
- function rolledText(rolled, hidden) {
186
- const screen = hidden?.screened === true ? `. ${screenNote}` : "";
187
- return hidden === undefined ? `Rolled ${rolled}.` : `Hidden roll ${hidden.id}, only for the master: ${rolled}${screen}\nIts fingerprint, only if the player asks for it: ${hidden.fingerprint}`;
188
- }
189
- /** The counter that shields a counter, losing first, as temporary hit points (DAT-14); undefined when none does. */
190
- function shieldOf(system, field) {
191
- return Object.entries(system?.shields ?? {}).find(([, shielded]) => comparableText(shielded) === comparableText(field))?.[0];
192
- }
193
- /** The damage a page takes of the type given (DMG-1): only with by, negative, on the counter the system's damage takes from. */
194
- function typedDamage(system, fields, field, input, page) {
195
- const rule = system?.damage;
196
- if (system === undefined || rule === undefined) {
197
- throw new Error(`The game system ${system?.name ?? "of the campaign"} has no damage types: give by alone, such as by -12. Nothing changed.`);
198
- }
199
- if (comparableText(field) !== comparableText(rule.counter)) {
200
- throw new Error(`A damage type goes with ${rule.counter}, not ${field}: change ${page} ${rule.counter} --by=-12 --damage fire. Nothing changed.`);
201
- }
202
- const by = typeof input.by === "number" ? input.by : Number(input.by);
203
- if (input.spend !== undefined || input.to !== undefined || !Number.isSafeInteger(by) || by >= 0) {
204
- throw new Error(`A damage type goes with by, negative, the damage before ${page}'s lists change it, such as by -12, damage fire. Nothing changed.`);
205
- }
206
- return damageTaken(system, rule, fields, -by, input.damage ?? "", page);
207
- }
208
- /**
209
- * Damage of a type taken by its counter (DMG-1): the counter that shields it loses first, as temporary hit points (DAT-14), then the counter the rest; one
210
- * outcome that says both, and why the damage is not the amount given.
211
- */
212
- function damageSteps(root, context, world, target, damage, why, system) {
213
- const { holder, fields, field, coins } = target;
214
- const page = holder.page.name;
215
- const withNote = (outcome, notes) => ({ ...outcome, note: [...notes, outcome.note].filter((part) => part !== "").join("; ") });
216
- const shield = shieldOf(system, field);
217
- const shieldField = shield === undefined ? undefined : Object.keys(fields).find((name) => comparableText(name) === comparableText(shield));
218
- const absorbed = shieldField === undefined ? 0 : Math.min(Math.max(readCounter(fields[shieldField])?.value ?? 0, 0), damage.amount);
219
- const onCounter = (current, currentHolder, amount) => applyStep(root, context, current, currentHolder, field, counterStep({ by: -amount }, fields[field], page, field, coins, target.limits), why, system).outcome;
220
- if (shieldField === undefined || absorbed === 0) {
221
- return { outcome: withNote(onCounter(world, holder, damage.amount), [damage.note]), lost: damage.amount };
222
- }
223
- const shieldStep = counterStep({ by: -absorbed }, fields[shieldField], page, shieldField, coins, counterLimits(world, fields, shieldField));
224
- const first = applyStep(root, context, world, holder, shieldField, shieldStep, why, system);
225
- if (absorbed === damage.amount) {
226
- return { outcome: withNote(first.outcome, [damage.note]), lost: 0 };
227
- }
228
- const outcome = onCounter(first.world, holderNamed(root, first.world, target.name), damage.amount - absorbed);
229
- const shielded = `${shieldField} ${first.outcome.before} → ${first.outcome.after} first`;
230
- // What someone keeps alive reads the whole damage, the shield's part too (EFF-14).
231
- const keeping = keepingLossNote(world, readOpenScene(root).scene, system, page, field, damage.amount);
232
- const merged = {
233
- ...withNote(outcome, [damage.note, shielded]),
234
- thresholds: [...first.outcome.thresholds, ...outcome.thresholds],
235
- // The shield is spent, so the only reminder left is what someone keeps (DAT-14).
236
- reminders: keeping === "" ? [] : [keeping],
237
- due: [...first.outcome.due, ...outcome.due],
238
- followers: [...new Set([...first.outcome.followers, ...outcome.followers])],
239
- keepers: [...new Set([...first.outcome.keepers, ...outcome.keepers])],
240
- };
241
- return { outcome: merged, lost: damage.amount - absorbed };
242
- }
243
- /** "Ghoul 1 has damage-immunities poison: …": for damage given without a type to a page whose lists change some (DMG-1); empty otherwise. */
244
- function untypedDamageNote(world, system, page, field) {
245
- const rule = system?.damage;
246
- if (rule === undefined || comparableText(field) !== comparableText(rule.counter)) {
247
- return "";
248
- }
249
- const lists = Object.entries(damageLists(world, page, rule)).flatMap(([list, value]) => {
250
- const items = textsIn(value);
251
- return items.length === 0 ? [] : [`${list} ${items.join(", ")}`];
252
- });
253
- return lists.length === 0 ? "" : `${page.name} has ${lists.join("; ")}: if this damage has a type, give it with damage, as rolled.`;
254
- }
255
126
  /** The counter a step changed on a page, never a copy, for the game system's code (D-448): before and after, its maximum, and what damage took of it. */
256
127
  function counterChangeOf(target, outcome, lost) {
257
128
  const { holder, field, fields } = target;
@@ -263,604 +134,3 @@ function counterChangeOf(target, outcome, lost) {
263
134
  }
264
135
  return { hitCounter: { page: holder.page.name, field, before: before.value, after, lost, ...(before.max === undefined ? {} : { max: before.max }) } };
265
136
  }
266
- /**
267
- * Writes a step: on the effect that gives the field (EFF-7), else on the page, from which the field goes when it comes back to its base's value (INH-9); with
268
- * its line in the log and those of the pages that read it from this one (INH-10), the events it sets off (EVT-4) and the thresholds it touches (DAT-3).
269
- * Returns the world as written, for a next step.
270
- */
271
- function applyStep(root, context, world, holder, field, step, why, system) {
272
- const page = holder.page.name;
273
- checkClock(holder.page, field, step.after);
274
- const written = ownField(holder.page, field) ?? field;
275
- // A value an effect gives changes on the effect, under which the page keeps its own (EFF-7).
276
- const layer = effectGiving(holder.page, field);
277
- // A maximum written by hand that is not the system's is put right even when the value reads the same, as validate's fix asks (FOR-6).
278
- const workedMax = holder.kind === "page" && counterLimits(world, inheritedFields(world, holder.page), field).max !== undefined;
279
- const stale = layer === undefined && workedMax && Object.hasOwn(holder.page.fields, written) && String(holder.page.fields[written]) !== String(storedCounter(world, holder, field, step.after));
280
- const changed = String(step.after) !== String(step.before) || stale;
281
- const base = layer === undefined ? baseValue(world, holder.page, field) : undefined;
282
- const backToBase = changed && base !== undefined && step.same(base.value);
283
- const followers = changed && holder.kind === "page" && layer === undefined ? followersOf(world, holder.page, field) : [];
284
- const keepers = changed && holder.kind === "page" && layer === undefined ? keepersOf(world, holder.page, field).map((keeper) => `${keeper.name} (${field} ${String(counterOf(world, keeper, field))})`) : [];
285
- let after;
286
- if (changed) {
287
- // Back to the base's value, the field goes in every spelling the page wrote it, so that the page reads the base's (INH-5, INH-9).
288
- const spellings = Object.keys(holder.page.fields).filter((name) => comparableText(name) === comparableText(field));
289
- if (layer === undefined) {
290
- after = holder.write(backToBase ? Object.fromEntries(spellings.map((name) => [name, undefined])) : { [written]: storedCounter(world, holder, field, step.after) });
291
- }
292
- else {
293
- const effects = effectsOf(holder.page).map((effect) => (effect.name === layer.name ? withValue(effect, field, String(step.after)) : effect));
294
- after = saveEffects(root, context, world, { page: holder.page, copy: holder.kind === "copy" }, effects);
295
- }
296
- const data = { page, copy: holder.kind === "copy" ? true : undefined, field, effect: layer?.name, before: step.before, after: step.after, ...step.amount, why };
297
- appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", holder.visibility, data));
298
- logFollowers(root, world, context, followers, { field, before: step.before, after: step.after });
299
- }
300
- const again = backToBase ? base?.base.name : undefined;
301
- const note = [layer === undefined ? "" : `in ${layer.name}`, step.note, again === undefined ? "" : `again as ${again}`].filter((part) => part !== "").join("; ");
302
- const updated = after === undefined ? world : withPage(world, holder.page, after);
303
- // Only an event's clock sets anything off when it changes (EVT-4).
304
- const due = after !== undefined && layer === undefined && isCounterField(after.type, field) ? fireEvents(root, context, world, updated, readPresent(root).date).due : [];
305
- // The rules a counter of the player character or a companion touches (DAT-3): never for a copy, nor for a page that is not in the party.
306
- const touched = changed || (step.amount.beyond ?? 0) !== 0;
307
- const party = holder.kind === "page" && isPartyMember(holder.page);
308
- // Points that reach a new level are said with the rule to read (PRO-6).
309
- const companion = holder.page.fields.role === "companion";
310
- const levelUp = () => situationPart("level-up", context, system);
311
- const [levelBefore, levelAfter] = [experienceOf(world, effectiveFields(world, holder.page)), after === undefined ? undefined : experienceOf(updated, effectiveFields(updated, after))];
312
- if (changed && party) {
313
- settleChoices(root, holder.page.name, levelBefore, levelAfter);
314
- }
315
- const levels = changed && party && after !== undefined ? newLevelNotes(page, levelBefore, levelAfter, companion, levelUp, levelWay(root, context, holder.page.name)) : [];
316
- // The player character's own counter, never a form's, falling to the system's down value: what lethality makes of it (D-530).
317
- const fall = changed && holder.kind === "page" && layer === undefined && isPlayerCharacter(holder.page) ? fallNotes(root, system, page, field, step) : [];
318
- const thresholds = [...(touched && party ? thresholdNotes(root, system, field, step, layer?.name) : []), ...fall, ...levels];
319
- // What the loss may break that someone keeps alive, on anyone, and what shields the counter that went down (EFF-14, DAT-14).
320
- const lost = touched ? lostBy(step) : 0;
321
- // What goes past 0 in an effect that gives the counter, as a beast form, may carry over to the page's own (D-454).
322
- const beyond = Math.abs(Number(step.amount.beyond ?? 0));
323
- const carried = layer !== undefined && lost > 0 && beyond > 0 && readCounterText(String(step.after))?.value === 0
324
- ? `${beyond} went past 0 in ${layer.name}: when it ends so, what goes past may carry over to ${page}'s own ${field}, as its text says.`
325
- : "";
326
- const reminders = [keepingLossNote(world, readOpenScene(root).scene, system, page, field, lost), ...shieldNotes(world, system, holder.page, field, lost, fellBy(step)), carried].filter((note) => note !== "");
327
- const outcome = {
328
- page,
329
- field,
330
- before: String(step.before),
331
- after: String(step.after),
332
- total: step.total,
333
- note,
334
- effect: layer?.name,
335
- again,
336
- changed,
337
- due,
338
- followers: followers.map((follower) => follower.name),
339
- keepers,
340
- thresholds,
341
- reminders,
342
- };
343
- return { outcome, world: updated };
344
- }
345
- /**
346
- * The fields, with a counter the game system declares and gives no maximum at 0 when a character, a quest or a copy that no page derives from does not hold it
347
- * yet, as temporary hit points: change starts it, since write never changes it once written (CNT-7, CNT-8, D-266).
348
- */
349
- function withDeclaredStart(world, holder, fields, name) {
350
- const declared = startingAtZero(world, name);
351
- const held = Object.keys(fields).some((field) => comparableText(field) === comparableText(name.trim()));
352
- if (declared === undefined || held || computedField(world, declared, fields) !== undefined) {
353
- return fields;
354
- }
355
- // Never on a place, an item or a kind: on a page others derive from, it would reach all of them, as on Ghoul instead of Ghoul 1.
356
- const owner = holder.kind === "copy" || ((holder.page.type === "character" || holder.page.type === "quest") && followersOf(world, holder.page, declared).length === 0);
357
- return owner ? { ...fields, [declared]: 0 } : fields;
358
- }
359
- /** How much a step took away: the whole of a negative by, even past a limit, as damage is taken; otherwise what the value went down. */
360
- function lostBy(step) {
361
- const by = step.amount.by;
362
- return typeof by === "number" ? Math.max(0, -by) : fellBy(step);
363
- }
364
- /** How far a step's counter went down, which stops at its least. */
365
- function fellBy(step) {
366
- const before = readCounter(step.before)?.value;
367
- const after = readCounter(step.after)?.value;
368
- return before === undefined || after === undefined ? 0 : Math.max(0, before - after);
369
- }
370
- /** What else a step says: the thresholds it touches, the events it sets off, the pages that changed with it, and those that keep their own. */
371
- function stepNotes(step) {
372
- const followers = followersNote(step.followers, `since they read ${step.field} from ${step.page}`, "change", `${step.field} ${step.after}`);
373
- return [...step.thresholds, ...step.reminders, nowDueNote(step.due), followers, keepersNote(step.keepers, step.field)].filter((note) => note !== "");
374
- }
375
- /**
376
- * 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
377
- * is written.
378
- */
379
- function recipeResult(root, context, world, input) {
380
- const named = campaignSystem(root, context);
381
- const page = input.page?.trim() === "" ? undefined : input.page;
382
- checkQuotedRecipe(named, input.recipe, [page, input.field]);
383
- // Dice the rest lets one spend, as hit dice in a short rest (D-449).
384
- if (input.field !== undefined && input.spend !== undefined && input.by === undefined && input.to === undefined && page !== undefined) {
385
- const { system, recipe } = recipeNamed(named, input.recipe);
386
- const why = input.why === undefined || input.why.trim() === "" ? recipe.name : input.why;
387
- return { recipe: recipe.name, system: system.name, outcomes: [], rules: [], spent: spendDice(root, context, world, { system, recipe }, page, input.field, input.spend, { why, values: input.values }).text };
388
- }
389
- if (input.field !== undefined || input.by !== undefined || input.spend !== undefined || input.to !== undefined || input.values !== undefined) {
390
- throw new Error(`A recipe changes by itself the fields it names: give it with the page, or alone for the player character and the companions with them, such as recipe "${restExample(named)}". Nothing changed.`);
391
- }
392
- const { system, recipe } = recipeNamed(named, input.recipe);
393
- const pages = page === undefined ? partyPages(world) : [recipePage(root, world, page)];
394
- if (pages.length === 0) {
395
- throw new Error("There is no living player character, so a recipe without a page goes to no one: give the page. Nothing changed.");
396
- }
397
- // A page given was checked when it was found; each must still be the only one of its name, and its effects must read.
398
- for (const candidate of pages) {
399
- findPage(world, candidate.name);
400
- checkEffectsReadable(candidate);
401
- }
402
- const why = input.why === undefined || input.why.trim() === "" ? recipe.name : input.why;
403
- let current = world;
404
- const outcomes = pages.map((candidate) => {
405
- const applied = recipeOn(root, context, current, system, recipe, candidate.name, why);
406
- current = applied.world;
407
- return applied.outcome;
408
- });
409
- // 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).
410
- const physical = readSettings(root).dice === "physical";
411
- return { recipe: recipe.name, system: system.name, outcomes, rules: recipe.rules, lasts: recipe.lasts, buttons: context.page?.spendDice !== undefined, physical };
412
- }
413
- /**
414
- * 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
415
- * its value, as change sets it.
416
- */
417
- function recipeOn(root, context, world, system, recipe, name, why) {
418
- let current = world;
419
- const start = pageHolder(current, pageCalled(current, name));
420
- const { ending, remaining } = effectsAtRecipe(start.page, recipe);
421
- if (ending.length > 0) {
422
- const written = saveEffects(root, context, current, { page: start.page, copy: false }, remaining);
423
- for (const effect of ending) {
424
- appendLogEntry(root, newDatedLogEntry(root, context, "effect-ended", start.visibility, { page: name, effect: effect.name, why }));
425
- }
426
- current = written === undefined ? current : withPage(current, start.page, written);
427
- }
428
- const steps = [];
429
- // A rest that needs a counter above 0, as a long rest hit points, gives nothing to who has none when it begins (D-449).
430
- const needed = recipe.needs === undefined ? undefined : readCounter(valueNamed(effectiveFields(current, pageCalled(current, name)), recipe.needs));
431
- const atZero = needed !== undefined && needed.value <= 0;
432
- // Nor to who had one too recently, as a second long rest within 24 hours (RST-1).
433
- const tooSoon = atZero ? undefined : tooSoonNote(root, recipe, name);
434
- const barred = atZero || tooSoon !== undefined;
435
- for (const { field, target } of barred ? [] : recipeTargets(current, recipe, pageCalled(current, name))) {
436
- const holder = pageHolder(current, pageCalled(current, name));
437
- const step = counterStep({ to: target }, effectiveFields(current, holder.page)[field], name, field, undefined);
438
- if (String(step.after) !== String(step.before)) {
439
- const applied = applyStep(root, context, current, holder, field, step, why, system);
440
- steps.push(applied.outcome);
441
- current = applied.world;
442
- }
443
- }
444
- const outcome = {
445
- page: name,
446
- pc: pageCalled(current, name).fields.role === "pc",
447
- ended: ending.map((effect) => effect.name),
448
- steps,
449
- choices: recipeChoices(current, recipe, pageCalled(current, name)),
450
- spendable: barred ? [] : spendableDice(current, recipe, pageCalled(current, name)),
451
- notBroughtBack: notBroughtBack(current, system, recipe, pageCalled(current, name)),
452
- kept: keptRolls(current, pageCalled(current, name)).map(([field, values]) => `${field} ${values.join(", ")}`),
453
- barred,
454
- resting: [atZero ? `At 0 ${recipe.needs ?? ""} when it began, ${name} gains nothing from it.` : tooSoon ?? "", restingEffectsNote(pageCalled(current, name))].filter((note) => note !== "").join(" "),
455
- };
456
- if (!barred) {
457
- logRecipeApplied(root, context, recipe, name, start.visibility);
458
- }
459
- return { outcome, world: current };
460
- }
461
- /** The page with this name, which a recipe has just checked or written. */
462
- function pageCalled(world, name) {
463
- const page = findPage(world, name);
464
- if (page === undefined) {
465
- throw new Error(`There is no page named ${name}. Look for it with the find command.`);
466
- }
467
- return page;
468
- }
469
- /** "--recipe long rest" without quotes reads rest as the page or the field: refused, with the quotes to give. */
470
- function checkQuotedRecipe(system, recipe, rest) {
471
- const known = (name) => (system?.recipes ?? []).some((candidate) => comparableText(candidate.name) === comparableText(name));
472
- const words = rest.filter((word) => word !== undefined);
473
- const joined = [...words.map((word) => `${recipe} ${word}`), [recipe, ...words].join(" ")].find(known);
474
- if (!known(recipe) && joined !== undefined) {
475
- throw new Error(`Put the recipe's name in quotes, such as recipe "${joined}". Nothing changed.`);
476
- }
477
- }
478
- /** The page a recipe goes to: a page of the campaign, never a copy in the scene. */
479
- function recipePage(root, world, name) {
480
- const holder = holderNamed(root, world, name);
481
- if (holder.kind === "copy") {
482
- throw new Error(`${holder.page.name} is a copy in the scene: a recipe goes to pages, such as the characters who rest. Nothing changed.`);
483
- }
484
- return holder.page;
485
- }
486
- /**
487
- * "Long rest (a recipe of the system 5e):", then for each page what ended and changed, as in "Ennio: Prosciugato ended; hp 8/12 → 12/12. Not brought back:
488
- * hit-dice 1/3.", with the thresholds it touched; the rules for the rest; the game date, which a recipe does not move.
489
- */
490
- function recipeText(result) {
491
- const notes = result.outcomes.flatMap((outcome) => outcome.steps.flatMap(stepNotes));
492
- const lines = result.outcomes.flatMap((outcome) => {
493
- const done = [...outcome.ended.map((effect) => `${effect} ended`), ...outcome.steps.map(stepText)];
494
- const left = outcome.notBroughtBack.length === 0 ? "" : ` Not brought back: ${outcome.notBroughtBack.join(", ")}.`;
495
- // The player chooses and rolls for the player character, the master for a companion (D-206, D-213).
496
- const chosen = [...outcome.choices.map((choice) => ` ${outcome.pc ? "Ask the player" : `Choose for ${outcome.page}`}: ${choice}.`), spendText(outcome, result)].join("");
497
- // Rolls kept for later: if this rest brings them back, they are rolled again (KEP-4).
498
- const roller = outcome.pc ? "the player rolls" : "roll";
499
- const kept = outcome.kept.length === 0 ? "" : ` ${outcome.page} keeps ${outcome.kept.join("; ")}: if this rest brings them back, ${roller} them again, with roll and keep.`;
500
- const resting = outcome.resting === "" ? "" : ` ${outcome.resting}`;
501
- return [`${outcome.page}: ${done.length === 0 ? "nothing changed" : done.join("; ")}.${chosen}${left}${kept}${resting}`, ...outcome.steps.flatMap(stepNotes).filter((note) => !note.includes("\n"))];
502
- });
503
- const rules = result.rules.length === 0 ? "" : `For the rest, read ${result.rules.map((rule) => `rules "${rule}"`).join(" and ")}.`;
504
- const title = `${result.recipe.charAt(0).toUpperCase()}${result.recipe.slice(1)} (a recipe of the system ${result.system}):`;
505
- // A refused rest has no hours to advance (D-500).
506
- const hours = result.outcomes.every((outcome) => outcome.barred)
507
- ? ""
508
- : `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.`;
509
- const text = [title, ...lines, rules, hours].filter((line) => line !== "").join("\n");
510
- return [text, ...notes.filter((note) => note.includes("\n"))].join("\n\n");
511
- }
512
- /**
513
- * The dice a rest lets a page spend, left to who chooses them (ASK-14): the player for the player character, with ask's buttons where they are, the master for
514
- * a companion.
515
- */
516
- function spendText(outcome, result) {
517
- if (outcome.spendable.length === 0) {
518
- return "";
519
- }
520
- const dice = outcome.spendable.join(", ");
521
- const spend = `change with spend and recipe "${result.recipe}"`;
522
- if (!outcome.pc) {
523
- return ` Choose whether ${outcome.page} spends ${dice}: ${spend}.`;
524
- }
525
- if (result.physical === true) {
526
- return ` Ask the player how many of ${dice} they spend and roll with their own dice, then ${spend} and values, the faces they tell.`;
527
- }
528
- return result.buttons === true ? ` The player spends ${dice} on the page, one die at a time: ask with recipe "${result.recipe}", even when they already said how many.` : ` Ask the player how many of ${dice} they spend, then ${spend}.`;
529
- }
530
- /** "hp 20/34 → 34/34 (in Forma d'orso)": a step of a recipe, with the effect it changed on or the base the page reads again. */
531
- function stepText(step) {
532
- // A value an effect gives never goes back to a base: one of the two at most.
533
- const where = step.effect !== undefined ? ` (in ${step.effect})` : step.again !== undefined ? ` (again as ${step.again})` : "";
534
- return `${step.field} ${step.before} → ${step.after}${where}`;
535
- }
536
- /** A change to a counter: by, spend or to, within its limits (D-92). */
537
- function counterStep(input, value, page, field, coins, limits = {}) {
538
- const read = readCounter(value);
539
- if (read === undefined) {
540
- throw new Error(notCounterMessage(page, field, value, coins));
541
- }
542
- const before = limits.min === undefined ? read : { ...read, min: limits.min };
543
- const counterChange = readChange(input, before, page, field, coins);
544
- // How to change a maximum the game system works out, said when a value goes past it.
545
- const raise = limits.hint?.raise === undefined ? "" : `; to raise the maximum, write ${limits.hint.raise}; to change it for a while, as a drain, give an effect that sets ${limits.hint.raise}`;
546
- // A maximum the game system works out is given only as it works it out (FOR-7).
547
- if ("to" in counterChange && limits.max !== undefined && counterChange.to.max !== undefined && counterChange.to.max !== limits.max) {
548
- throw new Error(`The maximum of ${field} on ${page} is worked out by the game system: ${limits.hint?.made ?? limits.max}. Give the current value alone, such as to ${Math.min(counterChange.to.value, limits.max)}${raise}. Nothing changed.`);
549
- }
550
- // A value given with to keeps the minimum the system gives, for where it stands: 0 is no limit of a counter that goes below it.
551
- const { counter: after, beyond } = changeCounter(before, counterChange);
552
- // Above a maximum the game system works out, a value reads as the maximum (FOR-6): what change says it wrote would not be what is read.
553
- if ("to" in counterChange && limits.max !== undefined && after.value > limits.max) {
554
- throw new Error(`${field} on ${page} goes no higher than its maximum, which the game system works out: ${limits.hint?.made ?? limits.max}. Give to ${limits.max} or less${raise}. Nothing changed.`);
555
- }
556
- if (!isSafeCounter(after)) {
557
- throw new Error(`${field} on ${page} would be too large to count exactly. Nothing changed.`);
558
- }
559
- const same = (base) => {
560
- const counter = readCounter(base);
561
- return counter !== undefined && formatCounter(counter) === formatCounter(after);
562
- };
563
- return { before: formatCounter(before), after: formatCounter(after), amount: { ...amountOf(counterChange), beyond: beyond === 0 ? undefined : beyond }, note: limitNote({ ...after, min: after.min ?? before.min }, beyond), same };
564
- }
565
- /** A counter as the page keeps it: with the maximum the game system works out from the page without its effects, which the reading puts back (FOR-6). */
566
- function storedCounter(world, holder, field, value) {
567
- const counter = readCounter(value);
568
- const { max } = holder.kind === "page" ? counterLimits(world, inheritedFields(world, holder.page), field) : {};
569
- return counter === undefined || max === undefined ? value : formatCounter({ value: counter.value, max });
570
- }
571
- /** A change to money (MON-4, MON-5): coins received with by, paid with spend or a negative by, the purse set with to. */
572
- function moneyStep(input, purse, coins, page, field) {
573
- const given = [input.by, input.spend, input.to].filter((part) => part !== undefined);
574
- if (given.length !== 1) {
575
- throw new Error(`Give one of by (coins received, or paid with a minus), spend (what is paid) or to (what the purse holds), such as spend "5 ${coinExamples(coins).smallCoin}".`);
576
- }
577
- // Coins in quotes, as a model may send "\"5 sp\"", are the coins.
578
- const asked = typeof given[0] === "string" ? given[0].trim().replace(/^"(.*)"$/s, "$1") : given[0];
579
- const parameter = input.by !== undefined ? "by" : input.spend !== undefined ? "spend" : "to";
580
- const signed = typeof asked === "string" ? readSignedAmount(asked, coins) : undefined;
581
- if (signed === undefined || (parameter !== "by" && String(asked).trim().startsWith("-"))) {
582
- const example = `${parameter === "by" ? "+" : ""}${Math.abs(Number(String(asked).trim())) || 5} ${coins[0].name}`;
583
- const what = parameter === "by" ? "coins to add or, with a minus, to pay" : "coins";
584
- throw new Error(`"${String(asked)}" is not ${what} for ${field} on ${page}: give coins of the campaign (${coinNames(coins)}), such as ${parameter} "${example}".`);
585
- }
586
- const paying = parameter === "spend" || (parameter === "by" && signed.sign === -1);
587
- if (paying && totalOf(signed.purse, coins) === 0) {
588
- throw new Error(`Give ${parameter} the coins paid, such as ${parameter} "${parameter === "by" ? "-" : ""}5 ${coins[0].name}".`);
589
- }
590
- const payment = paying ? payCoins(purse, signed.purse, coins) : undefined;
591
- if (paying && payment === undefined) {
592
- throw new Error(`${page} has ${field} ${formatAmount(purse, coins)} (${formatTotal(purse, coins)}): cannot pay ${formatAmount(signed.purse, coins)} (${formatTotal(signed.purse, coins)}). Nothing changed.`);
593
- }
594
- const after = payment?.purse ?? (parameter === "to" ? signed.purse : addCoins(purse, signed.purse));
595
- if (!isSafePurse(after, coins)) {
596
- throw new Error(`${field} on ${page} would be too large to count exactly. Nothing changed.`);
597
- }
598
- const text = (coinsGiven) => (coinsGiven === undefined || Object.keys(coinsGiven).length === 0 ? undefined : formatAmount(coinsGiven, coins));
599
- const handed = text(payment?.given);
600
- const back = text(payment?.back);
601
- const amount = formatAmount(signed.purse, coins);
602
- const request = parameter === "to" ? { to: amount } : parameter === "spend" ? { spend: amount } : { by: `${signed.sign === -1 ? "-" : "+"}${amount}` };
603
- const others = Object.keys(after).some((name) => name !== coins[0].name);
604
- const same = (base) => {
605
- const basePurse = readAmount(base, coins);
606
- return basePurse !== undefined && formatAmount(basePurse, coins) === formatAmount(after, coins);
607
- };
608
- return {
609
- before: formatAmount(purse, coins),
610
- after: formatAmount(after, coins),
611
- amount: { ...request, given: handed, back },
612
- note: back !== undefined ? `${handed} given, ${back} back` : handed === undefined ? "" : `paid with ${handed}`,
613
- total: others ? formatTotal(after, coins) : undefined,
614
- same,
615
- };
616
- }
617
- /**
618
- * The value a missing counter or purse is shown with, in the hint to add one: money that the page holds, when money was asked for;
619
- * a clock as given, or empty (EVT-2); 0 for a field usually at zero, such as exhaustion (DAT-2); else 12/12.
620
- */
621
- function exampleValue(input, coins, clock, zero) {
622
- const money = coins !== undefined && [input.by, input.spend, input.to].some((part) => typeof part === "string" && readSignedAmount(part, coins) !== undefined);
623
- if (money && coins !== undefined) {
624
- return `10 ${coins[0].name} (what it holds, not the price)`;
625
- }
626
- const given = typeof input.to === "string" ? readCounterText(input.to) : undefined;
627
- return clock ? (given?.max === undefined ? "0/4" : String(formatCounter(given))) : zero ? "0" : "12/12";
628
- }
629
- /** Whether the game system declares a field a counter and works out no maximum for it, as xp: it counts up from 0. */
630
- function withoutMaximum(system, field) {
631
- const counted = Object.entries(system?.fields ?? {}).some(([name, kind]) => kind === "counter" && comparableText(name) === comparableText(field));
632
- const limits = Object.entries(system?.formulas.counters ?? {}).find(([name]) => comparableText(name) === comparableText(field))?.[1];
633
- return counted && limits?.max === undefined;
634
- }
635
- /** Whether the game system's status line shows a field only when it is not at zero, as it does exhaustion: it is usually at zero (DAT-2). */
636
- function usuallyZero(system, field) {
637
- return system?.statusLine.some((entry) => entry.whenSet && comparableText(entry.field) === comparableText(field.trim())) === true;
638
- }
639
- /** An event's clock keeps a maximum of at least 1, as write asks (EVT-2). */
640
- function checkClock(page, field, after) {
641
- const counter = readCounter(after);
642
- if (isCounterField(page.type, field) && (counter?.max === undefined || counter.max < 1)) {
643
- throw new Error(`A clock needs a maximum of at least 1, such as 0/4: ${after} is not one. Nothing changed.`);
644
- }
645
- }
646
- /** "gp/mo, pp, sp, cp": the coins of the campaign, by all their names. */
647
- function coinNames(coins) {
648
- return coins.map((coin) => coin.names.join("/")).join(", ");
649
- }
650
- /** What holds the counter, given by name or as a link: a copy in the open scene first, then a page of the campaign; the field asked names the example. */
651
- function holderNamed(root, world, name, field) {
652
- const open = readOpenScene(root);
653
- const found = pageOrCopy(world, open, name, (page) => `a counter is a field of the page, such as page ${page}${field === undefined ? "" : `, field ${field}`}`);
654
- const copy = found.copy;
655
- if (copy !== undefined) {
656
- const write = (fields) => {
657
- updateScene(root, Object.entries(fields).map(([field, value]) => [["copies", copy, field], value]));
658
- return undefined;
659
- };
660
- return { page: found.page, kind: "copy", write, visibility: "hidden" };
661
- }
662
- checkNotSystemPage(world, open, found.page);
663
- checkNotCopied(world, open, found.page);
664
- return pageHolder(world, found.page);
665
- }
666
- /** A page as what holds its counters: written with write, its lines in the log public when it concerns the player. */
667
- function pageHolder(world, page) {
668
- return {
669
- page,
670
- kind: "page",
671
- write: (fields) => {
672
- const set = Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
673
- const unset = Object.keys(fields).filter((field) => fields[field] === undefined);
674
- return writePage(world, page.name, undefined, { set: Object.keys(set).length === 0 ? undefined : set, unset: unset.length === 0 ? undefined : unset }).page;
675
- },
676
- visibility: concernsPlayer(world, page) ? "public" : "hidden",
677
- };
678
- }
679
- /** One public line for each page that changed with a base and concerns the player, with its own name only and no why: the base and the other pages may be secret (INH-10, D-93). */
680
- function logFollowers(root, world, context, followers, change) {
681
- for (const follower of followers.filter((page) => concernsPlayer(world, page))) {
682
- appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", "public", { page: follower.name, ...change }));
683
- }
684
- }
685
- /**
686
- * The holder's field with this name, ignoring case and how accents are written; a missing or fixed one fails with the counters and money it holds and how to add one.
687
- * A field the game system never counts fails with how to write it instead, with `suggested` as its new value when the change gives one.
688
- */
689
- function fieldName(world, holder, fields, name, example, coins, suggested) {
690
- const keys = Object.keys(fields);
691
- const found = keys.find((key) => key === name) ?? keys.find((key) => comparableText(key) === comparableText(name.trim()));
692
- const page = holder.page;
693
- const computed = computedField(world, name, fields);
694
- if (computed !== undefined) {
695
- throw new Error(`${computedMessage(world, computed, page.name)}. Nothing changed.`);
696
- }
697
- if (found !== undefined && isStandardField(page.type, found) && !isCounterField(page.type, found)) {
698
- const what = holder.kind === "copy" && found === "creature" ? `${found} is the creature ${page.name} copies` : `${found} is a fixed field of ${page.name}`;
699
- throw new Error(`${what}, not a counter${holder.kind === "page" ? ": change it with write" : ""}.`);
700
- }
701
- const declared = found ?? name.trim();
702
- if (isDeclaredUncounted(world, declared)) {
703
- throw new Error(uncountedMessage(world, page.name, declared, suggested));
704
- }
705
- if (found !== undefined) {
706
- return found;
707
- }
708
- const held = keys.filter((key) => (!isStandardField(page.type, key) || isCounterField(page.type, key)) && !isDeclaredUncounted(world, key)).flatMap((key) => {
709
- const counter = readCounter(fields[key]);
710
- const purse = coins === undefined || declaredKind(world, key) !== undefined ? undefined : readAmount(fields[key], coins);
711
- return purse !== undefined && coins !== undefined ? [`${key} ${formatAmount(purse, coins)}`] : counter === undefined ? [] : [`${key} ${formatCounter(counter)}`];
712
- });
713
- const hasMoney = coins !== undefined && keys.some((key) => declaredKind(world, key) === undefined && readAmount(fields[key], coins) !== undefined);
714
- const listed = held.length > 0 ? `Its counters${hasMoney ? " and money" : ""}: ${held.join(", ")}.` : "It has no counters.";
715
- // A counter the system gives who has what it comes from is not added by hand, as a warlock's spell-slots to a wizard (DAT-9).
716
- const given = Object.keys(world.system?.formulas?.counters ?? {}).find((counter) => comparableText(counter) === comparableText(name.trim()));
717
- // A maximum that reads nothing, as a track of 5, is everyone's: it is written by hand as any other counter.
718
- const max = given === undefined ? undefined : world.system?.formulas?.counters[given]?.max;
719
- const everyones = max !== undefined && fieldsRead(max).length === 0;
720
- if (given !== undefined && !everyones && holder.kind === "page" && hasSheet(world, page)) {
721
- const sources = maximumSources(world, given, fields);
722
- const whence = sources.length === 0 ? `the tables of its ${world.system?.progression?.list ?? "lists"}` : sources.join(", ");
723
- throw new Error(`${page.name} has no ${given}: the system ${world.system?.name ?? ""} gives it from ${whence}, and ${page.name} has none from them. ${listed}`);
724
- }
725
- // Goods are stacks, never a field: the stacks the page holds, and the call for the kind the name means (STK-5).
726
- const stacks = holder.kind === "page" ? stacksOf(world, page).map((stack) => `${stackName(stack)} ${stack.count}`) : [];
727
- const goods = goodsNamed(world, name);
728
- const counted = stacks.length === 0 ? "" : `Its stacks: ${stacks.join(", ")}. `;
729
- // Its maximum, everyone's, in the example: the master writes it as the system works it out (FOR-7).
730
- const shown = everyones && given !== undefined ? `0/${counterLimits(world, fields, given).max ?? 0}` : example;
731
- const theirs = systemCountersHeld(world, fields);
732
- const how = goods === undefined ? howToAdd(world, holder, name, shown, theirs) : `Goods are a stack, changed by its kind, such as change ${page.name}, ${goods.name}, spend 1.`;
733
- throw new Error(`${page.name} has no field "${name}". ${counted}${listed} ${how}`);
734
- }
735
- /** An item a name means that may be counted though no stack counts it yet, as a kind of the campaign spent to 0 everywhere: change says how to write its stack (STK-5). */
736
- function countable(world, name) {
737
- const page = goodsNamed(world, name);
738
- return page !== undefined && comparableText(page.name) === comparableText(name.trim()) ? page : undefined;
739
- }
740
- /** Whether a name is a field of the page, one the game system declares or works out (CNT-8): a field before a kind of the same name (STK-5). */
741
- function holdsField(world, fields, name) {
742
- return Object.keys(fields).some((key) => comparableText(key) === comparableText(name.trim())) || declaredKind(world, name.trim()) !== undefined || computedField(world, name, fields) !== undefined;
743
- }
744
- /** The value a page reads for a field, written in any case. */
745
- function counterOf(world, page, field) {
746
- return Object.entries(inheritedFields(world, page)).find(([name]) => comparableText(name) === comparableText(field))?.[1];
747
- }
748
- /**
749
- * How to add a counter that neither the page nor its bases hold, on the nearest base of the campaign, since the system's are read-only (SYS-6); or why its base cannot be read.
750
- */
751
- function howToAdd(world, holder, name, example, theirs) {
752
- // A name the system does not have is most often one of its counters by another name, as health for hp: those first, an added field after (D-518).
753
- const meant = theirs.length === 0 ? "" : `If you meant a counter of the system ${world.system?.name ?? ""}, give its name, such as ${theirs.join(", ")}`;
754
- const page = holder.page;
755
- const field = baseFieldOf(page.type);
756
- const link = field === undefined || typeof page.fields[field] !== "string" ? undefined : page.fields[field];
757
- const chain = baseChain(world, page);
758
- const base = chain.find((candidate) => candidate.system === undefined);
759
- if (field !== undefined && link !== undefined && chain.length === 0) {
760
- const fix = holder.kind === "copy" ? "fix the creature's page, or let the copy leave the scene" : "fix the link with write";
761
- return `${page.name} ${holder.kind === "copy" ? "copies" : "derives from"} ${link}, which cannot be read: no ${field} has that name, two pages share it, or it is not ${withArticle(field)}. `
762
- + `To fix it, ${fix}; validate shows why.${missingSystemHint(world)}`;
763
- }
764
- if (base === undefined) {
765
- return meant === "" ? `To add one, use write, such as set ${name}=${example}.` : `${meant}; only one it lacks is added, with write, such as set ${name}=${example}.`;
766
- }
767
- // A page of the campaign named like one of the system's hides it (SYS-4): writing on it is not what the master means.
768
- const hides = systemPageNamed(world, base.name) === undefined ? "" : ` But ${base.name} hides the system ${world.system?.name ?? ""}'s ${base.name}: validate says how to fix it.`;
769
- const first = meant === "" ? "" : `${meant}. `;
770
- if (holder.kind === "copy") {
771
- return `${first}To add one to ${page.name} alone, use write, such as set ${name}=${example}. To give it to every ${base.name}, write it on ${base.name} once the scene is closed.${hides}`;
772
- }
773
- return `${first}${page.name} reads what it does not hold from ${base.name}: write the counter there, such as set ${name}=${example}, and everything that derives from ${base.name} takes it; or on ${page.name} alone.${hides}`;
774
- }
775
- /** The counters the game system declares among a page's fields, at most three, in the page's order. */
776
- function systemCountersHeld(world, fields) {
777
- return Object.keys(fields).filter((key) => declaredKind(world, key) === "counter" && readCounter(fields[key]) !== undefined).slice(0, 3);
778
- }
779
- /**
780
- * A field the game system never counts, such as ac: a number for a while is an effect, for good a write (SYS-8). `suggested` is the value the change would give, when it gives one.
781
- */
782
- function uncountedMessage(world, page, field, suggested) {
783
- const system = world.system?.name ?? "";
784
- if (!["number", "at-least"].includes(declaredKind(world, field) ?? "")) {
785
- const kind = declaredKind(world, field) === "text" ? "text" : declaredKind(world, field) === "list" ? "a list" : `a ${declaredKind(world, field) ?? "field"}`;
786
- return `${field} is ${kind} in the system ${system}, never counted: write it instead, such as write "${page}", set ${field}=${suggested}. Nothing changed.`;
787
- }
788
- return `${field} is a number in the system ${system}, never counted: for a while, such as a spell, effect, action add, page "${page}", set ${field}=${suggested}; `
789
- + `for good, write "${page}", set ${field}=${suggested}. Nothing changed.`;
790
- }
791
- /** The value a change would give a number, such as 18 for by 2 on ac 16; "<value>" when it gives none. */
792
- function suggestedNumber(fields, input) {
793
- const current = valueNamed(fields, input.field.trim());
794
- // From a command line a number arrives as text.
795
- if (input.to !== undefined && /^[+-]?\d+$/.test(String(input.to).trim())) {
796
- return String(Number(input.to));
797
- }
798
- return typeof current === "number" && typeof input.by === "number" ? String(current + input.by) : "<value>";
799
- }
800
- function notCounterMessage(page, field, value, coins) {
801
- if (typeof value === "string" && readCounterText(value) !== undefined) {
802
- return `${field} on ${page} is the text "${value}": write it without quotes, such as ${field}: ${value}, to make it a counter.`;
803
- }
804
- // Coins of the campaign after a number, such as "34 mo e 4 ma", meant money that does not read as an amount (MON-2).
805
- if (typeof value === "string" && coins !== undefined && namesCoins(value, coins)) {
806
- return `${field} on ${page} is "${value}", not money: write the coins one after the other, such as set ${field}=12 ${coins[0].name}.`;
807
- }
808
- const notCounter = `${field} on ${page} is ${JSON.stringify(value)}, not a counter: write a counter as a number (20) or as current/max (12/12).`;
809
- const word = typeof value === "string" ? /\d+\s*(\p{L}[\p{L}\p{M}]*)/u.exec(value)?.[1] : undefined;
810
- if (word === undefined) {
811
- return notCounter;
812
- }
813
- return coins === undefined
814
- ? `${notCounter} If it is money, the campaign needs its coins: set them with config, naming them as written here (${word}), each with its value in the smallest.`
815
- : `${notCounter} If it is money, ${word} is not a coin of the campaign (${coinNames(coins)}): write it with those, or give a coin that name too with config, such as ${coins[0].name}/${word}.`;
816
- }
817
- function readChange(input, counter, page, field, coins) {
818
- const given = [input.by, input.spend, input.to].filter((part) => part !== undefined);
819
- if (given.length !== 1) {
820
- throw new Error("Give one of by (damage, healing), spend (what is paid or used up) or to (a value, max, or current/max).");
821
- }
822
- if (typeof input.by === "string" || typeof input.spend === "string") {
823
- const parameter = typeof input.by === "string" ? "by" : "spend";
824
- // A plain number given coins may be money written without them; a current/max counter is no purse.
825
- const coinsAsked = counter.max === undefined && coins !== undefined && readSignedAmount(String(input.by ?? input.spend), coins) !== undefined;
826
- const money = coinsAsked && coins !== undefined
827
- ? `${field} on ${page} is a number, not money: to count it in coins, set it with its coins, such as set ${field}=${counter.value} ${coins[0].name}; or give ${parameter} a whole number.`
828
- : undefined;
829
- throw new Error(money ?? `${field} on ${page} is a counter: give ${parameter} a whole number, such as ${parameter === "by" ? "by -7" : "spend 1"}.`);
830
- }
831
- if (input.by !== undefined) {
832
- return { by: input.by };
833
- }
834
- if (input.spend !== undefined) {
835
- if (!canSpend(counter, input.spend)) {
836
- const floor = (counter.min ?? 0) > 0 ? `, which goes no lower than ${counter.min}` : "";
837
- throw new Error(input.spend > 0 ? `${page} has ${field} ${formatCounter(counter)}${floor}: cannot spend ${input.spend}. Nothing changed.` : "Give spend a number above 0.");
838
- }
839
- return { spend: input.spend };
840
- }
841
- return { to: readTarget(String(input.to).trim(), counter, page, field) };
842
- }
843
- /** The value given to `to`: max, a whole number, or current/max. */
844
- function readTarget(target, counter, page, field) {
845
- if (target.toLowerCase() === "max") {
846
- if (counter.max === undefined) {
847
- throw new Error(`${field} on ${page} has no maximum: give to a number, or write the field as current/max with write.`);
848
- }
849
- return { ...counter, value: counter.max };
850
- }
851
- const given = readCounterText(target);
852
- if (given === undefined) {
853
- throw new Error(`"${target}" is not a value for to: give a whole number, max, or current/max such as 15/15.`);
854
- }
855
- return given.max === undefined ? { ...counter, value: given.value } : given;
856
- }
857
- function amountOf(change) {
858
- return "to" in change ? { to: formatCounter(change.to) } : change;
859
- }
860
- /** Where the counter stands, when it matters: at 0 or at its maximum, how far a change went beyond, or outside the limits. */
861
- function limitNote(counter, beyond) {
862
- const limit = counterLimit(counter);
863
- const lowest = counter.min ?? 0;
864
- const where = limit === "outside" ? (counter.max === undefined ? `below ${lowest}` : `outside ${lowest}–${counter.max}`) : limit ?? "";
865
- return [where, beyond === 0 ? "" : `${Math.abs(beyond)} beyond`].filter((part) => part !== "").join(", ");
866
- }