rpg-engine 0.14.1 → 0.16.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 (493) hide show
  1. package/dist/campaign/index.d.ts +1 -1
  2. package/dist/campaign/index.js +1 -1
  3. package/dist/campaign/last-choices.js +1 -1
  4. package/dist/campaign/settings.d.ts +25 -5
  5. package/dist/campaign/settings.js +38 -9
  6. package/dist/cli/cli.js +1 -1
  7. package/dist/cli/command-line.js +1 -1
  8. package/dist/commands/advance.d.ts +1 -1
  9. package/dist/commands/advance.js +6 -6
  10. package/dist/commands/ask.js +7 -7
  11. package/dist/commands/change/amounts.d.ts +32 -0
  12. package/dist/commands/change/amounts.js +150 -0
  13. package/dist/commands/change/change.d.ts +4 -54
  14. package/dist/commands/change/change.js +19 -749
  15. package/dist/commands/change/damage.d.ts +30 -0
  16. package/dist/commands/change/damage.js +73 -2
  17. package/dist/commands/change/dice.d.ts +34 -0
  18. package/dist/commands/change/dice.js +59 -0
  19. package/dist/commands/change/fields.d.ts +37 -0
  20. package/dist/commands/change/fields.js +156 -0
  21. package/dist/commands/change/holder.d.ts +48 -0
  22. package/dist/commands/change/holder.js +162 -0
  23. package/dist/commands/change/recipe-pace.js +1 -1
  24. package/dist/commands/change/recipe.d.ts +58 -0
  25. package/dist/commands/change/recipe.js +179 -0
  26. package/dist/commands/choices.js +3 -3
  27. package/dist/commands/config/config.d.ts +15 -0
  28. package/dist/commands/config/config.js +355 -0
  29. package/dist/commands/config/custom-levels.d.ts +7 -0
  30. package/dist/commands/config/custom-levels.js +32 -0
  31. package/dist/commands/{config.d.ts → config/dashboard.d.ts} +4 -26
  32. package/dist/commands/config/dashboard.js +171 -0
  33. package/dist/commands/config/entries.d.ts +17 -0
  34. package/dist/commands/config/entries.js +76 -0
  35. package/dist/commands/config/news.d.ts +7 -0
  36. package/dist/commands/config/news.js +88 -0
  37. package/dist/commands/config/shown.d.ts +9 -0
  38. package/dist/commands/config/shown.js +80 -0
  39. package/dist/commands/config/words.d.ts +27 -0
  40. package/dist/commands/config/words.js +204 -0
  41. package/dist/commands/effect.js +9 -9
  42. package/dist/commands/find.d.ts +4 -4
  43. package/dist/commands/find.js +1 -1
  44. package/dist/commands/image.js +6 -6
  45. package/dist/commands/import/import.d.ts +0 -2
  46. package/dist/commands/import/import.js +45 -44
  47. package/dist/commands/import/run.js +1 -1
  48. package/dist/commands/index.js +3 -3
  49. package/dist/commands/init.js +2 -2
  50. package/dist/commands/install.js +1 -1
  51. package/dist/commands/instructions.js +17 -6
  52. package/dist/commands/mode.d.ts +2 -2
  53. package/dist/commands/mode.js +17 -9
  54. package/dist/commands/mood.js +4 -4
  55. package/dist/commands/move.js +10 -10
  56. package/dist/commands/package/consent.d.ts +11 -0
  57. package/dist/commands/package/consent.js +52 -0
  58. package/dist/commands/package/here.d.ts +51 -0
  59. package/dist/commands/package/here.js +128 -0
  60. package/dist/commands/package/install.d.ts +10 -0
  61. package/dist/commands/package/install.js +337 -0
  62. package/dist/commands/package/package.d.ts +18 -0
  63. package/dist/commands/package/package.js +236 -0
  64. package/dist/commands/package/result.d.ts +90 -0
  65. package/dist/commands/package/result.js +1 -0
  66. package/dist/commands/package/uninstall.d.ts +6 -0
  67. package/dist/commands/package/uninstall.js +70 -0
  68. package/dist/commands/rename.js +3 -3
  69. package/dist/commands/reveal.js +5 -5
  70. package/dist/commands/roll/roll.js +11 -9
  71. package/dist/commands/roll/tables.js +1 -1
  72. package/dist/commands/rules.d.ts +2 -2
  73. package/dist/commands/rules.js +3 -3
  74. package/dist/commands/save.d.ts +1 -1
  75. package/dist/commands/save.js +2 -2
  76. package/dist/commands/scene/close.d.ts +18 -0
  77. package/dist/commands/scene/close.js +179 -0
  78. package/dist/commands/scene/members.d.ts +14 -0
  79. package/dist/commands/scene/members.js +32 -0
  80. package/dist/commands/scene/open.d.ts +6 -0
  81. package/dist/commands/scene/open.js +298 -0
  82. package/dist/commands/scene/result.d.ts +98 -0
  83. package/dist/commands/scene/result.js +2 -0
  84. package/dist/commands/{scene.d.ts → scene/scene.d.ts} +10 -36
  85. package/dist/commands/scene/scene.js +210 -0
  86. package/dist/commands/scene/turns.d.ts +18 -0
  87. package/dist/commands/scene/turns.js +229 -0
  88. package/dist/commands/shared/{adventures.d.ts → books/adventures.d.ts} +5 -3
  89. package/dist/commands/shared/{adventures.js → books/adventures.js} +23 -19
  90. package/dist/commands/shared/{library-reader.js → books/library-reader.js} +3 -3
  91. package/dist/commands/shared/{library.d.ts → books/library.d.ts} +2 -2
  92. package/dist/commands/shared/{library.js → books/library.js} +9 -9
  93. package/dist/commands/shared/{rules.d.ts → books/rules.d.ts} +2 -2
  94. package/dist/commands/shared/{rules.js → books/rules.js} +5 -5
  95. package/dist/commands/shared/{system-texts.d.ts → books/system-texts.d.ts} +2 -2
  96. package/dist/commands/shared/{system-texts.js → books/system-texts.js} +9 -8
  97. package/dist/commands/shared/{page-words.d.ts → books/words.d.ts} +2 -2
  98. package/dist/commands/shared/{page-words.js → books/words.js} +4 -4
  99. package/dist/commands/shared/{checks.d.ts → campaign/checks.d.ts} +3 -3
  100. package/dist/commands/shared/{checks.js → campaign/checks.js} +7 -7
  101. package/dist/commands/shared/{images.d.ts → campaign/images.d.ts} +3 -3
  102. package/dist/commands/shared/{images.js → campaign/images.js} +5 -5
  103. package/dist/commands/shared/{mode.d.ts → campaign/mode.d.ts} +4 -4
  104. package/dist/commands/shared/{mode.js → campaign/mode.js} +28 -13
  105. package/dist/commands/shared/{money.d.ts → campaign/money.d.ts} +3 -3
  106. package/dist/commands/shared/{money.js → campaign/money.js} +2 -2
  107. package/dist/commands/shared/{offers.d.ts → campaign/offers.d.ts} +3 -3
  108. package/dist/commands/shared/{offers.js → campaign/offers.js} +3 -3
  109. package/dist/commands/shared/{outside.d.ts → campaign/outside.d.ts} +3 -3
  110. package/dist/commands/shared/{outside.js → campaign/outside.js} +7 -7
  111. package/dist/commands/shared/{parts.d.ts → campaign/parts.d.ts} +10 -3
  112. package/dist/commands/shared/{parts.js → campaign/parts.js} +26 -3
  113. package/dist/commands/shared/{problems.d.ts → campaign/problems.d.ts} +3 -3
  114. package/dist/commands/shared/{problems.js → campaign/problems.js} +17 -17
  115. package/dist/commands/shared/{quests.d.ts → campaign/quests.d.ts} +4 -4
  116. package/dist/commands/shared/{quests.js → campaign/quests.js} +6 -6
  117. package/dist/commands/shared/{saves.d.ts → campaign/saves.d.ts} +4 -4
  118. package/dist/commands/shared/{saves.js → campaign/saves.js} +10 -10
  119. package/dist/commands/shared/{theme.d.ts → campaign/theme.d.ts} +3 -3
  120. package/dist/commands/shared/{theme.js → campaign/theme.js} +1 -1
  121. package/dist/commands/shared/{world.d.ts → campaign/world.d.ts} +5 -5
  122. package/dist/commands/shared/{world.js → campaign/world.js} +17 -14
  123. package/dist/commands/shared/{knowledge.d.ts → characters/knowledge.d.ts} +3 -3
  124. package/dist/commands/shared/{knowledge.js → characters/knowledge.js} +4 -4
  125. package/dist/commands/shared/{moods.d.ts → characters/moods.d.ts} +3 -3
  126. package/dist/commands/shared/{moods.js → characters/moods.js} +3 -3
  127. package/dist/commands/shared/characters/orders.d.ts +4 -0
  128. package/dist/commands/shared/characters/orders.js +10 -0
  129. package/dist/commands/shared/{thoughts.d.ts → characters/thoughts.d.ts} +2 -2
  130. package/dist/commands/shared/{thoughts.js → characters/thoughts.js} +3 -3
  131. package/dist/commands/shared/{voices.d.ts → characters/voices.d.ts} +1 -1
  132. package/dist/commands/shared/{voices.js → characters/voices.js} +2 -2
  133. package/dist/commands/shared/examples.js +2 -2
  134. package/dist/commands/shared/packages/catalog.js +2 -2
  135. package/dist/commands/shared/packages/code.d.ts +1 -1
  136. package/dist/commands/shared/packages/code.js +8 -8
  137. package/dist/commands/shared/packages/extensions.d.ts +1 -1
  138. package/dist/commands/shared/packages/extensions.js +1 -1
  139. package/dist/commands/shared/packages/hooks.d.ts +1 -1
  140. package/dist/commands/shared/packages/hooks.js +1 -1
  141. package/dist/commands/shared/packages/widgets.d.ts +3 -3
  142. package/dist/commands/shared/packages/widgets.js +3 -3
  143. package/dist/commands/shared/{environment.d.ts → places/environment.d.ts} +1 -1
  144. package/dist/commands/shared/{environment.js → places/environment.js} +4 -4
  145. package/dist/commands/shared/{grid-moves.d.ts → places/grid-moves.d.ts} +4 -4
  146. package/dist/commands/shared/{grid-moves.js → places/grid-moves.js} +8 -7
  147. package/dist/commands/shared/{grids.d.ts → places/grids.d.ts} +4 -4
  148. package/dist/commands/shared/{grids.js → places/grids.js} +6 -6
  149. package/dist/commands/shared/{journey.d.ts → places/journey.d.ts} +3 -3
  150. package/dist/commands/shared/{journey.js → places/journey.js} +6 -6
  151. package/dist/commands/shared/{moves.d.ts → places/moves.d.ts} +2 -2
  152. package/dist/commands/shared/{moves.js → places/moves.js} +4 -4
  153. package/dist/commands/shared/{positions.d.ts → places/positions.d.ts} +2 -2
  154. package/dist/commands/shared/{positions.js → places/positions.js} +4 -4
  155. package/dist/commands/shared/{roads.d.ts → places/roads.d.ts} +5 -5
  156. package/dist/commands/shared/{roads.js → places/roads.js} +6 -6
  157. package/dist/commands/shared/{effects.d.ts → scene/effects.d.ts} +7 -7
  158. package/dist/commands/shared/{effects.js → scene/effects.js} +10 -10
  159. package/dist/commands/shared/{loot.d.ts → scene/loot.d.ts} +2 -2
  160. package/dist/commands/shared/{loot.js → scene/loot.js} +3 -3
  161. package/dist/commands/shared/{master-rolls.d.ts → scene/master-rolls.d.ts} +2 -2
  162. package/dist/commands/shared/{master-rolls.js → scene/master-rolls.js} +5 -5
  163. package/dist/commands/shared/{reminders.d.ts → scene/reminders.d.ts} +4 -4
  164. package/dist/commands/shared/{reminders.js → scene/reminders.js} +4 -4
  165. package/dist/commands/shared/{scene.d.ts → scene/scene.d.ts} +3 -3
  166. package/dist/commands/shared/{scene.js → scene/scene.js} +7 -7
  167. package/dist/commands/shared/{bonds.d.ts → sheet/bonds.d.ts} +3 -3
  168. package/dist/commands/shared/{bonds.js → sheet/bonds.js} +2 -2
  169. package/dist/commands/shared/{page-counters.d.ts → sheet/counters.d.ts} +3 -3
  170. package/dist/commands/shared/{page-counters.js → sheet/counters.js} +5 -5
  171. package/dist/commands/shared/{effect-layer.d.ts → sheet/effect-layer.d.ts} +2 -2
  172. package/dist/commands/shared/{effect-layer.js → sheet/effect-layer.js} +9 -6
  173. package/dist/commands/shared/sheet/effect-values.d.ts +9 -0
  174. package/dist/commands/shared/sheet/effect-values.js +69 -0
  175. package/dist/commands/shared/{experience.d.ts → sheet/experience.d.ts} +3 -3
  176. package/dist/commands/shared/{experience.js → sheet/experience.js} +5 -5
  177. package/dist/commands/shared/sheet/formula-problems.d.ts +8 -0
  178. package/dist/commands/shared/sheet/formula-problems.js +140 -0
  179. package/dist/commands/shared/sheet/formula-scope.d.ts +32 -0
  180. package/dist/commands/shared/sheet/formula-scope.js +235 -0
  181. package/dist/commands/shared/{limits.d.ts → sheet/limits.d.ts} +3 -3
  182. package/dist/commands/shared/{limits.js → sheet/limits.js} +5 -4
  183. package/dist/commands/shared/{progression.d.ts → sheet/progression.d.ts} +2 -2
  184. package/dist/commands/shared/{progression.js → sheet/progression.js} +4 -4
  185. package/dist/commands/shared/{sheet.d.ts → sheet/sheet.d.ts} +5 -5
  186. package/dist/commands/shared/{sheet.js → sheet/sheet.js} +11 -7
  187. package/dist/commands/shared/{stacks.d.ts → sheet/stacks.d.ts} +2 -2
  188. package/dist/commands/shared/{stacks.js → sheet/stacks.js} +4 -4
  189. package/dist/commands/shared/sheet/system-fields.d.ts +21 -0
  190. package/dist/commands/shared/sheet/system-fields.js +45 -0
  191. package/dist/commands/shared/{thresholds.d.ts → sheet/thresholds.d.ts} +1 -1
  192. package/dist/commands/shared/{thresholds.js → sheet/thresholds.js} +4 -4
  193. package/dist/commands/shared/{turn-uses.d.ts → sheet/turn-uses.d.ts} +3 -3
  194. package/dist/commands/shared/{turn-uses.js → sheet/turn-uses.js} +4 -3
  195. package/dist/commands/shared/{worked-out.d.ts → sheet/worked-out.d.ts} +11 -46
  196. package/dist/commands/shared/sheet/worked-out.js +291 -0
  197. package/dist/commands/shared/sheet/worked-text.d.ts +14 -0
  198. package/dist/commands/shared/sheet/worked-text.js +55 -0
  199. package/dist/commands/shared/{advance.d.ts → time/advance.d.ts} +3 -3
  200. package/dist/commands/shared/{advance.js → time/advance.js} +11 -11
  201. package/dist/commands/shared/{dice-pool.d.ts → time/dice-pool.d.ts} +3 -3
  202. package/dist/commands/shared/{dice-pool.js → time/dice-pool.js} +11 -11
  203. package/dist/commands/shared/{events.d.ts → time/events.d.ts} +5 -5
  204. package/dist/commands/shared/{events.js → time/events.js} +10 -13
  205. package/dist/commands/shared/{recipes.d.ts → time/recipes.d.ts} +3 -3
  206. package/dist/commands/shared/{recipes.js → time/recipes.js} +6 -5
  207. package/dist/commands/shared/{time.d.ts → time/time.d.ts} +4 -4
  208. package/dist/commands/shared/{time.js → time/time.js} +6 -6
  209. package/dist/commands/shared/{upkeep.d.ts → time/upkeep.d.ts} +3 -3
  210. package/dist/commands/shared/{upkeep.js → time/upkeep.js} +14 -13
  211. package/dist/commands/show.d.ts +4 -1
  212. package/dist/commands/show.js +28 -9
  213. package/dist/commands/status.d.ts +2 -1
  214. package/dist/commands/status.js +34 -23
  215. package/dist/commands/thoughts.js +3 -3
  216. package/dist/commands/trade.js +8 -8
  217. package/dist/commands/translate.d.ts +1 -1
  218. package/dist/commands/translate.js +3 -3
  219. package/dist/commands/travel/open.d.ts +1 -1
  220. package/dist/commands/travel/open.js +2 -2
  221. package/dist/commands/travel/route.js +7 -6
  222. package/dist/commands/travel/travel.d.ts +1 -1
  223. package/dist/commands/travel/travel.js +8 -8
  224. package/dist/commands/validate.js +3 -3
  225. package/dist/commands/view/journal.d.ts +2 -2
  226. package/dist/commands/view/journal.js +2 -2
  227. package/dist/commands/view/map.d.ts +1 -1
  228. package/dist/commands/view/map.js +6 -6
  229. package/dist/commands/view/memory.d.ts +16 -0
  230. package/dist/commands/view/memory.js +90 -0
  231. package/dist/commands/view/page.d.ts +32 -0
  232. package/dist/commands/view/page.js +163 -0
  233. package/dist/commands/view/place.d.ts +7 -2
  234. package/dist/commands/view/place.js +30 -12
  235. package/dist/commands/view/result.d.ts +245 -0
  236. package/dist/commands/view/result.js +1 -0
  237. package/dist/commands/view/saves.d.ts +6 -0
  238. package/dist/commands/view/saves.js +53 -0
  239. package/dist/commands/view/story.d.ts +32 -0
  240. package/dist/commands/view/story.js +227 -0
  241. package/dist/commands/view/view.d.ts +26 -292
  242. package/dist/commands/view/view.js +26 -534
  243. package/dist/commands/view/world.d.ts +1 -1
  244. package/dist/commands/view/world.js +3 -3
  245. package/dist/commands/write/checks.d.ts +42 -0
  246. package/dist/commands/write/checks.js +291 -0
  247. package/dist/commands/write/here.d.ts +1 -1
  248. package/dist/commands/write/here.js +5 -5
  249. package/dist/commands/write/inheritance.d.ts +40 -0
  250. package/dist/commands/write/inheritance.js +189 -0
  251. package/dist/commands/write/input.d.ts +29 -0
  252. package/dist/commands/write/input.js +124 -0
  253. package/dist/commands/write/layer.d.ts +36 -0
  254. package/dist/commands/write/layer.js +48 -0
  255. package/dist/commands/write/notes.d.ts +22 -0
  256. package/dist/commands/write/notes.js +76 -0
  257. package/dist/commands/write/progression.d.ts +27 -0
  258. package/dist/commands/write/progression.js +175 -0
  259. package/dist/commands/write/write.d.ts +2 -1
  260. package/dist/commands/write/write.js +33 -817
  261. package/dist/core/files.d.ts +2 -0
  262. package/dist/core/files.js +7 -0
  263. package/dist/core/{package-declarations.d.ts → packages/declarations.d.ts} +1 -1
  264. package/dist/core/{package-declarations.js → packages/declarations.js} +1 -1
  265. package/dist/core/session-store.js +3 -3
  266. package/dist/core/store.d.ts +2 -2
  267. package/dist/core/store.js +18 -4
  268. package/dist/dashboard/acts/acts.js +1 -1
  269. package/dist/dashboard/acts/sending.js +110 -0
  270. package/dist/dashboard/acts/sheet.js +2 -2
  271. package/dist/dashboard/acts/strip.js +1 -1
  272. package/dist/dashboard/address.js +6 -0
  273. package/dist/dashboard/api.js +1 -1
  274. package/dist/dashboard/app.js +47 -171
  275. package/dist/dashboard/dice/roller.js +1 -1
  276. package/dist/dashboard/dice/sets.js +2 -2
  277. package/dist/dashboard/dice/stage.js +1 -1
  278. package/dist/dashboard/dice/tray.js +6 -6
  279. package/dist/dashboard/guide/ar.md +9 -4
  280. package/dist/dashboard/guide/cs.md +10 -5
  281. package/dist/dashboard/guide/da.md +9 -4
  282. package/dist/dashboard/guide/de.md +9 -4
  283. package/dist/dashboard/guide/el.md +10 -5
  284. package/dist/dashboard/guide/en.md +7 -2
  285. package/dist/dashboard/guide/es.md +9 -4
  286. package/dist/dashboard/guide/fi.md +9 -4
  287. package/dist/dashboard/guide/fr.md +9 -4
  288. package/dist/dashboard/guide/he.md +9 -4
  289. package/dist/dashboard/guide/hi.md +10 -5
  290. package/dist/dashboard/guide/hu.md +10 -5
  291. package/dist/dashboard/guide/is.md +9 -4
  292. package/dist/dashboard/guide/it.md +9 -4
  293. package/dist/dashboard/guide/ja.md +12 -7
  294. package/dist/dashboard/guide/ko.md +11 -6
  295. package/dist/dashboard/guide/nb.md +9 -4
  296. package/dist/dashboard/guide/nl.md +10 -5
  297. package/dist/dashboard/guide/pl.md +9 -4
  298. package/dist/dashboard/guide/pt.md +9 -4
  299. package/dist/dashboard/guide/ro.md +9 -4
  300. package/dist/dashboard/guide/ru.md +9 -4
  301. package/dist/dashboard/guide/sv.md +9 -4
  302. package/dist/dashboard/guide/tr.md +11 -6
  303. package/dist/dashboard/guide/uk.md +9 -4
  304. package/dist/dashboard/guide/zh.md +9 -4
  305. package/dist/dashboard/help/help.js +3 -3
  306. package/dist/dashboard/i18n/ar.json +20 -0
  307. package/dist/dashboard/i18n/cs.json +20 -0
  308. package/dist/dashboard/i18n/da.json +20 -0
  309. package/dist/dashboard/i18n/de.json +20 -0
  310. package/dist/dashboard/i18n/el.json +20 -0
  311. package/dist/dashboard/i18n/es.json +20 -0
  312. package/dist/dashboard/i18n/fi.json +20 -0
  313. package/dist/dashboard/i18n/fr.json +20 -0
  314. package/dist/dashboard/i18n/he.json +20 -0
  315. package/dist/dashboard/i18n/hi.json +20 -0
  316. package/dist/dashboard/i18n/hu.json +20 -0
  317. package/dist/dashboard/i18n/is.json +20 -0
  318. package/dist/dashboard/i18n/it.json +20 -0
  319. package/dist/dashboard/i18n/ja.json +21 -1
  320. package/dist/dashboard/i18n/ko.json +20 -0
  321. package/dist/dashboard/i18n/nb.json +20 -0
  322. package/dist/dashboard/i18n/nl.json +20 -0
  323. package/dist/dashboard/i18n/pl.json +20 -0
  324. package/dist/dashboard/i18n/pt.json +20 -0
  325. package/dist/dashboard/i18n/ro.json +20 -0
  326. package/dist/dashboard/i18n/ru.json +20 -0
  327. package/dist/dashboard/i18n/sv.json +20 -0
  328. package/dist/dashboard/i18n/tr.json +20 -0
  329. package/dist/dashboard/i18n/uk.json +20 -0
  330. package/dist/dashboard/i18n/zh.json +20 -0
  331. package/dist/dashboard/{journal.js → journal/journal.js} +16 -16
  332. package/dist/dashboard/{notes.js → journal/notes.js} +4 -4
  333. package/dist/dashboard/kit.js +3 -3
  334. package/dist/dashboard/packages/ask-card.js +3 -3
  335. package/dist/dashboard/packages/catalog.js +196 -0
  336. package/dist/dashboard/packages/engine.js +87 -0
  337. package/dist/dashboard/packages/installed.js +53 -0
  338. package/dist/dashboard/packages/library.js +97 -0
  339. package/dist/dashboard/packages/outcomes.js +45 -0
  340. package/dist/dashboard/packages/packages.js +20 -576
  341. package/dist/dashboard/packages/page-code.js +15 -2
  342. package/dist/dashboard/packages/{package-page.js → page.js} +12 -5
  343. package/dist/dashboard/packages/rows.js +84 -0
  344. package/dist/dashboard/packages/share.js +44 -0
  345. package/dist/dashboard/packages/widgets.js +3 -3
  346. package/dist/dashboard/{card.js → parts/card.js} +1 -1
  347. package/dist/dashboard/{faces.js → parts/faces.js} +5 -5
  348. package/dist/dashboard/{game-words.js → parts/game-words.js} +1 -1
  349. package/dist/dashboard/{icons.js → parts/icons.js} +1 -1
  350. package/dist/dashboard/{labels.js → parts/labels.js} +8 -1
  351. package/dist/dashboard/{map-symbols.js → parts/map-symbols.js} +1 -1
  352. package/dist/dashboard/{markdown.js → parts/markdown.js} +2 -2
  353. package/dist/dashboard/{mood.js → parts/mood.js} +1 -1
  354. package/dist/dashboard/{refusals.js → parts/refusals.js} +1 -1
  355. package/dist/dashboard/{status.js → parts/status.js} +4 -4
  356. package/dist/dashboard/{widgets.js → parts/widgets.js} +2 -2
  357. package/dist/dashboard/place/key.js +24 -0
  358. package/dist/dashboard/place/paper.js +67 -0
  359. package/dist/dashboard/place/{map-sheet.js → sheet.js} +2 -2
  360. package/dist/dashboard/place/things.js +129 -0
  361. package/dist/dashboard/place/tokens.js +93 -0
  362. package/dist/dashboard/place/view.js +124 -0
  363. package/dist/dashboard/{asked-dice.js → play/asked-dice.js} +3 -3
  364. package/dist/dashboard/{asked.js → play/asked.js} +10 -10
  365. package/dist/dashboard/{choices.js → play/choices.js} +9 -9
  366. package/dist/dashboard/{requested.js → play/requested.js} +1 -1
  367. package/dist/dashboard/{rolls.js → play/rolls.js} +9 -9
  368. package/dist/dashboard/{scene.js → play/scene.js} +14 -14
  369. package/dist/dashboard/{turns.js → play/turns.js} +12 -12
  370. package/dist/dashboard/{language-choice.js → settings/language-choice.js} +1 -1
  371. package/dist/dashboard/{languages.js → settings/languages.js} +1 -1
  372. package/dist/dashboard/{saves.js → settings/saves.js} +8 -8
  373. package/dist/dashboard/{settings.js → settings/settings.js} +17 -15
  374. package/dist/dashboard/{setup.js → settings/setup.js} +6 -6
  375. package/dist/dashboard/{party.js → sheet/party.js} +8 -8
  376. package/dist/dashboard/{person-panel.js → sheet/person-panel.js} +4 -4
  377. package/dist/dashboard/{sheet.js → sheet/sheet.js} +17 -17
  378. package/dist/dashboard/{story.js → sheet/story.js} +3 -3
  379. package/dist/dashboard/{columns.js → shell/columns.js} +1 -1
  380. package/dist/dashboard/{footer.js → shell/footer.js} +3 -3
  381. package/dist/dashboard/{master.js → shell/master.js} +2 -2
  382. package/dist/dashboard/{notices.js → shell/notices.js} +3 -3
  383. package/dist/dashboard/{pages.js → shell/pages.js} +5 -5
  384. package/dist/dashboard/shell/shown.js +37 -0
  385. package/dist/dashboard/{table.js → shell/table.js} +2 -2
  386. package/dist/dashboard/{tabs.js → shell/tabs.js} +2 -2
  387. package/dist/dashboard/{top.js → shell/top.js} +7 -7
  388. package/dist/dashboard/style.css +90 -9
  389. package/dist/dashboard/world/calendar.js +4 -4
  390. package/dist/dashboard/world/drawing.js +92 -0
  391. package/dist/dashboard/world/key.js +21 -0
  392. package/dist/dashboard/world/lore.js +5 -5
  393. package/dist/dashboard/world/map-card.js +186 -0
  394. package/dist/dashboard/world/place-card.js +39 -0
  395. package/dist/dashboard/world/places.js +29 -0
  396. package/dist/dashboard/world/world.js +9 -341
  397. package/dist/extensions/extension.d.ts +1 -1
  398. package/dist/extensions/extension.js +1 -1
  399. package/dist/images/images.js +12 -9
  400. package/dist/index.d.ts +1 -1
  401. package/dist/languages/index.d.ts +1 -1
  402. package/dist/languages/index.js +1 -1
  403. package/dist/library/books.js +2 -0
  404. package/dist/packages/npm.js +1 -1
  405. package/dist/page.d.ts +2 -2
  406. package/dist/page.js +1 -1
  407. package/dist/pages/check.js +23 -1
  408. package/dist/pages/containers.d.ts +1 -1
  409. package/dist/pages/containers.js +1 -1
  410. package/dist/pages/index.d.ts +4 -2
  411. package/dist/pages/index.js +4 -2
  412. package/dist/pages/inheritance.d.ts +2 -2
  413. package/dist/pages/layers.d.ts +50 -0
  414. package/dist/pages/layers.js +97 -0
  415. package/dist/pages/rename-page.js +1 -1
  416. package/dist/pages/stacks/writes.js +48 -22
  417. package/dist/pages/standard-fields.d.ts +1 -1
  418. package/dist/pages/system-pages.d.ts +5 -3
  419. package/dist/pages/system-pages.js +16 -7
  420. package/dist/pages/world.d.ts +8 -1
  421. package/dist/pages/world.js +16 -4
  422. package/dist/pages/write-layer.d.ts +18 -0
  423. package/dist/pages/write-layer.js +108 -0
  424. package/dist/pages/write-page.d.ts +2 -2
  425. package/dist/pages/write-page.js +2 -2
  426. package/dist/rules/index.d.ts +1 -1
  427. package/dist/rules/index.js +1 -1
  428. package/dist/rules/search.d.ts +1 -1
  429. package/dist/rules/shown.d.ts +1 -1
  430. package/dist/server/dashboard/choices.js +3 -3
  431. package/dist/server/dashboard/files.js +5 -5
  432. package/dist/server/dashboard/index.d.ts +2 -2
  433. package/dist/server/dashboard/index.js +2 -2
  434. package/dist/server/dashboard/news.js +4 -3
  435. package/dist/server/dashboard/player.js +1 -1
  436. package/dist/server/dashboard/writes.js +10 -8
  437. package/dist/server/mcp.js +28 -13
  438. package/dist/systems/campaign-data.d.ts +15 -0
  439. package/dist/systems/campaign-data.js +85 -0
  440. package/dist/systems/{system-code.d.ts → code.d.ts} +1 -1
  441. package/dist/systems/{system-code.js → code.js} +2 -2
  442. package/dist/systems/game-system.d.ts +7 -61
  443. package/dist/systems/game-system.js +1 -984
  444. package/dist/systems/index.d.ts +6 -3
  445. package/dist/systems/index.js +6 -3
  446. package/dist/systems/installed.d.ts +31 -0
  447. package/dist/systems/installed.js +89 -0
  448. package/dist/systems/maps.d.ts +3 -0
  449. package/dist/systems/maps.js +9 -0
  450. package/dist/systems/read.d.ts +3 -0
  451. package/dist/systems/read.js +471 -0
  452. package/dist/systems/schema.d.ts +289 -0
  453. package/dist/systems/schema.js +243 -0
  454. package/dist/systems/settings.d.ts +19 -0
  455. package/dist/systems/settings.js +78 -0
  456. package/dist/systems/versions.d.ts +12 -0
  457. package/dist/systems/versions.js +52 -0
  458. package/dist/testing/index.js +1 -1
  459. package/instructions/import.md +1 -1
  460. package/instructions/length-a-few-sessions.md +1 -0
  461. package/instructions/length-one-evening.md +1 -0
  462. package/instructions/play.md +1 -1
  463. package/instructions/session-zero.md +1 -1
  464. package/instructions/setup.md +1 -1
  465. package/package.json +1 -1
  466. package/dist/commands/config.js +0 -917
  467. package/dist/commands/package.d.ts +0 -143
  468. package/dist/commands/package.js +0 -785
  469. package/dist/commands/scene.js +0 -894
  470. package/dist/commands/shared/worked-out.js +0 -805
  471. package/dist/dashboard/place/map-view.js +0 -417
  472. /package/dist/commands/shared/{library-reader.d.ts → books/library-reader.d.ts} +0 -0
  473. /package/dist/core/{package-api.d.ts → packages/api.d.ts} +0 -0
  474. /package/dist/core/{package-api.js → packages/api.js} +0 -0
  475. /package/dist/dashboard/{coins.js → parts/coins.js} +0 -0
  476. /package/dist/dashboard/{glass.js → parts/glass.js} +0 -0
  477. /package/dist/dashboard/{layout.js → parts/layout.js} +0 -0
  478. /package/dist/dashboard/{mood-faces.js → parts/mood-faces.js} +0 -0
  479. /package/dist/dashboard/{free-rolls.js → play/free-rolls.js} +0 -0
  480. /package/dist/dashboard/{reactions.js → play/reactions.js} +0 -0
  481. /package/dist/dashboard/{prefs.js → shell/prefs.js} +0 -0
  482. /package/dist/dashboard/{system-style.js → shell/system-style.js} +0 -0
  483. /package/dist/dashboard/{theme.js → shell/theme.js} +0 -0
  484. /package/dist/languages/{language-pack.d.ts → pack.d.ts} +0 -0
  485. /package/dist/languages/{language-pack.js → pack.js} +0 -0
  486. /package/dist/pages/{page-file.d.ts → file.d.ts} +0 -0
  487. /package/dist/pages/{page-file.js → file.js} +0 -0
  488. /package/dist/pages/{page-types.d.ts → types.d.ts} +0 -0
  489. /package/dist/pages/{page-types.js → types.js} +0 -0
  490. /package/dist/rules/{rule-book.d.ts → book.d.ts} +0 -0
  491. /package/dist/rules/{rule-book.js → book.js} +0 -0
  492. /package/dist/systems/{system-folders.d.ts → folders.d.ts} +0 -0
  493. /package/dist/systems/{system-folders.js → folders.js} +0 -0
