Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

- Two house rules for character creation, which the SRD doesn't print and `Ruleset()` leaves off (#341). [`Ruleset.ability_score_method`][osrlib.core.ruleset.Ruleset.ability_score_method] is `"3d6"` by default. With `"4d6_drop_lowest"`, [`create_character`][osrlib.core.character.create_character] throws four d6 for each ability and drops the lowest, the first of them thrown when two or more tie, and [`roll_ability_scores`][osrlib.core.character.roll_ability_scores] does the same when you pass the method to its new `method` keyword. [`AbilityScoreRolls.rolls`][osrlib.core.character.AbilityScoreRolls.rolls] keeps the three dice that count, and the new [`AbilityScoreRolls.dropped`][osrlib.core.character.AbilityScoreRolls.dropped] has the dropped die of each ability, so a client can show all four. The method draws 24 dice instead of 18, so the same seed gives a different character, and NPC adventurers always roll 3d6. With [`Ruleset.max_hp_at_first_level`][osrlib.core.ruleset.Ruleset.max_hp_at_first_level] on, a first-level character's hit points are the hit die's size plus the CON modifier, and at least 1, and the new [`HitPointRoll.maximized`][osrlib.core.character.HitPointRoll.maximized] is true. The hit die and any rerolls of `hp_reroll_at_first_level` are still thrown, so the starting gold is the same as with the flag off. `examples/rulesets/creation_house_rules.json` is a ruleset with both house rules on and every other field at its default, for a front end to copy. With both flags at their defaults, every draw and result is what 2.8.0 gave. A 2.8.0 save loads with both off, a 2.8.0 creation result parses with an empty `dropped` and a false `maximized`, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4.
- [`SpellMode.display_name`][osrlib.core.spells.SpellMode.display_name] is a short label for a mode, such as `"Blind a creature"`, for a client to show where a player chooses one of a form's modes, such as a cast dialog (#340). It says what the caster does, in sentence case with no closing punctuation, and in the built-in catalog no two modes of one form have the same label. Each built-in label comes from the lead-in that the OSE SRD prints before the usage, such as "Blinding a creature:". Where the page prints no lead-in, or one that names a situation such as *bless*'s "Battle:", the SRD compiler has a label written from the page's words, such as `"Bless allies in battle"`. A mode that leaves the label out, or gives one that is empty or only spaces, gets a label made from its key: each run of underscores becomes one space, the spaces at either end are dropped, and the first letter becomes a capital, so `"kill_green_slime"` is labelled `"Kill green slime"`. The one mode of a single-mode form is labelled the same way, such as *fire ball*'s `"Damage"`. As a result, a spell document, an adventure, or a save from 2.8.0 loads with a label on every mode, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4.
- [`MemberView.reverses_at`][osrlib.crawl.views.MemberView.reverses_at], [`MemberView.can_prepare_now`][osrlib.crawl.views.MemberView.can_prepare_now], and [`MemberView.needs_sleep_to_prepare`][osrlib.crawl.views.MemberView.needs_sleep_to_prepare] let a client decide when to offer a prepare dialog and which forms of a spell to put in it and in a cast dialog (#338). `reverses_at` is `"memorize"` for an arcane caster, `"cast"` for a divine caster, and `None` for a class that casts nothing, read from the class's casting ability, so it's right for a custom class too. `can_prepare_now` is true exactly when the session accepts a [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] from the member with a selection that fits `preparable_spells` and `spell_slots`, and `needs_sleep_to_prepare` is true exactly when the party hasn't slept since the member last prepared. The session reads them from its own state, so they're right in a session restored from a save. Before, a client inferred the kind of caster from the spell book and read the event log for the last rest and the last preparation.
- [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] gives the own name of each gem and piece of jewellery that has one, like `"Prior's chain of office"`, keyed by the instance id, for the pieces in the members' inventories and in the known piles (#339). A piece placed by a [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] with a `name` has one, and a piece rolled on the treasure tables doesn't. [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] doesn't change and still names every valuable by its kind. Before, a client that wanted a piece's own name in a pile paired the pile's `contents` with its `items` by position.

### Changed

- Each built-in mode of the reverses of *light* and *continual light*, of *charm monster*, and of *silence 15' radius* has the part of the SRD text that covers it as its [`prose`][osrlib.core.spells.SpellMode.prose], so no two modes of one form have the same prose (#340). Before, every mode of one of these forms had the whole passage. For example, the `blind` mode of *darkness*, the reverse of *light*, had "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell." and now has "Like light, it may alternatively be used to blind creatures." Each mode of *charm monster* has only its own alternative from the first sentence, and the `area` mode of *silence 15' radius* leaves out the "Casting upon a creature:" bullet. [`ReversedForm.prose`][osrlib.core.spells.ReversedForm.prose] still has the whole text of the reverse, and a spell that an adventure bundles keeps the prose its author wrote.

### Fixed

- [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] refuses a member whose class casts nothing with `magic.memorize.not_a_caster` whether or not the party has slept. Before, it refused such a member with `magic.memorize.needs_sleep` until the party's first sleep, which said that the member could prepare after a rest.

## [2.8.0] - 2026-11-25

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/front-ends/fastapi-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ except SaveVersionError:
--8<-- "examples/fastapi_crawler/app.py:player-view"
```

[`PlayerView`][osrlib.crawl.views.PlayerView] allowlists only fields safe for an untrusted client: explored and lit dungeon cells, entered areas, known features and transitions, public character sheets, masked descriptions for unidentified magic items, display names for every item the view shows (`item_names` and `item_names_plural`), the id and count of each thing in a known pile (`PileView.contents`), encounter groups without monster hit points, `journal` entries, and active `quests` with their revealed objectives. Pass each known [`MapFeatureView.id`][osrlib.crawl.views.MapFeatureView.id] back in a treasure command's `feature_id`. [`PlayerView.features_here`][osrlib.crawl.views.PlayerView.features_here] lists the handles the treasure commands accept from where the party stands, and [`MapFeatureView.emptied`][osrlib.crawl.views.MapFeatureView.emptied] marks an authored cache the party has emptied, so the client can draw that cache opened and stop offering it. Unexplored geometry, raw ids in the feature list, cache contents, undiscovered secret doors and traps, transition destinations, monster stats, `flags`, narrator `guidance`, the player-handle key, and RNG state are excluded from the model (see [Views and visibility](../guides/views-and-visibility.md)). `PlayerView.emptied_caches` can contain a fully qualified raw feature id after the party empties that cache.
[`PlayerView`][osrlib.crawl.views.PlayerView] allowlists only fields safe for an untrusted client: explored and lit dungeon cells, entered areas, known features and transitions, public character sheets, including whether each caster can prepare spells now (`MemberView.can_prepare_now`), masked descriptions for unidentified magic items, display names for every item the view shows (`item_names` and `item_names_plural`) and the own name of each named gem and piece of jewellery (`valuable_names`), the id and count of each thing in a known pile (`PileView.contents`), encounter groups without monster hit points, `journal` entries, and active `quests` with their revealed objectives. Pass each known [`MapFeatureView.id`][osrlib.crawl.views.MapFeatureView.id] back in a treasure command's `feature_id`. [`PlayerView.features_here`][osrlib.crawl.views.PlayerView.features_here] lists the handles the treasure commands accept from where the party stands, and [`MapFeatureView.emptied`][osrlib.crawl.views.MapFeatureView.emptied] marks an authored cache the party has emptied, so the client can draw that cache opened and stop offering it. Unexplored geometry, raw ids in the feature list, cache contents, undiscovered secret doors and traps, transition destinations, monster stats, `flags`, narrator `guidance`, the player-handle key, and RNG state are excluded from the model (see [Views and visibility](../guides/views-and-visibility.md)). `PlayerView.emptied_caches` can contain a fully qualified raw feature id after the party empties that cache.

Authored narrative also reaches web clients through `POST /sessions/{session_id}/commands` responses in two places:

Expand Down
6 changes: 4 additions & 2 deletions docs/guides/views-and-visibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ assert "current_hp" not in player_group.model_dump()

`PlayerView` includes the adventure and town names and descriptions, available town services and temple healing prices, the party's position and facing, the elapsed clock, fatigue and deprivation status, and the current `SessionMode`.

Each party member appears in `PlayerView.party` as a [`MemberView`][osrlib.crawl.views.MemberView] containing every stat needed to render a B/X character sheet: ID, name, race, class id and class name (`class_name`, which is right for a custom class too), level, title, alignment, XP and next-level XP threshold, current and maximum hit points, conditions, ability scores and modifiers, THAC0 and attack bonus, descending and ascending AC, saving throws, movement rate, languages, inventory, spell book, spell slots at each spell level (`spell_slots`), the spells the member may prepare (`preparable_spells`) and learn (`learnable_spells`), memorized spells, and thief skill chances.
Each party member appears in `PlayerView.party` as a [`MemberView`][osrlib.crawl.views.MemberView] containing every stat needed to render a B/X character sheet: ID, name, race, class id and class name (`class_name`, which is right for a custom class too), level, title, alignment, XP and next-level XP threshold, current and maximum hit points, conditions, ability scores and modifiers, THAC0 and attack bonus, descending and ascending AC, saving throws, movement rate, languages, inventory, spell book, spell slots at each spell level (`spell_slots`), the spells the member may prepare (`preparable_spells`) and learn (`learnable_spells`), when the member chooses a spell's form (`reverses_at`), whether they can prepare spells now (`can_prepare_now`) and whether they need to sleep first (`needs_sleep_to_prepare`), memorized spells, and thief skill chances.

[`MemberView.preparable_spells`][osrlib.crawl.views.MemberView.preparable_spells] lists the spells the member may select in a [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells], and [`MemberView.learnable_spells`][osrlib.crawl.views.MemberView.learnable_spells] lists the spells the member may write into their spell book with [`LearnSpell`][osrlib.crawl.commands.LearnSpell]. Build your prepare and learn dialogs from them. Both are in the order of the session's catalog, and the session checks each command with the same rules that build the lists. A spell is in `preparable_spells` exactly when the spell and the member pass every check that `PrepareSpells` makes of one copy in its normal form, and the selection as a whole still has to fit the member's slots. An arcane caster may also select the reversed form of a listed spell that has an entry in `PlayerView.reversed_spell_names`. A spell is in `learnable_spells` exactly when the spell and the member pass every check that `LearnSpell` makes. A divine caster may prepare every spell on their class's list at the spell levels where they have a slot, including the spells the adventure bundles for that list. An arcane caster may prepare the spells in their book at those levels, and may learn the spells on their list that aren't in the book, at the spell levels where the book has room. Neither list depends on the moment, so each is the same before the party has slept, during an encounter or a battle, and while the member can't act, although the session refuses the commands then. To fill a prepare dialog, group `preparable_spells` by spell level, and at each level offer no more copies than [`MemberView.spell_slots`][osrlib.crawl.views.MemberView.spell_slots] gives there.

Use three more fields of the member view to decide when to offer the dialog and which forms to put in it. [`MemberView.can_prepare_now`][osrlib.crawl.views.MemberView.can_prepare_now] is true exactly when the session accepts a `PrepareSpells` from the member now with a selection that fits the lists and the slots. It's false unless the session is in town or exploring (`session.command.wrong_mode`), while the member can't act (`session.command.member_incapacitated`), until the party has slept since the member last prepared (`magic.memorize.needs_sleep`), and for a class that casts nothing (`magic.memorize.not_a_caster`). [`MemberView.needs_sleep_to_prepare`][osrlib.crawl.views.MemberView.needs_sleep_to_prepare] states the sleep rule alone, so you can tell the table which casters need a night's rest even during an encounter. It's true for every caster in a new session, before the party's first sleep. The session reads both from its own state, so they're right in a session restored from a save, and you never need the event log to know when the party last slept. [`MemberView.reverses_at`][osrlib.crawl.views.MemberView.reverses_at] says when the member chooses the form of a spell that reverses, from the kind of caster their class is, so it's right for a custom class too. It's `"memorize"` for an arcane caster, who may select a reversed copy in `PrepareSpells`, `"cast"` for a divine caster, who prepares the normal form and may cast any memorized copy in either form, and `None` for a class that casts nothing. Offer reversed copies in the prepare dialog only when it's `"memorize"`, and both forms of a memorized copy in the cast dialog only when it's `"cast"`.

A spell id appears in five places in the view: in a member's `spell_book`, `preparable_spells`, `learnable_spells`, and `memorized_spells`, and as the `kind` of a spell's effect in `PlayerView.effects`. Show the names in [`PlayerView.spell_names`][osrlib.crawl.views.PlayerView.spell_names], keyed by those ids, and the names of reversed forms, like *darkness* for *light*, in [`PlayerView.reversed_spell_names`][osrlib.crawl.views.PlayerView.reversed_spell_names]. Group spells by the level in [`PlayerView.spell_levels`][osrlib.crawl.views.PlayerView.spell_levels]. The view reads all three from the session's catalog, so a spell the adventure bundles has its name and level there too. They name only the spells whose ids the view shows. A spell the adventure bundles for a list that the party's classes don't cast from stays hidden. So does a spell at a spell level where the members can neither prepare nor learn it. A spell on a scroll is named only when the view shows its id in one of the five places: in a member's book, either list, or memorized copies, or as the kind of an effect on a member.

Items work the same way. An inventory identifies a mundane stack by its template's catalog id, like `"holy_water"`, and a magic item or a gem or piece of jewellery by its instance id, like `"magic-item-0003"`, and the item events use the same ids. Show the names in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], a noun phrase for one with no article, like `"vial of holy water"`, and in [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] for a count, so you can word "The party finds 2 vials of holy water". Both have a key for each item id that the inventories and the known piles show, and only for those ids. A stack in a pile is named from the session's catalog, and a stack a member carries from the template it embeds, so an item the adventure bundles has its name in both places. The session gives the template each carried stack embeds the catalog's display names when it starts, when a save loads, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, so a stack from a 2.7.0 save, whose template has no display names, shows the catalog's names in `inventory` too, and the next save writes them. A carried stack whose id the catalog lacks, such as an item another adventure bundled, keeps the names its template has. A valuable is named by its kind, `"gem"` or `"piece of jewellery"`, whereas the inventory's `valuables` contain the piece's name and value. A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, and the [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] contains its names instead.
Items work the same way. An inventory identifies a mundane stack by its template's catalog id, like `"holy_water"`, and a magic item or a gem or piece of jewellery by its instance id, like `"magic-item-0003"`, and the item events use the same ids. Show the names in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], a noun phrase for one with no article, like `"vial of holy water"`, and in [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] for a count, so you can word "The party finds 2 vials of holy water". Both have a key for each item id that the inventories and the known piles show, and only for those ids. A stack in a pile is named from the session's catalog, and a stack a member carries from the template it embeds, so an item the adventure bundles has its name in both places. The session gives the template each carried stack embeds the catalog's display names when it starts, when a save loads, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, so a stack from a 2.7.0 save, whose template has no display names, shows the catalog's names in `inventory` too, and the next save writes them. A carried stack whose id the catalog lacks, such as an item another adventure bundled, keeps the names its template has. A valuable is named by its kind, `"gem"` or `"piece of jewellery"`, whereas the inventory's `valuables` contain the piece's name and value. A gem or piece of jewellery that an adventure author named, such as one a [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] with a `name` places in a cache, also has that name in [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names], keyed by the same instance id, for a member's inventory and for a known pile. Show it as written, with no article, so you can word "Sam takes Prior's chain of office." For an id that isn't a key, such as a piece rolled on the treasure tables, use the kind in `item_names` with an article: "Sam takes a gem." A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, and the [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] contains its names instead.

Derived combat and exploration stats include bonuses from worn equipment (such as armour, a shield, or a ring of protection), even before the party identifies a magic item:

Expand Down
Loading
Loading