Skip to content

Say in the player view when a caster picks a form, whether they can prepare now, and a valuable's own name - #349

Merged
mmacy merged 4 commits into
mainfrom
view-prepare-and-valuables
Nov 26, 2026
Merged

mmacy merged 4 commits into
mainfrom
view-prepare-and-valuables

Conversation

@mmacy

@mmacy mmacy commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Closes #338. Closes #339.

A client that builds its prepare dialog, cast dialog, town screen, and item sentences from the player view had to infer three facts from other fields. Each is now a field that comes from the check the command runs.

  • MemberView.reverses_at is "memorize", "cast", or None for a member who casts nothing. It comes from the class's kind of caster, so a divine caster with a spell book reads "cast".
  • MemberView.can_prepare_now is true exactly when the session accepts a PrepareSpells from the member whose selection fits preparable_spells and spell_slots.
  • MemberView.needs_sleep_to_prepare is the sleep rule by itself, from the sleep counts, so it's right after a save is restored into a new session.
  • PlayerView.valuable_names gives the own name of each named gem and piece of jewellery whose id the view shows, in a member's inventory or a known pile. item_names is unchanged, because 2.8.0 clients put an article in front of its values.

One refusal changes. A member whose class casts nothing is refused a PrepareSpells with magic.memorize.not_a_caster whether or not the party has slept. Before, a session that hadn't slept yet said magic.memorize.needs_sleep.

Every new field has a default, so a 2.8.0 player view still parses, a 2.8.0 save gives the view a fresh session gives, and SCHEMA_VERSION stays 4.

How it was checked

The acceptance tests in tests/test_view_prepare_now.py and tests/test_view_valuable_names.py were written before the implementation by a different agent. An independent review drove 80 sessions of 100 commands through this branch and osrlib 2.8.0: the only difference in 8,000 commands was the not_a_caster refusal above, 73 times. It made 65,280 checks that the three member fields agree with what the session accepts, and 2,400 steps of twin sessions that differ only in secrets gave identical player views. All ten mutations were caught.

The review measured the player view at about 5.5% slower than 2.8.0 for a ten-member party (1.16 ms to 1.22 ms), which is recorded on #335.

https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3

…, and a valuable's own name

The new fields are stubs with defaults: `reverses_at`, `can_prepare_now`, and
`needs_sleep_to_prepare` on `MemberView` (#338), and `valuable_names` on `PlayerView` (#339). The
docstrings of `PlayerView.item_names` and `PileItemView` now point to `valuable_names`, and
`item_names` itself doesn't change.

The tests in tests/test_view_prepare_now.py and tests/test_view_valuable_names.py are marked xfail
until the chunk lands, except the cases a stub already satisfies, which run as guards: the
fighter's cases, a caster whom the moment refuses after a sleep, `item_names` naming every
valuable by its kind, and a 2.8.0 player view parsing. tests/saves/view_prepare_now_2.8.0.json and
tests/saves/view_valuable_names_2.8.0.json are saves of the two test states written by osrlib
2.8.0.

`PrepareSpells` refuses a member whose class casts nothing with `magic.memorize.needs_sleep` in a
new session and with `magic.memorize.not_a_caster` after a sleep. A test of this chunk pins
`magic.memorize.not_a_caster` whether or not the party has slept.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
…layer view

`MemberView.reverses_at`, `can_prepare_now`, and `needs_sleep_to_prepare` (#338) and
`PlayerView.valuable_names` (#339) now come from the checks the commands make, so a front end that
builds its prepare, cast, and town screens from the view alone no longer infers them.

- `reverses_at` reads `_reverses_at` in osrlib.core.spells, which `_selection_rejection` now uses to
  refuse a divine caster's reversed selection and `_memorized_index` uses to match a cast to a copy.
- `can_prepare_now` and `needs_sleep_to_prepare` come from `_prepare_now` in osrlib.crawl._spells,
  which checks the command's allowed modes, `_member_able`, and `_prepare_refusal`, the refusal that
  `_handle_prepare_spells` now returns. `_needs_sleep` is the sleep rule both read.
- `valuable_names` is built in the walk `_item_names` already makes over the inventories and the
  known piles. A piece has its own name unless the name is empty or the one in
  `_ROLLED_VALUABLE_NAMES`, which `_generate_valuable` in osrlib.core.treasure now reads too.

`PrepareSpells` checked the sleep rule before the class, so it refused a member whose class casts
nothing with `magic.memorize.needs_sleep` until the party's first sleep. `_prepare_refusal` checks
the class first, so the refusal is `magic.memorize.not_a_caster` whether or not the party has slept.

No RNG draw changes and no golden file or generated page changes. The guide to views, the spec, the
FastAPI page, and the changelog describe the new fields and the fix.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
The acceptance tests of the prepare fields and the valuable names now run as
ordinary tests. The guide said can_prepare_now is false during an encounter
or a battle, and the rule is that it's false unless the session is in town
or exploring.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
@mmacy
mmacy merged commit cc56c5c into main Nov 26, 2026
5 checks passed
@mmacy
mmacy deleted the view-prepare-and-valuables branch November 26, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant