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.
- package/dist/campaign/index.d.ts +1 -1
- package/dist/campaign/index.js +1 -1
- package/dist/campaign/last-choices.js +1 -1
- package/dist/campaign/settings.d.ts +25 -5
- package/dist/campaign/settings.js +38 -9
- package/dist/cli/cli.js +1 -1
- package/dist/cli/command-line.js +1 -1
- package/dist/commands/advance.d.ts +1 -1
- package/dist/commands/advance.js +6 -6
- package/dist/commands/ask.js +7 -7
- package/dist/commands/change/amounts.d.ts +32 -0
- package/dist/commands/change/amounts.js +150 -0
- package/dist/commands/change/change.d.ts +4 -54
- package/dist/commands/change/change.js +19 -749
- package/dist/commands/change/damage.d.ts +30 -0
- package/dist/commands/change/damage.js +73 -2
- package/dist/commands/change/dice.d.ts +34 -0
- package/dist/commands/change/dice.js +59 -0
- package/dist/commands/change/fields.d.ts +37 -0
- package/dist/commands/change/fields.js +156 -0
- package/dist/commands/change/holder.d.ts +48 -0
- package/dist/commands/change/holder.js +162 -0
- package/dist/commands/change/recipe-pace.js +1 -1
- package/dist/commands/change/recipe.d.ts +58 -0
- package/dist/commands/change/recipe.js +179 -0
- package/dist/commands/choices.js +3 -3
- package/dist/commands/config/config.d.ts +15 -0
- package/dist/commands/config/config.js +355 -0
- package/dist/commands/config/custom-levels.d.ts +7 -0
- package/dist/commands/config/custom-levels.js +32 -0
- package/dist/commands/{config.d.ts → config/dashboard.d.ts} +4 -26
- package/dist/commands/config/dashboard.js +171 -0
- package/dist/commands/config/entries.d.ts +17 -0
- package/dist/commands/config/entries.js +76 -0
- package/dist/commands/config/news.d.ts +7 -0
- package/dist/commands/config/news.js +88 -0
- package/dist/commands/config/shown.d.ts +9 -0
- package/dist/commands/config/shown.js +80 -0
- package/dist/commands/config/words.d.ts +27 -0
- package/dist/commands/config/words.js +204 -0
- package/dist/commands/effect.js +9 -9
- package/dist/commands/find.d.ts +4 -4
- package/dist/commands/find.js +1 -1
- package/dist/commands/image.js +6 -6
- package/dist/commands/import/import.d.ts +0 -2
- package/dist/commands/import/import.js +45 -44
- package/dist/commands/import/run.js +1 -1
- package/dist/commands/index.js +3 -3
- package/dist/commands/init.js +2 -2
- package/dist/commands/install.js +1 -1
- package/dist/commands/instructions.js +17 -6
- package/dist/commands/mode.d.ts +2 -2
- package/dist/commands/mode.js +17 -9
- package/dist/commands/mood.js +4 -4
- package/dist/commands/move.js +10 -10
- package/dist/commands/package/consent.d.ts +11 -0
- package/dist/commands/package/consent.js +52 -0
- package/dist/commands/package/here.d.ts +51 -0
- package/dist/commands/package/here.js +128 -0
- package/dist/commands/package/install.d.ts +10 -0
- package/dist/commands/package/install.js +337 -0
- package/dist/commands/package/package.d.ts +18 -0
- package/dist/commands/package/package.js +236 -0
- package/dist/commands/package/result.d.ts +90 -0
- package/dist/commands/package/result.js +1 -0
- package/dist/commands/package/uninstall.d.ts +6 -0
- package/dist/commands/package/uninstall.js +70 -0
- package/dist/commands/rename.js +3 -3
- package/dist/commands/reveal.js +5 -5
- package/dist/commands/roll/roll.js +11 -9
- package/dist/commands/roll/tables.js +1 -1
- package/dist/commands/rules.d.ts +2 -2
- package/dist/commands/rules.js +3 -3
- package/dist/commands/save.d.ts +1 -1
- package/dist/commands/save.js +2 -2
- package/dist/commands/scene/close.d.ts +18 -0
- package/dist/commands/scene/close.js +179 -0
- package/dist/commands/scene/members.d.ts +14 -0
- package/dist/commands/scene/members.js +32 -0
- package/dist/commands/scene/open.d.ts +6 -0
- package/dist/commands/scene/open.js +298 -0
- package/dist/commands/scene/result.d.ts +98 -0
- package/dist/commands/scene/result.js +2 -0
- package/dist/commands/{scene.d.ts → scene/scene.d.ts} +10 -36
- package/dist/commands/scene/scene.js +210 -0
- package/dist/commands/scene/turns.d.ts +18 -0
- package/dist/commands/scene/turns.js +229 -0
- package/dist/commands/shared/{adventures.d.ts → books/adventures.d.ts} +5 -3
- package/dist/commands/shared/{adventures.js → books/adventures.js} +23 -19
- package/dist/commands/shared/{library-reader.js → books/library-reader.js} +3 -3
- package/dist/commands/shared/{library.d.ts → books/library.d.ts} +2 -2
- package/dist/commands/shared/{library.js → books/library.js} +9 -9
- package/dist/commands/shared/{rules.d.ts → books/rules.d.ts} +2 -2
- package/dist/commands/shared/{rules.js → books/rules.js} +5 -5
- package/dist/commands/shared/{system-texts.d.ts → books/system-texts.d.ts} +2 -2
- package/dist/commands/shared/{system-texts.js → books/system-texts.js} +9 -8
- package/dist/commands/shared/{page-words.d.ts → books/words.d.ts} +2 -2
- package/dist/commands/shared/{page-words.js → books/words.js} +4 -4
- package/dist/commands/shared/{checks.d.ts → campaign/checks.d.ts} +3 -3
- package/dist/commands/shared/{checks.js → campaign/checks.js} +7 -7
- package/dist/commands/shared/{images.d.ts → campaign/images.d.ts} +3 -3
- package/dist/commands/shared/{images.js → campaign/images.js} +5 -5
- package/dist/commands/shared/{mode.d.ts → campaign/mode.d.ts} +4 -4
- package/dist/commands/shared/{mode.js → campaign/mode.js} +28 -13
- package/dist/commands/shared/{money.d.ts → campaign/money.d.ts} +3 -3
- package/dist/commands/shared/{money.js → campaign/money.js} +2 -2
- package/dist/commands/shared/{offers.d.ts → campaign/offers.d.ts} +3 -3
- package/dist/commands/shared/{offers.js → campaign/offers.js} +3 -3
- package/dist/commands/shared/{outside.d.ts → campaign/outside.d.ts} +3 -3
- package/dist/commands/shared/{outside.js → campaign/outside.js} +7 -7
- package/dist/commands/shared/{parts.d.ts → campaign/parts.d.ts} +10 -3
- package/dist/commands/shared/{parts.js → campaign/parts.js} +26 -3
- package/dist/commands/shared/{problems.d.ts → campaign/problems.d.ts} +3 -3
- package/dist/commands/shared/{problems.js → campaign/problems.js} +17 -17
- package/dist/commands/shared/{quests.d.ts → campaign/quests.d.ts} +4 -4
- package/dist/commands/shared/{quests.js → campaign/quests.js} +6 -6
- package/dist/commands/shared/{saves.d.ts → campaign/saves.d.ts} +4 -4
- package/dist/commands/shared/{saves.js → campaign/saves.js} +10 -10
- package/dist/commands/shared/{theme.d.ts → campaign/theme.d.ts} +3 -3
- package/dist/commands/shared/{theme.js → campaign/theme.js} +1 -1
- package/dist/commands/shared/{world.d.ts → campaign/world.d.ts} +5 -5
- package/dist/commands/shared/{world.js → campaign/world.js} +17 -14
- package/dist/commands/shared/{knowledge.d.ts → characters/knowledge.d.ts} +3 -3
- package/dist/commands/shared/{knowledge.js → characters/knowledge.js} +4 -4
- package/dist/commands/shared/{moods.d.ts → characters/moods.d.ts} +3 -3
- package/dist/commands/shared/{moods.js → characters/moods.js} +3 -3
- package/dist/commands/shared/characters/orders.d.ts +4 -0
- package/dist/commands/shared/characters/orders.js +10 -0
- package/dist/commands/shared/{thoughts.d.ts → characters/thoughts.d.ts} +2 -2
- package/dist/commands/shared/{thoughts.js → characters/thoughts.js} +3 -3
- package/dist/commands/shared/{voices.d.ts → characters/voices.d.ts} +1 -1
- package/dist/commands/shared/{voices.js → characters/voices.js} +2 -2
- package/dist/commands/shared/examples.js +2 -2
- package/dist/commands/shared/packages/catalog.js +2 -2
- package/dist/commands/shared/packages/code.d.ts +1 -1
- package/dist/commands/shared/packages/code.js +8 -8
- package/dist/commands/shared/packages/extensions.d.ts +1 -1
- package/dist/commands/shared/packages/extensions.js +1 -1
- package/dist/commands/shared/packages/hooks.d.ts +1 -1
- package/dist/commands/shared/packages/hooks.js +1 -1
- package/dist/commands/shared/packages/widgets.d.ts +3 -3
- package/dist/commands/shared/packages/widgets.js +3 -3
- package/dist/commands/shared/{environment.d.ts → places/environment.d.ts} +1 -1
- package/dist/commands/shared/{environment.js → places/environment.js} +4 -4
- package/dist/commands/shared/{grid-moves.d.ts → places/grid-moves.d.ts} +4 -4
- package/dist/commands/shared/{grid-moves.js → places/grid-moves.js} +8 -7
- package/dist/commands/shared/{grids.d.ts → places/grids.d.ts} +4 -4
- package/dist/commands/shared/{grids.js → places/grids.js} +6 -6
- package/dist/commands/shared/{journey.d.ts → places/journey.d.ts} +3 -3
- package/dist/commands/shared/{journey.js → places/journey.js} +6 -6
- package/dist/commands/shared/{moves.d.ts → places/moves.d.ts} +2 -2
- package/dist/commands/shared/{moves.js → places/moves.js} +4 -4
- package/dist/commands/shared/{positions.d.ts → places/positions.d.ts} +2 -2
- package/dist/commands/shared/{positions.js → places/positions.js} +4 -4
- package/dist/commands/shared/{roads.d.ts → places/roads.d.ts} +5 -5
- package/dist/commands/shared/{roads.js → places/roads.js} +6 -6
- package/dist/commands/shared/{effects.d.ts → scene/effects.d.ts} +7 -7
- package/dist/commands/shared/{effects.js → scene/effects.js} +10 -10
- package/dist/commands/shared/{loot.d.ts → scene/loot.d.ts} +2 -2
- package/dist/commands/shared/{loot.js → scene/loot.js} +3 -3
- package/dist/commands/shared/{master-rolls.d.ts → scene/master-rolls.d.ts} +2 -2
- package/dist/commands/shared/{master-rolls.js → scene/master-rolls.js} +5 -5
- package/dist/commands/shared/{reminders.d.ts → scene/reminders.d.ts} +4 -4
- package/dist/commands/shared/{reminders.js → scene/reminders.js} +4 -4
- package/dist/commands/shared/{scene.d.ts → scene/scene.d.ts} +3 -3
- package/dist/commands/shared/{scene.js → scene/scene.js} +7 -7
- package/dist/commands/shared/{bonds.d.ts → sheet/bonds.d.ts} +3 -3
- package/dist/commands/shared/{bonds.js → sheet/bonds.js} +2 -2
- package/dist/commands/shared/{page-counters.d.ts → sheet/counters.d.ts} +3 -3
- package/dist/commands/shared/{page-counters.js → sheet/counters.js} +5 -5
- package/dist/commands/shared/{effect-layer.d.ts → sheet/effect-layer.d.ts} +2 -2
- package/dist/commands/shared/{effect-layer.js → sheet/effect-layer.js} +9 -6
- package/dist/commands/shared/sheet/effect-values.d.ts +9 -0
- package/dist/commands/shared/sheet/effect-values.js +69 -0
- package/dist/commands/shared/{experience.d.ts → sheet/experience.d.ts} +3 -3
- package/dist/commands/shared/{experience.js → sheet/experience.js} +5 -5
- package/dist/commands/shared/sheet/formula-problems.d.ts +8 -0
- package/dist/commands/shared/sheet/formula-problems.js +140 -0
- package/dist/commands/shared/sheet/formula-scope.d.ts +32 -0
- package/dist/commands/shared/sheet/formula-scope.js +235 -0
- package/dist/commands/shared/{limits.d.ts → sheet/limits.d.ts} +3 -3
- package/dist/commands/shared/{limits.js → sheet/limits.js} +5 -4
- package/dist/commands/shared/{progression.d.ts → sheet/progression.d.ts} +2 -2
- package/dist/commands/shared/{progression.js → sheet/progression.js} +4 -4
- package/dist/commands/shared/{sheet.d.ts → sheet/sheet.d.ts} +5 -5
- package/dist/commands/shared/{sheet.js → sheet/sheet.js} +11 -7
- package/dist/commands/shared/{stacks.d.ts → sheet/stacks.d.ts} +2 -2
- package/dist/commands/shared/{stacks.js → sheet/stacks.js} +4 -4
- package/dist/commands/shared/sheet/system-fields.d.ts +21 -0
- package/dist/commands/shared/sheet/system-fields.js +45 -0
- package/dist/commands/shared/{thresholds.d.ts → sheet/thresholds.d.ts} +1 -1
- package/dist/commands/shared/{thresholds.js → sheet/thresholds.js} +4 -4
- package/dist/commands/shared/{turn-uses.d.ts → sheet/turn-uses.d.ts} +3 -3
- package/dist/commands/shared/{turn-uses.js → sheet/turn-uses.js} +4 -3
- package/dist/commands/shared/{worked-out.d.ts → sheet/worked-out.d.ts} +11 -46
- package/dist/commands/shared/sheet/worked-out.js +291 -0
- package/dist/commands/shared/sheet/worked-text.d.ts +14 -0
- package/dist/commands/shared/sheet/worked-text.js +55 -0
- package/dist/commands/shared/{advance.d.ts → time/advance.d.ts} +3 -3
- package/dist/commands/shared/{advance.js → time/advance.js} +11 -11
- package/dist/commands/shared/{dice-pool.d.ts → time/dice-pool.d.ts} +3 -3
- package/dist/commands/shared/{dice-pool.js → time/dice-pool.js} +11 -11
- package/dist/commands/shared/{events.d.ts → time/events.d.ts} +5 -5
- package/dist/commands/shared/{events.js → time/events.js} +10 -13
- package/dist/commands/shared/{recipes.d.ts → time/recipes.d.ts} +3 -3
- package/dist/commands/shared/{recipes.js → time/recipes.js} +6 -5
- package/dist/commands/shared/{time.d.ts → time/time.d.ts} +4 -4
- package/dist/commands/shared/{time.js → time/time.js} +6 -6
- package/dist/commands/shared/{upkeep.d.ts → time/upkeep.d.ts} +3 -3
- package/dist/commands/shared/{upkeep.js → time/upkeep.js} +14 -13
- package/dist/commands/show.d.ts +4 -1
- package/dist/commands/show.js +28 -9
- package/dist/commands/status.d.ts +2 -1
- package/dist/commands/status.js +34 -23
- package/dist/commands/thoughts.js +3 -3
- package/dist/commands/trade.js +8 -8
- package/dist/commands/translate.d.ts +1 -1
- package/dist/commands/translate.js +3 -3
- package/dist/commands/travel/open.d.ts +1 -1
- package/dist/commands/travel/open.js +2 -2
- package/dist/commands/travel/route.js +7 -6
- package/dist/commands/travel/travel.d.ts +1 -1
- package/dist/commands/travel/travel.js +8 -8
- package/dist/commands/validate.js +3 -3
- package/dist/commands/view/journal.d.ts +2 -2
- package/dist/commands/view/journal.js +2 -2
- package/dist/commands/view/map.d.ts +1 -1
- package/dist/commands/view/map.js +6 -6
- package/dist/commands/view/memory.d.ts +16 -0
- package/dist/commands/view/memory.js +90 -0
- package/dist/commands/view/page.d.ts +32 -0
- package/dist/commands/view/page.js +163 -0
- package/dist/commands/view/place.d.ts +7 -2
- package/dist/commands/view/place.js +30 -12
- package/dist/commands/view/result.d.ts +245 -0
- package/dist/commands/view/result.js +1 -0
- package/dist/commands/view/saves.d.ts +6 -0
- package/dist/commands/view/saves.js +53 -0
- package/dist/commands/view/story.d.ts +32 -0
- package/dist/commands/view/story.js +227 -0
- package/dist/commands/view/view.d.ts +26 -292
- package/dist/commands/view/view.js +26 -534
- package/dist/commands/view/world.d.ts +1 -1
- package/dist/commands/view/world.js +3 -3
- package/dist/commands/write/checks.d.ts +42 -0
- package/dist/commands/write/checks.js +291 -0
- package/dist/commands/write/here.d.ts +1 -1
- package/dist/commands/write/here.js +5 -5
- package/dist/commands/write/inheritance.d.ts +40 -0
- package/dist/commands/write/inheritance.js +189 -0
- package/dist/commands/write/input.d.ts +29 -0
- package/dist/commands/write/input.js +124 -0
- package/dist/commands/write/layer.d.ts +36 -0
- package/dist/commands/write/layer.js +48 -0
- package/dist/commands/write/notes.d.ts +22 -0
- package/dist/commands/write/notes.js +76 -0
- package/dist/commands/write/progression.d.ts +27 -0
- package/dist/commands/write/progression.js +175 -0
- package/dist/commands/write/write.d.ts +2 -1
- package/dist/commands/write/write.js +33 -817
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +7 -0
- package/dist/core/{package-declarations.d.ts → packages/declarations.d.ts} +1 -1
- package/dist/core/{package-declarations.js → packages/declarations.js} +1 -1
- package/dist/core/session-store.js +3 -3
- package/dist/core/store.d.ts +2 -2
- package/dist/core/store.js +18 -4
- package/dist/dashboard/acts/acts.js +1 -1
- package/dist/dashboard/acts/sending.js +110 -0
- package/dist/dashboard/acts/sheet.js +2 -2
- package/dist/dashboard/acts/strip.js +1 -1
- package/dist/dashboard/address.js +6 -0
- package/dist/dashboard/api.js +1 -1
- package/dist/dashboard/app.js +47 -171
- package/dist/dashboard/dice/roller.js +1 -1
- package/dist/dashboard/dice/sets.js +2 -2
- package/dist/dashboard/dice/stage.js +1 -1
- package/dist/dashboard/dice/tray.js +6 -6
- package/dist/dashboard/guide/ar.md +9 -4
- package/dist/dashboard/guide/cs.md +10 -5
- package/dist/dashboard/guide/da.md +9 -4
- package/dist/dashboard/guide/de.md +9 -4
- package/dist/dashboard/guide/el.md +10 -5
- package/dist/dashboard/guide/en.md +7 -2
- package/dist/dashboard/guide/es.md +9 -4
- package/dist/dashboard/guide/fi.md +9 -4
- package/dist/dashboard/guide/fr.md +9 -4
- package/dist/dashboard/guide/he.md +9 -4
- package/dist/dashboard/guide/hi.md +10 -5
- package/dist/dashboard/guide/hu.md +10 -5
- package/dist/dashboard/guide/is.md +9 -4
- package/dist/dashboard/guide/it.md +9 -4
- package/dist/dashboard/guide/ja.md +12 -7
- package/dist/dashboard/guide/ko.md +11 -6
- package/dist/dashboard/guide/nb.md +9 -4
- package/dist/dashboard/guide/nl.md +10 -5
- package/dist/dashboard/guide/pl.md +9 -4
- package/dist/dashboard/guide/pt.md +9 -4
- package/dist/dashboard/guide/ro.md +9 -4
- package/dist/dashboard/guide/ru.md +9 -4
- package/dist/dashboard/guide/sv.md +9 -4
- package/dist/dashboard/guide/tr.md +11 -6
- package/dist/dashboard/guide/uk.md +9 -4
- package/dist/dashboard/guide/zh.md +9 -4
- package/dist/dashboard/help/help.js +3 -3
- package/dist/dashboard/i18n/ar.json +20 -0
- package/dist/dashboard/i18n/cs.json +20 -0
- package/dist/dashboard/i18n/da.json +20 -0
- package/dist/dashboard/i18n/de.json +20 -0
- package/dist/dashboard/i18n/el.json +20 -0
- package/dist/dashboard/i18n/es.json +20 -0
- package/dist/dashboard/i18n/fi.json +20 -0
- package/dist/dashboard/i18n/fr.json +20 -0
- package/dist/dashboard/i18n/he.json +20 -0
- package/dist/dashboard/i18n/hi.json +20 -0
- package/dist/dashboard/i18n/hu.json +20 -0
- package/dist/dashboard/i18n/is.json +20 -0
- package/dist/dashboard/i18n/it.json +20 -0
- package/dist/dashboard/i18n/ja.json +21 -1
- package/dist/dashboard/i18n/ko.json +20 -0
- package/dist/dashboard/i18n/nb.json +20 -0
- package/dist/dashboard/i18n/nl.json +20 -0
- package/dist/dashboard/i18n/pl.json +20 -0
- package/dist/dashboard/i18n/pt.json +20 -0
- package/dist/dashboard/i18n/ro.json +20 -0
- package/dist/dashboard/i18n/ru.json +20 -0
- package/dist/dashboard/i18n/sv.json +20 -0
- package/dist/dashboard/i18n/tr.json +20 -0
- package/dist/dashboard/i18n/uk.json +20 -0
- package/dist/dashboard/i18n/zh.json +20 -0
- package/dist/dashboard/{journal.js → journal/journal.js} +16 -16
- package/dist/dashboard/{notes.js → journal/notes.js} +4 -4
- package/dist/dashboard/kit.js +3 -3
- package/dist/dashboard/packages/ask-card.js +3 -3
- package/dist/dashboard/packages/catalog.js +196 -0
- package/dist/dashboard/packages/engine.js +87 -0
- package/dist/dashboard/packages/installed.js +53 -0
- package/dist/dashboard/packages/library.js +97 -0
- package/dist/dashboard/packages/outcomes.js +45 -0
- package/dist/dashboard/packages/packages.js +20 -576
- package/dist/dashboard/packages/page-code.js +15 -2
- package/dist/dashboard/packages/{package-page.js → page.js} +12 -5
- package/dist/dashboard/packages/rows.js +84 -0
- package/dist/dashboard/packages/share.js +44 -0
- package/dist/dashboard/packages/widgets.js +3 -3
- package/dist/dashboard/{card.js → parts/card.js} +1 -1
- package/dist/dashboard/{faces.js → parts/faces.js} +5 -5
- package/dist/dashboard/{game-words.js → parts/game-words.js} +1 -1
- package/dist/dashboard/{icons.js → parts/icons.js} +1 -1
- package/dist/dashboard/{labels.js → parts/labels.js} +8 -1
- package/dist/dashboard/{map-symbols.js → parts/map-symbols.js} +1 -1
- package/dist/dashboard/{markdown.js → parts/markdown.js} +2 -2
- package/dist/dashboard/{mood.js → parts/mood.js} +1 -1
- package/dist/dashboard/{refusals.js → parts/refusals.js} +1 -1
- package/dist/dashboard/{status.js → parts/status.js} +4 -4
- package/dist/dashboard/{widgets.js → parts/widgets.js} +2 -2
- package/dist/dashboard/place/key.js +24 -0
- package/dist/dashboard/place/paper.js +67 -0
- package/dist/dashboard/place/{map-sheet.js → sheet.js} +2 -2
- package/dist/dashboard/place/things.js +129 -0
- package/dist/dashboard/place/tokens.js +93 -0
- package/dist/dashboard/place/view.js +124 -0
- package/dist/dashboard/{asked-dice.js → play/asked-dice.js} +3 -3
- package/dist/dashboard/{asked.js → play/asked.js} +10 -10
- package/dist/dashboard/{choices.js → play/choices.js} +9 -9
- package/dist/dashboard/{requested.js → play/requested.js} +1 -1
- package/dist/dashboard/{rolls.js → play/rolls.js} +9 -9
- package/dist/dashboard/{scene.js → play/scene.js} +14 -14
- package/dist/dashboard/{turns.js → play/turns.js} +12 -12
- package/dist/dashboard/{language-choice.js → settings/language-choice.js} +1 -1
- package/dist/dashboard/{languages.js → settings/languages.js} +1 -1
- package/dist/dashboard/{saves.js → settings/saves.js} +8 -8
- package/dist/dashboard/{settings.js → settings/settings.js} +17 -15
- package/dist/dashboard/{setup.js → settings/setup.js} +6 -6
- package/dist/dashboard/{party.js → sheet/party.js} +8 -8
- package/dist/dashboard/{person-panel.js → sheet/person-panel.js} +4 -4
- package/dist/dashboard/{sheet.js → sheet/sheet.js} +17 -17
- package/dist/dashboard/{story.js → sheet/story.js} +3 -3
- package/dist/dashboard/{columns.js → shell/columns.js} +1 -1
- package/dist/dashboard/{footer.js → shell/footer.js} +3 -3
- package/dist/dashboard/{master.js → shell/master.js} +2 -2
- package/dist/dashboard/{notices.js → shell/notices.js} +3 -3
- package/dist/dashboard/{pages.js → shell/pages.js} +5 -5
- package/dist/dashboard/shell/shown.js +37 -0
- package/dist/dashboard/{table.js → shell/table.js} +2 -2
- package/dist/dashboard/{tabs.js → shell/tabs.js} +2 -2
- package/dist/dashboard/{top.js → shell/top.js} +7 -7
- package/dist/dashboard/style.css +90 -9
- package/dist/dashboard/world/calendar.js +4 -4
- package/dist/dashboard/world/drawing.js +92 -0
- package/dist/dashboard/world/key.js +21 -0
- package/dist/dashboard/world/lore.js +5 -5
- package/dist/dashboard/world/map-card.js +186 -0
- package/dist/dashboard/world/place-card.js +39 -0
- package/dist/dashboard/world/places.js +29 -0
- package/dist/dashboard/world/world.js +9 -341
- package/dist/extensions/extension.d.ts +1 -1
- package/dist/extensions/extension.js +1 -1
- package/dist/images/images.js +12 -9
- package/dist/index.d.ts +1 -1
- package/dist/languages/index.d.ts +1 -1
- package/dist/languages/index.js +1 -1
- package/dist/library/books.js +2 -0
- package/dist/packages/npm.js +1 -1
- package/dist/page.d.ts +2 -2
- package/dist/page.js +1 -1
- package/dist/pages/check.js +23 -1
- package/dist/pages/containers.d.ts +1 -1
- package/dist/pages/containers.js +1 -1
- package/dist/pages/index.d.ts +4 -2
- package/dist/pages/index.js +4 -2
- package/dist/pages/inheritance.d.ts +2 -2
- package/dist/pages/layers.d.ts +50 -0
- package/dist/pages/layers.js +97 -0
- package/dist/pages/rename-page.js +1 -1
- package/dist/pages/stacks/writes.js +48 -22
- package/dist/pages/standard-fields.d.ts +1 -1
- package/dist/pages/system-pages.d.ts +5 -3
- package/dist/pages/system-pages.js +16 -7
- package/dist/pages/world.d.ts +8 -1
- package/dist/pages/world.js +16 -4
- package/dist/pages/write-layer.d.ts +18 -0
- package/dist/pages/write-layer.js +108 -0
- package/dist/pages/write-page.d.ts +2 -2
- package/dist/pages/write-page.js +2 -2
- package/dist/rules/index.d.ts +1 -1
- package/dist/rules/index.js +1 -1
- package/dist/rules/search.d.ts +1 -1
- package/dist/rules/shown.d.ts +1 -1
- package/dist/server/dashboard/choices.js +3 -3
- package/dist/server/dashboard/files.js +5 -5
- package/dist/server/dashboard/index.d.ts +2 -2
- package/dist/server/dashboard/index.js +2 -2
- package/dist/server/dashboard/news.js +4 -3
- package/dist/server/dashboard/player.js +1 -1
- package/dist/server/dashboard/writes.js +10 -8
- package/dist/server/mcp.js +28 -13
- package/dist/systems/campaign-data.d.ts +15 -0
- package/dist/systems/campaign-data.js +85 -0
- package/dist/systems/{system-code.d.ts → code.d.ts} +1 -1
- package/dist/systems/{system-code.js → code.js} +2 -2
- package/dist/systems/game-system.d.ts +7 -61
- package/dist/systems/game-system.js +1 -984
- package/dist/systems/index.d.ts +6 -3
- package/dist/systems/index.js +6 -3
- package/dist/systems/installed.d.ts +31 -0
- package/dist/systems/installed.js +89 -0
- package/dist/systems/maps.d.ts +3 -0
- package/dist/systems/maps.js +9 -0
- package/dist/systems/read.d.ts +3 -0
- package/dist/systems/read.js +471 -0
- package/dist/systems/schema.d.ts +289 -0
- package/dist/systems/schema.js +243 -0
- package/dist/systems/settings.d.ts +19 -0
- package/dist/systems/settings.js +78 -0
- package/dist/systems/versions.d.ts +12 -0
- package/dist/systems/versions.js +52 -0
- package/dist/testing/index.js +1 -1
- package/instructions/import.md +1 -1
- package/instructions/length-a-few-sessions.md +1 -0
- package/instructions/length-one-evening.md +1 -0
- package/instructions/play.md +1 -1
- package/instructions/session-zero.md +1 -1
- package/instructions/setup.md +1 -1
- package/package.json +1 -1
- package/dist/commands/config.js +0 -917
- package/dist/commands/package.d.ts +0 -143
- package/dist/commands/package.js +0 -785
- package/dist/commands/scene.js +0 -894
- package/dist/commands/shared/worked-out.js +0 -805
- package/dist/dashboard/place/map-view.js +0 -417
- /package/dist/commands/shared/{library-reader.d.ts → books/library-reader.d.ts} +0 -0
- /package/dist/core/{package-api.d.ts → packages/api.d.ts} +0 -0
- /package/dist/core/{package-api.js → packages/api.js} +0 -0
- /package/dist/dashboard/{coins.js → parts/coins.js} +0 -0
- /package/dist/dashboard/{glass.js → parts/glass.js} +0 -0
- /package/dist/dashboard/{layout.js → parts/layout.js} +0 -0
- /package/dist/dashboard/{mood-faces.js → parts/mood-faces.js} +0 -0
- /package/dist/dashboard/{free-rolls.js → play/free-rolls.js} +0 -0
- /package/dist/dashboard/{reactions.js → play/reactions.js} +0 -0
- /package/dist/dashboard/{prefs.js → shell/prefs.js} +0 -0
- /package/dist/dashboard/{system-style.js → shell/system-style.js} +0 -0
- /package/dist/dashboard/{theme.js → shell/theme.js} +0 -0
- /package/dist/languages/{language-pack.d.ts → pack.d.ts} +0 -0
- /package/dist/languages/{language-pack.js → pack.js} +0 -0
- /package/dist/pages/{page-file.d.ts → file.d.ts} +0 -0
- /package/dist/pages/{page-file.js → file.js} +0 -0
- /package/dist/pages/{page-types.d.ts → types.d.ts} +0 -0
- /package/dist/pages/{page-types.js → types.js} +0 -0
- /package/dist/rules/{rule-book.d.ts → book.d.ts} +0 -0
- /package/dist/rules/{rule-book.js → book.js} +0 -0
- /package/dist/systems/{system-folders.d.ts → folders.d.ts} +0 -0
- /package/dist/systems/{system-folders.js → folders.js} +0 -0
|
@@ -1,805 +0,0 @@
|
|
|
1
|
-
// What the game system works out from the fields of a page (D-199, FOR-3–FOR-8): its computed fields, each with the values it came from, and the limits of
|
|
2
|
-
// its counters. The formulas are the system's data; this is where they meet the pages and the counters.
|
|
3
|
-
import { chosenDice, contributingReads, diceFields, factorOf, fieldsRead, listItems, numberOf, parseRollFormula, tablesRead, workOut, } from "../../core/formula.js";
|
|
4
|
-
import { comparableText, sameName } from "../../core/text.js";
|
|
5
|
-
import { formatCounter, readCounter } from "../../counters/index.js";
|
|
6
|
-
import { readEffects } from "../../effects/index.js";
|
|
7
|
-
import { bonusPages, carriedWeight, declaredKind, inheritedFields, isEmptyField, pagesWithName, readFieldValue, systemPageNamed, weightUnit } from "../../pages/index.js";
|
|
8
|
-
import { formatDuration } from "../../time/index.js";
|
|
9
|
-
import { progressionOf, progressionProblems, progressionValue } from "./progression.js";
|
|
10
|
-
/**
|
|
11
|
-
* The computed fields of the game system that have a value with these fields (FOR-4), in the order the system gives them; `explained`, each with only the
|
|
12
|
-
* values that changed it (FOR-8).
|
|
13
|
-
*/
|
|
14
|
-
export function workedFields(world, fields, explained = false) {
|
|
15
|
-
const scope = formulaScope(world, fields);
|
|
16
|
-
const computed = (world.system?.formulas?.computed ?? []).flatMap(([field, formula]) => {
|
|
17
|
-
const worked = scope.computed(field);
|
|
18
|
-
return worked?.value === undefined ? [] : [{ field, value: worked.value, reads: explained ? contributingReads(formula, scope, worked) : worked.reads }];
|
|
19
|
-
});
|
|
20
|
-
return [...computed, ...givenFields(world, scope, explained)];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The fields with what the game system works out over them: each computed field that has a value takes it, over what the page writes (FOR-4); a counter
|
|
24
|
-
* takes the maximum the system works out, and a current above it reads as the maximum (FOR-6). With `sheeted`, the uses it does not write read full (DAT-9).
|
|
25
|
-
*/
|
|
26
|
-
export function withWorkedOut(world, fields, sheeted) {
|
|
27
|
-
const formulas = world.system?.formulas;
|
|
28
|
-
if (formulas === undefined) {
|
|
29
|
-
return fields;
|
|
30
|
-
}
|
|
31
|
-
const result = { ...fields };
|
|
32
|
-
const scope = formulaScope(world, fields);
|
|
33
|
-
const progression = scope.progression();
|
|
34
|
-
// What the classes give, then what the formulas work out over it (PRO-2, FOR-3); a column named as a counter is that counter's maximum (DAT-9).
|
|
35
|
-
for (const worked of givenFields(world, scope)) {
|
|
36
|
-
result[keyOf(result, worked.field) ?? worked.field] = progressionValue(progression, worked.field) ?? worked.value;
|
|
37
|
-
}
|
|
38
|
-
for (const [field] of formulas.computed) {
|
|
39
|
-
const worked = scope.computed(field);
|
|
40
|
-
if (worked?.value !== undefined) {
|
|
41
|
-
result[keyOf(result, field) ?? field] = worked.value;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
for (const field of Object.keys(formulas.counters)) {
|
|
45
|
-
const key = keyOf(result, field);
|
|
46
|
-
const counter = key === undefined ? undefined : readCounter(result[key]);
|
|
47
|
-
const { max } = limitsIn(scope, formulas.counters[field], field);
|
|
48
|
-
if (key !== undefined && counter !== undefined && max !== undefined) {
|
|
49
|
-
result[key] = formatCounter({ value: Math.min(counter.value, max), max });
|
|
50
|
-
}
|
|
51
|
-
// A use the page does not write is full, for who keeps the sheet (DAT-9, D-225).
|
|
52
|
-
if (sheeted && key === undefined && max !== undefined && max > 0 && isUse(world, field)) {
|
|
53
|
-
result[field] = formatCounter({ value: max, max });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Whether a page keeps the sheet of the system (DAT-2, D-225): the player character, and a companion with a level, written or given by its classes, or that
|
|
60
|
-
* derives from no creature. A fighter who derives from her race does, a wolf with its stat block does not; nor does any other page.
|
|
61
|
-
*/
|
|
62
|
-
export function hasSheet(world, page) {
|
|
63
|
-
// A level or classes the page inherits count too, as a companion deriving from a creature with classes.
|
|
64
|
-
return page.type === "character" && keepsSheet(world, page.fields.role === "companion" ? inheritedFields(world, page) : page.fields);
|
|
65
|
-
}
|
|
66
|
-
/** Whether a character with these fields keeps the sheet (DAT-2): the player character, and a companion with a level or classes, or that derives from no creature. */
|
|
67
|
-
export function keepsSheet(world, fields) {
|
|
68
|
-
// The level's field is the game's, as its list is: a game without levels has none (review of 17 October).
|
|
69
|
-
const progression = world.system?.progression;
|
|
70
|
-
const list = progression === undefined ? undefined : keyOf(fields, progression.list);
|
|
71
|
-
const level = progression?.level === undefined ? undefined : (keyOf(fields, progression.level) ?? progression.level);
|
|
72
|
-
const levelled = (level !== undefined && !isEmptyField(fields[level])) || (list !== undefined && !isEmptyField(fields[list]));
|
|
73
|
-
return fields.role === "pc" || (fields.role === "companion" && (isEmptyField(fields.creature) || levelled));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* A page's fields with the values its effects give over them (EFF-3): from the newest effect that gives a field, then the page, then its bases; a bonus field
|
|
77
|
-
* adds up the effects that give it (FOR-5). Before what the system works out, as an item's formulas read it: a weapon under Magic Weapon (PRO-5).
|
|
78
|
-
*/
|
|
79
|
-
export function withEffectValues(world, page) {
|
|
80
|
-
// A world and its pages never change: worked out once in each world, and each caller gets its own copy (D-194).
|
|
81
|
-
let byPage = layeredByWorld.get(world);
|
|
82
|
-
if (byPage === undefined) {
|
|
83
|
-
byPage = new WeakMap();
|
|
84
|
-
layeredByWorld.set(world, byPage);
|
|
85
|
-
}
|
|
86
|
-
const known = byPage.get(page) ?? effectValuesOver(world, page);
|
|
87
|
-
byPage.set(page, known);
|
|
88
|
-
return { ...known };
|
|
89
|
-
}
|
|
90
|
-
const layeredByWorld = new WeakMap();
|
|
91
|
-
// Where a character's fields keep what it carries weighs, for its formulas alone.
|
|
92
|
-
const carriedKey = Symbol("carried weight");
|
|
93
|
-
/** What a character carries weighs, as its effective fields keep it (LOAD-1): worked out once with them; undefined for fields that do not keep it. */
|
|
94
|
-
export function carriedIn(fields) {
|
|
95
|
-
const value = fields[carriedKey];
|
|
96
|
-
return typeof value === "number" ? value : undefined;
|
|
97
|
-
}
|
|
98
|
-
/** Whether a counter of the system comes back with a rest (DAT-9): who keeps the sheet has it full until it spends it. */
|
|
99
|
-
export function isUse(world, field) {
|
|
100
|
-
return (world.system?.uses ?? []).some((name) => name.endsWith("*") ? comparableText(field).startsWith(comparableText(name.slice(0, -1))) : comparableText(name) === comparableText(field));
|
|
101
|
-
}
|
|
102
|
-
/** The uses the system gives a page with these fields that it does not write, each with its maximum (DAT-9): what write puts, full, on who keeps the sheet. */
|
|
103
|
-
export function missingUses(world, fields) {
|
|
104
|
-
return Object.keys(world.system?.formulas?.counters ?? {}).flatMap((field) => {
|
|
105
|
-
const { max } = keyOf(fields, field) === undefined && isUse(world, field) ? counterLimits(world, fields, field) : {};
|
|
106
|
-
return max === undefined || max <= 0 ? [] : [{ field, max }];
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* How much of a counter comes back with these occasions (DAT-9): the sum of what its refill gives for each, where max is the counter's maximum; undefined when
|
|
111
|
-
* it names none of them.
|
|
112
|
-
*/
|
|
113
|
-
export function refillAmount(world, fields, field, occasions, max) {
|
|
114
|
-
const refill = Object.entries(world.system?.formulas?.counters ?? {}).find(([name]) => comparableText(name) === comparableText(field))?.[1].refill;
|
|
115
|
-
const named = Object.entries(refill ?? {}).filter(([occasion]) => occasions.some((other) => comparableText(other) === comparableText(occasion)));
|
|
116
|
-
if (named.length === 0) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
const scope = formulaScope(world, fields);
|
|
120
|
-
const withMax = { ...scope, field: (name) => (comparableText(name) === "max" ? max : scope.field(name)) };
|
|
121
|
-
return named.reduce((total, [, formula]) => total + Math.max(0, Math.floor(workOut(formula, withMax).value ?? 0)), 0);
|
|
122
|
-
}
|
|
123
|
-
/** A formula of the system worked out on these fields, as a recipe's regain is; undefined when it has no value (FOR-4). */
|
|
124
|
-
export function formulaValue(world, fields, formula) {
|
|
125
|
-
return workOut(formula, formulaScope(world, fields)).value;
|
|
126
|
-
}
|
|
127
|
-
/** The list whose items' pages give a field as a formula, as classes for spell-save-dc (PRO-5); undefined when none does. */
|
|
128
|
-
export function itemList(world, field) {
|
|
129
|
-
return Object.entries(world.system?.itemFormulas ?? {}).find(([, names]) => names.some((name) => comparableText(name) === comparableText(field.trim())))?.[0];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Each item of a list with what the formulas of its page give, field by field, in the order of the list, for a sheet that shows them item by item, as the
|
|
133
|
-
* attacks of the weapons a character has equipped (PRO-5).
|
|
134
|
-
*/
|
|
135
|
-
export function itemLines(world, fields, list, names, explained = false) {
|
|
136
|
-
const scope = formulaScope(world, fields);
|
|
137
|
-
const items = listItems(scope.field(list)).map((item) => item.name);
|
|
138
|
-
const byField = names.map((field) => ({ field, values: itemValues(world, scope, field, explained) }));
|
|
139
|
-
return items.flatMap((item) => {
|
|
140
|
-
const values = byField.flatMap(({ field, values }) => values.filter((value) => value.name === item).map((value) => ({ field, value: value.value, reads: value.reads })));
|
|
141
|
-
return values.length === 0 ? [] : [{ item, values }];
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
/** The minimum and maximum the game system works out for a counter with these fields, where they have a whole value (FOR-6). */
|
|
145
|
-
export function counterLimits(world, fields, field) {
|
|
146
|
-
const limits = Object.entries(world.system?.formulas?.counters ?? {}).find(([name]) => comparableText(name) === comparableText(field.trim()))?.[1];
|
|
147
|
-
if (limits === undefined) {
|
|
148
|
-
return {};
|
|
149
|
-
}
|
|
150
|
-
return limitsIn(formulaScope(world, fields), limits, field);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The name, as the game system declares it, of a counter that starts at 0 where a page does not hold it yet, as temporary hit points or experience points:
|
|
154
|
-
* declared a counter, with no maximum and not a use that comes back with a rest (CNT-8, D-266). Undefined for any other.
|
|
155
|
-
*/
|
|
156
|
-
export function startingAtZero(world, field) {
|
|
157
|
-
const declared = Object.keys(world.system?.fields ?? {}).find((name) => comparableText(name) === comparableText(field.trim()));
|
|
158
|
-
const limits = Object.entries(world.system?.formulas?.counters ?? {}).find(([counter]) => comparableText(counter) === comparableText(field.trim()))?.[1];
|
|
159
|
-
return declared !== undefined && declaredKind(world, declared) === "counter" && limits?.max === undefined && limits?.refill === undefined ? declared : undefined;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The game system's computed field with this name, in any case, and the fields it comes from, when its formula has a value with these fields (FOR-7):
|
|
163
|
-
* where it has none, as on a creature without a level, the field is written like any other.
|
|
164
|
-
*/
|
|
165
|
-
export function computedField(world, field, fields) {
|
|
166
|
-
const entry = world.system?.formulas?.computed.find(([name]) => comparableText(name) === comparableText(field.trim()));
|
|
167
|
-
const scope = formulaScope(world, fields);
|
|
168
|
-
const value = entry === undefined ? undefined : scope.computed(entry[0])?.value;
|
|
169
|
-
if (entry === undefined || value === undefined) {
|
|
170
|
-
return progressedField(world, scope, field);
|
|
171
|
-
}
|
|
172
|
-
// Of several formulas, the one that gave the value says what it comes from (D-210).
|
|
173
|
-
const used = entry[1].kind === "first" ? (entry[1].options.find((option) => workOut(option, scope).value !== undefined) ?? entry[1]) : entry[1];
|
|
174
|
-
return { name: entry[0], value, from: writtenSources(world, used, scope), direct: fieldsRead(used) };
|
|
175
|
-
}
|
|
176
|
-
/** The written fields the maximum of a counter comes from with these fields, as hp-base, level and con for hp (FOR-6); none when the system works out no maximum. */
|
|
177
|
-
export function maximumSources(world, field, fields) {
|
|
178
|
-
const max = Object.entries(world.system?.formulas?.counters ?? {}).find(([name]) => comparableText(name) === comparableText(field.trim()))?.[1].max;
|
|
179
|
-
return max === undefined ? [] : writtenSources(world, max, formulaScope(world, fields));
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* How the maximum the game system works out for a counter is made, "38, from hp-base 28, level 11, con-mod +1", and the written field to raise it with, as at a
|
|
183
|
-
* new level (FOR-6, D-226); undefined where the system works out none.
|
|
184
|
-
*/
|
|
185
|
-
export function maximumHint(world, fields, field) {
|
|
186
|
-
const worked = workedMaximum(world, fields, field);
|
|
187
|
-
if (worked === undefined) {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
const parts = workedParts(world, worked.reads);
|
|
191
|
-
// A maximum of 0 says the character lacks what gives it: no field raises it.
|
|
192
|
-
const [raise] = worked.value === 0 ? [] : maximumSources(world, field, fields).filter((name) => declaredKind(world, name) !== "list");
|
|
193
|
-
return { made: `${worked.value}${parts === "" ? "" : `, from ${parts}`}`, ...(raise === undefined ? {} : { raise }) };
|
|
194
|
-
}
|
|
195
|
-
/** Why a computed field is not written or changed, and what to change instead: the fields it comes from, or an effect on a bonus among them (FOR-7). */
|
|
196
|
-
export function computedMessage(world, computed, page) {
|
|
197
|
-
const bonuses = directBonuses(world, computed);
|
|
198
|
-
const instead = bonuses.length === 0 ? "change one of those" : `change one of those, or give ${bonuses.join(" or ")} with an effect${aloneNote(world, computed.name, bonuses)}`;
|
|
199
|
-
return `${computed.name} on ${page} is ${signedText(world, computed.name, computed.value)}, worked out by the system ${world.system?.name ?? ""} from ${computed.from.join(", ")}: ${instead}`;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* "; bonus-skills also changes the other fields that read it…": of these bonuses, those other computed fields read too, as bonus-skills for every skill, which
|
|
203
|
-
* are no bonus to one alone (playtest 14); nothing when none is.
|
|
204
|
-
*/
|
|
205
|
-
export function aloneNote(world, field, bonuses) {
|
|
206
|
-
const readers = (bonus) => (world.system?.formulas?.computed ?? []).filter(([, formula]) => fieldsRead(formula).some((name) => comparableText(name) === comparableText(bonus))).length;
|
|
207
|
-
const shared = bonuses.filter((bonus) => readers(bonus) > 1);
|
|
208
|
-
const one = shared.length === 1;
|
|
209
|
-
return shared.length === 0 ? "" : `; ${shared.join(" and ")} also ${one ? "changes" : "change"} the other fields that read ${one ? "it" : "them"}, so for ${field} alone add the number to its roll`;
|
|
210
|
-
}
|
|
211
|
-
/** The bonus fields an effect gives to change a computed field that its formula reads itself, as bonus-skills for insight, not bonus-proficiency through proficiency. */
|
|
212
|
-
export function directBonuses(world, computed) {
|
|
213
|
-
return effectBonuses(world, computed.from).filter((field) => computed.direct?.some((name) => comparableText(name) === comparableText(field)) === true);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* The first item of its list whose page gives a field, with the fields of its own that its formula reads, as a shield's bonus (PRO-5): a page of the campaign,
|
|
217
|
-
* which an effect can change, not one of the system, as the unarmed strike (D-235).
|
|
218
|
-
*/
|
|
219
|
-
export function itemSource(world, fields, field) {
|
|
220
|
-
const list = itemList(world, field);
|
|
221
|
-
const scope = formulaScope(world, fields);
|
|
222
|
-
for (const item of list === undefined ? [] : listItems(scope.field(list))) {
|
|
223
|
-
const page = scope.page(item.name);
|
|
224
|
-
const given = itemFormula(page, field);
|
|
225
|
-
if (list !== undefined && page !== undefined && given?.formula !== undefined && pagesWithName(world, item.name).length > 0) {
|
|
226
|
-
return { item: item.name, list, own: fieldsRead(given.formula).filter((name) => keyOf(page, name) !== undefined) };
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return undefined;
|
|
230
|
-
}
|
|
231
|
-
/** A value of a field as the outputs show it: with its sign when the system declares the field a modifier or a bonus (FOR-8). */
|
|
232
|
-
export function signedText(world, field, value) {
|
|
233
|
-
const kind = declaredKind(world, field);
|
|
234
|
-
// A length in the system's unit, at most one decimal: 12.5 ft (SPD-1).
|
|
235
|
-
if (typeof value === "number" && kind === "length") {
|
|
236
|
-
return `${Math.round(value * 10) / 10}${world.system?.lengthUnit === undefined ? "" : ` ${world.system.lengthUnit}`}`;
|
|
237
|
-
}
|
|
238
|
-
// A weight in the unit the system's items are weighed in: 420 lb.
|
|
239
|
-
if (typeof value === "number" && kind === "weight") {
|
|
240
|
-
const unit = world.system?.load === undefined ? undefined : weightUnit(world, world.system.load.field);
|
|
241
|
-
return `${Math.round(value * 10) / 10}${unit === undefined ? "" : ` ${unit}`}`;
|
|
242
|
-
}
|
|
243
|
-
// A duration in minutes as the engine writes them, half a minute in seconds: 3m, 30s.
|
|
244
|
-
if (typeof value === "number" && kind === "duration") {
|
|
245
|
-
return value > 0 && value < 1 ? `${Math.round(value * 60)}s` : formatDuration(Math.round(value));
|
|
246
|
-
}
|
|
247
|
-
return typeof value === "number" && (kind === "modifier" || kind === "bonus") && value >= 0 ? `+${value}` : String(value);
|
|
248
|
-
}
|
|
249
|
-
/** "insight +5: wis-mod +3, proficiency +2, Insight in skill-proficiencies": a computed field and what it came from, leaving out what adds nothing (FOR-8). */
|
|
250
|
-
export function workedLine(world, worked) {
|
|
251
|
-
const parts = workedParts(world, worked.reads);
|
|
252
|
-
return `${worked.field} ${signedText(world, worked.field, worked.value)}${parts === "" ? "" : `: ${parts}`}`;
|
|
253
|
-
}
|
|
254
|
-
/** "wis-mod +3, proficiency +2, Insight in skill-proficiencies": the values a result came from, leaving out what adds nothing (FOR-8). */
|
|
255
|
-
export function workedParts(world, reads) {
|
|
256
|
-
const parts = reads.flatMap((read) => {
|
|
257
|
-
if ("table" in read) {
|
|
258
|
-
// A key the explanation does not already give, as text: "ranks dangerous: 8".
|
|
259
|
-
const keyed = reads.some((other) => "field" in other && "key" in other && other.key === true);
|
|
260
|
-
return [keyed ? `${read.table} ${read.value}` : `${read.table} ${read.key}: ${read.value}`];
|
|
261
|
-
}
|
|
262
|
-
// The dice a roll took from a field, as a monk's martial-arts 1d6 (D-235).
|
|
263
|
-
if ("dice" in read) {
|
|
264
|
-
return [`${read.field} ${read.dice}`];
|
|
265
|
-
}
|
|
266
|
-
if ("field" in read) {
|
|
267
|
-
// A bonus of 0 and a factor of 1 change nothing (FOR-5).
|
|
268
|
-
const kind = declaredKind(world, read.field);
|
|
269
|
-
return (read.value === 0 && kind === "bonus") || (read.value === 1 && kind === "factor") ? [] : [`${read.field} ${signedText(world, read.field, read.value)}`];
|
|
270
|
-
}
|
|
271
|
-
if ("item" in read) {
|
|
272
|
-
return read.value === 0 ? [] : [read.value === 1 && !/\d/.test(read.item) ? `${read.item} in ${read.list}` : `${read.item} ${read.value} in ${read.list}`];
|
|
273
|
-
}
|
|
274
|
-
// The total of a list says nothing more beside one of its items, "Cleric 3 in classes", nor when it is 0; how many items a list has is no part of a value.
|
|
275
|
-
if (read.count === true || read.value === 0 || reads.some((other) => "item" in other && other.list === read.list && other.value !== 0)) {
|
|
276
|
-
return [];
|
|
277
|
-
}
|
|
278
|
-
return [`${read.value} in ${read.list}${read.where === undefined ? "" : `, ${read.where}`}`];
|
|
279
|
-
});
|
|
280
|
-
// "Perception in skills" says nothing more beside "Perception 3 in skills".
|
|
281
|
-
const named = (part) => parts.some((other) => other !== part && other.startsWith(part.replace(/ in [^ ]+$/, " ")) && other.endsWith(part.slice(part.lastIndexOf(" in "))));
|
|
282
|
-
return parts.filter((part, index) => parts.indexOf(part) === index && !named(part)).join(", ");
|
|
283
|
-
}
|
|
284
|
-
/** The maximum the game system works out for a counter with these fields, with only the values that changed it (FOR-6, FOR-8); undefined where it has none. */
|
|
285
|
-
export function workedMaximum(world, fields, field) {
|
|
286
|
-
const entry = Object.entries(world.system?.formulas?.counters ?? {}).find(([name]) => comparableText(name) === comparableText(field.trim()));
|
|
287
|
-
const formula = entry?.[1].max;
|
|
288
|
-
const scope = formulaScope(world, fields);
|
|
289
|
-
if (entry === undefined) {
|
|
290
|
-
return undefined;
|
|
291
|
-
}
|
|
292
|
-
// Without a formula, the maximum a class's row gives, from the classes it comes from (DAT-9).
|
|
293
|
-
if (formula === undefined) {
|
|
294
|
-
const row = scope.progression()?.values.find((value) => comparableText(value.field) === comparableText(entry[0]));
|
|
295
|
-
const max = numberOf(row?.value);
|
|
296
|
-
return row === undefined || max === undefined ? undefined : { field: entry[0], value: max, reads: row.from.map((from) => ({ list: scope.progression()?.lists[0] ?? "", item: from.name, value: from.level })) };
|
|
297
|
-
}
|
|
298
|
-
const worked = workOut(formula, scope);
|
|
299
|
-
return worked.value === undefined ? undefined : { field: entry[0], value: atLeastZero(worked.value), reads: contributingReads(formula, scope, worked) };
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* What validate says of the pages of the campaign about what the game system works out (FOR-7): a computed field written on a page, where the system works it
|
|
303
|
-
* out and the page's value is never read; a written maximum that is not the one the system works out from the page without its effects; what the classes of a
|
|
304
|
-
* page cannot give (PRO-1, PRO-4). Found once for each world.
|
|
305
|
-
*/
|
|
306
|
-
export function workedOutProblems(world) {
|
|
307
|
-
const formulas = world.system?.formulas;
|
|
308
|
-
if (formulas === undefined) {
|
|
309
|
-
return [];
|
|
310
|
-
}
|
|
311
|
-
const known = checkedWorlds.get(world);
|
|
312
|
-
if (known !== undefined) {
|
|
313
|
-
return known;
|
|
314
|
-
}
|
|
315
|
-
const computedNames = new Set(formulas.computed.map(([name]) => comparableText(name)));
|
|
316
|
-
const counterNames = new Set(Object.keys(formulas.counters).map(comparableText));
|
|
317
|
-
const lists = new Set([...(world.system?.progression === undefined ? [] : [world.system.progression.list]), ...Object.keys(world.system?.itemFormulas ?? {})].map(comparableText));
|
|
318
|
-
const relevant = (field) => computedNames.has(comparableText(field)) || counterNames.has(comparableText(field)) || lists.has(comparableText(field));
|
|
319
|
-
const problems = world.pages.filter((page) => Object.keys(page.fields).some(relevant)).flatMap((page) => {
|
|
320
|
-
const fields = inheritedFields(world, page);
|
|
321
|
-
const scope = formulaScope(world, fields);
|
|
322
|
-
const progressed = new Set(givenFields(world, scope).map((worked) => comparableText(worked.field)));
|
|
323
|
-
// Only the fields the page writes are worked out: a page holds few of them.
|
|
324
|
-
const written = Object.keys(page.fields).filter((key) => computedNames.has(comparableText(key)) || progressed.has(comparableText(key))).flatMap((key) => {
|
|
325
|
-
const value = scope.computed(key)?.value ?? progressedField(world, scope, key)?.value;
|
|
326
|
-
return value === undefined ? [] : [{
|
|
327
|
-
path: page.path,
|
|
328
|
-
message: `${key} is worked out by the system ${world.system?.name ?? ""} (${signedText(world, key, value)}): the value written on ${page.name} is never read.`,
|
|
329
|
-
fix: `write ${page.name}, unset ${key}`,
|
|
330
|
-
}];
|
|
331
|
-
});
|
|
332
|
-
const limits = Object.keys(page.fields).filter((key) => counterNames.has(comparableText(key))).flatMap((key) => {
|
|
333
|
-
const counter = readCounter(page.fields[key]);
|
|
334
|
-
const { max } = counterLimits(world, fields, key);
|
|
335
|
-
return counter === undefined || max === undefined || counter.max === max ? [] : [{
|
|
336
|
-
path: page.path,
|
|
337
|
-
message: `${key} on ${page.name} has ${counter.max === undefined ? "no maximum" : `the maximum ${counter.max}`} written, but the system ${world.system?.name ?? ""} works out ${max}.`,
|
|
338
|
-
fix: `change ${page.name}, field ${key}, to ${counter.value}/${max}`,
|
|
339
|
-
}];
|
|
340
|
-
});
|
|
341
|
-
return [...written, ...limits, ...progressionProblems(world, page, fields), ...itemFormulaProblems(world, page, fields)];
|
|
342
|
-
});
|
|
343
|
-
checkedWorlds.set(world, problems);
|
|
344
|
-
return problems;
|
|
345
|
-
}
|
|
346
|
-
function effectValuesOver(world, page) {
|
|
347
|
-
const fields = { ...inheritedFields(world, page) };
|
|
348
|
-
const read = readEffects(Object.entries(page.fields).find(([field]) => comparableText(field) === "effects")?.[1]);
|
|
349
|
-
// What the pages of the system's bonus lists give, as a Ring of Protection one is attuned to or a feat, adds up as effects do (FOR-5, D-449); an at-least
|
|
350
|
-
// field rises to theirs, as Gauntlets of Ogre Power's str 19, and stays when higher.
|
|
351
|
-
for (const page of bonusPages(world, fields)) {
|
|
352
|
-
for (const [field, value] of Object.entries(inheritedFields(world, page))) {
|
|
353
|
-
const kind = declaredKind(world, field);
|
|
354
|
-
const amount = kind === "bonus" || kind === "at-least" ? numberOf(value) : undefined;
|
|
355
|
-
const key = keyOf(fields, field) ?? field;
|
|
356
|
-
const current = numberOf(fields[key]);
|
|
357
|
-
fields[key] = amount === undefined ? fields[key] : kind === "bonus" ? (current ?? 0) + amount : Math.max(current ?? amount, amount);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
for (const effect of "effects" in read ? read.effects : []) {
|
|
361
|
-
for (const [field, value] of effect.values) {
|
|
362
|
-
const key = keyOf(fields, field) ?? field;
|
|
363
|
-
const kind = declaredKind(world, field);
|
|
364
|
-
fields[key] = kind === "bonus"
|
|
365
|
-
? (numberOf(fields[key]) ?? 0) + (numberOf(effectValue(value)) ?? 0)
|
|
366
|
-
: kind === "factor"
|
|
367
|
-
? (factorOf(fields[key]) ?? 1) * (factorOf(value) ?? 1)
|
|
368
|
-
: effectValue(value);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
// What a character carries weighs, for the formulas that read it as load, as a speed; under a key no list of fields shows (FOR-2, LOAD-1).
|
|
372
|
-
if (page.type === "character" && world.system?.load !== undefined) {
|
|
373
|
-
fields[carriedKey] = carriedWeight(world, world.system.load, page);
|
|
374
|
-
}
|
|
375
|
-
return fields;
|
|
376
|
-
}
|
|
377
|
-
/** A value of an effect as a page would hold it: a number, a link, a counter as text; text as it is when it does not read. */
|
|
378
|
-
function effectValue(value) {
|
|
379
|
-
try {
|
|
380
|
-
return readFieldValue(value);
|
|
381
|
-
}
|
|
382
|
-
catch {
|
|
383
|
-
return value;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
/** What the lists of a page give as computed fields: what its classes give (PRO-2, PRO-3), then what the formulas of its items' pages work out (PRO-5). */
|
|
387
|
-
function givenFields(world, scope, explained = false) {
|
|
388
|
-
return [...progressionFields(world, scope), ...itemFields(world, scope, explained)];
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* The fields the classes give as computed fields, each with the items it comes from (PRO-2, FOR-8): the values of their rows, then the features. A column named
|
|
392
|
-
* as a counter of the system is not one: it is that counter's maximum (DAT-9).
|
|
393
|
-
*/
|
|
394
|
-
function progressionFields(world, scope) {
|
|
395
|
-
const progression = scope.progression();
|
|
396
|
-
if (progression === undefined) {
|
|
397
|
-
return [];
|
|
398
|
-
}
|
|
399
|
-
const values = progression.values.filter((value) => !isSystemCounter(world, value.field)).map((value) => ({
|
|
400
|
-
field: value.field,
|
|
401
|
-
value: value.value,
|
|
402
|
-
reads: value.from.map((from) => ({ list: progression.lists[0], item: from.name, value: from.level })),
|
|
403
|
-
}));
|
|
404
|
-
const features = progression.features.length + progression.written.length === 0 ? [] : [{
|
|
405
|
-
field: progression.featuresField,
|
|
406
|
-
value: [...progression.features.map((feature) => feature.name), ...progression.written].join(", "),
|
|
407
|
-
reads: progression.from.map((from) => ({ list: from.list, item: from.name, value: from.level ?? 1 })),
|
|
408
|
-
}];
|
|
409
|
-
return [...values, ...features];
|
|
410
|
-
}
|
|
411
|
-
/** The fields the formulas of the items' pages give, one value for each item, for every list the system names (PRO-5). */
|
|
412
|
-
function itemFields(world, scope, explained) {
|
|
413
|
-
return Object.values(world.system?.itemFormulas ?? {}).flat().flatMap((field) => {
|
|
414
|
-
const worked = scope.each(field, explained);
|
|
415
|
-
// A bonus an item gives as nothing, as the speed a heavy armor takes from who has its Strength, says nothing (FOR-8).
|
|
416
|
-
return worked === undefined || (worked.value === 0 && declaredKind(world, field) === "bonus") ? [] : [worked];
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* A formula that each item of its list gives on its page, such as a class's spell-save-dc or a weapon's attack, worked out on who lists them for each item that
|
|
421
|
-
* gives one (PRO-5): a number, or a roll as text, for one; "Cleric 13, Wizard 12" for several. Undefined when none gives it.
|
|
422
|
-
*/
|
|
423
|
-
function eachItem(world, field, items) {
|
|
424
|
-
if (items.length === 0) {
|
|
425
|
-
return undefined;
|
|
426
|
-
}
|
|
427
|
-
const [first] = items;
|
|
428
|
-
return items.length === 1
|
|
429
|
-
? { field, value: first.value, reads: first.reads }
|
|
430
|
-
: { field, value: items.map((item) => `${item.name} ${signedText(world, field, item.value)}`).join(", "), reads: items.flatMap((item) => item.reads) };
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* What a field gives for each item of its list whose page gives it (PRO-5): a number, or a roll as text, as "1d8+3 slashing". The formula reads first the
|
|
434
|
-
* item's own fields, as a magic weapon's bonus, then those of who lists it.
|
|
435
|
-
*/
|
|
436
|
-
function itemValues(world, scope, field, explained) {
|
|
437
|
-
const list = itemList(world, field);
|
|
438
|
-
if (list === undefined) {
|
|
439
|
-
return [];
|
|
440
|
-
}
|
|
441
|
-
return listItems(scope.field(list)).flatMap((item) => {
|
|
442
|
-
const page = scope.page(item.name);
|
|
443
|
-
const given = itemFormula(page, field);
|
|
444
|
-
if (page === undefined || given === undefined) {
|
|
445
|
-
return [];
|
|
446
|
-
}
|
|
447
|
-
const own = itemScope(world, scope, page, list);
|
|
448
|
-
const worked = given.formula === undefined ? undefined : workOut(given.formula, own);
|
|
449
|
-
// The dice it takes, as the Martial Arts die of a monk when it is larger (D-235); none of its choices with a value, no value.
|
|
450
|
-
const dice = given.dice === undefined ? undefined : chosenDice(given.dice, own);
|
|
451
|
-
if ((given.formula !== undefined && worked?.value === undefined) || (given.dice !== undefined && dice === undefined)) {
|
|
452
|
-
return [];
|
|
453
|
-
}
|
|
454
|
-
const reads = worked === undefined || given.formula === undefined ? [] : explained ? contributingReads(given.formula, own, worked) : worked.reads;
|
|
455
|
-
return [{ name: item.name, value: rollValue(given, dice, worked?.value), reads: [...(dice?.reads ?? []), ...reads] }];
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* "1d8+3 slashing": a roll's dice, the number its formula works out, unless 0, and its words; the number alone for a plain formula. Dice that are a number, as an
|
|
460
|
-
* unarmed strike's 1, add to it: "4 bludgeoning" (D-235).
|
|
461
|
-
*/
|
|
462
|
-
function rollValue(given, dice, value) {
|
|
463
|
-
const rolled = dice?.dice;
|
|
464
|
-
const total = dice?.number === undefined ? value : (value ?? 0) + dice.number;
|
|
465
|
-
if (rolled === undefined && given.words === undefined && total !== undefined) {
|
|
466
|
-
return total;
|
|
467
|
-
}
|
|
468
|
-
const number = total === undefined || (total === 0 && rolled !== undefined) ? "" : rolled === undefined ? String(total) : total > 0 ? `+${total}` : String(total);
|
|
469
|
-
return `${rolled ?? ""}${number}${given.words === undefined ? "" : ` ${given.words}`}`;
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* The scope of an item's formula: the item's own fields first, as a magic weapon's bonus, written 1 or +1, then those of who lists it (PRO-5). The formulas
|
|
473
|
-
* the item gives for its list are worked out on who lists it: a monk's Unarmored Defense reads the armor-class-bonus of the shield it has equipped.
|
|
474
|
-
*/
|
|
475
|
-
function itemScope(world, scope, page, list) {
|
|
476
|
-
const given = world.system?.itemFormulas?.[list] ?? [];
|
|
477
|
-
return {
|
|
478
|
-
...scope,
|
|
479
|
-
field: (name) => {
|
|
480
|
-
const key = keyOf(page, name);
|
|
481
|
-
if (key === undefined || isEmptyField(page[key]) || given.some((field) => comparableText(field) === comparableText(name))) {
|
|
482
|
-
return scope.field(name);
|
|
483
|
-
}
|
|
484
|
-
return numberOf(page[key]) ?? page[key];
|
|
485
|
-
},
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
/** The formula an item's page gives in a field, read once for each text; undefined when it gives none, or one that does not read, which validate reports (PRO-5). */
|
|
489
|
-
function itemFormula(fields, field) {
|
|
490
|
-
const text = fields === undefined ? undefined : fields[keyOf(fields, field) ?? ""];
|
|
491
|
-
if (typeof text !== "string" && typeof text !== "number") {
|
|
492
|
-
return undefined;
|
|
493
|
-
}
|
|
494
|
-
const key = String(text);
|
|
495
|
-
if (!itemFormulas.has(key)) {
|
|
496
|
-
try {
|
|
497
|
-
itemFormulas.set(key, parseRollFormula(key));
|
|
498
|
-
}
|
|
499
|
-
catch {
|
|
500
|
-
itemFormulas.set(key, undefined);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return itemFormulas.get(key);
|
|
504
|
-
}
|
|
505
|
-
const itemFormulas = new Map();
|
|
506
|
-
/** A field the classes give, as a computed field that cannot be written, with the lists it comes from (PRO-2, FOR-7); undefined for any other field. */
|
|
507
|
-
function progressedField(world, scope, field) {
|
|
508
|
-
const found = givenFields(world, scope).find((worked) => comparableText(worked.field) === comparableText(field.trim()));
|
|
509
|
-
const list = found === undefined ? undefined : itemList(world, found.field);
|
|
510
|
-
// The features are written too, beside those the rows give (PRO-3).
|
|
511
|
-
if (found === undefined || comparableText(found.field) === comparableText(scope.progression()?.featuresField ?? "")) {
|
|
512
|
-
return undefined;
|
|
513
|
-
}
|
|
514
|
-
// A formula of the items' pages comes from what it reads, as the bonus an item gives, and from its list (PRO-5); the rows, from the lists alone.
|
|
515
|
-
if (list !== undefined) {
|
|
516
|
-
const read = listItems(scope.field(list)).flatMap((item) => {
|
|
517
|
-
const page = scope.page(item.name);
|
|
518
|
-
const given = itemFormula(page, found.field);
|
|
519
|
-
// What the item holds itself, as a weapon's bonus, comes from it, not from who lists it.
|
|
520
|
-
// Only the dice a field gives count, as a monk's martial-arts: one no one has is no source.
|
|
521
|
-
const dice = (given === undefined ? [] : diceFields(given)).filter((name) => scope.field(name) !== undefined).flatMap((name) => writtenSources(world, { kind: "field", name }, scope));
|
|
522
|
-
const formula = given?.formula === undefined ? [] : writtenSources(world, given.formula, scope);
|
|
523
|
-
return [...formula, ...dice].filter((name) => page === undefined || keyOf(page, name) === undefined);
|
|
524
|
-
});
|
|
525
|
-
return { name: found.field, value: found.value, from: [...new Set([...read, list])] };
|
|
526
|
-
}
|
|
527
|
-
return { name: found.field, value: found.value, from: scope.progression()?.lists ?? [] };
|
|
528
|
-
}
|
|
529
|
-
/** The limits of a counter worked out in a scope, where they have a whole value (FOR-6); without a max formula, the column of a class's row (DAT-9). */
|
|
530
|
-
function limitsIn(scope, limits, field) {
|
|
531
|
-
const whole = (worked) => (worked?.value !== undefined && Number.isSafeInteger(worked.value) ? worked.value : undefined);
|
|
532
|
-
const min = whole(limits.min === undefined ? undefined : workOut(limits.min, scope));
|
|
533
|
-
const row = limits.max === undefined ? numberOf(progressionValue(scope.progression(), field)) : undefined;
|
|
534
|
-
const max = limits.max === undefined ? (row !== undefined && Number.isSafeInteger(row) ? row : undefined) : whole(workOut(limits.max, scope));
|
|
535
|
-
return { ...(min === undefined ? {} : { min }), ...(max === undefined ? {} : { max: atLeastZero(max) }) };
|
|
536
|
-
}
|
|
537
|
-
/** A maximum worked out below 0, as 1 + cha-mod with Charisma 7, is 0: a counter is never written with a maximum below 0 (FOR-6). */
|
|
538
|
-
function atLeastZero(max) {
|
|
539
|
-
return Math.max(0, max);
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* The written fields a formula comes from, through the computed fields it reads that have a value: what can be changed, as wis for passive-perception, and
|
|
543
|
-
* level where the page writes it, having no classes (FOR-7).
|
|
544
|
-
*/
|
|
545
|
-
function writtenSources(world, formula, scope, seen = new Set()) {
|
|
546
|
-
const formulas = world.system?.formulas;
|
|
547
|
-
const index = formulas === undefined ? undefined : formulaIndex(formulas);
|
|
548
|
-
const sources = fieldsRead(formula).flatMap((name) => {
|
|
549
|
-
const entry = index?.computed.get(comparableText(name));
|
|
550
|
-
// What the classes give comes from the lists that name them (PRO-3); what the items' pages give, from their list, as armor-class from equipped (PRO-5).
|
|
551
|
-
// Whether the classes or the items give it, without asking where they come from, which may read this field again.
|
|
552
|
-
if (entry === undefined && givenFields(world, scope).some((worked) => comparableText(worked.field) === comparableText(name))) {
|
|
553
|
-
const list = itemList(world, name);
|
|
554
|
-
return list === undefined ? (scope.progression()?.lists ?? [name]) : [list];
|
|
555
|
-
}
|
|
556
|
-
// What the engine gives a formula, as the campaign's rigor or a character's load, is no field anyone writes (FOR-2).
|
|
557
|
-
if (["rigor", "effects", "load", "load-limit"].includes(comparableText(name))) {
|
|
558
|
-
return [];
|
|
559
|
-
}
|
|
560
|
-
if (entry === undefined || scope.computed(name)?.value === undefined) {
|
|
561
|
-
return [name];
|
|
562
|
-
}
|
|
563
|
-
if (seen.has(comparableText(name))) {
|
|
564
|
-
return [];
|
|
565
|
-
}
|
|
566
|
-
seen.add(comparableText(name));
|
|
567
|
-
return writtenSources(world, entry[1], scope, seen);
|
|
568
|
-
});
|
|
569
|
-
return sources.filter((name, position) => sources.findIndex((other) => comparableText(other) === comparableText(name)) === position);
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* The bonus fields among those a computed field comes from, which an effect on the page gives to change it, as bonus-ac for ac (FOR-5); not those the items of a
|
|
573
|
-
* list give, as a shield's armor-class-bonus, which change on the item (PRO-5).
|
|
574
|
-
*/
|
|
575
|
-
function effectBonuses(world, from) {
|
|
576
|
-
return from.filter((field) => declaredKind(world, field) === "bonus" && itemList(world, field) === undefined);
|
|
577
|
-
}
|
|
578
|
-
const checkedWorlds = new WeakMap();
|
|
579
|
-
/**
|
|
580
|
-
* A formula an item's page gives that who lists it can have no value from (PRO-5): one that does not read, that reads itself, a table the system lacks or a name
|
|
581
|
-
* that neither the system, the item nor who lists it has.
|
|
582
|
-
*/
|
|
583
|
-
function itemFormulaProblems(world, page, fields) {
|
|
584
|
-
const system = world.system;
|
|
585
|
-
const scope = formulaScope(world, fields);
|
|
586
|
-
// What the system and the page have, once for the page: a formula of an item reads among these, or the item's own fields.
|
|
587
|
-
const known = new Set([
|
|
588
|
-
...Object.keys(system?.fields ?? {}),
|
|
589
|
-
...(system?.formulas?.computed ?? []).map(([name]) => name),
|
|
590
|
-
...Object.keys(system?.formulas?.counters ?? {}),
|
|
591
|
-
...Object.values(system?.itemFormulas ?? {}).flat(),
|
|
592
|
-
...(scope.progression()?.values.map((value) => value.field) ?? []),
|
|
593
|
-
...Object.keys(fields),
|
|
594
|
-
// What every formula reads besides the fields (FOR-2).
|
|
595
|
-
"effects",
|
|
596
|
-
"rigor",
|
|
597
|
-
...(system?.load === undefined ? [] : ["load", "load-limit"]),
|
|
598
|
-
].map(comparableText));
|
|
599
|
-
return Object.entries(system?.itemFormulas ?? {}).flatMap(([list, names]) => listItems(keyOf(fields, list) === undefined ? undefined : fields[keyOf(fields, list) ?? ""]).flatMap((item) => {
|
|
600
|
-
const holder = scope.page(item.name);
|
|
601
|
-
return holder === undefined ? [] : names.flatMap((field) => {
|
|
602
|
-
const key = keyOf(holder, field);
|
|
603
|
-
const text = key === undefined ? undefined : holder[key];
|
|
604
|
-
if (typeof text !== "string" && typeof text !== "number") {
|
|
605
|
-
return [];
|
|
606
|
-
}
|
|
607
|
-
let given;
|
|
608
|
-
try {
|
|
609
|
-
given = parseRollFormula(String(text));
|
|
610
|
-
}
|
|
611
|
-
catch (error) {
|
|
612
|
-
const why = error instanceof Error ? error.message : String(error);
|
|
613
|
-
return [{ path: page.path, message: `${field} on ${item.name} does not read, so ${page.name} has none from it: ${why}`, fix: `write ${item.name}, set ${field} as a formula` }];
|
|
614
|
-
}
|
|
615
|
-
const why = given.formula === undefined ? undefined : formulaGap(world, known, holder, field, given.formula);
|
|
616
|
-
if (why !== undefined) {
|
|
617
|
-
return [{ path: page.path, message: `${field} on ${item.name} ${why}, so ${page.name} has none from it.`, fix: `write ${item.name}, set ${field} as a formula of what the system has` }];
|
|
618
|
-
}
|
|
619
|
-
// Dice from a field no one has never count, while the other dice still do (D-235).
|
|
620
|
-
const dice = diceFields(given).find((name) => comparableText(name) === comparableText(field) || (!known.has(comparableText(name)) && keyOf(holder, name) === undefined));
|
|
621
|
-
if (dice !== undefined) {
|
|
622
|
-
return [{
|
|
623
|
-
path: page.path,
|
|
624
|
-
message: `${field} on ${item.name} takes dice from ${dice}, which ${comparableText(dice) === comparableText(field) ? "is the field itself" : "neither the system nor the character has"}: they never count for ${page.name}.`,
|
|
625
|
-
fix: `write ${item.name}, set ${field}="${withoutDiceField(String(text), dice)}"`,
|
|
626
|
-
}];
|
|
627
|
-
}
|
|
628
|
-
// Words after a number another formula reads, as "12 + Dex modifier", make it text, which no formula counts.
|
|
629
|
-
return given.words === undefined || given.dice !== undefined || !isReadAsNumber(world, field) ? [] : [{
|
|
630
|
-
path: page.path,
|
|
631
|
-
message: `${field} on ${item.name} ends with "${given.words}", words no formula counts, so ${page.name} has it only as text.`,
|
|
632
|
-
fix: `write ${item.name}, set ${field} as a formula alone, without "${given.words}"`,
|
|
633
|
-
}];
|
|
634
|
-
});
|
|
635
|
-
}));
|
|
636
|
-
}
|
|
637
|
-
/** A roll formula without one of the fields its dice(…) names: "dice(1d6) + dex-mod bludgeoning" for ki-die in "dice(1d6, ki-die) + dex-mod bludgeoning". */
|
|
638
|
-
function withoutDiceField(text, field) {
|
|
639
|
-
return text.replace(/^(\s*dice\s*\()([^()]*)\)/i, (_whole, opening, inside) => {
|
|
640
|
-
const kept = inside.split(",").map((part) => part.trim()).filter((part) => comparableText(part) !== comparableText(field));
|
|
641
|
-
return kept.length === 0 ? "" : `${opening}${kept.join(", ")})`;
|
|
642
|
-
}).trim().replace(/^\+\s*/, "");
|
|
643
|
-
}
|
|
644
|
-
/** Whether a field is a number for the system: declared as one, or read by one of its computed fields, as an armor's armor-class by ac. */
|
|
645
|
-
function isReadAsNumber(world, field) {
|
|
646
|
-
return ["number", "at-least", "modifier", "bonus"].includes(declaredKind(world, field) ?? "")
|
|
647
|
-
|| (world.system?.formulas?.computed ?? []).some(([, formula]) => fieldsRead(formula).some((name) => comparableText(name) === comparableText(field)));
|
|
648
|
-
}
|
|
649
|
-
/** Why a formula of an item's page can give no value: it reads itself, a table the system lacks, or a name no one has; undefined when none of these. */
|
|
650
|
-
function formulaGap(world, known, item, field, formula) {
|
|
651
|
-
const system = world.system;
|
|
652
|
-
const read = fieldsRead(formula);
|
|
653
|
-
if (read.some((name) => comparableText(name) === comparableText(field))) {
|
|
654
|
-
return "reads itself";
|
|
655
|
-
}
|
|
656
|
-
const table = tablesRead(formula).find((name) => !Object.keys(system?.formulas?.tables ?? {}).some((other) => comparableText(other) === comparableText(name)));
|
|
657
|
-
if (table !== undefined) {
|
|
658
|
-
return `reads the table "${table}", which the system lacks`;
|
|
659
|
-
}
|
|
660
|
-
const unknown = read.find((name) => !known.has(comparableText(name)) && keyOf(item, name) === undefined);
|
|
661
|
-
return unknown === undefined ? undefined : `reads ${unknown}, which neither the system nor the character has`;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* What a formula reads for a field the page lacks (FOR-2, FOR-4, FOR-5): a bonus as 0, a factor as 1, the effects by their names, the campaign's rigor; the
|
|
665
|
-
* page's own value, as always-in lists give it, for anything else.
|
|
666
|
-
*/
|
|
667
|
-
function missingValue(world, fields, name) {
|
|
668
|
-
const kind = declaredKind(world, name);
|
|
669
|
-
if (kind === "bonus" || kind === "factor") {
|
|
670
|
-
return kind === "bonus" ? 0 : 1;
|
|
671
|
-
}
|
|
672
|
-
if (comparableText(name) === "rigor") {
|
|
673
|
-
return world.rigor;
|
|
674
|
-
}
|
|
675
|
-
// What a character carries weighs, and its limit by the system's formula (LOAD-1, LOAD-4).
|
|
676
|
-
if (comparableText(name) === "load") {
|
|
677
|
-
return fields[carriedKey];
|
|
678
|
-
}
|
|
679
|
-
if (comparableText(name) === "load-limit" && world.system?.load !== undefined) {
|
|
680
|
-
return formulaValue(world, fields, world.system.load.limit);
|
|
681
|
-
}
|
|
682
|
-
return withAlwaysIn(world, fields, name, undefined);
|
|
683
|
-
}
|
|
684
|
-
/** The scope a formula reads on these fields: computed fields by their formulas, each worked out once; a bonus field the page lacks as 0 (FOR-4, FOR-5). */
|
|
685
|
-
function formulaScope(world, fields) {
|
|
686
|
-
const formulas = world.system?.formulas;
|
|
687
|
-
const index = formulas === undefined ? undefined : formulaIndex(formulas);
|
|
688
|
-
const keys = new Map();
|
|
689
|
-
const done = new Map();
|
|
690
|
-
let progressed;
|
|
691
|
-
// What the classes give, worked out once and only when a formula reads a field it may give (PRO-2).
|
|
692
|
-
const progression = () => (progressed ??= { progression: progressionOf(world, fields) }).progression;
|
|
693
|
-
for (const key of Object.keys(fields)) {
|
|
694
|
-
if (!keys.has(comparableText(key))) {
|
|
695
|
-
keys.set(comparableText(key), key);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
const computed = (name) => {
|
|
699
|
-
const entry = index?.computed.get(comparableText(name));
|
|
700
|
-
if (entry === undefined) {
|
|
701
|
-
return undefined;
|
|
702
|
-
}
|
|
703
|
-
const key = comparableText(entry[0]);
|
|
704
|
-
const worked = done.get(key) ?? workOut(entry[1], scope);
|
|
705
|
-
done.set(key, worked);
|
|
706
|
-
return worked;
|
|
707
|
-
};
|
|
708
|
-
// What the items' pages give a field, worked out once; a formula that reads itself, round and round, has no value (PRO-5).
|
|
709
|
-
const itemsDone = new Map();
|
|
710
|
-
const working = new Set();
|
|
711
|
-
const items = (field, explained) => {
|
|
712
|
-
const key = `${comparableText(field)}|${explained}`;
|
|
713
|
-
if (itemsDone.has(key) || working.has(comparableText(field))) {
|
|
714
|
-
return itemsDone.get(key) ?? [];
|
|
715
|
-
}
|
|
716
|
-
working.add(comparableText(field));
|
|
717
|
-
const found = itemValues(world, full, field, explained);
|
|
718
|
-
working.delete(comparableText(field));
|
|
719
|
-
itemsDone.set(key, found);
|
|
720
|
-
return found;
|
|
721
|
-
};
|
|
722
|
-
const each = (field, explained) => eachItem(world, field, items(field, explained));
|
|
723
|
-
const scope = {
|
|
724
|
-
field: (name) => {
|
|
725
|
-
const worked = computed(name);
|
|
726
|
-
if (worked?.value !== undefined) {
|
|
727
|
-
return worked.value;
|
|
728
|
-
}
|
|
729
|
-
// A formula of the items' pages counts in another as the number of the first item that gives it, as the Unarmored Defense of the first class
|
|
730
|
-
// that has it (p. 57); with none, the page's own value, as a witch's written DC.
|
|
731
|
-
if (itemList(world, name) !== undefined) {
|
|
732
|
-
const [first] = items(name, false);
|
|
733
|
-
if (first !== undefined) {
|
|
734
|
-
return typeof first.value === "number" ? first.value : undefined;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
const given = isSystemCounter(world, name) ? undefined : progressionValue(progression(), name);
|
|
738
|
-
if (given !== undefined) {
|
|
739
|
-
return given;
|
|
740
|
-
}
|
|
741
|
-
const key = keys.get(comparableText(name));
|
|
742
|
-
const value = key === undefined ? undefined : fields[key];
|
|
743
|
-
// The effects read by their names, as has(effects, Grappled) (FOR-2); one named in the campaign's language by the system's English, Afferrato as Grappled (D-403).
|
|
744
|
-
if (comparableText(name) === "effects") {
|
|
745
|
-
const read = readEffects(value);
|
|
746
|
-
return "effects" in read ? read.effects.map((effect) => systemName(world.words, effect.name)) : [];
|
|
747
|
-
}
|
|
748
|
-
return value === undefined ? missingValue(world, fields, name) : withAlwaysIn(world, fields, name, value);
|
|
749
|
-
},
|
|
750
|
-
table: (name) => index?.tables.get(comparableText(name)),
|
|
751
|
-
// The page an item names, of the campaign or of the system, with its effects, as a class with its hit die (D-215) or a weapon under Magic Weapon.
|
|
752
|
-
page: (name) => {
|
|
753
|
-
const [named] = pagesWithName(world, name);
|
|
754
|
-
const page = named ?? systemPageNamed(world, name);
|
|
755
|
-
return page === undefined ? undefined : withEffectValues(world, page);
|
|
756
|
-
},
|
|
757
|
-
};
|
|
758
|
-
const full = { ...scope, computed, progression, each, page: (name) => scope.page?.(name) };
|
|
759
|
-
return full;
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* A list as the formulas read it (DAT-13, D-235): what the page writes, then what the system puts in it for who keeps the sheet, as the unarmed strike among what a
|
|
763
|
-
* character has equipped, so that the attacks show it.
|
|
764
|
-
*/
|
|
765
|
-
function withAlwaysIn(world, fields, list, value) {
|
|
766
|
-
const added = Object.entries(world.system?.alwaysIn ?? {}).find(([name]) => comparableText(name) === comparableText(list))?.[1];
|
|
767
|
-
if (added === undefined || !keepsSheet(world, fields)) {
|
|
768
|
-
return value;
|
|
769
|
-
}
|
|
770
|
-
const written = value === undefined || value === null || value === "" ? [] : Array.isArray(value) ? value : [value];
|
|
771
|
-
const names = new Set(listItems(written).map((item) => comparableText(item.name)));
|
|
772
|
-
return [...written, ...added.filter((name) => !names.has(comparableText(name)))];
|
|
773
|
-
}
|
|
774
|
-
/** A system's computed fields and tables by the name as it is compared, built once for each system: a formula reads many names (D-194). */
|
|
775
|
-
function formulaIndex(formulas) {
|
|
776
|
-
const known = indexes.get(formulas);
|
|
777
|
-
if (known !== undefined) {
|
|
778
|
-
return known;
|
|
779
|
-
}
|
|
780
|
-
const computed = new Map();
|
|
781
|
-
const tables = new Map();
|
|
782
|
-
for (const entry of formulas.computed) {
|
|
783
|
-
computed.set(comparableText(entry[0]), entry);
|
|
784
|
-
}
|
|
785
|
-
for (const [name, table] of Object.entries(formulas.tables)) {
|
|
786
|
-
tables.set(comparableText(name), table);
|
|
787
|
-
}
|
|
788
|
-
const index = { computed, tables };
|
|
789
|
-
indexes.set(formulas, index);
|
|
790
|
-
return index;
|
|
791
|
-
}
|
|
792
|
-
const indexes = new WeakMap();
|
|
793
|
-
/** Whether the system gives the limits of a counter by this name (FOR-1). */
|
|
794
|
-
function isSystemCounter(world, field) {
|
|
795
|
-
return Object.keys(world.system?.formulas?.counters ?? {}).some((name) => comparableText(name) === comparableText(field));
|
|
796
|
-
}
|
|
797
|
-
/** The name under which the fields hold a field, in any case. */
|
|
798
|
-
function keyOf(fields, field) {
|
|
799
|
-
return sameName(Object.keys(fields), field);
|
|
800
|
-
}
|
|
801
|
-
/** The English name the system's words give a name written in the campaign's language, Grappled for Afferrato (D-403); the name itself when they give none. */
|
|
802
|
-
function systemName(words, name) {
|
|
803
|
-
const written = comparableText(name.trim());
|
|
804
|
-
return Object.entries(words ?? {}).find(([, word]) => comparableText(word) === written)?.[0] ?? name;
|
|
805
|
-
}
|