@@ -1,894 +0,0 @@
1
- import { z } from "zod";
2
- import { requireCampaign } from "../campaign/index.js";
3
- import { numberOf } from "../core/formula.js";
4
- import { appendLogEntry } from "../core/log.js";
5
- import { defineCommand } from "../core/registry.js";
6
- import { comparableText, sameName, valueNamed, withArticle } from "../core/text.js";
7
- import { readCounter } from "../counters/index.js";
8
- import { concernsPlayer, findPage, isEmptyField, isInParty, isPartyMember, isPlayerCharacter, linkListItems, linksIn, locate, pageNamed, pagesWithName, pageWithPath, parsePageReference, playerCharacters, writePage, } from "../pages/index.js";
9
- import { copyNames, nextTurn, sceneTypes } from "../scene/index.js";
10
- import { formatGameDate } from "../time/index.js";
11
- import { newStateChecks } from "./shared/checks.js";
12
- import { effectiveFields, effectsOf } from "./shared/effect-layer.js";
13
- import { effectShown, endedByTurn, endEffects, endsWithScene, keptBy, systemNamed } from "./shared/effects.js";
14
- import { surroundings, surroundingsText } from "./shared/environment.js";
15
- import { clearCopies, offMapNote, placeGrid, standing } from "./shared/grids.js";
16
- import { metPictureNote, picturesNote } from "./shared/images.js";
17
- import { textList } from "./shared/inputs.js";
18
- import { readJourney } from "./shared/journey.js";
19
- import { fallenLine, isFallen } from "./shared/loot.js";
20
- import { campaignMode, checklistLine } from "./shared/mode.js";
21
- import { movePages } from "./shared/moves.js";
22
- import { packagesTurnStarted } from "./shared/packages/hooks.js";
23
- import { countersText, pageCounters, partyCounters } from "./shared/page-counters.js";
24
- import { firstInChat, situationPart } from "./shared/parts.js";
25
- import { isTickedOpenQuest, tickedQuestNote } from "./shared/quests.js";
26
- import { turnEffectsNote } from "./shared/reminders.js";
27
- import { partyLead, playersApart } from "./shared/roads.js";
28
- import { isPlayerDead, makeSave, saveText } from "./shared/saves.js";
29
- import { copyCounters, copyPage, openScene, rawScene, readOpenScene, saveScene, scenePlace, updateScene } from "./shared/scene.js";
30
- import { newDatedLogEntry, readPresent } from "./shared/time.js";
31
- import { turnUsesOf, useInTurn, usesAtTurn } from "./shared/turn-uses.js";
32
- import { hasSheet, startingAtZero } from "./shared/worked-out.js";
33
- import { campaignSystem, campaignSystemWords, campaignWorld, missingSystemHint, systemPagesHint } from "./shared/world.js";
34
- const actions = ["open", "add", "leave", "order", "next", "use", "now", "hostile", "calm", "close"];
35
- // The parameters each action takes; any other is refused, so that nothing given is silently ignored.
36
- const actionParameters = {
37
- open: ["title", "type", "place", "with", "creatures", "now", "seen"],
38
- add: ["with", "creatures", "seen"],
39
- leave: ["who"],
40
- order: ["order"],
41
- next: [],
42
- use: ["who", "uses", "by"],
43
- now: ["now"],
44
- hostile: ["who"],
45
- calm: ["who"],
46
- close: ["summary"],
47
- };
48
- // The most copies of one creature a scene takes.
49
- const mostCopies = 50;
50
- export const scene = defineCommand({
51
- name: "scene",
52
- description: "Open, run and close a scene of the story. "
53
- + "Creatures come as numbered copies, such as Annegato 1: a copy holds only what changes, the rest is read from the creature. "
54
- + "At open, whoever of the party is elsewhere moves to the scene's place, except in a travel scene. "
55
- + "order sets who takes turns, after rolling for it if the game does; next passes the turn; use marks what one uses of a turn: the engine counts the uses the game declares and refuses one too many. "
56
- + "now is the line the player's dashboard shows: give it at open too, and change it as the scene turns. "
57
- + "hostile marks who attacks the party, calm takes the mark off; seen gives what the character sees of those it does not know by name; the player's dashboard shows both. "
58
- + "close ends the scene with a summary the player may read. Change a copy's counters with change, as for a page. "
59
- + 'Example: action open, title "Scontro all\'ossario", type combat, creatures {"Annegato": 2}.',
60
- group: "game",
61
- positionals: ["action"],
62
- input: z.object({
63
- action: z.enum(actions).describe("open, add, leave, order, next, use, now, hostile, calm or close"),
64
- title: z.string().optional().describe("open: the scene's title"),
65
- type: z.enum(sceneTypes).optional().describe(`open: ${sceneTypes.join(", ")}`),
66
- place: z.string().optional().describe("open: the place, such as [[Ossario]]; the character's if left out"),
67
- with: textList.optional().describe("open, add: the characters in the scene, the player character included, such as [[Lena]]; at open, the character and the companions with them if left out"),
68
- creatures: z.union([textList, z.record(z.string(), z.number().int())]).optional().describe('open, add: creatures as numbered copies: Annegato=2 (Annegato alone is one), or through MCP an object such as {"Annegato": 2}'),
69
- who: textList.optional().describe("leave: who leaves the scene; hostile, calm: who attacks the party, or stops; use: who uses it; characters or copies, such as Annegato 2"),
70
- uses: z.string().optional().describe("use: what of a turn, by the game's names, such as {{uses}}"),
71
- by: z.string().optional().describe("use: what gives one more, or lets it in another's turn, such as a feature"),
72
- order: textList.optional().describe("order: who takes turns, in order; those left out (fallen, fled) take none"),
73
- now: z.string().optional().describe('open, now: what is happening now, in one line as the player sees it, such as "The bandits overturn the tables"; never what they cannot see'),
74
- summary: z.string().optional().describe("close: what happened, in one or two sentences, as the player saw it"),
75
- seen: z.union([textList, z.record(z.string(), z.string())]).optional().describe("open, add: what the character sees of one it does not know by name, by its page or creature, in two or three words, never its kind when that is a secret: "
76
- + 'Bandito=brigante incappucciato, or through MCP an object such as {"Varro": "il mugnaio"}'),
77
- }),
78
- run(given, context) {
79
- const root = requireCampaign(context.folder);
80
- const input = asLists(given);
81
- checkParameters(input);
82
- const world = campaignWorld(root, context);
83
- if (input.action === "close") {
84
- return close(root, world, input.summary ?? "", context);
85
- }
86
- const current = openScene(root);
87
- if (input.action === "open") {
88
- return openNew(root, world, input, context, current);
89
- }
90
- if (current === undefined) {
91
- throw new Error("No scene is open: open one with scene open, giving its title and type.");
92
- }
93
- switch (input.action) {
94
- case "now":
95
- return tellNow(root, input.now ?? "", context, current);
96
- case "add":
97
- return addTo(root, world, input, context, current);
98
- case "leave":
99
- return withActing(root, context, current, leave(root, world, input.who ?? [], context, current));
100
- case "hostile":
101
- case "calm":
102
- return markHostile(root, input.who ?? [], input.action === "hostile", context, current);
103
- case "order":
104
- return withActing(root, context, current, setOrder(root, world, input.order ?? [], context, current));
105
- case "use":
106
- return useOfTurn(root, world, input, context, current);
107
- default:
108
- return withActing(root, context, current, passTurn(root, world, context, current));
109
- }
110
- },
111
- format(result) {
112
- switch (result.action) {
113
- case "open": {
114
- const when = result.opened === undefined ? "" : `, ${result.opened}`;
115
- const where = result.place === undefined ? "" : ` at ${result.place}`;
116
- const members = result.members.length === 0 ? "No one in it yet: add who is there with scene add." : `In it: ${membersText(result.members)}.`;
117
- const around = result.around === "" ? undefined : `Here: ${result.around}.`;
118
- const part = result.part === "" ? undefined : result.part;
119
- return `Scene opened${when}: ${result.title} (${result.type})${where}. ${members}${broughtText(result, result.place)}${lineOf(around)}${lineOf(part)}`;
120
- }
121
- case "add": {
122
- const last = result.ordered ? " They take their turns last: change the order with scene order if needed." : "";
123
- const added = result.members.length === 0 ? "" : `Added to ${result.title}: ${membersText(result.members)}.${last}`;
124
- const seen = result.seen === undefined ? "" : `Seen: ${Object.entries(result.seen).map(([name, said]) => `${name} as ${said}`).join(", ")}.`;
125
- return `${[added, seen].filter((line) => line !== "").join(" ")}${broughtText(result, result.place)}`;
126
- }
127
- case "leave": {
128
- const turns = result.turns === undefined ? (result.noTurns ? "\nNo one takes turns now." : "") : `\n${turnText(result.turns)}`;
129
- const left = result.left.map((member) => (Object.keys(member.counters).length === 0 ? member.name : `${member.name} (${countersText(member.counters)})`));
130
- return `${left.join(", ")} left the scene.${turns}${actingText(result.acting)}${endedText(result.ended)}`;
131
- }
132
- case "order":
133
- return `Order: ${result.order.join(" · ")}.${result.noTurn.length === 0 ? "" : ` No turn: ${result.noTurn.join(", ")}.`}\n${turnText(result)}${actingText(result.acting)}${endedText(result.ended)}`;
134
- case "next":
135
- return `${turnText(result)}${actingText(result.acting)}${endedText(result.ended)}`;
136
- // Who is in it, so that the master sees a scene the story has left (playtest 19): another place or other people make a new one.
137
- case "now":
138
- return `${result.title}, with ${result.members.length === 0 ? "no one" : result.members.join(", ")}: the player's dashboard now shows "${result.now}". `
139
- + "If the story has moved elsewhere or to other people, close this scene and open the next.";
140
- case "use":
141
- return result.line;
142
- case "hostile":
143
- case "calm":
144
- return markedText(result);
145
- default:
146
- return closedText(result);
147
- }
148
- },
149
- });
150
- /** Lists as lists: one text is a list of one, or of its links when it gives them separated by commas; an empty text, list or object counts as left out (SCN-8). */
151
- function asLists(given) {
152
- const items = (texts) => texts.flatMap((text) => linkListItems(text) ?? [text]);
153
- const list = (value) => {
154
- if (isEmptyField(value) || (typeof value === "object" && Object.keys(value).length === 0)) {
155
- return undefined;
156
- }
157
- return typeof value === "string" ? items([value]) : Array.isArray(value) ? items(value) : value;
158
- };
159
- return { ...given, with: list(given.with), creatures: list(given.creatures), who: list(given.who), order: list(given.order), seen: list(given.seen) };
160
- }
161
- /** The line of what is happening now, which the player's dashboard shows (SCN-11): a public line of the log, out of the diary. */
162
- function tellNow(root, now, context, current) {
163
- if (now.trim() === "") {
164
- throw new Error('Give now: what is happening, in one line as the player sees it, such as "The bandits overturn the tables".');
165
- }
166
- updateScene(root, [[["now"], now.trim()]]);
167
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-now", "public", { title: current.title, now: now.trim() }));
168
- return { action: "now", title: current.title, now: now.trim(), members: memberNames(current) };
169
- }
170
- function checkParameters(input) {
171
- const allowed = actionParameters[input.action];
172
- const given = (name) => {
173
- const value = input[name];
174
- return !isEmptyField(value) && !(Array.isArray(value) && value.length === 0) && !(typeof value === "object" && Object.keys(value).length === 0);
175
- };
176
- const extra = Object.keys(input).filter((name) => name !== "action" && given(name) && !allowed.includes(name));
177
- if (extra.length > 0) {
178
- throw new Error(`scene ${input.action} does not take ${extra.join(", ")}: it takes ${allowed.length === 0 ? "nothing else" : allowed.join(", ")}.`);
179
- }
180
- }
181
- function openNew(root, world, input, context, current) {
182
- if (current !== undefined) {
183
- throw new Error(`A scene is open: ${current.title}. Close it first with scene close and a summary.`);
184
- }
185
- if (input.title === undefined || input.title.trim() === "" || input.type === undefined) {
186
- throw new Error(`Give the scene a title and a type: ${sceneTypes.join(", ")}.`);
187
- }
188
- checkInPlay(root, context, world);
189
- const named = input.with?.map((name) => characterPage(world, name));
190
- const movers = readJourney(root)?.movers ?? [];
191
- const place = input.place === undefined ? defaultPlace(world, movers, named) : placePage(world, input.place);
192
- const characters = [...new Set(named ?? enteringParty(world, movers, place))];
193
- const copies = newCopies(world, input.creatures, characters.map((page) => page.name));
194
- const brought = bringParty(root, context, world, characters, place, input.type);
195
- const opened = readPresent(root).date;
196
- // A scene without copies leaves the key out: an empty {} would be written on one line.
197
- const seen = seenOf(world, input.seen, characters, copies);
198
- const created = {
199
- title: input.title.trim(),
200
- type: input.type,
201
- place: place === undefined ? undefined : `[[${place.name}]]`,
202
- opened: opened === undefined ? undefined : formatGameDate(opened),
203
- now: input.now?.trim() || undefined,
204
- with: characters.map((page) => `[[${page.name}]]`),
205
- copies,
206
- ...(seen === undefined ? {} : { seen }),
207
- };
208
- saveScene(root, withoutUndefined({ ...created, copies: Object.keys(copies).length === 0 ? undefined : copies }));
209
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-opened", "public", { title: created.title, type: created.type, place: created.place, with: created.with }));
210
- // What the character sees, kept for the rolls of this scene once it closes (D-421); hidden, as the names it is given by are.
211
- if (seen !== undefined) {
212
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: created.title, seen }));
213
- }
214
- logCopies(root, context, created.title, copies);
215
- const after = brought.world;
216
- const system = campaignSystem(root, context);
217
- const members = [...characters.map((page) => characterMember(after, page, system)), ...copyMembers(after, copies)];
218
- const around = surroundingsText(surroundings(after, place === undefined ? undefined : pageWithPath(after, place.path)));
219
- // The part of the instructions that the scene's type opens, such as how a fight is told (D-111, D-139).
220
- const part = situationPart(created.type, context, system);
221
- // A place without a picture, where the campaign wants one for each new place (D-308).
222
- const picture = picturesNote(root, context, after, place === undefined ? undefined : pageWithPath(after, place.path));
223
- const offMap = offMapNote(after, place === undefined ? undefined : pageWithPath(after, place.path), created, [...characters.map((page) => page.name), ...Object.keys(copies)]);
224
- // Who enters without a picture, where the campaign wants one for each one met (D-420).
225
- const met = metPictureNote(root, context, [...characters, ...copyCreatures(world, copies)]);
226
- return {
227
- action: "open",
228
- title: created.title,
229
- type: created.type,
230
- opened: created.opened,
231
- place: place?.name,
232
- members,
233
- around,
234
- part,
235
- moved: brought.moved,
236
- notes: [...brought.notes, ...(picture === undefined ? [] : [picture]), ...(met === undefined ? [] : [met]), ...(offMap === undefined ? [] : [offMap])],
237
- };
238
- }
239
- function addTo(root, world, input, context, current) {
240
- if (input.with === undefined && input.creatures === undefined && input.seen === undefined) {
241
- throw new Error("Give who enters the scene: with (characters) or creatures (such as Annegato=1); or seen, what the character sees of who is already in it.");
242
- }
243
- const members = memberNames(current);
244
- const characters = [...new Set((input.with ?? []).map((name) => characterPage(world, name)))];
245
- const already = characters.filter((page) => sameName(members, page.name) !== undefined);
246
- if (already.length > 0) {
247
- throw new Error(`${already.map((page) => page.name).join(", ")} ${already.length === 1 ? "is" : "are"} already in the scene.`);
248
- }
249
- const copies = newCopies(world, input.creatures, [...members, ...(current.left ?? []), ...characters.map((page) => page.name)], current.copies);
250
- const place = current.place === undefined ? undefined : findPage(world, parsePageReference(current.place).name);
251
- const brought = bringParty(root, context, world, characters, place, current.type);
252
- const added = [...characters.map((page) => page.name), ...Object.keys(copies)];
253
- const changes = [[["with"], [...current.with, ...characters.map((page) => `[[${page.name}]]`)]], ...Object.entries(copies).map(([name, copy]) => [["copies", name], copy])];
254
- const inScene = [...current.with.flatMap((link) => findPage(world, parsePageReference(link).name) ?? []), ...characters];
255
- const seen = seenOf(world, input.seen, inScene, { ...current.copies, ...copies });
256
- if (seen !== undefined) {
257
- changes.push([["seen"], { ...current.seen, ...seen }]);
258
- }
259
- if (current.order !== undefined) {
260
- changes.push([["order"], [...current.order, ...added]]);
261
- }
262
- updateScene(root, changes);
263
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: current.title, added, ...(seen === undefined ? {} : { seen }) }));
264
- logCopies(root, context, current.title, copies);
265
- const system = campaignSystem(root, context);
266
- const entered = [...characters.map((page) => characterMember(brought.world, page, system)), ...copyMembers(brought.world, copies)];
267
- const offMap = offMapNote(brought.world, place === undefined ? undefined : pageWithPath(brought.world, place.path), { ...current, copies: { ...current.copies, ...copies } }, added);
268
- const met = metPictureNote(root, context, [...characters, ...copyCreatures(world, copies)]);
269
- return {
270
- action: "add",
271
- title: current.title,
272
- place: place?.name,
273
- members: entered,
274
- ordered: current.order !== undefined,
275
- ...(seen === undefined ? {} : { seen }),
276
- moved: brought.moved,
277
- notes: [...brought.notes, ...(met === undefined ? [] : [met]), ...(offMap === undefined ? [] : [offMap])],
278
- };
279
- }
280
- /**
281
- * Brings into the scene's place whoever of the party in the scene is elsewhere, as move does, with what that sets off (CON-6); a travel scene moves no one.
282
- * Done before the scene is written, so that a move refused leaves no scene behind.
283
- */
284
- function bringParty(root, context, world, characters, place, type) {
285
- const away = place === undefined || type === "travel" ? [] : characters.filter((page) => isInParty(page) && !locate(world, page).chain.includes(place));
286
- if (place === undefined || away.length === 0) {
287
- return { moved: [], notes: [], world };
288
- }
289
- const done = movePages(root, context, world, away, place);
290
- return { moved: done.moved.map((page) => page.name), notes: done.notes, world: done.world };
291
- }
292
- /** "\nMoved into Ossario: Ennio, Lena.", with what that set off, or nothing when no one moved (CON-6). */
293
- function broughtText(result, place) {
294
- const moved = result.moved.length === 0 ? [] : [`Moved into ${place ?? "the scene's place"}: ${result.moved.join(", ")}.`];
295
- return [...moved, ...result.notes].map((line) => `\n${line}`).join("");
296
- }
297
- /**
298
- * Marks who attacks the party, or takes the mark off (D-415): only in a fight, and only who is in the scene. The player's dashboard shows it, so that a token
299
- * changes only when the master says so.
300
- */
301
- function markHostile(root, who, hostile, context, current) {
302
- if (current.type !== "combat") {
303
- throw new Error(`${current.title} is a ${current.type} scene: hostile and calm mark who fights in a combat scene. When a fight breaks out, close this one and open one of type combat.`);
304
- }
305
- if (who.length === 0) {
306
- throw new Error(`Give who ${hostile ? "attacks the party" : "stops attacking"}, such as who "Annegato 2".`);
307
- }
308
- const members = memberNames(current);
309
- const marked = [
310
- ...new Set(who.map((name) => {
311
- const member = sameName(members, parsePageReference(name).name);
312
- if (member === undefined) {
313
- throw new Error(`${name} is not in the scene. In it: ${members.length === 0 ? "no one" : members.join(", ")}.`);
314
- }
315
- return member;
316
- })),
317
- ];
318
- const before = current.hostile ?? [];
319
- const now = hostile ? [...before, ...marked.filter((name) => !before.includes(name))] : before.filter((name) => !marked.includes(name));
320
- updateScene(root, [[["hostile"], now.length === 0 ? undefined : now]]);
321
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: current.title, [hostile ? "hostile" : "calm"]: marked }));
322
- return { action: hostile ? "hostile" : "calm", title: current.title, marked, hostile: now };
323
- }
324
- /** Takes out who goes (D-114): a copy vanishes with its numbers, a character leaves the scene without changing place. The turn of who leaves passes on. */
325
- function leave(root, world, who, context, current) {
326
- if (who.length === 0) {
327
- throw new Error('Give who leaves the scene, such as who "Annegato 2".');
328
- }
329
- const members = memberNames(current);
330
- const leaving = who.map((name) => {
331
- const member = sameName(members, parsePageReference(name).name);
332
- if (member === undefined) {
333
- throw new Error(`${name} is not in the scene. In it: ${members.length === 0 ? "no one" : members.join(", ")}.`);
334
- }
335
- return member;
336
- }).filter((name, index, all) => all.indexOf(name) === index);
337
- const copies = Object.fromEntries(Object.entries(current.copies).filter(([name]) => leaving.includes(name)));
338
- const staying = Object.keys(current.copies).filter((name) => !leaving.includes(name));
339
- const changes = [[["with"], current.with.filter((link) => !leaving.includes(parsePageReference(link).name))]];
340
- changes.push(...(staying.length === 0 ? [[["copies"], undefined]] : Object.keys(copies).map((name) => [["copies", name], undefined])));
341
- const order = current.order?.filter((name) => !leaving.includes(name));
342
- const kept = order === undefined || order.length === 0 ? undefined : keptTurn(current, order);
343
- const turns = order === undefined || kept === undefined ? undefined : { order, ...kept, player: isPlayerTurn(world, kept.turn), ...severalPlayers(world) };
344
- if (current.order !== undefined) {
345
- changes.push([["order"], turns?.order], [["turn"], turns?.turn]);
346
- if (turns !== undefined) {
347
- changes.push([["round"], turns.round]);
348
- }
349
- }
350
- changes.push([["left"], [...(current.left ?? []), ...leaving]]);
351
- // Who leaves is hostile no more (D-415).
352
- const hostile = current.hostile?.filter((name) => !leaving.includes(name));
353
- if (current.hostile !== undefined) {
354
- changes.push([["hostile"], hostile === undefined || hostile.length === 0 ? undefined : hostile]);
355
- }
356
- // A copy that leaves, fallen or fled, is kept as it left, without its effects, which go with it (D-145): closing the scene counts what overcoming it gives (DAT-11).
357
- changes.push(...Object.entries(copies).map(([name, copy]) => [["gone", name], Object.fromEntries(Object.entries(copy).filter(([field]) => field !== "effects"))]));
358
- updateScene(root, changes);
359
- clearCopies(world, current, Object.keys(copies));
360
- // The turn it moves to, as next logs it, so that the open scene's log reads the round (SCN-10).
361
- const moved = turns === undefined || (turns.turn === current.turn && turns.round === (current.round ?? 1)) ? {} : { round: turns.round, turn: turns.turn };
362
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: current.title, left: leaving, copies: Object.keys(copies).length === 0 ? undefined : copies, ...moved }));
363
- const left = leaving.map((name) => (name in copies ? { name, counters: copyCounters(world, copies[name]) } : { name, counters: {} }));
364
- // The copies that left are gone with their effects, and with those they kept alive (D-145); the turn may have passed, and with it the end of some effects.
365
- const remaining = { ...current, copies: Object.fromEntries(Object.entries(current.copies).filter(([name]) => !leaving.includes(name))) };
366
- const keptByGone = (effect) => Object.keys(copies).some((name) => keptBy(effect, name));
367
- const byTurn = (effect) => turns !== undefined && endedByTurn(effect, turns.round, turns.turn, turns.order);
368
- const ended = endEffects(root, context, world, remaining, (effect) => keptByGone(effect) || byTurn(effect), (effect) => (keptByGone(effect) ? "who kept it left" : "turn"));
369
- return { action: "leave", left, turns, noTurns: current.order !== undefined && turns === undefined, ended };
370
- }
371
- /** Who takes turns, in order; those left out take none. A new order in a running scene keeps the round, and the turn if its owner is still in it. */
372
- function setOrder(root, world, order, context, current) {
373
- const members = memberNames(current);
374
- const inScene = members.length === 0 ? "no one yet" : members.join(", ");
375
- const named = order.map((name) => {
376
- const member = sameName(members, parsePageReference(name).name);
377
- if (member === undefined) {
378
- throw new Error(`${name} is not in the scene. In it: ${inScene}.`);
379
- }
380
- return member;
381
- });
382
- const repeated = named.find((name, index) => named.indexOf(name) !== index);
383
- if (repeated !== undefined) {
384
- throw new Error(`${repeated} is in the order twice: give each one once.`);
385
- }
386
- if (named.length === 0) {
387
- throw new Error(`Give who takes turns, in order. In the scene: ${inScene}.`);
388
- }
389
- const { round, turn } = keptTurn(current, named);
390
- updateScene(root, [[["order"], named], [["round"], round], [["turn"], turn]]);
391
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: current.title, order: named }));
392
- const ended = endEffects(root, context, world, current, (effect) => endedByTurn(effect, round, turn, named), "turn");
393
- return { action: "order", order: named, round, turn, player: isPlayerTurn(world, turn), ...severalPlayers(world), noTurn: members.filter((name) => !named.includes(name)), ended };
394
- }
395
- /**
396
- * The round and turn after a new order. A first order starts round 1. In a running scene the round goes on: the turn stays with its owner,
397
- * or, if they left the order, passes to the next of the old order still in it, or to a new round when no one after them is.
398
- */
399
- function keptTurn(current, named) {
400
- const round = current.round ?? 1;
401
- if (current.order === undefined || current.turn === undefined) {
402
- return { round: 1, turn: named[0] };
403
- }
404
- if (named.includes(current.turn)) {
405
- return { round, turn: current.turn };
406
- }
407
- const after = current.order.slice(current.order.indexOf(current.turn) + 1).find((name) => named.includes(name));
408
- return after === undefined ? { round: round + 1, turn: named[0] } : { round, turn: after };
409
- }
410
- /** One use of a turn by one in the scene (TRN-1–TRN-3), kept in the scene, with its line in the log. */
411
- function useOfTurn(root, world, input, context, current) {
412
- const [who, ...others] = input.who ?? [];
413
- if (who === undefined || input.uses === undefined || input.uses.trim() === "") {
414
- throw new Error("Give who and what they use, such as who Ettore, uses attack.");
415
- }
416
- if (others.length > 0) {
417
- throw new Error(`One at a time: give who as one name, then use again for ${others.join(", ")}. Nothing changed.`);
418
- }
419
- if (current.order === undefined) {
420
- throw new Error("The scene has no order of turns, so no turn to use: set it with scene order first, after rolling for it if the game does.");
421
- }
422
- const name = memberNames(current).find((member) => comparableText(member) === comparableText(parsePageReference(who).name));
423
- if (name === undefined) {
424
- throw new Error(`${who} is not in the scene ${current.title}: bring them in with scene add, or give one of ${memberNames(current).join(", ")}.`);
425
- }
426
- const copy = current.copies[name];
427
- const page = copy === undefined ? findPage(world, name) : copyPage(name, copy);
428
- if (page === undefined) {
429
- throw new Error(`There is no page named ${name}. Look for it with the find command.`);
430
- }
431
- const by = input.by?.trim() === "" ? undefined : input.by?.trim();
432
- const system = campaignSystem(root, context);
433
- const done = useInTurn(world, system, current, { name, page }, input.uses.trim(), by);
434
- updateScene(root, [[["used", name], done.used]]);
435
- appendLogEntry(root, newDatedLogEntry(root, context, "turn-used", "hidden", { title: current.title, who: name, use: input.uses.trim(), by }));
436
- // What gave one more, spent from the sheet that counts it (TRN-5).
437
- if (done.spends !== undefined) {
438
- spendOne(root, context, world, { name, copy: copy !== undefined, page }, done.spends, by ?? "");
439
- }
440
- // One who cannot act, as Stunned, is said so: the game's rule, which the master applies (pp. 91, 358); by its name in the campaign's language too (D-403).
441
- const words = campaignSystemWords(root, context);
442
- const inactive = effectsOf(page).map((effect) => effect.name).filter((effect) => systemNamed(system?.combat?.inactive ?? [], effect, words) !== undefined);
443
- const warned = inactive.length === 0 ? "" : ` ${name} is ${inactive.join(", ")}: read what it may still do.`;
444
- return { action: "use", line: `${done.line}${warned}` };
445
- }
446
- /** One of a counter spent, on a page as it writes it or on a copy in the scene, with its line in the log. */
447
- function spendOne(root, context, world, who, spends, why) {
448
- const after = spends.before - 1;
449
- const value = spends.max === undefined ? after : `${after}/${spends.max}`;
450
- if (who.copy) {
451
- updateScene(root, [[["copies", who.name, spends.field], value]]);
452
- }
453
- else {
454
- writePage(world, who.page.name, undefined, { set: { [spends.field]: value } });
455
- }
456
- // Seen where the player sees the page, as change writes it: never a foe's count.
457
- const visibility = who.copy || !concernsPlayer(world, who.page) ? "hidden" : "public";
458
- appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: who.name, field: spends.field, before: String(spends.before), after: String(after), why }));
459
- }
460
- function passTurn(root, world, context, current) {
461
- if (current.order === undefined) {
462
- throw new Error("The scene has no order of turns: set it with scene order, after rolling for it if the game does.");
463
- }
464
- const { turn, round } = nextTurn(current.order, current.turn, current.round ?? 1);
465
- updateScene(root, [[["round"], round], [["turn"], turn]]);
466
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: current.title, round, turn }));
467
- const order = current.order;
468
- const ended = endEffects(root, context, world, current, (effect) => endedByTurn(effect, round, turn, order), "turn");
469
- return { action: "next", order, round, turn, player: isPlayerTurn(world, turn), ...severalPlayers(world), noTurn: [], ended };
470
- }
471
- /** Ends the scene; one that cannot be read is closed too, so that a scene written wrongly by hand never blocks the game. */
472
- function close(root, world, summary, context) {
473
- if (summary.trim() === "") {
474
- throw new Error("Give the scene a summary of one or two sentences: what happened, as the player saw it.");
475
- }
476
- const { scene: current, problem } = readOpenScene(root);
477
- if (current === undefined && problem === undefined) {
478
- throw new Error("No scene is open: there is nothing to close.");
479
- }
480
- const present = readPresent(root).date;
481
- const closed = present === undefined ? undefined : formatGameDate(present);
482
- const raw = current === undefined ? rawScene(root) : undefined;
483
- // Rounds exist only in the scene: the effects counted in them end with it, on the pages; the copies go with theirs, and with what they kept alive (D-145).
484
- const keptByCopy = (effect) => current !== undefined && Object.keys(current.copies).some((name) => keptBy(effect, name));
485
- // What the close says is worked out before anything is written: a page it cannot find stops it with the scene still open.
486
- const endless = (current?.with ?? []).flatMap((link) => {
487
- const page = findPage(world, parsePageReference(link).name);
488
- return page === undefined ? [] : effectsOf(page).filter((effect) => effect.end === undefined && !keptByCopy(effect)).map((effect) => `${effect.name} on ${page.name}`);
489
- });
490
- const rewards = current === undefined ? [] : rewardLines(world, campaignSystem(root, context), current);
491
- // What the fallen carried stays where they fell, a copy's read on its creature, which ends with the scene (D-530).
492
- const fallen = current === undefined ? "" : fallenLine(fallenOf(world, campaignSystem(root, context), current));
493
- // A scene that ends may end the story of a quest whose goals are all ticked: the master says whether it did (D-239).
494
- const quests = world.pages.filter(isTickedOpenQuest).map(tickedQuestNote);
495
- const ended = endEffects(root, context, world, undefined, (effect) => endsWithScene(effect) || keptByCopy(effect), "scene closed");
496
- if (current !== undefined) {
497
- clearCopies(campaignWorld(root, context), current, Object.keys(current.copies));
498
- }
499
- saveScene(root, undefined);
500
- if (current === undefined) {
501
- const titled = rawTitleAndType(raw);
502
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-closed", "public", { ...titled, closed, summary: summary.trim() }));
503
- return { action: "close", copies: [], unreadable: problem?.message, ended, endless: [], quests, ...endOfSceneSave(root, context, world, titled.title) };
504
- }
505
- logCopies(root, context, current.title, current.copies);
506
- const left = current.left?.filter((name) => pagesWithName(world, name).length > 0);
507
- // Who the character saw without learning their name stays so after the scene (D-416).
508
- const unnamed = current.seen === undefined ? undefined : Object.keys(current.seen);
509
- const data = { title: current.title, type: current.type, place: current.place, with: current.with, left: left?.length === 0 ? undefined : left, unnamed, opened: current.opened, closed, rounds: current.round, summary: summary.trim() };
510
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-closed", "public", data));
511
- // The copies that left during the scene, fled or fallen, end with it too: one that may come back needs a page now, with its wounds (D-246).
512
- const gone = copyMembers(world, current.gone ?? {});
513
- const saved = endOfSceneSave(root, context, world, current.title);
514
- return {
515
- action: "close",
516
- title: current.title,
517
- rounds: current.round,
518
- copies: copyMembers(world, current.copies),
519
- gone,
520
- ended,
521
- endless,
522
- ...(rewards.length === 0 ? {} : { rewards }),
523
- ...(fallen === "" ? {} : { fallen }),
524
- ...(peakEnded(current.type) && firstInChat(context, "after-peak") ? { afterPeak } : {}),
525
- quests,
526
- ...saved,
527
- };
528
- }
529
- /**
530
- * The save at the end of a scene, named by its title (D-55, SAV-3): none while the player character is dead, since going back is what one is for. A save that
531
- * cannot be written never stops the close, which is already done: it says why.
532
- */
533
- function endOfSceneSave(root, context, world, title) {
534
- if (isPlayerDead(world)) {
535
- return { unsaved: "No save: the player character is dead. If the player wants to go back, save load, as the campaign's saves setting allows." };
536
- }
537
- try {
538
- return { saved: saveText(makeSave(root, context, title, "scene closed")) };
539
- }
540
- catch (error) {
541
- const reason = error instanceof Error ? error.message : String(error);
542
- return { unsaved: `No save: it could not be written (${reason}). Make .saves a folder that can be written; the next scene's end saves again.` };
543
- }
544
- }
545
- /**
546
- * What the creatures overcome in a scene give the party there (DAT-11): for each reward of the system, the copies, also those that left, and the characters
547
- * outside the party at its counter's value or below, or dead, with what each gives, shared, rounded down, among the living party members who were there and
548
- * keep the sheet. Said with the calls to make, never given: a character may have been an ally, and who fled or was overcome another way is the master's to judge.
549
- */
550
- function rewardLines(world, system, scene) {
551
- const there = [...scene.with.map((link) => parsePageReference(link).name), ...(scene.left ?? [])].flatMap((name) => findPage(world, name) ?? []);
552
- const party = there.filter((page, index) => there.indexOf(page) === index && isPartyMember(page) && page.fields.status !== "dead" && hasSheet(world, page));
553
- const copies = [...Object.entries(scene.copies), ...Object.entries(scene.gone ?? {})].map(([name, copy]) => ({ page: copyPage(name, copy), left: name in (scene.gone ?? {}) }));
554
- const others = [...copies, ...there.filter((page) => !isPartyMember(page)).map((page) => ({ page, left: (scene.left ?? []).includes(page.name) }))];
555
- const read = (fields, field) => valueNamed(fields, field);
556
- return (system?.rewards ?? []).flatMap((reward) => {
557
- const worth = others.flatMap(({ page, left }) => {
558
- const fields = effectiveFields(world, page);
559
- const value = numberOf(read(fields, reward.from));
560
- const counter = readCounter(read(fields, reward.counter))?.value;
561
- const down = page.fields.status === "dead" || (counter !== undefined && counter <= reward.value);
562
- return [{ name: page.name, kind: linksIn(page.fields.creature)[0] ?? page.name, worth: value ?? 0, given: value !== undefined, down, left, character: page.type === "character" }];
563
- });
564
- const overcome = worth.filter((item) => item.down && item.worth > 0);
565
- const fled = worth.filter((item) => !item.down && item.left && item.worth > 0);
566
- // A creature of the campaign written without the field, as cr 2 (450 XP), would count nothing in silence.
567
- const unknown = worth.filter((item) => item.down && !item.given);
568
- const total = overcome.reduce((sum, item) => sum + item.worth, 0);
569
- if ((total === 0 && fled.length === 0 && unknown.length === 0) || party.length === 0) {
570
- return [];
571
- }
572
- const share = Math.floor(total / party.length);
573
- const to = party.length === 1 ? `${share} to ${party[0].name}` : `${share} each to ${party.map((page) => page.name).join(", ")}`;
574
- // Who has no such field yet gets it written, unless change starts it at 0 (CNT-8).
575
- const held = (page) => read(effectiveFields(world, page), reward.field) !== undefined || startingAtZero(world, reward.field) !== undefined;
576
- const calls = party.map((page) => (held(page) ? `change ${page.name}, field ${reward.field}, by ${share}` : `write ${page.name}, set ${reward.field}=${share}`)).join("; ");
577
- const kinds = [...new Set(unknown.map((item) => item.kind))];
578
- const characters = overcome.filter((item) => item.character).map((item) => item.name);
579
- const parts = [
580
- total === 0 ? `${reward.field}:` : `${reward.field} of those overcome: ${overcome.map((item) => `${item.name} ${item.worth}`).join(", ")}, ${total} in all; ${to}: ${calls}.`,
581
- characters.length === 0 ? "" : `${characters.join(", ")} ${characters.length === 1 ? "is a character" : "are characters"}: leave out any who fought on your side, and share again.`,
582
- fled.length === 0 ? "" : `Fled: ${fled.map((item) => `${item.name} ${item.worth}`).join(", ")}, to count if the party overcame them.`,
583
- unknown.length === 0
584
- ? ""
585
- : `${unknown.map((item) => item.name).join(", ")} ${unknown.length === 1 ? "counts" : "count"} nothing, with no ${reward.from} on ${kinds.join(", ")}: write it, such as write ${kinds[0]}, set ${reward.from}=…, and share it.`,
586
- "Leave out what the party summoned; count those overcome another way and what the story rewards, as you judge, and tell the player only what each gained.",
587
- ];
588
- return [parts.filter((part) => part !== "").join(" ")];
589
- });
590
- }
591
- /** What a fight or a challenge that ends asks of the master, once in a chat, as play's rules left the instructions for it (D-532). */
592
- const afterPeak = "After a peak, give a quiet scene the player can fill: a meal, rain, a talk. Judge a challenge by what it cost, not by whether it was won: "
593
- + "after two that cost nothing, let the next rise, within what the difficulty allows.";
594
- /** Whether a scene of this type is a peak: a fight or a challenge. */
595
- function peakEnded(type) {
596
- return type === "combat" || type === "challenge";
597
- }
598
- /** Who fell in a scene, dead or down: its copies, those that left during it too, each with its creature, and the characters outside the party. */
599
- function fallenOf(world, system, scene) {
600
- const copies = [...Object.entries(scene.copies), ...Object.entries(scene.gone ?? {})].map(([name, copy]) => ({ page: copyPage(name, copy), kind: parsePageReference(copy.creature).name }));
601
- const names = [...new Set([...scene.with.map((link) => parsePageReference(link).name), ...(scene.left ?? [])])];
602
- const characters = names.flatMap((name) => findPage(world, name) ?? []).map((page) => ({ page, kind: undefined }));
603
- return [...copies, ...characters].filter(({ page }) => isFallen(world, system, page)).map(({ page, kind }) => ({ name: page.name, ...(kind === undefined ? {} : { kind }) }));
604
- }
605
- /** The title and type of a scene that cannot be read, as far as they can be, so that the log still holds a closed scene. */
606
- function rawTitleAndType(raw) {
607
- const fields = raw !== null && typeof raw === "object" ? raw : {};
608
- const title = typeof fields.title === "string" && fields.title.trim() !== "" ? fields.title : "Untitled scene";
609
- const type = typeof fields.type === "string" && sceneTypes.includes(fields.type) ? fields.type : "other";
610
- return { title, type };
611
- }
612
- function closedText(result) {
613
- const saved = result.saved === undefined ? (result.unsaved === undefined ? "" : `\n${result.unsaved}`) : `\nSaved: ${result.saved}.`;
614
- const advance = "Advance any time it took that you have not advanced yet; write on their pages what it changed for good, such as a fire put out or a door broken.";
615
- const endless = result.endless.length === 0 ? "" : `\nStill there, with no end: ${result.endless.join(" · ")}. End those the scene ended, with effect end.`;
616
- const ended = `${result.ended.length === 0 ? "" : `\nEnded with the scene: ${result.ended.join(" · ")}.`}${endless}`;
617
- const quests = result.quests.map((line) => `\n${line}`).join("");
618
- if (result.unreadable !== undefined) {
619
- return `The open scene could not be read (${result.unreadable}): closed it, without its copies. ${advance}${ended}${quests}${saved}`;
620
- }
621
- const rounds = result.rounds === undefined ? "" : ` after ${result.rounds} ${result.rounds === 1 ? "round" : "rounds"}`;
622
- const gone = result.copies.length === 0 ? "" : ` Copies gone: ${membersText(result.copies)}.`;
623
- const left = (result.gone ?? []).length === 0
624
- ? ""
625
- : `\nLeft during the scene: ${membersText(result.gone ?? [])}. A copy ends with its scene: if one may come back, give it a page now, with its wounds.`;
626
- const rewards = (result.rewards ?? []).map((line) => `\n${line}`).join("");
627
- const fallen = result.fallen === undefined ? "" : `\n${result.fallen}`;
628
- const peak = result.afterPeak === undefined ? "" : `\n${result.afterPeak}`;
629
- return `Scene closed${rounds}: ${result.title}.${gone} ${advance}${ended}${left}${fallen}${rewards}${quests}${peak}${saved}`;
630
- }
631
- /** "\nEnded: Spaventato on Annegato 2.", or nothing when no effect ended. */
632
- function endedText(ended) {
633
- return ended.length === 0 ? "" : `\nEnded: ${ended.join(" · ")}.`;
634
- }
635
- /** The copies and what they changed go in a hidden line: the player does not see the enemies' numbers, nor the names of creatures in disguise. */
636
- function logCopies(root, context, title, copies) {
637
- if (Object.keys(copies).length > 0) {
638
- appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title, copies }));
639
- }
640
- }
641
- /**
642
- * The result of a change of turn, with the effects on who ends the turn and on who starts the next (EFF-15), read after the effects that the turn ends have
643
- * ended; nothing when the turn stays where it was.
644
- */
645
- function withActing(root, context, before, result) {
646
- if (result.action !== "leave" && result.action !== "order" && result.action !== "next") {
647
- return result;
648
- }
649
- const turns = result.action === "leave" ? result.turns : result;
650
- if (turns === undefined || (turns.turn === before.turn && turns.round === (before.round ?? 1))) {
651
- return result;
652
- }
653
- // A turn that begins gives back what its one used, and every turn what lasts only a turn (TRN-4).
654
- const used = readOpenScene(root).scene?.used;
655
- if (used !== undefined) {
656
- updateScene(root, [[["used"], usesAtTurn(campaignSystem(root, context), used, turns.turn)]]);
657
- }
658
- const world = campaignWorld(root, context);
659
- const system = campaignSystem(root, context);
660
- const scene = readOpenScene(root).scene;
661
- const effects = turnEffectsNote(world, scene, before.turn, turns.turn);
662
- // The player character's turn reminds what to mark of it, which the player sees on the dashboard (TRN-1); a companion's counts went right without (playtest
663
- // 08); dying, the death save it starts with (DIE-5).
664
- const member = findPage(world, turns.turn);
665
- const turn = packagesTurnStarted(root, context, turns.turn);
666
- const dying = turn.lines.join(" ");
667
- // Who cannot act, as one stable but still Unconscious, marks nothing.
668
- const words = campaignSystemWords(root, context);
669
- const inactive = member !== undefined && effectsOf(member).some((effect) => systemNamed(system?.combat?.inactive ?? [], effect.name, words) !== undefined);
670
- const pc = member !== undefined && isPlayerCharacter(member);
671
- const uses = !pc || dying !== "" || inactive ? [] : turnUsesOf(system);
672
- const mark = uses.length > 0 ? `Mark with scene use what ${turns.turn} uses of the turn, as it happens: ${uses.join(", ")}.` : "";
673
- // Notes written between the calls of another's turn reached the player (playtests 06, 08, 09, 11).
674
- const quiet = pc ? "" : "Write nothing until the round is told: what you work out stays in your thinking.";
675
- // What cannot be true together, once in a chat, after the system's code had its say (CHK-3).
676
- const checks = newStateChecks(root, context).join(" ");
677
- // The extensions' lines come after the engine's reminder, which only the system's take the place of (D-514).
678
- const acting = [effects, dying, mark, ...turn.added, offTheMap(world, scene, turns.turn), turn.problem ?? "", checks, quiet].filter((line) => line !== "").join(" ");
679
- return acting === "" ? result : { ...result, acting };
680
- }
681
- /** Who acts and stands on no square of the scene's map, when its place has one (GRD-3, playtest 07): where it stands decides reach, cover and the way. */
682
- function offTheMap(world, scene, name) {
683
- const place = scenePlace(world, scene);
684
- if (place === undefined || placeGrid(place) === undefined || standing(world, place, scene).some((one) => sameName([one.name], name) !== undefined && one.square !== undefined)) {
685
- return "";
686
- }
687
- return `${name} is not on the map of ${place.name}: put it on its square with move ${name} --at, such as E4, before telling its turn.`;
688
- }
689
- /** "Marked hostile: Annegato 1. Hostile now: Annegato 1, Annegato 2." (D-415). */
690
- function markedText(result) {
691
- const now = result.hostile.length === 0 ? "No one is hostile now." : `Hostile now: ${result.hostile.join(", ")}.`;
692
- return `${result.action === "hostile" ? "Marked hostile" : "Calm"}: ${result.marked.join(", ")}. ${now}`;
693
- }
694
- function actingText(acting) {
695
- return acting === undefined ? "" : `\n${acting}`;
696
- }
697
- /** "Round 2 · now Lena (then Annegato 2).", and on the player's character's turn, to stop there (D-139). */
698
- function turnText(result) {
699
- const then = result.order.length > 1 ? nextTurn(result.order, result.turn, 1).turn : undefined;
700
- const now = !result.player ? result.turn : result.several === true ? `${result.turn}, a player character` : `${result.turn}, the player's character`;
701
- // With more than one, a message that already said what this one does goes on (D-480 (5)).
702
- const stop = !result.player ? "." : result.several === true ? `: stop here and hand ${result.turn} the turn, by name, unless the player already said what ${result.turn} does.` : ": stop here and hand them the turn.";
703
- return `Round ${result.round} · now ${now}${then === undefined ? "" : ` (then ${then})`}${stop}`;
704
- }
705
- /** Whether more than one player character is alive, each handed their turn by name (D-480 (5)). */
706
- function severalPlayers(world) {
707
- return playerCharacters(world).filter((page) => page.fields.status !== "dead").length > 1 ? { several: true } : {};
708
- }
709
- /** Whether the turn is the player's character's, which only the player plays; a dead one's is no one's. */
710
- function isPlayerTurn(world, name) {
711
- const page = findPage(world, name);
712
- return page !== undefined && isPlayerCharacter(page) && page.fields.status !== "dead";
713
- }
714
- /** A note on a line of its own, or nothing. */
715
- function lineOf(note) {
716
- return note === undefined ? "" : `\n${note}`;
717
- }
718
- /** "Ennio: hp 12/12; Annegato 1: hp 22/22". */
719
- function membersText(members) {
720
- return members.map((member) => {
721
- const shown = [countersText(member.counters), ...(member.effects ?? [])].filter((part) => part !== "").join(" · ");
722
- return shown === "" ? member.name : `${member.name}: ${shown}`;
723
- }).join("; ");
724
- }
725
- /** A character in the scene, with their effects: the player character and a companion with the counters of their line (DAT-2), anyone else with all of theirs. */
726
- function characterMember(world, page, system) {
727
- const counters = isPartyMember(page) ? partyCounters(world, page, undefined, system) : pageCounters(world, page);
728
- return { name: page.name, counters, effects: effectsOf(page).map((effect) => effectShown(world, effect)) };
729
- }
730
- function copyMembers(world, copies) {
731
- return Object.entries(copies).map(([name, copy]) => ({ name, counters: copyCounters(world, copy) }));
732
- }
733
- /** The names of everyone in the scene: its characters and its copies. */
734
- function memberNames(current) {
735
- return [...current.with.map((link) => parsePageReference(link).name), ...Object.keys(current.copies)];
736
- }
737
- /**
738
- * New copies of the creatures asked for: each holds only the creature it copies, and later what changes (D-110). They are numbered after the copies in the scene,
739
- * skipping the names of pages and of those in the scene, so that a copy written as a character never blocks the next ones.
740
- */
741
- function newCopies(world, creatures, names, existing = {}) {
742
- const copies = {};
743
- const taken = [...names, ...world.pages.map((page) => page.name)];
744
- for (const [creature, count] of creatureCounts(world, creatures)) {
745
- const inScene = Object.values(existing).filter((copy) => comparableText(parsePageReference(copy.creature).name) === comparableText(creature.name)).length;
746
- if (inScene + count > mostCopies) {
747
- throw new Error(`A scene takes at most ${mostCopies} copies of ${creature.name}; it has ${inScene}.`);
748
- }
749
- for (const name of copyNames(creature.name, count, [...taken, ...Object.keys(existing), ...Object.keys(copies)])) {
750
- copies[name] = { creature: `[[${creature.name}]]` };
751
- }
752
- }
753
- return copies;
754
- }
755
- /** The creatures of some copies, each once. */
756
- function copyCreatures(world, copies) {
757
- return [...new Set(Object.values(copies).flatMap((copy) => findPage(world, parsePageReference(copy.creature).name) ?? []))];
758
- }
759
- /**
760
- * What the character sees of those it does not know by name (D-416), by the name of a character in the scene or of a creature with copies in it: Bandito=brigante
761
- * incappucciato on the command line, {"Varro": "il mugnaio"} through MCP; none when not given.
762
- */
763
- function seenOf(world, seen, characters, copies) {
764
- const pairs = Array.isArray(seen)
765
- ? seen.map((entry) => {
766
- const separator = entry.indexOf("=");
767
- return separator === -1 ? [entry, ""] : [entry.slice(0, separator), entry.slice(separator + 1)];
768
- })
769
- : Object.entries(seen ?? {});
770
- if (pairs.length === 0) {
771
- return undefined;
772
- }
773
- const kinds = [...new Set(Object.values(copies).map((copy) => parsePageReference(copy.creature).name))];
774
- const names = [...characters.map((page) => page.name), ...kinds];
775
- return Object.fromEntries(pairs.map(([name, said]) => {
776
- const named = sameName(names, parsePageReference(name.trim()).name);
777
- // A copy's name, as Cultista 1: seen is given by its creature, once for all its copies.
778
- const kind = sameName(kinds, /^(.*\S)\s+\d+$/.exec(name.trim())?.[1] ?? "");
779
- if (named === undefined && kind !== undefined) {
780
- throw new Error(`seen ${name.trim()}: give it by the creature, ${kind}, once for all its copies, such as ${kind}=${said.trim() || "uomo incappucciato"}: they are numbered from those words.`);
781
- }
782
- if (named === undefined) {
783
- throw new Error(`seen ${name.trim()}: there is no character or creature of that name in the scene. In it: ${names.length === 0 ? "no one" : names.join(", ")}.`);
784
- }
785
- // The party knows itself: seen is for those the character does not know by name.
786
- if (characters.some((page) => page.name === named && isPartyMember(page))) {
787
- throw new Error(`seen ${named}: ${named} is of the party, whom the character knows by name. Give seen only for those it does not know, such as a stranger or a creature.`);
788
- }
789
- if (said.trim() === "") {
790
- throw new Error(`Give what the character sees of ${named}, in two or three words, such as ${named}=uomo incappucciato.`);
791
- }
792
- return [named, said.trim()];
793
- }));
794
- }
795
- /** Creatures and how many of each, the same creature given twice counted once: Annegato=2 or Annegato on the command line, {"Annegato": 2} through MCP. */
796
- function creatureCounts(world, creatures) {
797
- const pairs = Array.isArray(creatures)
798
- ? creatures.map((entry) => {
799
- const separator = entry.lastIndexOf("=");
800
- return separator === -1 ? [entry, 1] : [entry.slice(0, separator), Number(entry.slice(separator + 1).trim())];
801
- })
802
- : Object.entries(creatures ?? {});
803
- const counts = new Map();
804
- for (const [name, count] of pairs) {
805
- if (name.trim().startsWith("{")) {
806
- throw new Error(`Write creatures as Name=count, such as Annegato=2: an object such as {"Annegato": 2} works only through MCP.`);
807
- }
808
- if (!Number.isInteger(count) || count < 1 || count > mostCopies) {
809
- throw new Error(`Give how many ${name.trim()} enter as a whole number from 1 to ${mostCopies}, such as ${name.trim()}=2.`);
810
- }
811
- const creature = creaturePage(world, parsePageReference(name).name);
812
- counts.set(creature, (counts.get(creature) ?? 0) + count);
813
- }
814
- return [...counts];
815
- }
816
- function creaturePage(world, name) {
817
- const page = findPage(world, name);
818
- if (page?.type === "creature") {
819
- return page;
820
- }
821
- const creatures = world.pages.filter((candidate) => candidate.type === "creature").map((candidate) => candidate.name);
822
- const more = creatures.length > 10 ? `, and ${creatures.length - 10} more: find --type creature` : "";
823
- const system = systemPagesHint(world, "creature");
824
- const none = system === "" ? "There are no creature pages yet: create one with write, type creature." : "The campaign has no creature pages yet.";
825
- const known = `${creatures.length === 0 ? none : `The campaign's creatures are: ${creatures.slice(0, 10).join(", ")}${more}.`}${system}${missingSystemHint(world)}`;
826
- throw new Error(page === undefined ? `There is no creature named ${name}. ${known}` : `${page.name} is ${withArticle(page.type ?? "free page")}, not a creature: characters enter with with. ${known}`);
827
- }
828
- function characterPage(world, name) {
829
- const reference = parsePageReference(name).name;
830
- // A renamed page answers to its old name too, among its aliases (D-417).
831
- const page = pageNamed(world, reference);
832
- if (page === undefined) {
833
- throw new Error(`There is no page named ${reference}. Create the character with write first, or bring in a creature with creatures.`);
834
- }
835
- if (page.type !== "character") {
836
- const how = page.type === "creature" ? `creatures enter as copies, with creatures, such as ${page.name}=1` : "only characters and creatures take part in a scene";
837
- throw new Error(`${page.name} is ${withArticle(page.type ?? "free page")}, not a character: ${how}.`);
838
- }
839
- if (page.fields.status === "dead") {
840
- throw new Error(`${page.name} is dead (status dead): set their status first, if they rise.`);
841
- }
842
- return page;
843
- }
844
- function placePage(world, name) {
845
- const reference = parsePageReference(name).name;
846
- // A renamed page answers to its old name too, among its aliases (D-417).
847
- const page = pageNamed(world, reference);
848
- if (page?.type !== "place") {
849
- throw new Error(page === undefined ? `There is no place named ${reference}. Create it with write, type place, or leave place out.` : `${page.name} is ${withArticle(page.type ?? "free page")}, not a place.`);
850
- }
851
- return page;
852
- }
853
- /** A scene opens only in play: the game starts once the checklists of setup and session zero are complete (D-221, MOD-6). */
854
- function checkInPlay(root, context, world) {
855
- const mode = campaignMode(root, world);
856
- if (mode !== "play") {
857
- throw new Error(`The game has not started: the campaign is in ${mode}, and scenes open in play. ${checklistLine(mode, root, context, world) ?? ""}`.trim());
858
- }
859
- }
860
- /**
861
- * Where a scene opens without a place (SCN-2): where the player characters are; while they are apart (VIEW-12), where those it is with are, when they are
862
- * together; else refused, with where each is.
863
- */
864
- function defaultPlace(world, movers, named) {
865
- if (named !== undefined && playersApart(world, movers) !== undefined) {
866
- const places = [...new Set(named.map((page) => nearestPlace(world, page)))];
867
- if (places.length > 1) {
868
- throw new Error(`${named.map((page) => `${page.name}, in ${nearestPlace(world, page)?.name ?? "the open"}`).join("; ")}: a scene is in one place. Give place to bring the others there now, `
869
- + "if they can be there at once; if the way takes time, travel first, or open a scene for each group. Nothing changed.");
870
- }
871
- return places[0];
872
- }
873
- const lead = partyLead(world, movers, "Give place, where the scene is, or with, who is in it.");
874
- return lead === undefined ? undefined : nearestPlace(world, lead);
875
- }
876
- /** The nearest place of the living player characters when they are all together; undefined when they are apart (VIEW-12), or in the open. */
877
- function togetherPlace(world, movers) {
878
- const lead = playersApart(world, movers) === undefined ? partyLead(world, movers, "") : undefined;
879
- return lead === undefined ? undefined : nearestPlace(world, lead);
880
- }
881
- function nearestPlace(world, page) {
882
- return locate(world, page).chain.find((holder) => holder.type === "place");
883
- }
884
- /**
885
- * Who of the party enters a scene when with is left out (CON-6): the living members in its place, and those where the player characters are, when they are
886
- * together (VIEW-12); all of them when there is no place.
887
- */
888
- function enteringParty(world, movers, place) {
889
- const lead = togetherPlace(world, movers);
890
- return world.pages.filter((page) => isInParty(page) && (place === undefined || locate(world, page).chain.includes(place) || (lead !== undefined && nearestPlace(world, page) === lead)));
891
- }
892
- function withoutUndefined(current) {
893
- return Object.fromEntries(Object.entries(current).filter(([, value]) => value !== undefined));
894
- }