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: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- [`PileView.contents`][osrlib.crawl.views.PileView.contents] gives each thing in a pile as a [`PileItemView`][osrlib.crawl.views.PileItemView], with the id that the events use for it and its count, in the order of `items` (#316). A client reads `"holy_water"` and 2 there where `items` has `"holy_water×2"`. `items` doesn't change.
- [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] has two new fields, `display_name` and `display_name_plural`, the identified item's display names, like `"potion of healing"` (#316). A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, but the event does. An event recorded before this release has empty names. Every field this release adds has a default, so a 2.7.0 save, view, or event still parses, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4.
- The gear in a save or a party document that osrlib 2.7.0 wrote takes the display names of the session's catalog (#316). Its embedded templates have no display names, so they validate with the defaults from the price-list `name`, like `"Holy water (vial)"`. When a session starts, when [`load_game`][osrlib.persistence.load_game] restores one, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, each template that a party member's or an NPC adventurer's stack embeds takes the `display_name` and `display_name_plural` of the catalog's template with the same id, with the `overrides_applied` entries that name those two fields. So holy water from a 2.7.0 save reads `"vial of holy water"` in `MemberView.inventory`, in the referee view, and in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], and the next save writes those names. Nothing else in the template changes, a template whose id the catalog lacks keeps its names, `AddMember`'s logged character keeps the templates it arrived with, and loading a save draws nothing.
- [`MemberView.preparable_spells`][osrlib.crawl.views.MemberView.preparable_spells] and [`MemberView.learnable_spells`][osrlib.crawl.views.MemberView.learnable_spells] list the spells a member may select in a [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] and write into their spell book with [`LearnSpell`][osrlib.crawl.commands.LearnSpell], in the order of [`GameSession.effective_spells`][osrlib.crawl.session.GameSession.effective_spells] (#326). The view and the commands make the same checks. A spell is in `preparable_spells` exactly when a `PrepareSpells` that selects one copy of it in its normal form is accepted, or is refused only for the moment and with none of `magic.memorize.not_a_caster`, `magic.memorize.unknown_spell`, `magic.memorize.wrong_list`, `magic.memorize.not_in_book`, and `magic.memorize.slots_exceeded`. An arcane caster may also prepare the reverse of a listed spell that `reversed_spell_names` names. A spell is in `learnable_spells` exactly when a `LearnSpell` for it is accepted, or is refused only for the moment and with none of `magic.book.not_arcane`, `magic.book.unknown_spell`, `magic.book.wrong_list`, `magic.book.duplicate`, and `magic.book.capacity_exceeded`. A selection made only of listed spells is still refused when it has more copies at a spell level than the member has slots there. A divine caster's `preparable_spells` has every spell on the class's list at the spell levels where the caster has a slot, including the spells the adventure bundles for that list. An arcane caster's `learnable_spells` has the spells on the 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. Before, the view named a spell only once a member had it, so a player couldn't find out that the adventure adds a spell their cleric may prepare or their magic-user may learn.
- [`MemberView.spell_slots`][osrlib.crawl.views.MemberView.spell_slots] is how many spells the member can memorize at each spell level, from the class's progression row for the member's level, so it's right for a custom class too, and [`PlayerView.spell_levels`][osrlib.crawl.views.PlayerView.spell_levels] is the level of each spell in `spell_names` (#326). With them, a client groups a prepare or learn dialog by spell level and fits it to the slots. `spell_names`, `reversed_spell_names`, and `spell_levels` name every spell in the two lists, and a spell that the members can't choose stays hidden, such as one the adventure bundles for a list that the party's classes don't cast from. The session works the four new fields out from the characters and the catalog, so a 2.7.0 save loads with them filled in. Every new field has a default, so a 2.7.0 player view still parses, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4.

### Fixed

Expand Down Expand Up @@ -705,7 +707,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- The documentation site: quickstart, guides, front-end walk-throughs, and a full reference for every command, event, rejection code, message code, RNG stream, and content id.
- The typed surface: complete type hints under `py.typed`, checked in CI.

[Unreleased]: https://github.com/mmacy/osrlib-python/compare/v2.5.1...HEAD
[Unreleased]: https://github.com/mmacy/osrlib-python/compare/v2.7.0...HEAD
[2.7.0]: https://github.com/mmacy/osrlib-python/compare/v2.6.0...v2.7.0
[2.6.0]: https://github.com/mmacy/osrlib-python/compare/v2.5.1...v2.6.0
[2.5.1]: https://github.com/mmacy/osrlib-python/compare/v2.5.0...v2.5.1
[2.5.0]: https://github.com/mmacy/osrlib-python/compare/v2.4.0...v2.5.0
[2.4.0]: https://github.com/mmacy/osrlib-python/compare/v2.3.0...v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/authoring-custom-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ miri = create_character(
assert miri.spell_book == ("frost_dart",)
```

Once the session starts, [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells], [`LearnSpell`][osrlib.crawl.commands.LearnSpell], [`CastSpell`][osrlib.crawl.commands.CastSpell], and battle `cast` declarations resolve bundled spells alongside built-in spells. [`MemberView`][osrlib.crawl.views.MemberView] lists `spell_book` and `memorized_spells` by spell ID (such as `"frost_dart"`), and [`PlayerView.spell_names`][osrlib.crawl.views.PlayerView.spell_names] contains the name of each one, read from `session.effective_spells`, so show those names rather than looking the ids up in `load_spells()`, which lacks the spells the adventure bundles:
Once the session starts, [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells], [`LearnSpell`][osrlib.crawl.commands.LearnSpell], [`CastSpell`][osrlib.crawl.commands.CastSpell], and battle `cast` declarations resolve bundled spells alongside built-in spells. [`MemberView`][osrlib.crawl.views.MemberView] lists `spell_book`, `preparable_spells`, `learnable_spells`, and `memorized_spells` by spell ID (such as `"frost_dart"`). A bundled spell is in [`preparable_spells`][osrlib.crawl.views.MemberView.preparable_spells] for a divine caster whose class casts from its list and who has a slot at its level, and in [`learnable_spells`][osrlib.crawl.views.MemberView.learnable_spells] for an arcane caster whose class casts from its list and whose book has room at its level, so a player can find it before any member has it. [`PlayerView.spell_names`][osrlib.crawl.views.PlayerView.spell_names] contains the name of each listed spell and [`PlayerView.spell_levels`][osrlib.crawl.views.PlayerView.spell_levels] its level, both read from `session.effective_spells`, so show those names rather than looking the ids up in `load_spells()`, which lacks the spells the adventure bundles:

```{.python .no-run}
bran = Character(
Expand Down Expand Up @@ -895,7 +895,7 @@ assert COFFER.referee_notes not in view.model_dump_json()

- **Read-only built-in loaders**: `load_classes`, `load_spells`, `load_monsters`, and `load_equipment` return cached, immutable SRD catalogs and provide no global registration or mutation API. Pass extended catalogs explicitly to kernel functions or bundle custom spells, monsters, and items on `Adventure`.
- **Generated scrolls and NPC casters**: Randomly rolled treasure scrolls and NPC party spell lists draw exclusively from the built-in `load_spells()` catalog, never from `Adventure.spells`.
- **Cross-adventure spell books**: If a character enters a session with a spell ID from another adventure that is absent from `session.effective_spells`, the session rejects [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] (`magic.memorize.unknown_spell`), [`CastSpell`][osrlib.crawl.commands.CastSpell] (`magic.cast.unknown_spell`), and battle `cast` declarations for that spell. While any unknown spell remains in the character's `spell_book`, the session also rejects [`LearnSpell`][osrlib.crawl.commands.LearnSpell] (`magic.book.unknown_spell`) because remaining spell-book capacity depends on every known spell's level. Energy drain cannot determine the level of an unknown memorized spell, so it leaves that entry untouched in `memorized_spells`.
- **Cross-adventure spell books**: If a character enters a session with a spell ID from another adventure that is absent from `session.effective_spells`, the session rejects [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] (`magic.memorize.unknown_spell`), [`CastSpell`][osrlib.crawl.commands.CastSpell] (`magic.cast.unknown_spell`), and battle `cast` declarations for that spell. While any unknown spell remains in the character's `spell_book`, the session also rejects [`LearnSpell`][osrlib.crawl.commands.LearnSpell] (`magic.book.unknown_spell`) because remaining spell-book capacity depends on every known spell's level. Energy drain cannot determine the level of an unknown memorized spell, so it leaves that entry untouched in `memorized_spells`. In the player view, the character's [`learnable_spells`][osrlib.crawl.views.MemberView.learnable_spells] is empty while the book contains the unknown spell, and [`preparable_spells`][osrlib.crawl.views.MemberView.preparable_spells] leaves the unknown id out.

See [the class id index][classes-index] and [the spell id index][spells-index] for built-in IDs, and [the API reference](../reference/api/index.md) for full model definitions.

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,9 +30,11 @@ 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, 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`), memorized spells, and thief skill chances.

A member's spell book and memorized spells name each spell by id, and so does 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]. The view reads both from the session's catalog, so a spell the adventure bundles has its name there too. Neither includes a spell that is absent from the rest of the view, like one on a scroll.
[`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.

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 mundane stack, carried or in a pile, is named as the session's catalog names it, so an item the adventure bundles has its name there too. 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.

Expand Down
Loading
Loading