diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3eb0e..f8895f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/front-ends/fastapi-pattern.md b/docs/front-ends/fastapi-pattern.md index 47ba640..46f8d66 100644 --- a/docs/front-ends/fastapi-pattern.md +++ b/docs/front-ends/fastapi-pattern.md @@ -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: diff --git a/docs/guides/views-and-visibility.md b/docs/guides/views-and-visibility.md index 25df461..24482b0 100644 --- a/docs/guides/views-and-visibility.md +++ b/docs/guides/views-and-visibility.md @@ -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: diff --git a/docs/spec.md b/docs/spec.md index c166f97..0774904 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -127,7 +127,7 @@ for event in result.events: view = session.view(Visibility.PLAYER) ``` -The player view is a safe projection: party status, explored map cells, entered dungeons and areas, known features and transitions, known active effects, active quests (id, name, display narrative with the block's speaker attribution beside it, since a wire client holds no adventure document to resolve one from, and visible objectives with their ids, display names, and states), and the journal. When areas overlap, the first area in `LevelSpec.areas` owns a shared cell, matching `LevelSpec.area_at`. An area enters only when the party walks an owned cell. An entered area exposes its authored id, name, description, only those owned cells the party walked, and the `trap_state` of its room trap once the party has found or sprung it, so a room whose trap the party hasn't met looks the same as a room without one. A `MapFeatureView` exposes a stable `feature:` handle, public kind, description, safe location, a `trap_state` limited to `"found"`, `"sprung"`, or `"removed"`, and `emptied`, true for an authored treasure cache the party has emptied, which stays listed under its handle. A feature's `area_id` names the entered area that lists it, or for a generated cache the entered area that owns its cell, and never an area the party hasn't entered. The handle is HMAC-SHA-256 over a length-prefixed tuple of dungeon id, level number, and authored feature id or generated cache key, with separate domains for those two identity types. Individual dungeon, area, and feature ids may contain colons. Validation requires every canonical `"{dungeon}:{level}:{id}"` area and feature reference to occur once, so repeated definitions and colon-delimited component collisions both fail. New sessions and loaded saves fail closed before they can use ambiguous state. A server adapter supplies an independent key of at least 32 bytes. Omitting the key derives a deterministic pseudonym from the master seed, which is not confidential from someone who knows or can guess that seed. A generated lair cache appears only after the party resolves its keyed encounter. Feature commands resolve only current-location authored features and available generated caches. `PlayerView.features_here` lists the handles of the treasure caches among those candidates, from the same resolution the commands run, and is empty unless the mode is exploring. An ambiguous legacy raw id rejects, and an id that starts with `feature:` never falls back to a raw id. A feature with no trap and a cache with an unfound trap give the same `exploration.feature.unknown` response to trap removal. The map feature list never exposes a raw internal id. `PlayerView.emptied_caches` retains its existing fully qualified raw references, and a client reads `MapFeatureView.emptied` to tell which listed cache is emptied. `PlayerView.can_travel_to_town` is true only while the mode is exploring, the current level has an entrance, and the party stands on it. The player view names every item id it shows, a mundane stack's catalog id and a magic item's or valuable's instance id, in `item_names` and `item_names_plural`, read from the template a carried stack embeds, which the session gives the catalog's display names when it starts, loads a save, or adds a member, and from the session's catalog for a pile, and a pile lists each thing's id and count in `PileView.contents`. An unidentified magic item is named by its category mask or its base, like "potion" or "arrow with a faint aura", never by its true name or template id, and a valuable by its kind. The player view never contains unexplored geometry, cache contents, hidden trap or construction data, a transition destination or gate, monster HP, referee-only roll outcomes, session flags, hidden objectives, gate or trigger wiring, the player-handle key, or the master seed. +The player view is a safe projection: party status, explored map cells, entered dungeons and areas, known features and transitions, known active effects, active quests (id, name, display narrative with the block's speaker attribution beside it, since a wire client holds no adventure document to resolve one from, and visible objectives with their ids, display names, and states), and the journal. When areas overlap, the first area in `LevelSpec.areas` owns a shared cell, matching `LevelSpec.area_at`. An area enters only when the party walks an owned cell. An entered area exposes its authored id, name, description, only those owned cells the party walked, and the `trap_state` of its room trap once the party has found or sprung it, so a room whose trap the party hasn't met looks the same as a room without one. A `MapFeatureView` exposes a stable `feature:` handle, public kind, description, safe location, a `trap_state` limited to `"found"`, `"sprung"`, or `"removed"`, and `emptied`, true for an authored treasure cache the party has emptied, which stays listed under its handle. A feature's `area_id` names the entered area that lists it, or for a generated cache the entered area that owns its cell, and never an area the party hasn't entered. The handle is HMAC-SHA-256 over a length-prefixed tuple of dungeon id, level number, and authored feature id or generated cache key, with separate domains for those two identity types. Individual dungeon, area, and feature ids may contain colons. Validation requires every canonical `"{dungeon}:{level}:{id}"` area and feature reference to occur once, so repeated definitions and colon-delimited component collisions both fail. New sessions and loaded saves fail closed before they can use ambiguous state. A server adapter supplies an independent key of at least 32 bytes. Omitting the key derives a deterministic pseudonym from the master seed, which is not confidential from someone who knows or can guess that seed. A generated lair cache appears only after the party resolves its keyed encounter. Feature commands resolve only current-location authored features and available generated caches. `PlayerView.features_here` lists the handles of the treasure caches among those candidates, from the same resolution the commands run, and is empty unless the mode is exploring. An ambiguous legacy raw id rejects, and an id that starts with `feature:` never falls back to a raw id. A feature with no trap and a cache with an unfound trap give the same `exploration.feature.unknown` response to trap removal. The map feature list never exposes a raw internal id. `PlayerView.emptied_caches` retains its existing fully qualified raw references, and a client reads `MapFeatureView.emptied` to tell which listed cache is emptied. `PlayerView.can_travel_to_town` is true only while the mode is exploring, the current level has an entrance, and the party stands on it. The player view names every item id it shows, a mundane stack's catalog id and a magic item's or valuable's instance id, in `item_names` and `item_names_plural`, read from the template a carried stack embeds, which the session gives the catalog's display names when it starts, loads a save, or adds a member, and from the session's catalog for a pile, and a pile lists each thing's id and count in `PileView.contents`. An unidentified magic item is named by its category mask or its base, like "potion" or "arrow with a faint aura", never by its true name or template id, and a valuable by its kind. A gem or piece of jewellery that an author named, unlike one rolled on the treasure tables, also has that name in `valuable_names` under its instance id. The player view never contains unexplored geometry, cache contents, hidden trap or construction data, a transition destination or gate, monster HP, referee-only roll outcomes, session flags, hidden objectives, gate or trigger wiring, the player-handle key, or the master seed. Generated caches record whether they came from an area, a lair, or a legacy save with no provenance. A legacy cache stays hidden and refuses commands when any keyed encounter in an area containing its parsed cell remains unresolved. Malformed or unresolvable legacy cell references fail closed. After resolution establishes safety, the old cache becomes available. diff --git a/src/osrlib/core/spells.py b/src/osrlib/core/spells.py index d9dc0c2..67f7393 100644 --- a/src/osrlib/core/spells.py +++ b/src/osrlib/core/spells.py @@ -1434,9 +1434,7 @@ def memorize_spells( """ profile = caster_profile(definition) if profile is None: - return MemorizationResult( - rejections=(Rejection(code="magic.memorize.not_a_caster", params={"class": definition.id}),) - ) + return MemorizationResult(rejections=(_not_a_caster(definition),)) rejections: list[Rejection] = [] counts: dict[int, int] = {} for selection in selections: @@ -1470,6 +1468,22 @@ def memorize_spells( return MemorizationResult(events=(event,)) +def _not_a_caster(definition: ClassDefinition) -> Rejection: + """Return the refusal of a preparation for a class that casts nothing, for which `caster_profile` is None.""" + return Rejection(code="magic.memorize.not_a_caster", params={"class": definition.id}) + + +def _reverses_at(profile: CasterProfile) -> Literal["memorize", "cast"]: + """Return when a caster of this kind chooses the form of a spell that reverses. + + An arcane caster chooses it when memorizing, so `memorize_spells` takes a reversed selection and a cast must match + the copy's form. A divine caster chooses it when casting, so `memorize_spells` refuses a reversed selection with + `magic.memorize.divine_reverses_at_cast` and a cast matches any copy of the spell. It's the member view's + `reverses_at`. + """ + return "cast" if profile.kind == "divine" else "memorize" + + def _slot_count(slots: Sequence[int], spell_level: int) -> int: """Return a progression row's slot count at a spell level, which is 0 past the end of the row.""" return slots[spell_level - 1] if spell_level <= len(slots) else 0 @@ -1487,7 +1501,7 @@ def _selection_rejection( return Rejection( code="magic.memorize.wrong_list", params={"spell": selection.spell_id, "list": template.spell_list} ) - if profile.kind == "divine" and selection.reversed: + if _reverses_at(profile) == "cast" and selection.reversed: return Rejection(code="magic.memorize.divine_reverses_at_cast", params={"spell": selection.spell_id}) if profile.kind == "arcane": if selection.spell_id not in getattr(caster, "spell_book", ()): @@ -2046,7 +2060,7 @@ def _memorized_index(caster: Any, spell: SpellTemplate, reversed: bool, profile: for index, copy in enumerate(getattr(caster, "memorized_spells", ())): if copy.spell_id != spell.id: continue - if profile.kind == "divine" or copy.reversed == reversed: + if _reverses_at(profile) == "cast" or copy.reversed == reversed: return index return None diff --git a/src/osrlib/core/treasure.py b/src/osrlib/core/treasure.py index 1260554..cabe69a 100644 --- a/src/osrlib/core/treasure.py +++ b/src/osrlib/core/treasure.py @@ -897,6 +897,13 @@ def _int_param(params: Mapping[str, Any], key: str, default: int = 0) -> int: return int(params.get(key, default)) +_ROLLED_VALUABLE_NAMES: dict[str, str] = {"gem": "Gem", "jewellery": "Jewellery"} +"""The plain name that `_generate_valuable` gives a rolled piece of each kind, which is no name of the piece's own. + +The player view's `valuable_names` leaves out a piece whose name is the one here, so the view and the generator use the +same names.""" + + def _generate_valuable( kind: Literal["gem", "jewellery"], *, stream: RngStream, allocator: Any ) -> osrlib.core.items.ValuableInstance: @@ -906,14 +913,12 @@ def _generate_valuable( weights = {row.id: row.weight_coins for row in load_equipment().treasure_weights} if kind == "gem": value = load_treasure_tables().gems.value_for_roll(stream.randbelow(20) + 1) - name = "Gem" else: value = roll(load_treasure_tables().gems.jewellery_dice, stream).total - name = "Jewellery" return osrlib.core.items.ValuableInstance( instance_id=allocator.allocate("valuable"), kind=kind, - name=name, + name=_ROLLED_VALUABLE_NAMES[kind], value_gp=value, weight_coins=weights[kind], ) diff --git a/src/osrlib/crawl/_spells.py b/src/osrlib/crawl/_spells.py index 189ac2b..bcd34f8 100644 --- a/src/osrlib/crawl/_spells.py +++ b/src/osrlib/crawl/_spells.py @@ -19,11 +19,13 @@ from osrlib.core.spells import ( MAGIC_STREAM, CastContext, + CasterProfile, CastResult, SpellCatalog, SpellEffect, SpellTemplate, _learnable_spell_ids, + _not_a_caster, _preparable_spell_ids, add_spell_to_book, cast_spell, @@ -41,9 +43,10 @@ def _handle_prepare_spells(session, command: PrepareSpells) -> tuple[list[Reject member, rejections = _member_able(session, command.character_id) if rejections: return rejections, [] - if session.sleep_count == 0 or session.last_prepared_sleep.get(member.id, 0) >= session.sleep_count: - return [Rejection(code="magic.memorize.needs_sleep", params={"character": member.id})], [] definition = member.definition + refusal = _prepare_refusal(session, member, caster_profile(definition)) + if refusal is not None: + return [refusal], [] result = memorize_spells(member, definition, session.effective_spells, command.selections) if result.rejections: return list(result.rejections), [] @@ -54,6 +57,39 @@ def _handle_prepare_spells(session, command: PrepareSpells) -> tuple[list[Reject return [], events +def _prepare_refusal(session, member, profile: CasterProfile | None) -> Rejection | None: + """Return why a `PrepareSpells` from a member who can act is refused whatever the selections, or None. + + `profile` is the member's `caster_profile`. It checks the class before the sleep rule, so a class that casts + nothing is refused with `magic.memorize.not_a_caster` whether or not the party has slept. + """ + if profile is None: + return _not_a_caster(member.definition) + if _needs_sleep(session, member): + return Rejection(code="magic.memorize.needs_sleep", params={"character": member.id}) + return None + + +def _needs_sleep(session, member: Character) -> bool: + """Return whether the party hasn't slept since the member last prepared, which is the sleep rule of `PrepareSpells`. + + It reads the session's sleep counts, which a save includes, and never the event log. It's the member view's + `needs_sleep_to_prepare` for a caster. + """ + return session.sleep_count == 0 or session.last_prepared_sleep.get(member.id, 0) >= session.sleep_count + + +def _prepare_now(session, member, profile: CasterProfile | None) -> tuple[bool, bool]: + """Return the member view's `can_prepare_now` and `needs_sleep_to_prepare`, with `profile` the member's. + + It computes `can_prepare_now` from the checks of `PrepareSpells` that don't read the selections, in the order the + session makes them: the mode, whether the member can act, the class, and the sleep rule. + """ + able = session.mode in PrepareSpells.allowed_modes and not _member_able(session, member.id)[1] + can_prepare_now = able and _prepare_refusal(session, member, profile) is None + return can_prepare_now, profile is not None and _needs_sleep(session, member) + + def _handle_learn_spell(session, command: LearnSpell) -> tuple[list[Rejection], list[Event]]: member, rejections = _member_able(session, command.character_id) if rejections: diff --git a/src/osrlib/crawl/views.py b/src/osrlib/crawl/views.py index a7e73cb..00e10a3 100644 --- a/src/osrlib/crawl/views.py +++ b/src/osrlib/crawl/views.py @@ -126,12 +126,15 @@ Coins, MagicItemCategory, MagicItemInstance, + ValuableInstance, _masked_names, _with_article, magic_item_template, ) from osrlib.core.monsters import IdAllocator, MonsterInstance, _regular_plural from osrlib.core.ruleset import Ruleset +from osrlib.core.spells import _reverses_at, caster_profile +from osrlib.core.treasure import _ROLLED_VALUABLE_NAMES from osrlib.crawl._feature_handles import ( _authored_feature_id, _cache_available, @@ -470,6 +473,64 @@ class too. (`session.command.member_incapacitated`). Learning one spell can fill the book at that spell's level, so read the view again after each `LearnSpell`. To show a spell's name, look its id up in [`PlayerView.spell_names`][osrlib.crawl.views.PlayerView.spell_names].""" + reverses_at: Literal["memorize", "cast"] | None = None + """When the member chooses the form of a spell that reverses: `"memorize"`, `"cast"`, or `None` for a + class that casts nothing. + + It comes from the kind of caster the class is, as + [`caster_profile`][osrlib.core.spells.caster_profile] reads it from + [`Character.definition`][osrlib.core.character.Character.definition], so it's right for a custom class + too, whatever its spell list and whether or not the member has a spell book. The OSE SRD says of arcane + casters that "The normal or reversed form of a spell must be selected when the spell is memorized", and + of divine casters that they "can cast the reversed version of a spell by speaking the words and + performing the gestures backwards when it is cast." + + - `"memorize"`, for an arcane caster: a [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] may + select the reversed form of a spell that has an entry in + [`PlayerView.reversed_spell_names`][osrlib.crawl.views.PlayerView.reversed_spell_names], and each + memorized copy is cast in the form its `reversed` in `memorized_spells` gives. + - `"cast"`, for a divine caster: the session refuses a reversed selection with + `magic.memorize.divine_reverses_at_cast`, and every memorized copy of a spell that reverses can be cast + in either form, with the `reversed` of [`CastSpell`][osrlib.crawl.commands.CastSpell] or of a `cast` + [`BattleDeclaration`][osrlib.crawl.commands.BattleDeclaration]. + + So offer a reversed copy in a prepare dialog only when it's `"memorize"`, and offer both forms of a + memorized copy in a cast dialog only when it's `"cast"`.""" + can_prepare_now: bool = False + """Whether the session accepts a [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] from the member + now, with selections that fit `preparable_spells` and `spell_slots`. Read it to offer or withhold a + prepare dialog. + + It's false exactly when one of the refusals that belong to the moment applies to the member: + + - `session.command.wrong_mode`: the session isn't in town or exploring. + - `session.command.member_incapacitated`: the member can't act. + - `magic.memorize.needs_sleep`: the party hasn't slept since the member last prepared, which + `needs_sleep_to_prepare` gives by itself. + + It's also false for a class that casts nothing, which the session refuses with + `magic.memorize.not_a_caster`. It doesn't depend on the slots, so it's true for a 1st-level cleric who + has slept, whose `preparable_spells` is empty and who can prepare only an empty selection. + + The session reads the moment from its own state, never from the event log, so the field is right in a + session restored from a save. A [`Rest`][osrlib.crawl.commands.Rest], a `PrepareSpells`, an encounter, + or a condition can change it, so read the view again after each command.""" + needs_sleep_to_prepare: bool = False + """Whether the member has to sleep before they can prepare spells again. Read it to tell the table which + casters need a night's rest. + + It's true exactly when the party hasn't slept since the member last prepared, the rule by which the + session refuses a [`PrepareSpells`][osrlib.crawl.commands.PrepareSpells] with + `magic.memorize.needs_sleep`. So it's true for every caster in a new session, before the party's first + sleep, and for a caster who has prepared, until the party sleeps again. A `night` or `day` + [`Rest`][osrlib.crawl.commands.Rest] that a wandering encounter doesn't interrupt is sleep. The OSE SRD + says "A spell caster can memorize new spells once a day, after an uninterrupted night’s sleep." + + It reads the party's sleeps and the member's last preparation alone. During an encounter or a battle, + and while the member can't act, the session refuses the command with `session.command.wrong_mode` or + `session.command.member_incapacitated` before it checks the sleep, and this field still says whether the + member will need to sleep. It's false for a class that casts nothing, which the session refuses with + `magic.memorize.not_a_caster` whether or not the party has slept.""" thief_skills: dict[str, int] = {} """The member's chance at each thief skill at their level, keyed by the skill field names of [`ThiefSkillRow`][osrlib.core.classes.ThiefSkillRow], like `"open_locks"` and `"move_silently"`. @@ -531,7 +592,10 @@ class PileItemView(_Model): You get these from [`PileView.contents`][osrlib.crawl.views.PileView.contents]. Look `item_id` up in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] and - [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] to name it. + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] to name it. A gem or + piece of jewellery that has a name of its own has it in + [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] too. Show that name as + written, with no article. """ model_config = ConfigDict(frozen=True) @@ -1262,7 +1326,9 @@ class PlayerView(_Model): - The instance id of a gem or a piece of jewellery, like `"valuable-0007"`. Its name is its kind, `"gem"` or `"piece of jewellery"`. The players see everything else about it from the moment they take it, its own name and its value in gold pieces included, in the inventory's - `valuables`. + `valuables`. A piece that has a name of its own, like `"Prior's chain of office"`, has it in + `valuable_names` under the same id. Show that name as written, with no article, in place of + the kind. It names no item whose id the view doesn't show. The player-visible item events, like [`ItemAcquiredEvent`][osrlib.crawl.events.ItemAcquiredEvent], name items by the same ids. An @@ -1280,6 +1346,24 @@ class PlayerView(_Model): masked name, like `"shields with a faint aura"`, or `"gems"` or `"pieces of jewellery"`. Use it with a count from a pile's [`contents`][osrlib.crawl.views.PileView.contents], an inventory entry's `quantity`, or the ids an event repeats, one per unit: "2 vials of holy water".""" + valuable_names: dict[str, str] = {} + """The own name of each gem and piece of jewellery that has one, keyed by its instance id, like + `{"valuable-0007": "Prior's chain of office"}`. Show it as written, with no article: "Sam takes + Prior's chain of office." For an id that isn't a key, use the kind in `item_names`, with an + article: "Sam takes a gem." + + A piece has a name of its own when its `name` is neither empty nor the plain name that treasure + generation gives its kind, `"Gem"` or `"Jewellery"`. So a piece an adventure places in a cache + with a named [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] is a key, and neither a piece + the session rolls on the treasure tables nor a placed piece whose `name` is empty is a key. + + The keys are the instance ids of those pieces in the members' + [`inventory`][osrlib.crawl.views.MemberView.inventory] `valuables` and in the + [`contents`][osrlib.crawl.views.PileView.contents] of the known piles. Each value is the name that + the inventory's `valuables` give the piece, and the string at the same place in the pile's + [`items`][osrlib.crawl.views.PileView.items]. A piece in a pile the party doesn't know, or in a + cache the party hasn't emptied, isn't a key, as it isn't one in `item_names`. Every key here is + also a key in `item_names`.""" fatigued: bool """Whether any member is fatigued.""" exhausted: bool @@ -1664,7 +1748,7 @@ def build_player_view(session) -> PlayerView: if state.worst > 0 } spell_names, reversed_spell_names, spell_levels = _spell_names(session, members, effects) - item_names, item_names_plural = _item_names(session, known_piles.values()) + item_names, item_names_plural, valuable_names = _item_names(session, known_piles.values()) return PlayerView( adventure_name=session.adventure.name, adventure_description=session.adventure.description, @@ -1691,6 +1775,7 @@ def build_player_view(session) -> PlayerView: spell_levels=spell_levels, item_names=item_names, item_names_plural=item_names_plural, + valuable_names=valuable_names, fatigued=fatigued, exhausted=exhausted, deprivation=deprivation, @@ -1753,7 +1838,8 @@ def _pile_view(pile: DropPile) -> PileView: """What the players call a valuable of each kind, whatever name the piece has.""" -def _item_names(session, piles: Iterable[DropPile]) -> tuple[dict[str, str], dict[str, str]]: +def _item_names(session, piles: Iterable[DropPile]) -> tuple[dict[str, str], dict[str, str], dict[str, str]]: + # The view's `item_names`, `item_names_plural`, and `valuable_names`, in one walk over what the view shows. # Each id the inventories and the known piles show gets one entry, from the first place it appears. A # carried stack is named from the template it embeds, which the session gave the catalog's names, and a # pile's stack from the session's catalog, which has the items the adventure bundles. An unidentified magic @@ -1761,6 +1847,7 @@ def _item_names(session, piles: Iterable[DropPile]) -> tuple[dict[str, str], dic # pile shows a magic item by its instance id alone. names: dict[str, str] = {} plurals: dict[str, str] = {} + valuable_names: dict[str, str] = {} equipment = session.effective_equipment catalog = { template.id: template @@ -1772,6 +1859,12 @@ def add(item_id: str, singular: str, plural: str) -> None: names[item_id] = singular plurals[item_id] = plural + def add_valuable(valuable: ValuableInstance) -> None: + add(valuable.instance_id, *_VALUABLE_NAMES[valuable.kind]) + # A piece has a name of its own unless its name is empty or the one treasure generation gives its kind. + if valuable.name and valuable.name != _ROLLED_VALUABLE_NAMES[valuable.kind]: + valuable_names[valuable.instance_id] = valuable.name + def add_magic_item(instance: MagicItemInstance, *, carried: bool) -> None: if instance.identified: template = magic_item_template(instance) @@ -1788,7 +1881,7 @@ def add_magic_item(instance: MagicItemInstance, *, carried: bool) -> None: else: add(instance.template.id, instance.template.display_name, instance.template.display_name_plural) for valuable in member.inventory.valuables: - add(valuable.instance_id, *_VALUABLE_NAMES[valuable.kind]) + add_valuable(valuable) for pile in piles: for entry in pile.items: template = catalog.get(entry.item_id) @@ -1797,8 +1890,8 @@ def add_magic_item(instance: MagicItemInstance, *, carried: bool) -> None: for instance in pile.magic_items: add_magic_item(instance, carried=False) for valuable in pile.valuables: - add(valuable.instance_id, *_VALUABLE_NAMES[valuable.kind]) - return names, plurals + add_valuable(valuable) + return names, plurals, valuable_names def _quest_views(session): @@ -2043,9 +2136,11 @@ def _canonical_edge(cell: Position, direction: Direction) -> str: def _member_view(session, member) -> MemberView: """One member's sheet, read from the live character.""" - from osrlib.crawl._spells import _learnable_spells, _preparable_spells + from osrlib.crawl._spells import _learnable_spells, _preparable_spells, _prepare_now definition = member.definition + profile = caster_profile(definition) + can_prepare_now, needs_sleep_to_prepare = _prepare_now(session, member, profile) thief_skills = {} if definition.thief_skills: thief_skills = definition.thief_skills[member.level - 1].model_dump(exclude={"level"}) @@ -2087,6 +2182,9 @@ def _member_view(session, member) -> MemberView: spell_slots=definition.row(member.level).spell_slots, preparable_spells=_preparable_spells(session, member), learnable_spells=_learnable_spells(session, member), + reverses_at=None if profile is None else _reverses_at(profile), + can_prepare_now=can_prepare_now, + needs_sleep_to_prepare=needs_sleep_to_prepare, thief_skills=thief_skills, ) diff --git a/tests/saves/view_prepare_now_2.8.0.json b/tests/saves/view_prepare_now_2.8.0.json new file mode 100644 index 0000000..ac2e98d --- /dev/null +++ b/tests/saves/view_prepare_now_2.8.0.json @@ -0,0 +1,1444 @@ +{ + "engine_version": "2.8.0", + "kind": "save", + "payload": { + "adventure": { + "description": "", + "dungeons": [ + { + "id": "crypt", + "levels": [ + { + "areas": [], + "edges": { + "1,0:west": { + "door": null, + "kind": "open" + } + }, + "entrance": [ + 0, + 0 + ], + "features": [], + "guidance": "", + "height": 1, + "number": 1, + "transitions": [], + "wandering": { + "chance_in_six": 1, + "interval_turns": 2, + "table": null + }, + "width": 2 + } + ], + "name": "Crypt" + } + ], + "hooks": [], + "items": [], + "monsters": [], + "name": "A", + "party": null, + "quests": [], + "spells": [], + "town": { + "description": "", + "healing_prices": {}, + "name": "Threshold", + "services": [], + "travel_turns": { + "crypt": 1 + } + }, + "triggers": [] + }, + "allocator": { + "counters": { + "character": 7 + } + }, + "battle": null, + "clock_rounds": 3600, + "command_log": [ + { + "command_type": "rest", + "hidden": false, + "kind": "night", + "source": null + }, + { + "character_id": "character-0003", + "command_type": "prepare_spells", + "selections": [ + { + "reversed": false, + "spell_id": "light_mu" + } + ], + "source": null + }, + { + "character_id": "character-0005", + "command_type": "prepare_spells", + "selections": [ + { + "reversed": false, + "spell_id": "cure_light_wounds" + } + ], + "source": null + } + ], + "death_records": {}, + "defeated_monsters": [], + "deprivation": {}, + "dungeon_state": { + "doors": {}, + "emptied_caches": [], + "explored": {}, + "found_traps": [], + "found_tricks": [], + "generated_caches": {}, + "generated_lair_hoards": [], + "generated_treasure_areas": [], + "inspect_attempts": {}, + "listen_attempts": {}, + "location": { + "dungeon_id": null, + "facing": null, + "kind": "town", + "level_number": null, + "position": null + }, + "lock_failures": {}, + "piles": {}, + "removal_attempts": {}, + "removed_traps": [], + "resolved_encounters": [], + "search_attempts": {}, + "seen": {}, + "sprung_traps": [] + }, + "encounter": null, + "event_log": [ + { + "code": "exploration.rest.rested", + "event_type": "rested", + "kind": "night", + "visibility": "player" + }, + { + "caster_id": "character-0003", + "code": "magic.memorize.prepared", + "event_type": "spells_memorized", + "prepared": [ + { + "reversed": false, + "spell_id": "light_mu" + } + ], + "visibility": "player" + }, + { + "caster_id": "character-0005", + "code": "magic.memorize.prepared", + "event_type": "spells_memorized", + "prepared": [ + { + "reversed": false, + "spell_id": "cure_light_wounds" + } + ], + "visibility": "player" + } + ], + "exploration": { + "alerted_areas": [], + "heard_areas": [], + "last_prepared_sleep": { + "character-0003": 1, + "character-0005": 1 + }, + "noise_since_check": false, + "odometer_thirds": 0, + "provisions_day": 0, + "sleep_count": 1, + "turns_since_rest": 0, + "wandering_counter": 0 + }, + "fired_triggers": [], + "flags": {}, + "journal": [], + "ledger": { + "effects": [] + }, + "listener_state": {}, + "master_seed": 7, + "mode": "town", + "monsters": [], + "npcs": [], + "party": { + "members": [ + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0001", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 3, + "max_hp": 400, + "memorized_spells": [], + "name": "Hild", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 4000 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "elf", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0002", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 400, + "memorized_spells": [], + "name": "Aelin", + "nonregen_damage": 0, + "race": "elf", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [ + "light_mu" + ], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0003", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 3, + "max_hp": 400, + "memorized_spells": [ + { + "reversed": false, + "spell_id": "light_mu" + } + ], + "name": "Wren", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [ + "magic_missile", + "light_mu" + ], + "stat_modifiers": [], + "xp": 5000 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0004", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 400, + "memorized_spells": [], + "name": "Tam", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0005", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 4, + "max_hp": 400, + "memorized_spells": [ + { + "reversed": false, + "spell_id": "cure_light_wounds" + } + ], + "name": "Mara", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 6000 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "sage", + "conditions": [], + "current_hp": 400, + "custom_class": { + "abilities": [ + { + "manual": false, + "name": "Arcane Magic", + "params": { + "spell_list": "cleric" + }, + "prose": "See Spells for full details on arcane magic.\nMagical research: A magic-user of any level may spend time and money on magical research. This allows them to add new spells to their spell book and to research other magical effects. When a magic-user reaches 9th level, they are also able to create magic items.\nSpell casting: Magic-users own spell books containing the formulae for arcane spells. The level progression table (below) shows both the number of spells in the magic-user\u2019s spell book and the number they may memorize, determined by the character\u2019s experience level. Thus, a 1st level magic-user has one spell in their spell book, selected by the referee (who may allow the player to choose). The list of spells available to magic-users is found in Magic-User Spells.\nUsing magic items: As spell casters, magic-users are able to use magic scrolls of spells on their spell list. They can also use items that may only be used by arcane spell casters (e.g. magic wands).", + "tag": "arcane_magic" + } + ], + "armour": { + "kind": "none", + "shields_allowed": false + }, + "hit_die": 4, + "id": "sage", + "languages": [ + "common" + ], + "level_titles": [ + "Medium", + "Seer", + "Conjurer", + "Magician", + "Enchanter (Enchantress)", + "Warlock (Witch)", + "Sorcerer (Sorceress)", + "Necromancer", + "Wizard" + ], + "max_level": 14, + "may_not_lower": [], + "name": "Sage", + "overrides_applied": [], + "prime_requisites": [ + "int" + ], + "progression": [ + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 1, + "die": 4 + }, + "level": 1, + "saves": { + "breath": 16, + "death": 13, + "paralysis": 13, + "spells": 15, + "wands": 14 + }, + "spell_slots": [ + 1, + 0, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 0 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 2, + "die": 4 + }, + "level": 2, + "saves": { + "breath": 16, + "death": 13, + "paralysis": 13, + "spells": 15, + "wands": 14 + }, + "spell_slots": [ + 2, + 0, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 2500 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 3, + "die": 4 + }, + "level": 3, + "saves": { + "breath": 16, + "death": 13, + "paralysis": 13, + "spells": 15, + "wands": 14 + }, + "spell_slots": [ + 2, + 1, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 5000 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 4, + "die": 4 + }, + "level": 4, + "saves": { + "breath": 16, + "death": 13, + "paralysis": 13, + "spells": 15, + "wands": 14 + }, + "spell_slots": [ + 2, + 2, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 10000 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 5, + "die": 4 + }, + "level": 5, + "saves": { + "breath": 16, + "death": 13, + "paralysis": 13, + "spells": 15, + "wands": 14 + }, + "spell_slots": [ + 2, + 2, + 1, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 20000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 6, + "die": 4 + }, + "level": 6, + "saves": { + "breath": 14, + "death": 11, + "paralysis": 11, + "spells": 12, + "wands": 12 + }, + "spell_slots": [ + 2, + 2, + 2, + 0, + 0, + 0 + ], + "thac0": 17, + "xp": 40000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 7, + "die": 4 + }, + "level": 7, + "saves": { + "breath": 14, + "death": 11, + "paralysis": 11, + "spells": 12, + "wands": 12 + }, + "spell_slots": [ + 3, + 2, + 2, + 1, + 0, + 0 + ], + "thac0": 17, + "xp": 80000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 8, + "die": 4 + }, + "level": 8, + "saves": { + "breath": 14, + "death": 11, + "paralysis": 11, + "spells": 12, + "wands": 12 + }, + "spell_slots": [ + 3, + 3, + 2, + 2, + 0, + 0 + ], + "thac0": 17, + "xp": 150000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 9, + "die": 4 + }, + "level": 9, + "saves": { + "breath": 14, + "death": 11, + "paralysis": 11, + "spells": 12, + "wands": 12 + }, + "spell_slots": [ + 3, + 3, + 3, + 2, + 1, + 0 + ], + "thac0": 17, + "xp": 300000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 1, + "con_applies": false, + "count": 9, + "die": 4 + }, + "level": 10, + "saves": { + "breath": 14, + "death": 11, + "paralysis": 11, + "spells": 12, + "wands": 12 + }, + "spell_slots": [ + 3, + 3, + 3, + 3, + 2, + 0 + ], + "thac0": 17, + "xp": 450000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 2, + "con_applies": false, + "count": 9, + "die": 4 + }, + "level": 11, + "saves": { + "breath": 11, + "death": 8, + "paralysis": 8, + "spells": 8, + "wands": 9 + }, + "spell_slots": [ + 4, + 3, + 3, + 3, + 2, + 1 + ], + "thac0": 14, + "xp": 600000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 3, + "con_applies": false, + "count": 9, + "die": 4 + }, + "level": 12, + "saves": { + "breath": 11, + "death": 8, + "paralysis": 8, + "spells": 8, + "wands": 9 + }, + "spell_slots": [ + 4, + 4, + 3, + 3, + 3, + 2 + ], + "thac0": 14, + "xp": 750000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 4, + "con_applies": false, + "count": 9, + "die": 4 + }, + "level": 13, + "saves": { + "breath": 11, + "death": 8, + "paralysis": 8, + "spells": 8, + "wands": 9 + }, + "spell_slots": [ + 4, + 4, + 4, + 3, + 3, + 3 + ], + "thac0": 14, + "xp": 900000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 5, + "con_applies": false, + "count": 9, + "die": 4 + }, + "level": 14, + "saves": { + "breath": 11, + "death": 8, + "paralysis": 8, + "spells": 8, + "wands": 9 + }, + "spell_slots": [ + 4, + 4, + 4, + 4, + 3, + 3 + ], + "thac0": 14, + "xp": 1050000 + } + ], + "race": "human", + "requirements": {}, + "thief_skills": [], + "weapons": { + "kind": "allowed", + "manual_notes": [], + "weapon_ids": [ + "dagger" + ] + }, + "xp_tiers": [ + { + "minimums": { + "int": 16 + }, + "modifier_pct": 10 + }, + { + "minimums": { + "int": 13 + }, + "modifier_pct": 5 + }, + { + "minimums": { + "int": 9 + }, + "modifier_pct": 0 + }, + { + "minimums": { + "int": 6 + }, + "modifier_pct": -10 + }, + { + "minimums": { + "int": 3 + }, + "modifier_pct": -20 + } + ] + }, + "extra_languages": [], + "id": "character-0006", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 400, + "memorized_spells": [], + "name": "Sefa", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [ + "cure_light_wounds" + ], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "warden", + "conditions": [], + "current_hp": 400, + "custom_class": { + "abilities": [ + { + "manual": false, + "name": "Divine Magic", + "params": { + "spell_list": "cleric" + }, + "prose": "See Spells for full details on divine magic.\nHoly symbol: A cleric must carry a holy symbol (see Adventuring Gear).\nDeity disfavour: Clerics must be faithful to the tenets of their alignment, clergy, and religion. Clerics who fall from favour with their deity may incur penalties.\nMagical research: A cleric of any level may spend time and money on magical research. This allows them to create new spells or other magical effects associated with their deity. When a cleric reaches 9th level, they are also able to create magic items.\nSpell casting: Once a cleric has proven their faith (from 2nd level), the character may pray to receive spells. The level progression table (below) shows the number of spells a cleric may memorize, based on their experience level. The list of spells available to clerics is found in Cleric Spells.\nUsing magic items: As spell casters, clerics can use magic scrolls of spells on their spell list. They can also use items that may only be used by divine spell casters (e.g. some magic staves).", + "tag": "divine_magic" + }, + { + "manual": false, + "name": "Turning the Undead", + "params": {}, + "prose": "Clerics can invoke the power of their deity to repel undead monsters encountered. To turn the undead, the player rolls 2d6. The referee then consults the table below, comparing the roll against the HD of the type of undead monsters targeted.", + "tag": "turn_undead" + } + ], + "armour": { + "kind": "any", + "shields_allowed": true + }, + "hit_die": 6, + "id": "warden", + "languages": [ + "common" + ], + "level_titles": [ + "Acolyte", + "Adept", + "Priest(ess)", + "Vicar", + "Curate", + "Elder", + "Bishop", + "Lama", + "Matriarch (Patriarch)" + ], + "max_level": 14, + "may_not_lower": [], + "name": "Warden", + "overrides_applied": [], + "prime_requisites": [ + "wis" + ], + "progression": [ + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 1, + "die": 6 + }, + "level": 1, + "saves": { + "breath": 16, + "death": 11, + "paralysis": 14, + "spells": 15, + "wands": 12 + }, + "spell_slots": [ + 0, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 0 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 2, + "die": 6 + }, + "level": 2, + "saves": { + "breath": 16, + "death": 11, + "paralysis": 14, + "spells": 15, + "wands": 12 + }, + "spell_slots": [ + 1, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 1500 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 3, + "die": 6 + }, + "level": 3, + "saves": { + "breath": 16, + "death": 11, + "paralysis": 14, + "spells": 15, + "wands": 12 + }, + "spell_slots": [ + 2, + 0, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 3000 + }, + { + "attack_bonus": 0, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 4, + "die": 6 + }, + "level": 4, + "saves": { + "breath": 16, + "death": 11, + "paralysis": 14, + "spells": 15, + "wands": 12 + }, + "spell_slots": [ + 2, + 1, + 0, + 0, + 0 + ], + "thac0": 19, + "xp": 6000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 5, + "die": 6 + }, + "level": 5, + "saves": { + "breath": 14, + "death": 9, + "paralysis": 12, + "spells": 12, + "wands": 10 + }, + "spell_slots": [ + 2, + 2, + 0, + 0, + 0 + ], + "thac0": 17, + "xp": 12000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 6, + "die": 6 + }, + "level": 6, + "saves": { + "breath": 14, + "death": 9, + "paralysis": 12, + "spells": 12, + "wands": 10 + }, + "spell_slots": [ + 2, + 2, + 1, + 1, + 0 + ], + "thac0": 17, + "xp": 25000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 7, + "die": 6 + }, + "level": 7, + "saves": { + "breath": 14, + "death": 9, + "paralysis": 12, + "spells": 12, + "wands": 10 + }, + "spell_slots": [ + 2, + 2, + 2, + 1, + 1 + ], + "thac0": 17, + "xp": 50000 + }, + { + "attack_bonus": 2, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 8, + "die": 6 + }, + "level": 8, + "saves": { + "breath": 14, + "death": 9, + "paralysis": 12, + "spells": 12, + "wands": 10 + }, + "spell_slots": [ + 3, + 3, + 2, + 2, + 1 + ], + "thac0": 17, + "xp": 100000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 0, + "con_applies": true, + "count": 9, + "die": 6 + }, + "level": 9, + "saves": { + "breath": 11, + "death": 6, + "paralysis": 9, + "spells": 9, + "wands": 7 + }, + "spell_slots": [ + 3, + 3, + 3, + 2, + 2 + ], + "thac0": 14, + "xp": 200000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 1, + "con_applies": false, + "count": 9, + "die": 6 + }, + "level": 10, + "saves": { + "breath": 11, + "death": 6, + "paralysis": 9, + "spells": 9, + "wands": 7 + }, + "spell_slots": [ + 4, + 4, + 3, + 3, + 2 + ], + "thac0": 14, + "xp": 300000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 2, + "con_applies": false, + "count": 9, + "die": 6 + }, + "level": 11, + "saves": { + "breath": 11, + "death": 6, + "paralysis": 9, + "spells": 9, + "wands": 7 + }, + "spell_slots": [ + 4, + 4, + 4, + 3, + 3 + ], + "thac0": 14, + "xp": 400000 + }, + { + "attack_bonus": 5, + "hit_dice": { + "bonus": 3, + "con_applies": false, + "count": 9, + "die": 6 + }, + "level": 12, + "saves": { + "breath": 11, + "death": 6, + "paralysis": 9, + "spells": 9, + "wands": 7 + }, + "spell_slots": [ + 5, + 5, + 4, + 4, + 3 + ], + "thac0": 14, + "xp": 500000 + }, + { + "attack_bonus": 7, + "hit_dice": { + "bonus": 4, + "con_applies": false, + "count": 9, + "die": 6 + }, + "level": 13, + "saves": { + "breath": 8, + "death": 3, + "paralysis": 7, + "spells": 7, + "wands": 5 + }, + "spell_slots": [ + 5, + 5, + 5, + 4, + 4 + ], + "thac0": 12, + "xp": 600000 + }, + { + "attack_bonus": 7, + "hit_dice": { + "bonus": 5, + "con_applies": false, + "count": 9, + "die": 6 + }, + "level": 14, + "saves": { + "breath": 8, + "death": 3, + "paralysis": 7, + "spells": 7, + "wands": 5 + }, + "spell_slots": [ + 6, + 5, + 5, + 5, + 4 + ], + "thac0": 12, + "xp": 700000 + } + ], + "race": "human", + "requirements": {}, + "thief_skills": [], + "weapons": { + "kind": "allowed", + "manual_notes": [], + "weapon_ids": [ + "club", + "mace", + "sling", + "staff", + "war_hammer" + ] + }, + "xp_tiers": [ + { + "minimums": { + "wis": 16 + }, + "modifier_pct": 10 + }, + { + "minimums": { + "wis": 13 + }, + "modifier_pct": 5 + }, + { + "minimums": { + "wis": 9 + }, + "modifier_pct": 0 + }, + { + "minimums": { + "wis": 6 + }, + "modifier_pct": -10 + }, + { + "minimums": { + "wis": 3 + }, + "modifier_pct": -20 + } + ] + }, + "extra_languages": [], + "id": "character-0007", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 2, + "max_hp": 400, + "memorized_spells": [], + "name": "Bryn", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [ + "cure_light_wounds" + ], + "stat_modifiers": [], + "xp": 1500 + } + ] + }, + "quests": {}, + "rng_streams": { + "effects": { + "inc": 110921974297112361420962594425958014099, + "state": 323578275112908533770403587567316273018 + } + }, + "ruleset": { + "aoe_friendly_fire": true, + "back_stab_needs_both_skills": true, + "deprivation_penalties": false, + "encumbrance": "basic", + "failed_trap_removal_springs": true, + "formation_width_limit": true, + "hd5_counts_as_magical": false, + "hp_reroll_at_first_level": false, + "individual_initiative": false, + "magic_item_death_save": true, + "thac0_arithmetic": false, + "variable_weapon_damage": true, + "weapon_reload": false, + "xp_award_timing": "on_return" + }, + "treasure_snapshot_cp": null + }, + "schema_version": 4 +} diff --git a/tests/saves/view_valuable_names_2.8.0.json b/tests/saves/view_valuable_names_2.8.0.json new file mode 100644 index 0000000..4459f02 --- /dev/null +++ b/tests/saves/view_valuable_names_2.8.0.json @@ -0,0 +1,1027 @@ +{ + "engine_version": "2.8.0", + "kind": "save", + "payload": { + "adventure": { + "description": "", + "dungeons": [ + { + "id": "priory", + "levels": [ + { + "areas": [ + { + "cells": [ + [ + 0, + 0 + ] + ], + "description": "", + "encounter": null, + "features": [ + { + "cell": [ + 0, + 0 + ], + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "description": "A lead-lined reliquary.", + "id": "reliquary", + "item_ids": [], + "kind": "treasure_cache", + "magic_item_ids": [], + "referee_notes": "", + "trap": null, + "valuables": [ + { + "kind": "jewellery", + "name": "Prior's chain of office", + "value_gp": 1200, + "weight_coins": 0 + }, + { + "kind": "jewellery", + "name": "Ring of the drowned abbot", + "value_gp": 900, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "Eye of Ossor", + "value_gp": 500, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "Star of the lower chapel", + "value_gp": 400, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "", + "value_gp": 50, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "", + "value_gp": 60, + "weight_coins": 0 + }, + { + "kind": "jewellery", + "name": "", + "value_gp": 300, + "weight_coins": 0 + }, + { + "kind": "jewellery", + "name": "", + "value_gp": 350, + "weight_coins": 0 + } + ] + } + ], + "id": "nave", + "name": "Nave", + "trap": null, + "treasure": { + "letters": [ + "C" + ], + "unguarded": false + } + }, + { + "cells": [ + [ + 2, + 0 + ] + ], + "description": "", + "encounter": null, + "features": [ + { + "cell": [ + 2, + 0 + ], + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "description": "A sealed tomb.", + "id": "tomb", + "item_ids": [], + "kind": "treasure_cache", + "magic_item_ids": [], + "referee_notes": "", + "trap": null, + "valuables": [ + { + "kind": "jewellery", + "name": "Bishop's mitre jewel", + "value_gp": 800, + "weight_coins": 0 + } + ] + } + ], + "id": "crypt", + "name": "Crypt", + "trap": null, + "treasure": null + } + ], + "edges": {}, + "entrance": [ + 0, + 0 + ], + "features": [], + "guidance": "", + "height": 1, + "number": 1, + "transitions": [], + "wandering": { + "chance_in_six": 1, + "interval_turns": 2, + "table": null + }, + "width": 3 + } + ], + "name": "The Priory" + } + ], + "hooks": [], + "items": [], + "monsters": [], + "name": "The Drowned Priory", + "party": null, + "quests": [], + "spells": [], + "town": { + "description": "", + "healing_prices": {}, + "name": "Threshold", + "services": [], + "travel_turns": { + "priory": 1 + } + }, + "triggers": [] + }, + "allocator": { + "counters": { + "cache": 1, + "character": 4, + "valuable": 13 + } + }, + "battle": null, + "clock_rounds": 180, + "command_log": [ + { + "command_type": "enter_dungeon", + "dungeon_id": "priory", + "source": null + }, + { + "command_type": "take_treasure", + "feature_id": "feature:7330e36966ca939e30075bc8cce1cfec46f480dc740b854b21cc58bdd5cad108", + "recipient_id": null, + "source": null + }, + { + "command_type": "take_treasure", + "feature_id": "feature:d6b53fd7fc03f4d7bcb32a1c95f71e4d8ec467ba7834d23422283c12cc644640", + "recipient_id": null, + "source": null + }, + { + "character_id": "character-0002", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "valuable-0007" + ], + "source": null + }, + { + "character_id": "character-0004", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "valuable-0009" + ], + "source": null + }, + { + "character_id": "character-0004", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "valuable-0011" + ], + "source": null + }, + { + "character_id": "character-0004", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "valuable-0013" + ], + "source": null + }, + { + "character_id": "character-0001", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "valuable-0003" + ], + "source": null + }, + { + "character_id": "character-0003", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "valuable-0004" + ], + "source": null + } + ], + "death_records": {}, + "defeated_monsters": [], + "deprivation": {}, + "dungeon_state": { + "doors": {}, + "emptied_caches": [ + "priory:1:reliquary" + ], + "explored": { + "priory:1": [ + [ + 0, + 0 + ] + ] + }, + "found_traps": [], + "found_tricks": [], + "generated_caches": {}, + "generated_lair_hoards": [], + "generated_treasure_areas": [ + "priory:1:nave" + ], + "inspect_attempts": {}, + "listen_attempts": {}, + "location": { + "dungeon_id": "priory", + "facing": "north", + "kind": "dungeon", + "level_number": 1, + "position": [ + 0, + 0 + ] + }, + "lock_failures": {}, + "piles": { + "cell:priory:1:0,0": { + "coins": { + "cp": 623, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "items": [], + "magic_items": [], + "valuables": [ + { + "instance_id": "valuable-0007", + "instance_type": "valuable", + "kind": "jewellery", + "name": "Ring of the drowned abbot", + "value_gp": 900, + "weight_coins": 0 + }, + { + "instance_id": "valuable-0009", + "instance_type": "valuable", + "kind": "gem", + "name": "Star of the lower chapel", + "value_gp": 400, + "weight_coins": 0 + }, + { + "instance_id": "valuable-0011", + "instance_type": "valuable", + "kind": "gem", + "name": "", + "value_gp": 60, + "weight_coins": 0 + }, + { + "instance_id": "valuable-0013", + "instance_type": "valuable", + "kind": "jewellery", + "name": "", + "value_gp": 350, + "weight_coins": 0 + }, + { + "instance_id": "valuable-0003", + "instance_type": "valuable", + "kind": "gem", + "name": "Gem", + "value_gp": 500, + "weight_coins": 1 + }, + { + "instance_id": "valuable-0004", + "instance_type": "valuable", + "kind": "jewellery", + "name": "Jewellery", + "value_gp": 600, + "weight_coins": 10 + } + ] + } + }, + "removal_attempts": {}, + "removed_traps": [], + "resolved_encounters": [], + "search_attempts": {}, + "seen": {}, + "sprung_traps": [] + }, + "encounter": null, + "event_log": [ + { + "code": "exploration.location.entered", + "dungeon_id": null, + "event_type": "location_entered", + "level_number": 1, + "location_id": "priory", + "location_kind": "dungeon", + "narrative": null, + "transition_ref": null, + "via": "entrance", + "visibility": "player" + }, + { + "code": "exploration.location.entered", + "dungeon_id": "priory", + "event_type": "location_entered", + "level_number": 1, + "location_id": "nave", + "location_kind": "area", + "narrative": null, + "transition_ref": null, + "via": null, + "visibility": "player" + }, + { + "cache_ref": "cache-0001", + "code": "treasure.hoard.generated", + "coins": { + "cp": 5000, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 2000 + }, + "coins_gp_value": 250, + "event_type": "hoard_generated", + "magic_item_ids": [], + "treasure_types": [ + "C" + ], + "valuable_ids": [ + "valuable-0001", + "valuable-0002", + "valuable-0003", + "valuable-0004", + "valuable-0005" + ], + "visibility": "referee" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0006" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0002", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0007" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0003", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0008", + "valuable-0012", + "valuable-0010" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0004", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0009", + "valuable-0013", + "valuable-0011" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 1099, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "coins_gp_value": 60, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0003" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0002", + "code": "exploration.item.acquired", + "coins": { + "cp": 1098, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "coins_gp_value": 60, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0002", + "valuable-0001" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0003", + "code": "exploration.item.acquired", + "coins": { + "cp": 1090, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "coins_gp_value": 60, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0004" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "character_id": "character-0004", + "code": "exploration.item.acquired", + "coins": { + "cp": 1090, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "coins_gp_value": 60, + "event_type": "item_acquired", + "item_ids": [ + "valuable-0005" + ], + "origin": "treasure", + "visibility": "player" + }, + { + "code": "exploration.item.left_behind", + "coins": { + "cp": 623, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 6, + "event_type": "items_left_behind", + "item_ids": [], + "visibility": "player" + }, + { + "chance": 1, + "code": "exploration.wandering.checked", + "encounter": false, + "event_type": "wandering_check", + "roll": 4, + "visibility": "referee" + }, + { + "character_id": "character-0002", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "valuable-0007" + ], + "visibility": "player" + }, + { + "character_id": "character-0004", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "valuable-0009" + ], + "visibility": "player" + }, + { + "character_id": "character-0004", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "valuable-0011" + ], + "visibility": "player" + }, + { + "character_id": "character-0004", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "valuable-0013" + ], + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "valuable-0003" + ], + "visibility": "player" + }, + { + "character_id": "character-0003", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "valuable-0004" + ], + "visibility": "player" + } + ], + "exploration": { + "alerted_areas": [], + "heard_areas": [], + "last_prepared_sleep": {}, + "noise_since_check": false, + "odometer_thirds": 0, + "provisions_day": 0, + "sleep_count": 0, + "turns_since_rest": 2, + "wandering_counter": 0 + }, + "fired_triggers": [], + "flags": {}, + "journal": [], + "ledger": { + "effects": [] + }, + "listener_state": {}, + "master_seed": 27, + "mode": "exploring", + "monsters": [], + "npcs": [], + "party": { + "members": [ + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0001", + "inventory": { + "items": [], + "purse": { + "cp": 1099, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "rings": [], + "shield": null, + "valuables": [ + { + "instance_id": "valuable-0006", + "instance_type": "valuable", + "kind": "jewellery", + "name": "Prior's chain of office", + "value_gp": 1200, + "weight_coins": 0 + } + ], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Brakk", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "thief", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0002", + "inventory": { + "items": [], + "purse": { + "cp": 1098, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "rings": [], + "shield": null, + "valuables": [ + { + "instance_id": "valuable-0002", + "instance_type": "valuable", + "kind": "gem", + "name": "Gem", + "value_gp": 500, + "weight_coins": 1 + }, + { + "instance_id": "valuable-0001", + "instance_type": "valuable", + "kind": "gem", + "name": "Gem", + "value_gp": 10, + "weight_coins": 1 + } + ], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Sable", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0003", + "inventory": { + "items": [], + "purse": { + "cp": 1090, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "rings": [], + "shield": null, + "valuables": [ + { + "instance_id": "valuable-0008", + "instance_type": "valuable", + "kind": "gem", + "name": "Eye of Ossor", + "value_gp": 500, + "weight_coins": 0 + }, + { + "instance_id": "valuable-0012", + "instance_type": "valuable", + "kind": "jewellery", + "name": "", + "value_gp": 300, + "weight_coins": 0 + }, + { + "instance_id": "valuable-0010", + "instance_type": "valuable", + "kind": "gem", + "name": "", + "value_gp": 50, + "weight_coins": 0 + } + ], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Wynn", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 13 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0004", + "inventory": { + "items": [], + "purse": { + "cp": 1090, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 500 + }, + "rings": [], + "shield": null, + "valuables": [ + { + "instance_id": "valuable-0005", + "instance_type": "valuable", + "kind": "jewellery", + "name": "Jewellery", + "value_gp": 1100, + "weight_coins": 10 + } + ], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Elara", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [ + "sleep" + ], + "stat_modifiers": [], + "xp": 0 + } + ] + }, + "quests": {}, + "rng_streams": { + "effects": { + "inc": 161704555315776110171764090639480678751, + "state": 109108230614976479328307440680952588028 + }, + "treasure": { + "inc": 322451513583708784342284873492055170771, + "state": 217063782945546774946961329956136329198 + }, + "wandering": { + "inc": 152606351475272007436479506050361165153, + "state": 46619059622755885719013782209138395214 + } + }, + "ruleset": { + "aoe_friendly_fire": true, + "back_stab_needs_both_skills": true, + "deprivation_penalties": false, + "encumbrance": "basic", + "failed_trap_removal_springs": true, + "formation_width_limit": true, + "hd5_counts_as_magical": false, + "hp_reroll_at_first_level": false, + "individual_initiative": false, + "magic_item_death_save": true, + "thac0_arithmetic": false, + "variable_weapon_damage": true, + "weapon_reload": false, + "xp_award_timing": "on_return" + }, + "treasure_snapshot_cp": 0 + }, + "schema_version": 4 +} diff --git a/tests/test_view_prepare_now.py b/tests/test_view_prepare_now.py new file mode 100644 index 0000000..8d484bd --- /dev/null +++ b/tests/test_view_prepare_now.py @@ -0,0 +1,485 @@ +"""The member view says when a caster picks a spell's form, and whether they can prepare now (issue #338). + +A remote front end builds its prepare dialog, its cast dialog, and its town screen from `PlayerView` alone. Before, +the view didn't say which kind of caster a member is, so a client inferred it from the spell book, and it didn't +show the sleep rule's state, so a client read the event log for the last rest and the last preparation, which a +client that restored a save doesn't have. `MemberView.reverses_at`, `MemberView.can_prepare_now`, and +`MemberView.needs_sleep_to_prepare` state the three facts, from the checks `PrepareSpells` makes. + +The rules are the OSE SRD's Rules of Magic. Arcane casters: "The normal or reversed form of a spell must be selected +when the spell is memorized." Divine casters: "Divine spell casters can cast the reversed version of a spell by +speaking the words and performing the gestures backwards when it is cast." And for both: "A spell caster can memorize +new spells once a day, after an uninterrupted night’s sleep." +""" + +import json +from collections.abc import Callable +from pathlib import Path + +import pytest + +import positions_fixtures as pf +from osrlib.core.abilities import AbilityScore +from osrlib.core.character import Character +from osrlib.core.classes import ClassDefinition +from osrlib.core.combat import incapacitated +from osrlib.core.effects import Condition, grant_condition +from osrlib.core.events import Visibility +from osrlib.core.items import MagicItemInstance +from osrlib.core.spells import MemorizedSpell +from osrlib.crawl.commands import EnterDungeon, PrepareSpells, Rest, SpawnMonsters +from osrlib.crawl.party import Party +from osrlib.crawl.session import GameSession +from osrlib.crawl.views import MemberView, PlayerView +from osrlib.data import load_classes +from osrlib.persistence import load_game, save_game + +SAVE_2_8_0 = Path(__file__).parent / "saves" / "view_prepare_now_2.8.0.json" +"""A save of `scenario("prepared")`, written by osrlib 2.8.0 before the three fields existed.""" + +MOMENT_CODES = {"session.command.wrong_mode", "session.command.member_incapacitated", "magic.memorize.needs_sleep"} +"""The codes by which `PrepareSpells` refuses a caster for the moment, whatever the selection.""" + + +# ---------------------------------------------------------------------- the party + + +def _custom(base_id: str, class_id: str, tag: str) -> ClassDefinition: + """A class of your own with `base_id`'s progression, whose casting ability is `tag` on the cleric's list.""" + document = load_classes().get(base_id).model_dump(mode="json") + document.update(id=class_id, name=class_id.title()) + document["abilities"] = [ + {**ability, "tag": tag, "params": {"spell_list": "cleric"}} + if ability["tag"] in ("arcane_magic", "divine_magic") + else ability + for ability in document["abilities"] + ] + return ClassDefinition.model_validate(document) + + +SAGE = _custom("magic_user", "sage", "arcane_magic") +"""An arcane class that casts from the cleric's list, with the magic-user's progression.""" +WARDEN = _custom("cleric", "warden", "divine_magic") +"""A divine class that casts from the cleric's list, with the cleric's progression.""" + + +def member(name: str, class_id: str, level: int, *book: str) -> Character: + """A built-in-class character at `level`, with `book` as the spell book.""" + return Character.model_validate({**pf.character(name, class_id, level=level).model_dump(), "spell_book": book}) + + +def custom(name: str, definition: ClassDefinition, level: int, *book: str) -> Character: + return Character( + name=name, + class_id=definition.id, + custom_class=definition, + race="human", + level=level, + xp=definition.row(level).xp, + scores={ability: 10 for ability in AbilityScore}, + alignment="lawful", + max_hp=400, + current_hp=400, + spell_book=book, + ) + + +def party() -> Party: + """Casters of each kind, two of them of classes of your own, beside a fighter who casts nothing. + + - Hild, a 3rd-level fighter, casts nothing. + - Aelin, a 1st-level elf, and Wren, a 3rd-level magic-user, are arcane casters whose books hold *light*. + - Tam, a 1st-level cleric, has no slots, and Mara, a 4th-level cleric, has three. + - Sefa, a 1st-level sage, and Bryn, a 2nd-level warden, have the same spell book, *cure light wounds*, and cast + from the same list, the cleric's. Sefa's class is arcane and Bryn's divine, so they differ only in their kind. + `Character` doesn't tie a spell book to the kind of caster, so Bryn, a divine caster, has a book, and a client + that inferred the kind from the book would take Bryn for an arcane caster. + """ + return Party( + members=[ + member("Hild", "fighter", 3), + member("Aelin", "elf", 1, "light_mu"), + member("Wren", "magic_user", 3, "magic_missile", "light_mu"), + member("Tam", "cleric", 1), + member("Mara", "cleric", 4), + custom("Sefa", SAGE, 1, "cure_light_wounds"), + custom("Bryn", WARDEN, 2, "cure_light_wounds"), + ] + ) + + +CASTERS = ("Aelin", "Wren", "Tam", "Mara", "Sefa", "Bryn") + +REVERSES_AT = { + "Hild": None, + "Aelin": "memorize", + "Wren": "memorize", + "Tam": "cast", + "Mara": "cast", + "Sefa": "memorize", + "Bryn": "cast", +} + +REVERSIBLE = { + "Hild": "light_c", + "Aelin": "light_mu", + "Wren": "light_mu", + "Tam": "cure_light_wounds", + "Mara": "cure_light_wounds", + "Sefa": "cure_light_wounds", + "Bryn": "cure_light_wounds", +} +"""A spell on each member's list that reverses: *light* reverses into *darkness*, and *cure light wounds* into +*cause light wounds*. The fighter has no list, so any spell does.""" + + +# ---------------------------------------------------------------------- the moments + + +def _prepare(game: GameSession, name: str, *spell_ids: str) -> None: + selections = tuple(MemorizedSpell(spell_id=spell_id) for spell_id in spell_ids) + result = game.execute(PrepareSpells(character_id=pf.named(game, name), selections=selections)) + assert result.accepted, (name, [rejection.code for rejection in result.rejections]) + + +def _new(seed: int = 7) -> GameSession: + return GameSession.new(party(), pf.corridor(), seed=seed) + + +def _slept(seed: int = 7) -> GameSession: + game = _new(seed) + assert game.execute(Rest(kind="night")).accepted + return game + + +def _prepared(seed: int = 7) -> GameSession: + """After a night's rest, Wren prepares *light* and Mara *cure light wounds*. Nobody else prepares.""" + game = _slept(seed) + _prepare(game, "Wren", "light_mu") + _prepare(game, "Mara", "cure_light_wounds") + return game + + +def _slept_again(seed: int = 7) -> GameSession: + game = _prepared(seed) + assert game.execute(Rest(kind="night")).accepted + return game + + +def _encounter(seed: int = 7) -> GameSession: + """The prepared party walks into the corridor and meets a goblin.""" + game = _prepared(seed) + assert game.execute(EnterDungeon(dungeon_id="crypt")).accepted + assert game.execute(SpawnMonsters(template_id="goblin", count_fixed=1, distance_feet=60)).accepted + assert game.mode.value in ("encounter", "battle") + return game + + +def _incapacitated(seed: int = 7) -> GameSession: + """The prepared party in town, with Aelin and Wren asleep under a spell and Tam dead.""" + game = _prepared(seed) + for name in ("Aelin", "Wren"): + grant_condition(game.member(pf.named(game, name)), Condition.ASLEEP, None) + tam = game.member(pf.named(game, "Tam")) + tam.current_hp = 0 + grant_condition(tam, Condition.DEAD, None) + return game + + +SCENARIOS: dict[str, Callable[..., GameSession]] = { + "new": _new, + "slept": _slept, + "prepared": _prepared, + "slept_again": _slept_again, + "encounter": _encounter, + "incapacitated": _incapacitated, +} + + +def scenario(name: str, seed: int = 7) -> GameSession: + return SCENARIOS[name](seed) + + +CAN = (True, False) +"""`(can_prepare_now, needs_sleep_to_prepare)` for a caster who may prepare now.""" +SLEEP = (False, True) +"""For a caster the sleep rule refuses, in town.""" +NEITHER = (False, False) +"""For a member who casts nothing, and for a caster who has slept but whom the moment refuses.""" + + +def _moment(default: tuple[bool, bool], **names: tuple[bool, bool]) -> dict[str, tuple[bool, bool]]: + return {"Hild": NEITHER, **dict.fromkeys(CASTERS, default), **names} + + +EXPECTED = { + # The party hasn't slept in a new session, so every caster needs a night's sleep first. + "new": _moment(SLEEP), + "slept": _moment(CAN), + # Wren and Mara prepared after the party's one sleep, so they need another. The others haven't prepared since it. + "prepared": _moment(CAN, Wren=SLEEP, Mara=SLEEP), + "slept_again": _moment(CAN), + # Nobody can prepare in an encounter (`session.command.wrong_mode`), and the sleep fact doesn't change. + "encounter": _moment(NEITHER, Wren=SLEEP, Mara=SLEEP), + # Aelin and Wren are asleep, and Tam is dead (`session.command.member_incapacitated`). + "incapacitated": _moment(CAN, Aelin=NEITHER, Wren=SLEEP, Tam=NEITHER, Mara=SLEEP), +} + + +def _player_view(game: GameSession) -> PlayerView: + view = game.view(Visibility.PLAYER) + assert isinstance(view, PlayerView) + return view + + +def _sheet(view: PlayerView, name: str) -> MemberView: + return next(sheet for sheet in view.party if sheet.name == name) + + +def _moments(view: PlayerView) -> dict[str, tuple[bool, bool]]: + return {sheet.name: (sheet.can_prepare_now, sheet.needs_sleep_to_prepare) for sheet in view.party} + + +def _fields(view: PlayerView) -> dict[str, tuple[str | None, bool, bool]]: + return { + sheet.name: (sheet.reverses_at, sheet.can_prepare_now, sheet.needs_sleep_to_prepare) for sheet in view.party + } + + +# ---------------------------------------------------------------------- when a caster picks a spell's form + + +def _members() -> list: + """Every member, the fighter included, whose `reverses_at` is `None`.""" + return list(REVERSES_AT) + + +@pytest.mark.parametrize("name", _members()) +def test_each_member_says_when_they_choose_a_spells_form(name): + sheet = _sheet(_player_view(scenario("slept")), name) + + assert sheet.reverses_at == REVERSES_AT[name] + + +@pytest.mark.parametrize("name", _members()) +def test_reverses_at_agrees_with_the_refusal_of_a_reversed_selection(name): + """One reversed copy of a spell that reverses, from each member who has slept. + + An arcane caster's is accepted. A divine caster's is refused with `magic.memorize.divine_reverses_at_cast` alone, + even Tam's, who has no slot for it, because the session doesn't count a copy it refuses for its form. The + fighter's is refused with `magic.memorize.not_a_caster`. + """ + game = scenario("slept") + sheet = _sheet(_player_view(game), name) + reversed_copy = MemorizedSpell(spell_id=REVERSIBLE[name], reversed=True) + + result = game.execute(PrepareSpells(character_id=sheet.id, selections=(reversed_copy,))) + + codes = [rejection.code for rejection in result.rejections] + expected = { + "memorize": [], + "cast": ["magic.memorize.divine_reverses_at_cast"], + None: ["magic.memorize.not_a_caster"], + }[sheet.reverses_at] + assert codes == expected + assert sheet.reverses_at == REVERSES_AT[name] + + +def test_the_kind_comes_from_the_class_and_not_from_the_book(): + """Sefa and Bryn have the same book and the same list, and only their classes' casting tags differ.""" + view = _player_view(scenario("slept")) + sefa, bryn = _sheet(view, "Sefa"), _sheet(view, "Bryn") + + assert sefa.spell_book == bryn.spell_book == ("cure_light_wounds",) + assert (sefa.reverses_at, bryn.reverses_at) == ("memorize", "cast") + + +def test_reverses_at_doesnt_change_with_the_moment(): + """The kind is the class's, so it's the same before the party sleeps, during an encounter, and while asleep.""" + for name in SCENARIOS: + view = _player_view(scenario(name)) + assert {sheet.name: sheet.reverses_at for sheet in view.party} == REVERSES_AT, name + + +# ---------------------------------------------------------------------- whether a member can prepare now + + +@pytest.mark.parametrize("moment", list(EXPECTED)) +def test_each_member_says_whether_they_can_prepare_now_and_whether_they_need_sleep(moment): + view = _player_view(scenario(moment)) + + assert _moments(view) == EXPECTED[moment] + + +def _selections(view: PlayerView, sheet: MemberView) -> list[tuple[MemorizedSpell, ...]]: + """An empty selection, and one copy of the first spell at each spell level the member has a slot at.""" + picks = [()] + for spell_level, slots in enumerate(sheet.spell_slots, start=1): + at_level = [spell_id for spell_id in sheet.preparable_spells if view.spell_levels[spell_id] == spell_level] + if slots and at_level: + picks.append((MemorizedSpell(spell_id=at_level[0]),)) + return picks + + +def _members_at_moments() -> list: + """Every member at every moment.""" + return [pytest.param(moment, name) for moment in EXPECTED for name in REVERSES_AT] + + +@pytest.mark.parametrize(("moment", "name"), _members_at_moments()) +def test_can_prepare_now_is_true_exactly_when_the_session_accepts_a_fitting_selection(moment, name): + """Each selection that fits `preparable_spells` and `spell_slots`, sent from a fresh copy of the moment. + + When the member can't prepare now, each refusal of a caster is one of the moment's codes, and the sleep rule's + code comes exactly when `needs_sleep_to_prepare` is true and nothing the session checks first applies. A + selection made from the lists never draws a refusal for the spell or the member. + """ + view = _player_view(scenario(moment)) + sheet = _sheet(view, name) + first_checks_pass = view.mode in ("town", "exploring") and not incapacitated(scenario(moment).member(sheet.id)) + + for selections in _selections(view, sheet): + game = scenario(moment) + result = game.execute(PrepareSpells(character_id=sheet.id, selections=selections)) + codes = {rejection.code for rejection in result.rejections} + assert result.accepted == sheet.can_prepare_now, (selections, codes) + if name in CASTERS and not result.accepted: + assert codes <= MOMENT_CODES, (selections, codes) + assert ("magic.memorize.needs_sleep" in codes) == (sheet.needs_sleep_to_prepare and first_checks_pass) + assert (sheet.can_prepare_now, sheet.needs_sleep_to_prepare) == EXPECTED[moment][name] + + +@pytest.mark.parametrize("moment", ["new", "slept", "prepared"]) +def test_a_member_who_casts_nothing_is_refused_as_no_caster_whether_or_not_the_party_has_slept(moment): + """The fighter's class casts nothing, which doesn't depend on the moment, so neither does the refusal. + + Before, a fighter in a new session was refused with `magic.memorize.needs_sleep`, which said the fighter could + prepare after a night's rest, and after the rest with `magic.memorize.not_a_caster`. + """ + game = scenario(moment) + hild = pf.named(game, "Hild") + + result = game.execute(PrepareSpells(character_id=hild)) + + assert [(rejection.code, rejection.params) for rejection in result.rejections] == [ + ("magic.memorize.not_a_caster", {"class": "fighter"}) + ] + assert _sheet(_player_view(game), "Hild").needs_sleep_to_prepare is False + + +def test_preparing_turns_the_fields_over_until_the_next_sleep(): + """Wren prepares, needs a sleep, sleeps, and can prepare again, with nobody else changing.""" + game = scenario("slept") + assert _sheet(_player_view(game), "Wren").can_prepare_now + + _prepare(game, "Wren", "light_mu") + after = _player_view(game) + assert (_sheet(after, "Wren").can_prepare_now, _sheet(after, "Wren").needs_sleep_to_prepare) == SLEEP + assert _moments(after) == {**EXPECTED["slept"], "Wren": SLEEP} + + assert game.execute(Rest(kind="night")).accepted + assert _moments(_player_view(game)) == EXPECTED["slept"] + + +# ---------------------------------------------------------------------- saves + + +def _round_trip(game: GameSession) -> GameSession: + return load_game(json.loads(json.dumps(save_game(game)))) + + +def test_a_session_restored_from_a_save_has_the_same_fields(): + """The save is taken between Wren's and Mara's preparation and the next sleep, and the restored session has no + events from before the save to read.""" + game = scenario("prepared") + + loaded = _round_trip(game) + + assert _fields(_player_view(loaded)) == _fields(_player_view(game)) + assert _moments(_player_view(loaded)) == EXPECTED["prepared"] + assert loaded.execute(Rest(kind="night")).accepted + assert _moments(_player_view(loaded)) == EXPECTED["slept_again"] + _prepare(loaded, "Bryn") + assert _moments(_player_view(loaded)) == {**EXPECTED["slept_again"], "Bryn": SLEEP} + + +def test_a_save_from_osrlib_2_8_0_gives_the_fields(): + """The fields come from the classes and the sleep counts, which a 2.8.0 save already has. + + The whole view of the loaded save is the view of the same moment built now, so nothing else the save embeds + reads differently either. + """ + document = json.loads(SAVE_2_8_0.read_text(encoding="utf-8")) + assert document["engine_version"] == "2.8.0" + + loaded = load_game(document) + + view = _player_view(loaded) + assert {sheet.name: sheet.reverses_at for sheet in view.party} == REVERSES_AT + assert _moments(view) == EXPECTED["prepared"] + assert view == _player_view(scenario("prepared")) + assert loaded.execute(Rest(kind="night")).accepted + assert _moments(_player_view(loaded)) == EXPECTED["slept_again"] + + +# ---------------------------------------------------------------------- what the referee knows + + +def _twin(moment: str) -> GameSession: + """The same moment with what only the referee knows changed: another master seed, and Mara's unidentified + potion a potion of delusion in place of a potion of healing. Both potions show as `"a potion"`.""" + game = scenario(moment, seed=8191) + mara = game.member(pf.named(game, "Mara")) + mara.inventory.items.append(MagicItemInstance(instance_id="magic-item-9001", template_id="potion_of_delusion")) + return game + + +@pytest.mark.parametrize("moment", list(EXPECTED)) +def test_a_twin_that_differs_in_what_the_referee_knows_has_the_same_fields(moment): + game = scenario(moment) + game.member(pf.named(game, "Mara")).inventory.items.append( + MagicItemInstance(instance_id="magic-item-9001", template_id="potion_of_healing") + ) + + fields, twin = _fields(_player_view(game)), _fields(_player_view(_twin(moment))) + + assert fields == twin + assert {name: (can, needs) for name, (_, can, needs) in fields.items()} == EXPECTED[moment] + + +# ---------------------------------------------------------------------- the schema and the docs + + +def test_a_player_view_from_before_the_fields_still_parses(): + """A client that kept a 2.8.0 player view's JSON reads it with every new field at its default.""" + document = json.loads(_player_view(scenario("prepared")).model_dump_json()) + for sheet in document["party"]: + for field in ("reverses_at", "can_prepare_now", "needs_sleep_to_prepare"): + sheet.pop(field) + document.pop("valuable_names") + + view = PlayerView.model_validate(document) + + assert all( + (sheet.reverses_at, sheet.can_prepare_now, sheet.needs_sleep_to_prepare) == (None, False, False) + for sheet in view.party + ) + assert view.valuable_names == {} + + +def _bullet(changelog: str, issue: str) -> str: + """The changelog bullets that cite `issue`, wherever they are in the file, joined into one string.""" + lines = [line for line in changelog.splitlines() if line.startswith("- ") and f"({issue})" in line] + assert lines, f"no changelog bullet cites ({issue})" + return "\n".join(lines) + + +def test_the_views_guide_and_the_changelog_describe_the_fields(): + root = Path(__file__).parent.parent + guide = (root / "docs" / "guides" / "views-and-visibility.md").read_text(encoding="utf-8") + bullet = _bullet((root / "CHANGELOG.md").read_text(encoding="utf-8"), "#338") + + for name in ("reverses_at", "can_prepare_now", "needs_sleep_to_prepare", "magic.memorize.needs_sleep"): + assert name in guide, name + for name in ("reverses_at", "can_prepare_now", "needs_sleep_to_prepare"): + assert name in bullet, name diff --git a/tests/test_view_valuable_names.py b/tests/test_view_valuable_names.py new file mode 100644 index 0000000..4fb3a60 --- /dev/null +++ b/tests/test_view_valuable_names.py @@ -0,0 +1,295 @@ +"""The player view gives a named gem's or piece of jewellery's own name (issue #339). + +`PlayerView.item_names` names a valuable by its kind, `"gem"` or `"piece of jewellery"`, a common noun a client puts +an article in front of. The same view shows a piece's own name in a member's `inventory` and in a pile's `items`, so a +client that words "Sam takes a piece of jewellery." from `item_names` reads worse than the view allows, and a client +that wants the own name has to pair a pile's `contents` with its `items` by position. `PlayerView.valuable_names` +gives the own name of every piece that has one, by its instance id, for the client to use as written. + +A piece has a name of its own when an author gave it one. Treasure generation names every gem it rolls `"Gem"` and +every piece of jewellery `"Jewellery"`, the kind with a capital, which is no name of the piece's own, and a +`ValuableSpec` with no `name` makes a piece whose name is empty. +""" + +import json +from pathlib import Path + +from crawl_fixtures import build_party +from osrlib.core.events import Visibility +from osrlib.core.items import ValuableInstance +from osrlib.crawl.adventure import Adventure, TownSpec +from osrlib.crawl.commands import DropItems, EnterDungeon, TakeTreasure +from osrlib.crawl.dungeon import ( + AreaSpec, + AreaTreasureSpec, + DropPile, + DungeonSpec, + FeatureSpec, + LevelSpec, + ValuableSpec, + cell_ref, +) +from osrlib.crawl.events import ItemAcquiredEvent +from osrlib.crawl.session import GameSession +from osrlib.crawl.views import PlayerView +from osrlib.persistence import load_game, save_game + +SAVE_2_8_0 = Path(__file__).parent / "saves" / "view_valuable_names_2.8.0.json" +"""A save of `looted()`, written by osrlib 2.8.0 before `valuable_names` existed.""" + +SEED = 27 +"""A seed whose roll of treasure type C in the nave gives at least two gems and two pieces of jewellery, all of which +the party carries away, leaving only copper behind. `looted()` checks it.""" + +CHAIN = ValuableSpec(kind="jewellery", name="Prior's chain of office", value_gp=1200) +RING = ValuableSpec(kind="jewellery", name="Ring of the drowned abbot", value_gp=900) +EYE = ValuableSpec(kind="gem", name="Eye of Ossor", value_gp=500) +STAR = ValuableSpec(kind="gem", name="Star of the lower chapel", value_gp=400) +BARE_GEM_KEPT = ValuableSpec(kind="gem", value_gp=50) +BARE_GEM_DROPPED = ValuableSpec(kind="gem", value_gp=60) +BARE_JEWEL_KEPT = ValuableSpec(kind="jewellery", value_gp=300) +BARE_JEWEL_DROPPED = ValuableSpec(kind="jewellery", value_gp=350) + +RELIQUARY = (CHAIN, RING, EYE, STAR, BARE_GEM_KEPT, BARE_GEM_DROPPED, BARE_JEWEL_KEPT, BARE_JEWEL_DROPPED) +"""The placed pieces: a named and an unnamed piece of each kind for the packs, and the same again for the pile.""" +DROPPED = (RING, STAR, BARE_GEM_DROPPED, BARE_JEWEL_DROPPED) + +NAMED = (CHAIN, RING, EYE, STAR) + +MITRE = ValuableSpec(kind="jewellery", name="Bishop's mitre jewel", value_gp=800) +"""In the tomb, a cache on a cell the party never walks.""" +CROWN = ValuableInstance(instance_id="valuable-9001", kind="gem", name="Drowned crown", value_gp=700) +"""In a pile on the tomb's cell, which the party doesn't know.""" + + +def _adventure() -> Adventure: + """Three cells in a row. The party enters at the nave, on the west, whose reliquary holds the placed pieces and + whose rolled treasure lies where the party enters. The tomb, on the east, stays unvisited.""" + reliquary = FeatureSpec( + id="reliquary", kind="treasure_cache", description="A lead-lined reliquary.", cell=(0, 0), valuables=RELIQUARY + ) + tomb = FeatureSpec(id="tomb", kind="treasure_cache", description="A sealed tomb.", cell=(2, 0), valuables=(MITRE,)) + level = LevelSpec( + number=1, + width=3, + height=1, + entrance=(0, 0), + areas=( + AreaSpec( + id="nave", + name="Nave", + cells=((0, 0),), + features=(reliquary,), + treasure=AreaTreasureSpec(letters=("C",)), + ), + AreaSpec(id="crypt", name="Crypt", cells=((2, 0),), features=(tomb,)), + ), + ) + return Adventure( + name="The Drowned Priory", + town=TownSpec(name="Threshold", travel_turns={"priory": 1}), + dungeons=(DungeonSpec(id="priory", name="The Priory", levels=(level,)),), + ) + + +def _player_view(game: GameSession) -> PlayerView: + view = game.view(Visibility.PLAYER) + assert isinstance(view, PlayerView) + return view + + +def _carried(game: GameSession) -> list[tuple[str, ValuableInstance]]: + """Each valuable a member carries, with the member's id, in party order.""" + return [(member.id, valuable) for member in game.party.members for valuable in member.inventory.valuables] + + +def _placed_id(game: GameSession, spec: ValuableSpec) -> str: + """The instance id of the piece `spec` placed, wherever it is now, found by its kind, name, and value.""" + pieces = [valuable for _, valuable in _carried(game)] + pieces += [valuable for pile in game.dungeon_state.piles.values() for valuable in pile.valuables] + (instance_id,) = ( + valuable.instance_id + for valuable in pieces + if (valuable.kind, valuable.name, valuable.value_gp) == (spec.kind, spec.name, spec.value_gp) + ) + return instance_id + + +def _take_everything(game: GameSession, seed: int) -> list[ItemAcquiredEvent]: + acquired = [] + for feature_id in _player_view(game).features_here: + taken = game.execute(TakeTreasure(feature_id=feature_id)) + assert taken.accepted, [rejection.code for rejection in taken.rejections] + acquired += [event for event in taken.events if isinstance(event, ItemAcquiredEvent)] + left = [valuable for pile in game.dungeon_state.piles.values() for valuable in pile.valuables] + assert not left, f"precondition: the party carries every piece away with seed {seed}" + return acquired + + +def looted(seed: int = SEED) -> tuple[GameSession, list[ItemAcquiredEvent]]: + """The stock party enters the priory, empties the reliquary and the rolled cache, and drops some pieces. + + The members drop the four pieces in `DROPPED`, then the first rolled gem and the first rolled piece of jewellery + in the party's packs, onto the nave's cell. So the packs and the pile each hold a named and an unnamed placed + piece of each kind, and a rolled piece of each kind. Returns the session and the acquisitions. + """ + game = GameSession.new(build_party(), _adventure(), seed=seed) + assert game.execute(EnterDungeon(dungeon_id="priory")).accepted + acquired = _take_everything(game, seed) + rolled = [(holder, valuable) for holder, valuable in _carried(game) if valuable.name in ("Gem", "Jewellery")] + for kind in ("gem", "jewellery"): + assert sum(valuable.kind == kind for _, valuable in rolled) >= 2, f"precondition: seed {seed} rolls two {kind}" + drops = [_placed_id(game, spec) for spec in DROPPED] + drops += [ + next(valuable.instance_id for _, valuable in rolled if valuable.kind == kind) for kind in ("gem", "jewellery") + ] + holders = {valuable.instance_id: holder for holder, valuable in _carried(game)} + for instance_id in drops: + dropped = game.execute(DropItems(character_id=holders[instance_id], item_ids=(instance_id,))) + assert dropped.accepted, [rejection.code for rejection in dropped.rejections] + return game, acquired + + +def _expected(game: GameSession) -> dict[str, str]: + return {_placed_id(game, spec): spec.name for spec in NAMED} + + +def _shown(view: PlayerView) -> tuple[dict[str, str], dict[str, str]]: + """The name the view shows for each valuable: in the inventories' `valuables`, and in the piles' `items`.""" + in_packs = { + valuable["instance_id"]: valuable["name"] for sheet in view.party for valuable in sheet.inventory["valuables"] + } + in_piles = { + entry.item_id: text + for pile in view.piles.values() + for entry, text in zip(pile.contents, pile.items, strict=True) + if entry.item_id.startswith("valuable-") + } + return in_packs, in_piles + + +# ---------------------------------------------------------------------- what the map holds + + +def test_valuable_names_has_each_named_piece_in_a_pack_or_a_pile(): + """The four named pieces, two carried and two in the pile. No unnamed or rolled piece is a key.""" + game, _ = looted() + view = _player_view(game) + + assert view.valuable_names == _expected(game) + assert set(view.valuable_names) <= set(view.item_names) + + +def test_valuable_names_agree_with_the_inventory_and_the_pile(): + """Every valuable the view shows, in the packs and the pile, of every variant. + + The variants are a named, an unnamed, and a rolled piece of each kind, and the packs and the pile each hold one of + every variant. A key's value is the name both places show. A piece that isn't a key shows an empty name or the + rolled name in a pack, and its kind or the rolled name in a pile. + """ + game, _ = looted() + view = _player_view(game) + in_packs, in_piles = _shown(view) + kinds = {valuable.instance_id: valuable.kind for _, valuable in _carried(game)} + kinds |= { + valuable.instance_id: valuable.kind for pile in game.dungeon_state.piles.values() for valuable in pile.valuables + } + for place, shown in (("packs", in_packs), ("pile", in_piles)): + named = {kinds[instance_id] for instance_id in shown if instance_id in _expected(game)} + rolled = {kinds[instance_id] for instance_id, text in shown.items() if text in ("Gem", "Jewellery")} + bare = {kinds[instance_id] for instance_id, text in shown.items() if text in ("", "gem", "jewellery")} + assert named == rolled == bare == {"gem", "jewellery"}, f"precondition: the {place} hold every variant" + + for instance_id, name in view.valuable_names.items(): + assert name == {**in_piles, **in_packs}[instance_id], instance_id + for instance_id in set(in_packs) - set(view.valuable_names): + assert in_packs[instance_id] in ("", "Gem", "Jewellery"), instance_id + for instance_id in set(in_piles) - set(view.valuable_names): + assert in_piles[instance_id] in ("gem", "jewellery", "Gem", "Jewellery"), instance_id + assert view.valuable_names == _expected(game) + + +def test_item_names_still_names_every_valuable_by_its_kind(): + """`item_names` doesn't change: a common noun for a client to put an article in front of.""" + game, _ = looted() + view = _player_view(game) + in_packs, in_piles = _shown(view) + kinds = {valuable.instance_id: valuable.kind for _, valuable in _carried(game)} + kinds |= { + valuable.instance_id: valuable.kind for pile in game.dungeon_state.piles.values() for valuable in pile.valuables + } + + for instance_id in {*in_packs, *in_piles}: + assert view.item_names[instance_id] == {"gem": "gem", "jewellery": "piece of jewellery"}[kinds[instance_id]] + assert ( + view.item_names_plural[instance_id] + == {"gem": "gems", "jewellery": "pieces of jewellery"}[kinds[instance_id]] + ) + + +def test_the_acquisitions_of_named_pieces_are_named_in_the_view_after_them(): + """The issue's case: `ItemAcquiredEvent` names each piece by its instance id, and the view after the take gives + the own name of each named piece, so a client writes "Prior's chain of office" and not "a piece of jewellery".""" + game = GameSession.new(build_party(), _adventure(), seed=SEED) + assert game.execute(EnterDungeon(dungeon_id="priory")).accepted + acquired = _take_everything(game, SEED) + + view = _player_view(game) + + taken = {item_id for event in acquired for item_id in event.item_ids if item_id.startswith("valuable-")} + assert {instance_id for instance_id in taken if instance_id in view.valuable_names} == set(_expected(game)) + assert view.valuable_names[_placed_id(game, CHAIN)] == "Prior's chain of office" + + +def test_a_piece_the_party_cant_see_has_no_name_in_the_view(): + """The tomb's mitre jewel is in a cache the party hasn't emptied, and the crown in a pile on a cell the party has + never walked. Neither is a key in either map, and neither name is anywhere in the view.""" + game, _ = looted() + game.dungeon_state.piles[cell_ref("priory", 1, (2, 0))] = DropPile(valuables=[CROWN]) + + view = _player_view(game) + + assert view.valuable_names == _expected(game) + assert CROWN.instance_id not in view.item_names + blob = view.model_dump_json() + for hidden in (MITRE.name, CROWN.name, "mitre", "crown"): + assert hidden not in blob, hidden + + +# ---------------------------------------------------------------------- saves + + +def test_a_session_restored_from_a_save_has_the_same_names(): + game, _ = looted() + + loaded = load_game(json.loads(json.dumps(save_game(game)))) + + assert _player_view(loaded).valuable_names == _player_view(game).valuable_names == _expected(game) + + +def test_a_save_from_osrlib_2_8_0_gives_the_names(): + """The names come from the pieces, which a 2.8.0 save already has, and the whole view of the loaded save is the + view of the same state built now.""" + document = json.loads(SAVE_2_8_0.read_text(encoding="utf-8")) + assert document["engine_version"] == "2.8.0" + + loaded = load_game(document) + + game, _ = looted() + view = _player_view(loaded) + assert view.valuable_names == _expected(game) + assert view == _player_view(game) + + +# ---------------------------------------------------------------------- the docs + + +def test_the_views_guide_and_the_changelog_describe_the_names(): + root = Path(__file__).parent.parent + guide = (root / "docs" / "guides" / "views-and-visibility.md").read_text(encoding="utf-8") + changelog = (root / "CHANGELOG.md").read_text(encoding="utf-8") + bullets = [line for line in changelog.splitlines() if line.startswith("- ") and "(#339)" in line] + + assert "valuable_names" in guide + assert bullets, "no changelog bullet cites (#339)" + assert "valuable_names" in "\n".join(bullets)