diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf1522..5378c16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### Added + +- [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases] gives what to call each piece in `valuable_names` in the middle of a sentence, with its article and its case, such as `"a silver altar candlestick"` or `"Ossor's Eye"`, keyed by the same instance id (#354). Use `valuable_names` in a list and `valuable_phrases` in a sentence. The phrase is the piece's [`phrase`][osrlib.core.items.ValuableInstance.phrase], which the session copies from the [`ValuableSpec.phrase`][osrlib.crawl.dungeon.ValuableSpec.phrase] that placed it. When that's empty or only whitespace, osrlib makes the phrase from the name: a name whose first word is "the", "a", or "an" has that word in lowercase, and any other name has its first character in lowercase and "an" or "a" in front, by its first letter. Set `phrase` when the piece has a proper name, takes "the", or has a first letter that doesn't give its article. A piece from a 2.9.0 save has no `phrase`, so the view makes its phrase from its name, and a `PlayerView` that osrlib 2.9.0 built validates with `valuable_phrases` empty. + +### Fixed + +- A gem or piece of jewellery whose `name` is only whitespace has no name of its own (#355). It isn't a key in [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] or `valuable_phrases`, and a pile's [`items`][osrlib.crawl.views.PileView.items] show its kind. Before, it was a key in `valuable_names` with the blank name, and the pile's `items` showed the blank string. Spaces around a name don't count either: `valuable_names` and the pile's `items` show the name without them, and a gem named `" Gem "` has no name of its own. + ## [2.9.0] - 2026-11-26 ### Added diff --git a/docs/front-ends/fastapi-pattern.md b/docs/front-ends/fastapi-pattern.md index 46f8d66..19c59ec 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, 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. +[`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`) with the phrase that puts it in a sentence (`valuable_phrases`), 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/authoring-custom-content.md b/docs/guides/authoring-custom-content.md index 3ed3381..ed9b296 100644 --- a/docs/guides/authoring-custom-content.md +++ b/docs/guides/authoring-custom-content.md @@ -891,6 +891,20 @@ assert feature.description == COFFER.description assert COFFER.referee_notes not in view.model_dump_json() ``` +### Name a gem or piece of jewellery + +A [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] with a `name` places a piece that the players know by that name. [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] gives that name, which a client shows in a list, such as an inventory row. A client also puts the piece in a sentence, such as "Hild takes a silver censer on a chain.", and [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases] gives the phrase to use there, with the article and the case. You can write that phrase yourself in the spec's [`phrase`][osrlib.crawl.dungeon.ValuableSpec.phrase]. + +When `phrase` is empty or only whitespace, osrlib makes the phrase from the name, as for a common noun. A name whose first word is "the", "a", or "an" has that word in lowercase, so the censer above, "A silver censer on a chain", reads "a silver censer on a chain". Any other name has its first character in lowercase and an article in front, "an" before `a`, `e`, `i`, `o`, or `u`, with or without an accent, and "a" otherwise, so "Silver altar candlestick" reads "a silver altar candlestick". Only the first character changes case, so "Eye of Ossor" reads "an eye of Ossor". The view leaves out any spaces around a name or a phrase. + +Set `phrase` yourself when the piece isn't a common noun whose first letter gives its article: + +- For a proper name, such as "Ossor's Eye", set `phrase="Ossor's Eye"`. +- For a piece that takes the definite article, such as "Prior's chain of office", set `phrase="the Prior's chain of office"`. +- For a name whose first letter doesn't give its article, such as "Unicorn-horn cup" or "Hourglass of smoked crystal", set `phrase="a unicorn-horn cup"` or `phrase="an hourglass of smoked crystal"`. + +A piece with no name of its own never has a phrase in the view, whatever `phrase` holds. That's a piece whose `name` is empty, is only whitespace, or is the name treasure generation gives its kind, `"Gem"` for a gem or `"Jewellery"` for a piece of jewellery. The view names such a piece by its kind in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], and a client puts it in a sentence with an article, as in "Hild takes a gem." + ## Scope and cross-adventure limits - **Read-only built-in loaders**: `load_classes`, `load_spells`, `load_monsters`, and `load_equipment` return cached, immutable SRD catalogs and provide no global registration or mutation API. Pass extended catalogs explicitly to kernel functions or bundle custom spells, monsters, and items on `Adventure`. diff --git a/docs/guides/views-and-visibility.md b/docs/guides/views-and-visibility.md index 24482b0..8abea0a 100644 --- a/docs/guides/views-and-visibility.md +++ b/docs/guides/views-and-visibility.md @@ -38,7 +38,7 @@ Use three more fields of the member view to decide when to offer the dialog and 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 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. +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 in a list, such as an inventory row. To put the piece in a sentence, use [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases], which has the same keys and gives each piece's phrase with its article and its case, like `"the Prior's chain of office"`, so you can word "Sam takes the Prior's chain of office." The phrase is the one the author set in the `ValuableSpec`'s `phrase`, or one osrlib makes from the name, as [Name a gem or piece of jewellery](authoring-custom-content.md#name-a-gem-or-piece-of-jewellery) describes. 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 5406674..d04a56a 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. 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. +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. Each of those pieces also has, under the same id in `valuable_phrases`, what to call it in the middle of a sentence, with its article and its case: its author's `phrase`, or a phrase made from the name when the author set none. 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/items.py b/src/osrlib/core/items.py index 9675dd6..df14fc7 100644 --- a/src/osrlib/core/items.py +++ b/src/osrlib/core/items.py @@ -89,6 +89,7 @@ """ import re +import unicodedata from collections.abc import Mapping from typing import TYPE_CHECKING, Annotated, Any, Literal @@ -2096,6 +2097,19 @@ class ValuableInstance(_Model): """A display name for the piece. Generation sets a plain one. When you place treasure by hand in an adventure, you can give it any name. """ + phrase: str = "" + """What to call the piece in the middle of a sentence, with its article and its case, like + `"the abbot's seal ring"`. The session copies it from the + [`ValuableSpec.phrase`][osrlib.crawl.dungeon.ValuableSpec.phrase] that placed the piece, as it copies `name`. It's + empty for a piece that treasure generation rolls, for a piece placed with no phrase, and for a piece from a save + that osrlib 2.9.0 or earlier wrote. + + To word a sentence, read + [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases], which has this phrase when it's + set and, when it's empty or only whitespace, the phrase osrlib makes from `name`. A piece with no name of its own, + whose `name` is empty, is only whitespace, or is the one treasure generation gives its kind, has no phrase in the + view, whatever this field holds. + """ value_gp: int = Field(ge=0) """What it's worth in gold pieces, and what it pays when sold.""" weight_coins: int = Field(default=0, ge=0) @@ -2541,8 +2555,12 @@ def _masked_names(instance: MagicItemInstance) -> tuple[str, str]: def _with_article(name: str) -> str: - """Return `name` after the indefinite article, `"an"` before a vowel and `"a"` otherwise.""" - return f"{'an' if name[:1].lower() in ('a', 'e', 'i', 'o', 'u') else 'a'} {name}" + """Return `name` after the indefinite article, `"an"` before a vowel and `"a"` otherwise. + + A vowel with an accent, like the `É` of `"Émeraude"`, counts as a vowel. + """ + first = unicodedata.normalize("NFD", name[:1])[:1].lower() + return f"{'an' if first in ('a', 'e', 'i', 'o', 'u') else 'a'} {name}" def _shield_ac_parts(shield: AnyInstance | None, *, ascending: bool) -> tuple[int | None, int]: diff --git a/src/osrlib/crawl/_hauling.py b/src/osrlib/crawl/_hauling.py index 6a1c95f..1ea9d6e 100644 --- a/src/osrlib/crawl/_hauling.py +++ b/src/osrlib/crawl/_hauling.py @@ -104,6 +104,7 @@ def _handle_take_treasure(session, command: TakeTreasure) -> tuple[list[Rejectio instance_id=session.allocator.allocate("valuable"), kind=spec.kind, name=spec.name, + phrase=spec.phrase, value_gp=spec.value_gp, weight_coins=spec.weight_coins, ) diff --git a/src/osrlib/crawl/dungeon.py b/src/osrlib/crawl/dungeon.py index d5ca66d..13c3a65 100644 --- a/src/osrlib/crawl/dungeon.py +++ b/src/osrlib/crawl/dungeon.py @@ -790,6 +790,7 @@ class ValuableSpec(_Model): Attributes: kind: Whether it is a gem or jewellery. name: The name the party sees. + phrase: What to call it in the middle of a sentence, if osrlib can't make that from `name`. value_gp: What it is worth, in gold pieces. weight_coins: What it weighs, in coins. @@ -815,6 +816,23 @@ class ValuableSpec(_Model): name: str = "" """The name the party sees, like `"The abbot's seal ring"`. Leave it empty for an unnamed valuable, like the ones the session rolls on the treasure tables.""" + phrase: str = "" + """What to call the piece in the middle of a sentence, with its article and its case, like + `"a silver altar candlestick"`, `"the abbot's seal ring"`, or `"Ossor's Eye"`. A client shows `name` in a list, + such as an inventory row, and words a sentence, such as "Wren takes the abbot's seal ring.", with the phrase that + [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases] gives. + + Leave it empty, and osrlib makes the phrase from `name`, as for a common noun. A name whose first word is "the", + "a", or "an" has that word in lowercase, so `"The abbot's seal ring"` reads `"the abbot's seal ring"`. Any other + name has its first character in lowercase and "an" or "a" in front, by its first letter, so + `"Silver altar candlestick"` reads `"a silver altar candlestick"`. Set the phrase when the piece has a proper name, + like `"Ossor's Eye"`, when it takes "the", like `"the Prior's chain of office"`, or when its first letter doesn't + give its article, like `"a unicorn-horn cup"`. A phrase that's only whitespace counts as empty, and the view + leaves out any spaces around a name or a phrase. + + Only a piece with a name of its own has a phrase in the view. A piece whose `name` is empty, is only whitespace, + or is the name treasure generation gives its kind, `"Gem"` for a gem or `"Jewellery"` for a piece of jewellery, + is named by its kind, whatever `phrase` holds.""" value_gp: int = Field(ge=0) """What the valuable is worth in gold pieces. It sells for this much in town, and it is worth this much experience to the party.""" diff --git a/src/osrlib/crawl/views.py b/src/osrlib/crawl/views.py index 00e10a3..e8e8b46 100644 --- a/src/osrlib/crawl/views.py +++ b/src/osrlib/crawl/views.py @@ -594,8 +594,10 @@ class PileItemView(_Model): 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. 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. + [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] too, which you show as + written in a list, and a phrase in + [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases], which you use as + written in a sentence. """ model_config = ConfigDict(frozen=True) @@ -625,7 +627,7 @@ class PileView(_Model): """One display string per thing in the pile, in the order mundane items, magic items, then valuables. A mundane entry has the form `"{item_id}×{quantity}"`. A magic item shows its name once identified and its masked display name before that. A valuable shows its - name, or its kind when it has no name.""" + name, without any spaces around it, or its kind when its name is empty or only whitespace.""" coins_gp_value: int """The pile's coins, as their value in whole gold pieces, rounded down.""" coins: Coins = Coins() @@ -1327,8 +1329,9 @@ class PlayerView(_Model): `"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`. 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. + `valuable_names` under the same id, and what to call it in a sentence, like + `"the Prior's chain of office"`, in `valuable_phrases`. Show the name in place of the kind in + a list, and the phrase in place of the kind in a sentence. 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 @@ -1348,22 +1351,46 @@ class PlayerView(_Model): 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. + `{"valuable-0007": "Prior's chain of office"}`. Show it as written in a list, such as an inventory + row. To put the piece in a sentence, use its phrase in + [`valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases], which has the article and + the case: "Sam takes the 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 only whitespace, nor the + plain name that treasure generation gives its kind, `"Gem"` for a gem or `"Jewellery"` for a piece + of jewellery. Spaces around the name don't count. 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`.""" + the inventory's `valuables` give the piece, without any spaces around it, 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`.""" + valuable_phrases: dict[str, str] = {} + """What to call each piece in `valuable_names` in the middle of a sentence, with its article and its case, keyed + by the same instance id, like `{"valuable-0007": "the abbot's seal ring", "valuable-0008": "a silver altar + candlestick", "valuable-0009": "Ossor's Eye"}`. Use it as written in a sentence: "Wren takes a silver altar + candlestick." Use `valuable_names` in a list, such as an inventory row. + + The keys are exactly the keys of `valuable_names`, for a piece in a member's + [`inventory`][osrlib.crawl.views.MemberView.inventory] and for a piece in a known pile alike. Each value is the + piece's [`phrase`][osrlib.core.items.ValuableInstance.phrase] when it has one. Otherwise osrlib makes the phrase + from the name. A name whose first word is "the", "a", or "an", in any case, keeps its words with that first word in + lowercase, so `"The abbot's seal ring"` becomes `"the abbot's seal ring"`. Any other name has its first character in + lowercase and the indefinite article in front, "an" before `a`, `e`, `i`, `o`, or `u`, with or without an accent, + and "a" otherwise, so `"Silver altar candlestick"` becomes `"a silver altar candlestick"` and `"Eye of Ossor"` + becomes `"an eye of Ossor"`. Only that first character changes case. A phrase that's only whitespace counts as no + phrase, and no value here has spaces around it. + + A piece from a save that osrlib 2.9.0 wrote has no phrase, so the view makes its phrase from its name, and every + key of `valuable_names` is a key here. A `PlayerView` that osrlib 2.9.0 built, such as a stored feed entry, has no + `valuable_phrases`, and it validates with this map empty. For such a view, word each name in `valuable_names` + yourself.""" fatigued: bool """Whether any member is fatigued.""" exhausted: bool @@ -1748,7 +1775,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, valuable_names = _item_names(session, known_piles.values()) + item_names, item_names_plural, valuable_names, valuable_phrases = _item_names(session, known_piles.values()) return PlayerView( adventure_name=session.adventure.name, adventure_description=session.adventure.description, @@ -1776,6 +1803,7 @@ def build_player_view(session) -> PlayerView: item_names=item_names, item_names_plural=item_names_plural, valuable_names=valuable_names, + valuable_phrases=valuable_phrases, fatigued=fatigued, exhausted=exhausted, deprivation=deprivation, @@ -1822,7 +1850,7 @@ def _pile_view(pile: DropPile) -> PileView: items=( *(f"{entry.item_id}×{entry.quantity}" for entry in pile.items), *(str(item.get("name", item.get("display"))) for item in magic_items), - *(valuable.name or valuable.kind for valuable in pile.valuables), + *(valuable.name.strip() or valuable.kind for valuable in pile.valuables), ), coins_gp_value=pile.coins.value_gp, coins=pile.coins, @@ -1838,8 +1866,31 @@ 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], dict[str, str]]: - # The view's `item_names`, `item_names_plural`, and `valuable_names`, in one walk over what the view shows. +_ARTICLES = frozenset({"the", "a", "an"}) +"""The first words that make a valuable's name a phrase already, in lowercase.""" + + +def _valuable_phrase(valuable: ValuableInstance) -> str: + """Return what to call a piece with a name of its own in the middle of a sentence. + + The view uses the piece's `phrase`, trimmed, unless it's empty or only whitespace. Otherwise a name whose first + word is "the", "a", or "an" keeps its words with that first word in lowercase, and any other name gets its first + character in lowercase and the indefinite article in front. The name is trimmed first. + """ + if phrase := valuable.phrase.strip(): + return phrase + name = valuable.name.strip() + first = name.split(maxsplit=1)[0] + if first.lower() in _ARTICLES: + return first.lower() + name[len(first) :] + return _with_article(name[0].lower() + name[1:]) + + +def _item_names( + session, piles: Iterable[DropPile] +) -> tuple[dict[str, str], dict[str, str], dict[str, str], dict[str, str]]: + # The view's `item_names`, `item_names_plural`, `valuable_names`, and `valuable_phrases`, 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 @@ -1848,6 +1899,7 @@ def _item_names(session, piles: Iterable[DropPile]) -> tuple[dict[str, str], dic names: dict[str, str] = {} plurals: dict[str, str] = {} valuable_names: dict[str, str] = {} + valuable_phrases: dict[str, str] = {} equipment = session.effective_equipment catalog = { template.id: template @@ -1861,9 +1913,12 @@ def add(item_id: str, singular: str, plural: str) -> None: 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 + # A piece has a name of its own unless its trimmed name is empty or the one treasure generation gives its + # kind. + name = valuable.name.strip() + if name and name != _ROLLED_VALUABLE_NAMES[valuable.kind]: + valuable_names[valuable.instance_id] = name + valuable_phrases[valuable.instance_id] = _valuable_phrase(valuable) def add_magic_item(instance: MagicItemInstance, *, carried: bool) -> None: if instance.identified: @@ -1891,7 +1946,7 @@ def add_magic_item(instance: MagicItemInstance, *, carried: bool) -> None: add_magic_item(instance, carried=False) for valuable in pile.valuables: add_valuable(valuable) - return names, plurals, valuable_names + return names, plurals, valuable_names, valuable_phrases def _quest_views(session): diff --git a/tests/goldens/phase5_hoards.json b/tests/goldens/phase5_hoards.json index 78015a1..726875d 100644 --- a/tests/goldens/phase5_hoards.json +++ b/tests/goldens/phase5_hoards.json @@ -57,6 +57,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 }, @@ -65,6 +66,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1500, "weight_coins": 10 }, @@ -73,6 +75,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -81,6 +84,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1400, "weight_coins": 10 }, @@ -89,6 +93,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -97,6 +102,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -105,6 +111,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 }, @@ -113,6 +120,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -121,6 +129,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1400, "weight_coins": 10 }, @@ -129,6 +138,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -137,6 +147,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 }, @@ -145,6 +156,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1600, "weight_coins": 10 }, @@ -153,6 +165,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -161,6 +174,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1500, "weight_coins": 10 }, @@ -169,6 +183,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1400, "weight_coins": 10 }, @@ -177,6 +192,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -185,6 +201,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -193,6 +210,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 }, @@ -201,6 +219,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1300, "weight_coins": 10 }, @@ -209,6 +228,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 }, @@ -217,6 +237,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -225,6 +246,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 }, @@ -233,6 +255,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -241,6 +264,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1600, "weight_coins": 10 }, @@ -249,6 +273,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 } @@ -269,6 +294,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 } @@ -289,6 +315,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 } @@ -419,6 +446,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -427,6 +455,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -435,6 +464,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -443,6 +473,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -451,6 +482,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -459,6 +491,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -467,6 +500,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -475,6 +509,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 1000, "weight_coins": 1 }, @@ -483,6 +518,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -491,6 +527,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -499,6 +536,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -507,6 +545,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -515,6 +554,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -523,6 +563,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -531,6 +572,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -539,6 +581,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 1000, "weight_coins": 1 }, @@ -547,6 +590,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -555,6 +599,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -563,6 +608,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -571,6 +617,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -579,6 +626,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -587,6 +635,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -595,6 +644,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1800, "weight_coins": 10 }, @@ -603,6 +653,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -611,6 +662,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1300, "weight_coins": 10 }, @@ -619,6 +671,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 }, @@ -627,6 +680,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -635,6 +689,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 } @@ -655,6 +710,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 } @@ -748,6 +804,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -756,6 +813,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -764,6 +822,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -772,6 +831,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -780,6 +840,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -788,6 +849,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -796,6 +858,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -804,6 +867,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -812,6 +876,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -820,6 +885,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -828,6 +894,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -836,6 +903,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 1000, "weight_coins": 1 }, @@ -844,6 +912,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -852,6 +921,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -860,6 +930,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -868,6 +939,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -876,6 +948,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -884,6 +957,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -892,6 +966,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -900,6 +975,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -908,6 +984,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -916,6 +993,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -924,6 +1002,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -932,6 +1011,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -940,6 +1020,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -948,6 +1029,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -956,6 +1038,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -964,6 +1047,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -972,6 +1056,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -980,6 +1065,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -988,6 +1074,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -996,6 +1083,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1004,6 +1092,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1012,6 +1101,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1020,6 +1110,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1028,6 +1119,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1036,6 +1128,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1044,6 +1137,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1052,6 +1146,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1060,6 +1155,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1068,6 +1164,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1076,6 +1173,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1084,6 +1182,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1092,6 +1191,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1100,6 +1200,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1108,6 +1209,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1116,6 +1218,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1124,6 +1227,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1132,6 +1236,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1140,6 +1245,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1148,6 +1254,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1156,6 +1263,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1164,6 +1272,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1172,6 +1281,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1180,6 +1290,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1188,6 +1299,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1196,6 +1308,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1204,6 +1317,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 1000, "weight_coins": 1 }, @@ -1212,6 +1326,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1220,6 +1335,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1228,6 +1344,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1236,6 +1353,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1244,6 +1362,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1252,6 +1371,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1260,6 +1380,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1268,6 +1389,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 }, @@ -1276,6 +1398,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -1284,6 +1407,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 500, "weight_coins": 10 }, @@ -1292,6 +1416,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 }, @@ -1300,6 +1425,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 }, @@ -1308,6 +1434,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 }, @@ -1316,6 +1443,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -1324,6 +1452,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 }, @@ -1332,6 +1461,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1400, "weight_coins": 10 }, @@ -1340,6 +1470,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1500, "weight_coins": 10 } @@ -1360,6 +1491,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -1368,6 +1500,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1500, "weight_coins": 10 }, @@ -1376,6 +1509,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1600, "weight_coins": 10 }, @@ -1384,6 +1518,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -1392,6 +1527,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1500, "weight_coins": 10 }, @@ -1400,6 +1536,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 }, @@ -1408,6 +1545,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 500, "weight_coins": 10 } @@ -1450,6 +1588,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1458,6 +1597,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 } @@ -1478,6 +1618,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1486,6 +1627,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1494,6 +1636,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1502,6 +1645,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1510,6 +1654,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1518,6 +1663,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1526,6 +1672,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -1534,6 +1681,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1542,6 +1690,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1550,6 +1699,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 } @@ -1743,6 +1893,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 } @@ -1763,6 +1914,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -1771,6 +1923,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1779,6 +1932,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1787,6 +1941,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1795,6 +1950,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1803,6 +1959,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -1811,6 +1968,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -1819,6 +1977,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 }, @@ -1827,6 +1986,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1300, "weight_coins": 10 }, @@ -1835,6 +1995,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -1843,6 +2004,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -1851,6 +2013,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1400, "weight_coins": 10 }, @@ -1859,6 +2022,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -1867,6 +2031,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -1875,6 +2040,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 } @@ -2036,6 +2202,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -2044,6 +2211,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2052,6 +2220,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -2060,6 +2229,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -2068,6 +2238,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -2076,6 +2247,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 } @@ -2183,6 +2355,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -2191,6 +2364,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -2199,6 +2373,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2207,6 +2382,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -2215,6 +2391,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -2223,6 +2400,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2231,6 +2409,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 50, "weight_coins": 1 }, @@ -2239,6 +2418,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2247,6 +2427,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 } @@ -2278,6 +2459,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -2286,6 +2468,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 1000, "weight_coins": 1 }, @@ -2294,6 +2477,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2302,6 +2486,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -2310,6 +2495,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -2318,6 +2504,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2326,6 +2513,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1300, "weight_coins": 10 }, @@ -2334,6 +2522,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1000, "weight_coins": 10 }, @@ -2342,6 +2531,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1300, "weight_coins": 10 }, @@ -2350,6 +2540,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -2358,6 +2549,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -2366,6 +2558,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 700, "weight_coins": 10 }, @@ -2374,6 +2567,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 } @@ -2416,6 +2610,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 100, "weight_coins": 1 }, @@ -2424,6 +2619,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 }, @@ -2432,6 +2628,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 500, "weight_coins": 1 }, @@ -2440,6 +2637,7 @@ "instance_type": "valuable", "kind": "gem", "name": "Gem", + "phrase": "", "value_gp": 10, "weight_coins": 1 } @@ -2460,6 +2658,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -2468,6 +2667,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 }, @@ -2476,6 +2676,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 900, "weight_coins": 10 }, @@ -2484,6 +2685,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 300, "weight_coins": 10 }, @@ -2492,6 +2694,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1400, "weight_coins": 10 }, @@ -2500,6 +2703,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 800, "weight_coins": 10 }, @@ -2508,6 +2712,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1200, "weight_coins": 10 }, @@ -2516,6 +2721,7 @@ "instance_type": "valuable", "kind": "jewellery", "name": "Jewellery", + "phrase": "", "value_gp": 1100, "weight_coins": 10 } diff --git a/tests/saves/view_valuable_phrases_2.9.0.json b/tests/saves/view_valuable_phrases_2.9.0.json new file mode 100644 index 0000000..3538292 --- /dev/null +++ b/tests/saves/view_valuable_phrases_2.9.0.json @@ -0,0 +1,720 @@ +{ + "kind": "save", + "schema_version": 4, + "engine_version": "2.9.0", + "payload": { + "master_seed": 31, + "ruleset": { + "hp_reroll_at_first_level": false, + "max_hp_at_first_level": false, + "ability_score_method": "3d6", + "encumbrance": "basic", + "variable_weapon_damage": true, + "individual_initiative": false, + "thac0_arithmetic": false, + "weapon_reload": false, + "hd5_counts_as_magical": false, + "magic_item_death_save": true, + "xp_award_timing": "on_return", + "deprivation_penalties": false, + "aoe_friendly_fire": true, + "formation_width_limit": true, + "failed_trap_removal_springs": true, + "back_stab_needs_both_skills": true + }, + "party": { + "members": [ + { + "id": "character-0001", + "name": "Brakk", + "class_id": "fighter", + "custom_class": null, + "race": "human", + "level": 1, + "xp": 0, + "scores": { + "str": 11, + "int": 11, + "wis": 11, + "dex": 11, + "con": 11, + "cha": 11 + }, + "alignment": "lawful", + "extra_languages": [], + "max_hp": 6, + "current_hp": 6, + "nonregen_damage": 0, + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0002", + "kind": "jewellery", + "name": "The abbot's seal ring", + "value_gp": 900, + "weight_coins": 0 + } + ], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "carrying_treasure": false, + "conditions": [], + "stat_modifiers": [], + "spell_book": [], + "memorized_spells": [] + }, + { + "id": "character-0002", + "name": "Sable", + "class_id": "thief", + "custom_class": null, + "race": "human", + "level": 1, + "xp": 0, + "scores": { + "str": 11, + "int": 11, + "wis": 11, + "dex": 11, + "con": 11, + "cha": 11 + }, + "alignment": "lawful", + "extra_languages": [], + "max_hp": 6, + "current_hp": 6, + "nonregen_damage": 0, + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "carrying_treasure": false, + "conditions": [], + "stat_modifiers": [], + "spell_book": [], + "memorized_spells": [] + }, + { + "id": "character-0003", + "name": "Wynn", + "class_id": "cleric", + "custom_class": null, + "race": "human", + "level": 1, + "xp": 0, + "scores": { + "str": 11, + "int": 11, + "wis": 13, + "dex": 11, + "con": 11, + "cha": 11 + }, + "alignment": "lawful", + "extra_languages": [], + "max_hp": 6, + "current_hp": 6, + "nonregen_damage": 0, + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0003", + "kind": "gem", + "name": "Gem", + "value_gp": 40, + "weight_coins": 0 + } + ], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "carrying_treasure": false, + "conditions": [], + "stat_modifiers": [], + "spell_book": [], + "memorized_spells": [] + }, + { + "id": "character-0004", + "name": "Elara", + "class_id": "magic_user", + "custom_class": null, + "race": "human", + "level": 1, + "xp": 0, + "scores": { + "str": 11, + "int": 11, + "wis": 11, + "dex": 11, + "con": 11, + "cha": 11 + }, + "alignment": "lawful", + "extra_languages": [], + "max_hp": 6, + "current_hp": 6, + "nonregen_damage": 0, + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0001", + "kind": "jewellery", + "name": "Silver altar candlestick", + "value_gp": 300, + "weight_coins": 0 + } + ], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "carrying_treasure": false, + "conditions": [], + "stat_modifiers": [], + "spell_book": [ + "sleep" + ], + "memorized_spells": [] + } + ] + }, + "adventure": { + "name": "The Drowned Priory", + "description": "", + "hooks": [], + "party": null, + "town": { + "name": "Threshold", + "description": "", + "services": [], + "travel_turns": { + "priory": 1 + }, + "healing_prices": {} + }, + "dungeons": [ + { + "id": "priory", + "name": "The Priory", + "levels": [ + { + "number": 1, + "width": 3, + "height": 1, + "edges": {}, + "areas": [ + { + "id": "nave", + "name": "Nave", + "description": "", + "cells": [ + [ + 0, + 0 + ] + ], + "encounter": null, + "features": [ + { + "id": "reliquary", + "kind": "treasure_cache", + "description": "", + "referee_notes": "", + "cell": [ + 0, + 0 + ], + "item_ids": [], + "magic_item_ids": [], + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "kind": "jewellery", + "name": "Silver altar candlestick", + "value_gp": 300, + "weight_coins": 0 + }, + { + "kind": "jewellery", + "name": "The abbot's seal ring", + "value_gp": 900, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "Gem", + "value_gp": 40, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "Eye of Ossor", + "value_gp": 500, + "weight_coins": 0 + }, + { + "kind": "gem", + "name": "An amber tear", + "value_gp": 250, + "weight_coins": 0 + }, + { + "kind": "jewellery", + "name": "", + "value_gp": 350, + "weight_coins": 0 + } + ], + "trap": null + } + ], + "trap": null, + "treasure": null + }, + { + "id": "crypt", + "name": "Crypt", + "description": "", + "cells": [ + [ + 2, + 0 + ] + ], + "encounter": null, + "features": [ + { + "id": "tomb", + "kind": "treasure_cache", + "description": "A sealed tomb.", + "referee_notes": "", + "cell": [ + 2, + 0 + ], + "item_ids": [], + "magic_item_ids": [], + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "kind": "jewellery", + "name": "Bishop's mitre jewel", + "value_gp": 800, + "weight_coins": 0 + } + ], + "trap": null + } + ], + "trap": null, + "treasure": null + } + ], + "features": [], + "transitions": [], + "wandering": { + "chance_in_six": 1, + "interval_turns": 2, + "table": null + }, + "entrance": [ + 0, + 0 + ], + "guidance": "" + } + ] + } + ], + "monsters": [], + "items": [], + "spells": [], + "triggers": [], + "quests": [] + }, + "mode": "exploring", + "clock_rounds": 120, + "allocator": { + "counters": { + "character": 4, + "valuable": 6 + } + }, + "ledger": { + "effects": [] + }, + "dungeon_state": { + "location": { + "kind": "dungeon", + "dungeon_id": "priory", + "level_number": 1, + "position": [ + 0, + 0 + ], + "facing": "north" + }, + "explored": { + "priory:1": [ + [ + 0, + 0 + ] + ] + }, + "seen": {}, + "doors": {}, + "sprung_traps": [], + "removed_traps": [], + "found_traps": [], + "found_tricks": [], + "emptied_caches": [ + "priory:1:reliquary" + ], + "piles": { + "cell:priory:1:0,0": { + "items": [], + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0004", + "kind": "gem", + "name": "Eye of Ossor", + "value_gp": 500, + "weight_coins": 0 + }, + { + "instance_type": "valuable", + "instance_id": "valuable-0005", + "kind": "gem", + "name": "An amber tear", + "value_gp": 250, + "weight_coins": 0 + }, + { + "instance_type": "valuable", + "instance_id": "valuable-0006", + "kind": "jewellery", + "name": "", + "value_gp": 350, + "weight_coins": 0 + } + ], + "magic_items": [] + } + }, + "generated_caches": {}, + "generated_treasure_areas": [], + "generated_lair_hoards": [], + "resolved_encounters": [], + "listen_attempts": {}, + "search_attempts": {}, + "inspect_attempts": {}, + "removal_attempts": {}, + "lock_failures": {} + }, + "monsters": [], + "npcs": [], + "flags": {}, + "fired_triggers": [], + "journal": [], + "quests": {}, + "listener_state": {}, + "death_records": {}, + "defeated_monsters": [], + "deprivation": {}, + "treasure_snapshot_cp": 0, + "exploration": { + "odometer_thirds": 0, + "turns_since_rest": 1, + "wandering_counter": 1, + "noise_since_check": false, + "sleep_count": 0, + "last_prepared_sleep": {}, + "alerted_areas": [], + "heard_areas": [], + "provisions_day": 0 + }, + "encounter": null, + "battle": null, + "rng_streams": { + "effects": { + "state": 275415882623875960588889580098736168391, + "inc": 64135087755310806947476396026910373991 + } + }, + "command_log": [ + { + "command_type": "enter_dungeon", + "source": null, + "dungeon_id": "priory" + }, + { + "command_type": "take_treasure", + "source": null, + "feature_id": "feature:dd21a6abe37eb019fdfdc28df11b6e0fa3db5354d97156edc48660de6f99dc4f", + "recipient_id": null + }, + { + "command_type": "drop_items", + "source": null, + "character_id": "character-0002", + "item_ids": [ + "valuable-0004" + ], + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + } + }, + { + "command_type": "drop_items", + "source": null, + "character_id": "character-0004", + "item_ids": [ + "valuable-0005" + ], + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + } + }, + { + "command_type": "drop_items", + "source": null, + "character_id": "character-0003", + "item_ids": [ + "valuable-0006" + ], + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + } + } + ], + "event_log": [ + { + "code": "exploration.location.entered", + "visibility": "player", + "event_type": "location_entered", + "location_kind": "dungeon", + "location_id": "priory", + "level_number": 1, + "dungeon_id": null, + "narrative": null, + "via": "entrance", + "transition_ref": null + }, + { + "code": "exploration.location.entered", + "visibility": "player", + "event_type": "location_entered", + "location_kind": "area", + "location_id": "nave", + "level_number": 1, + "dungeon_id": "priory", + "narrative": null, + "via": null, + "transition_ref": null + }, + { + "code": "exploration.item.acquired", + "visibility": "player", + "event_type": "item_acquired", + "character_id": "character-0001", + "item_ids": [ + "valuable-0002" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "origin": "treasure" + }, + { + "code": "exploration.item.acquired", + "visibility": "player", + "event_type": "item_acquired", + "character_id": "character-0002", + "item_ids": [ + "valuable-0004" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "origin": "treasure" + }, + { + "code": "exploration.item.acquired", + "visibility": "player", + "event_type": "item_acquired", + "character_id": "character-0003", + "item_ids": [ + "valuable-0006", + "valuable-0003" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "origin": "treasure" + }, + { + "code": "exploration.item.acquired", + "visibility": "player", + "event_type": "item_acquired", + "character_id": "character-0004", + "item_ids": [ + "valuable-0001", + "valuable-0005" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "origin": "treasure" + }, + { + "code": "exploration.item.dropped", + "visibility": "player", + "event_type": "items_dropped", + "character_id": "character-0002", + "item_ids": [ + "valuable-0004" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + } + }, + { + "code": "exploration.item.dropped", + "visibility": "player", + "event_type": "items_dropped", + "character_id": "character-0004", + "item_ids": [ + "valuable-0005" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + } + }, + { + "code": "exploration.item.dropped", + "visibility": "player", + "event_type": "items_dropped", + "character_id": "character-0003", + "item_ids": [ + "valuable-0006" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + } + } + ] + } +} diff --git a/tests/saves/view_valuable_phrases_player_view_2.9.0.json b/tests/saves/view_valuable_phrases_player_view_2.9.0.json new file mode 100644 index 0000000..e48ef31 --- /dev/null +++ b/tests/saves/view_valuable_phrases_player_view_2.9.0.json @@ -0,0 +1,516 @@ +{ + "adventure_name": "The Drowned Priory", + "adventure_description": "", + "town_name": "Threshold", + "town_description": "", + "town_services": [], + "town_healing_prices": { + "cure_light_wounds": 25, + "cure_serious_wounds": 100, + "cure_disease": 150, + "neutralize_poison": 150, + "remove_curse": 200, + "raise_dead": 1500 + }, + "party": [ + { + "id": "character-0001", + "name": "Brakk", + "class_id": "fighter", + "class_name": "Fighter", + "level": 1, + "current_hp": 6, + "max_hp": 6, + "conditions": [], + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0002", + "kind": "jewellery", + "name": "The abbot's seal ring", + "value_gp": 900, + "weight_coins": 0 + } + ], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "memorized_spells": [], + "encounter_rate_feet": 40, + "race": "human", + "alignment": "lawful", + "title": "Veteran", + "xp": 0, + "xp_next_level": 2000, + "scores": { + "str": 11, + "int": 11, + "wis": 11, + "dex": 11, + "con": 11, + "cha": 11 + }, + "effective_strength": 11, + "melee_modifier": 0, + "missile_modifier": 0, + "initiative_modifier": 0, + "hit_point_modifier": 0, + "magic_save_modifier": 0, + "npc_reaction_modifier": 0, + "open_doors_chance": 2, + "thac0": 19, + "attack_bonus": 0, + "armour_class": 9, + "armour_class_ascending": 10, + "saves": { + "death": 12, + "wands": 13, + "paralysis": 14, + "breath": 15, + "spells": 16 + }, + "movement_rate_feet": 120, + "languages": [ + "alignment_lawful", + "common" + ], + "spell_book": [], + "spell_slots": [], + "preparable_spells": [], + "learnable_spells": [], + "reverses_at": null, + "can_prepare_now": false, + "needs_sleep_to_prepare": false, + "thief_skills": {} + }, + { + "id": "character-0002", + "name": "Sable", + "class_id": "thief", + "class_name": "Thief", + "level": 1, + "current_hp": 6, + "max_hp": 6, + "conditions": [], + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "memorized_spells": [], + "encounter_rate_feet": 40, + "race": "human", + "alignment": "lawful", + "title": "Apprentice", + "xp": 0, + "xp_next_level": 1200, + "scores": { + "str": 11, + "int": 11, + "wis": 11, + "dex": 11, + "con": 11, + "cha": 11 + }, + "effective_strength": 11, + "melee_modifier": 0, + "missile_modifier": 0, + "initiative_modifier": 0, + "hit_point_modifier": 0, + "magic_save_modifier": 0, + "npc_reaction_modifier": 0, + "open_doors_chance": 2, + "thac0": 19, + "attack_bonus": 0, + "armour_class": 9, + "armour_class_ascending": 10, + "saves": { + "death": 13, + "wands": 14, + "paralysis": 13, + "breath": 16, + "spells": 15 + }, + "movement_rate_feet": 120, + "languages": [ + "alignment_lawful", + "common" + ], + "spell_book": [], + "spell_slots": [], + "preparable_spells": [], + "learnable_spells": [], + "reverses_at": null, + "can_prepare_now": false, + "needs_sleep_to_prepare": false, + "thief_skills": { + "climb_sheer_surfaces": 87, + "find_remove_treasure_traps": 10, + "hear_noise": 2, + "hide_in_shadows": 10, + "move_silently": 20, + "open_locks": 15, + "pick_pockets": 20 + } + }, + { + "id": "character-0003", + "name": "Wynn", + "class_id": "cleric", + "class_name": "Cleric", + "level": 1, + "current_hp": 6, + "max_hp": 6, + "conditions": [], + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0003", + "kind": "gem", + "name": "Gem", + "value_gp": 40, + "weight_coins": 0 + } + ], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "memorized_spells": [], + "encounter_rate_feet": 40, + "race": "human", + "alignment": "lawful", + "title": "Acolyte", + "xp": 0, + "xp_next_level": 1500, + "scores": { + "str": 11, + "int": 11, + "wis": 13, + "dex": 11, + "con": 11, + "cha": 11 + }, + "effective_strength": 11, + "melee_modifier": 0, + "missile_modifier": 0, + "initiative_modifier": 0, + "hit_point_modifier": 0, + "magic_save_modifier": 1, + "npc_reaction_modifier": 0, + "open_doors_chance": 2, + "thac0": 19, + "attack_bonus": 0, + "armour_class": 9, + "armour_class_ascending": 10, + "saves": { + "death": 11, + "wands": 12, + "paralysis": 14, + "breath": 16, + "spells": 15 + }, + "movement_rate_feet": 120, + "languages": [ + "alignment_lawful", + "common" + ], + "spell_book": [], + "spell_slots": [ + 0, + 0, + 0, + 0, + 0 + ], + "preparable_spells": [], + "learnable_spells": [], + "reverses_at": "cast", + "can_prepare_now": false, + "needs_sleep_to_prepare": true, + "thief_skills": {} + }, + { + "id": "character-0004", + "name": "Elara", + "class_id": "magic_user", + "class_name": "Magic-User", + "level": 1, + "current_hp": 6, + "max_hp": 6, + "conditions": [], + "inventory": { + "items": [], + "purse": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "valuables": [ + { + "instance_type": "valuable", + "instance_id": "valuable-0001", + "kind": "jewellery", + "name": "Silver altar candlestick", + "value_gp": 300, + "weight_coins": 0 + } + ], + "worn_armour": null, + "shield": null, + "wielded": [], + "rings": [] + }, + "memorized_spells": [], + "encounter_rate_feet": 40, + "race": "human", + "alignment": "lawful", + "title": "Medium", + "xp": 0, + "xp_next_level": 2500, + "scores": { + "str": 11, + "int": 11, + "wis": 11, + "dex": 11, + "con": 11, + "cha": 11 + }, + "effective_strength": 11, + "melee_modifier": 0, + "missile_modifier": 0, + "initiative_modifier": 0, + "hit_point_modifier": 0, + "magic_save_modifier": 0, + "npc_reaction_modifier": 0, + "open_doors_chance": 2, + "thac0": 19, + "attack_bonus": 0, + "armour_class": 9, + "armour_class_ascending": 10, + "saves": { + "death": 13, + "wands": 14, + "paralysis": 13, + "breath": 16, + "spells": 15 + }, + "movement_rate_feet": 120, + "languages": [ + "alignment_lawful", + "common" + ], + "spell_book": [ + "sleep" + ], + "spell_slots": [ + 1, + 0, + 0, + 0, + 0, + 0 + ], + "preparable_spells": [ + "sleep" + ], + "learnable_spells": [], + "reverses_at": "memorize", + "can_prepare_now": false, + "needs_sleep_to_prepare": true, + "thief_skills": {} + } + ], + "location": { + "kind": "dungeon", + "dungeon_id": "priory", + "level_number": 1, + "position": [ + 0, + 0 + ], + "facing": "north" + }, + "clock_rounds": 120, + "mode": "exploring", + "explored": [ + { + "dungeon_id": "priory", + "level_number": 1, + "cells": [ + [ + 0, + 0 + ] + ], + "edges": { + "0,0:north": { + "kind": "wall", + "door_open": null, + "door_wedged": null + }, + "1,0:west": { + "kind": "wall", + "door_open": null, + "door_wedged": null + }, + "0,1:north": { + "kind": "wall", + "door_open": null, + "door_wedged": null + }, + "0,0:west": { + "kind": "wall", + "door_open": null, + "door_wedged": null + } + }, + "areas": [ + { + "id": "nave", + "name": "Nave", + "description": "", + "cells": [ + [ + 0, + 0 + ] + ], + "trap_state": null + } + ], + "features": [ + { + "id": "feature:dd21a6abe37eb019fdfdc28df11b6e0fa3db5354d97156edc48660de6f99dc4f", + "kind": "treasure_cache", + "description": "", + "cell": [ + 0, + 0 + ], + "area_id": "nave", + "trap_state": null, + "emptied": true + } + ], + "transitions": [], + "entrance": [ + 0, + 0 + ] + } + ], + "dungeons": [ + { + "id": "priory", + "name": "The Priory" + } + ], + "can_travel_to_town": true, + "features_here": [ + "feature:dd21a6abe37eb019fdfdc28df11b6e0fa3db5354d97156edc48660de6f99dc4f" + ], + "piles": { + "cell:priory:1:0,0": { + "items": [ + "Eye of Ossor", + "An amber tear", + "jewellery" + ], + "coins_gp_value": 0, + "coins": { + "pp": 0, + "gp": 0, + "ep": 0, + "sp": 0, + "cp": 0 + }, + "contents": [ + { + "item_id": "valuable-0004", + "quantity": 1 + }, + { + "item_id": "valuable-0005", + "quantity": 1 + }, + { + "item_id": "valuable-0006", + "quantity": 1 + } + ] + } + }, + "emptied_caches": [ + "priory:1:reliquary" + ], + "effects": [], + "spell_names": { + "sleep": "Sleep" + }, + "reversed_spell_names": {}, + "spell_levels": { + "sleep": 1 + }, + "item_names": { + "valuable-0002": "piece of jewellery", + "valuable-0003": "gem", + "valuable-0001": "piece of jewellery", + "valuable-0004": "gem", + "valuable-0005": "gem", + "valuable-0006": "piece of jewellery" + }, + "item_names_plural": { + "valuable-0002": "pieces of jewellery", + "valuable-0003": "gems", + "valuable-0001": "pieces of jewellery", + "valuable-0004": "gems", + "valuable-0005": "gems", + "valuable-0006": "pieces of jewellery" + }, + "valuable_names": { + "valuable-0002": "The abbot's seal ring", + "valuable-0001": "Silver altar candlestick", + "valuable-0004": "Eye of Ossor", + "valuable-0005": "An amber tear" + }, + "fatigued": false, + "exhausted": false, + "deprivation": {}, + "journal": [], + "quests": [], + "encounter": null +} diff --git a/tests/test_view_valuable_phrases.py b/tests/test_view_valuable_phrases.py new file mode 100644 index 0000000..2ea494b --- /dev/null +++ b/tests/test_view_valuable_phrases.py @@ -0,0 +1,472 @@ +"""The player view words each named gem's or piece of jewellery's phrase for the middle of a sentence (issue #354). + +`PlayerView.valuable_names` gives a piece's own name as its author wrote it for a list, with a capital, like +`"Silver altar candlestick"` or `"Prior's chain of office"`. A client can't put that in a sentence, because it can't +tell a common noun, which needs an article and a lowercase start, from a proper name, which needs neither. +`PlayerView.valuable_phrases` gives the whole phrase, article and case included, under the same keys: the piece's +`phrase` when its author set one, and otherwise a phrase osrlib makes from the name. + +The made phrase follows one rule. A name whose first word is "the", "a", or "an", in any case, keeps its words with +that first word in lowercase. Any other name gets its first letter in lowercase and "an" in front before a vowel, "a" +otherwise. A `phrase` that's only whitespace counts as empty. A piece with no name of its own, whose name is empty or +the `"Gem"` or `"Jewellery"` that treasure generation gives its kind, is a key in neither map, whatever its `phrase` +holds. +""" + +import json +from pathlib import Path + +import pytest + +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, DropPile, DungeonSpec, FeatureSpec, LevelSpec, ValuableSpec, cell_ref +from osrlib.crawl.session import GameSession +from osrlib.crawl.views import PileItemView, PlayerView +from osrlib.persistence import load_game, save_game + +SAVES = Path(__file__).parent / "saves" +SAVE_2_9_0 = SAVES / "view_valuable_phrases_2.9.0.json" +"""A save of `hauled(OLD_KEPT, OLD_DROPPED)`, written by osrlib 2.9.0 before `phrase` existed.""" +VIEW_2_9_0 = SAVES / "view_valuable_phrases_player_view_2.9.0.json" +"""The `PlayerView` of the same state, dumped as JSON by osrlib 2.9.0, as a client might store a feed entry.""" + +SEED = 31 +"""Any seed: the adventure has no rolled treasure and no wandering monsters, so nothing here depends on a roll.""" + +NAVE = cell_ref("priory", 1, (0, 0)) +"""The entrance cell, where the party stands, so a pile here is a known pile.""" +TOMB = cell_ref("priory", 1, (2, 0)) +"""A cell the party never walks, so a pile here is a pile the party doesn't know.""" + +# The placed pieces of the 2.9.0 save. None has a phrase, because osrlib 2.9.0 wrote the save, so each named piece's +# phrase is made from its name. +CANDLESTICK = ValuableSpec(kind="jewellery", name="Silver altar candlestick", value_gp=300) +SEAL_RING = ValuableSpec(kind="jewellery", name="The abbot's seal ring", value_gp=900) +ROLLED_LOOKALIKE = ValuableSpec(kind="gem", name="Gem", value_gp=40) +EYE = ValuableSpec(kind="gem", name="Eye of Ossor", value_gp=500) +AMBER = ValuableSpec(kind="gem", name="An amber tear", value_gp=250) +BARE_JEWEL = ValuableSpec(kind="jewellery", value_gp=350) +OLD_KEPT = (CANDLESTICK, SEAL_RING, ROLLED_LOOKALIKE) +OLD_DROPPED = (EYE, AMBER, BARE_JEWEL) +OLD_PHRASES = { + # No phrase, so each is made from the name. "Silver" isn't an article and starts with a consonant: "a", and only + # the first letter is lowered. + CANDLESTICK: "a silver altar candlestick", + # The first word is "The": it keeps its words, with "The" lowered. + SEAL_RING: "the abbot's seal ring", + # "Eye" starts with a vowel: "an". Only the first letter is lowered, so "Ossor" keeps its capital. + EYE: "an eye of Ossor", + # The first word is "An": it keeps its words, with "An" lowered. + AMBER: "an amber tear", +} +"""The phrase of each named piece in the 2.9.0 save. `ROLLED_LOOKALIKE` is named `"Gem"`, the name treasure +generation gives a gem, and `BARE_JEWEL` has no name, so neither is a key.""" + +# The placed pieces with phrases, for the haul that only this version can make. +OSSOR = ValuableSpec(kind="gem", name="Ossor's Eye", phrase="Ossor's Eye", value_gp=1500) +CHAIN = ValuableSpec( + kind="jewellery", name="Prior's chain of office", phrase="the Prior's chain of office", value_gp=1200 +) +STAR = ValuableSpec(kind="gem", name="Star of the lower chapel", phrase=" \t ", value_gp=400) +CLOUDY = ValuableSpec(kind="gem", phrase="a cloudy opal", value_gp=60) +BROOCH = ValuableSpec(kind="jewellery", name="Jewellery", phrase="a tarnished brooch", value_gp=70) +NEW_KEPT = (OSSOR, STAR, CLOUDY, CANDLESTICK) +NEW_DROPPED = (CHAIN, BROOCH) +NEW_PHRASES = { + # A phrase is used as written. + OSSOR: "Ossor's Eye", + CHAIN: "the Prior's chain of office", + # A phrase of whitespace alone counts as empty, so the phrase is made from the name: "a", first letter lowered. + STAR: "a star of the lower chapel", + # No phrase. + CANDLESTICK: "a silver altar candlestick", +} +"""The phrase of each named piece in the phrased haul. `CLOUDY` has no name, and `BROOCH` has the name treasure +generation gives a piece of jewellery, so neither is a key, whatever its phrase.""" + +MITRE = ValuableSpec(kind="jewellery", name="Bishop's mitre jewel", phrase="the 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", phrase="the drowned crown", value_gp=700 +) +"""In a pile on the tomb's cell, which the party doesn't know.""" + + +def _adventure(reliquary: tuple[ValuableSpec, ...]) -> Adventure: + """Three cells in a row. The party enters at the nave, on the west, whose reliquary holds `reliquary`. The tomb, + on the east, stays unvisited.""" + nave_features = ( + (FeatureSpec(id="reliquary", kind="treasure_cache", cell=(0, 0), valuables=reliquary),) if reliquary else () + ) + 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=nave_features), + 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 _pieces(game: GameSession) -> list[ValuableInstance]: + """Every valuable in the session, carried or in a pile, known or not.""" + carried = [valuable for member in game.party.members for valuable in member.inventory.valuables] + return carried + [valuable for pile in game.dungeon_state.piles.values() for valuable in pile.valuables] + + +def _placed(game: GameSession, spec: ValuableSpec) -> ValuableInstance: + """The piece `spec` placed, wherever it is now, found by its kind, name, and value.""" + (piece,) = ( + valuable + for valuable in _pieces(game) + if (valuable.kind, valuable.name, valuable.value_gp) == (spec.kind, spec.name, spec.value_gp) + ) + return piece + + +def hauled(kept: tuple[ValuableSpec, ...], dropped: tuple[ValuableSpec, ...]) -> GameSession: + """The stock party enters the priory, empties the reliquary of `kept` and `dropped`, and drops `dropped` onto + the nave's cell, so the packs hold `kept` and a known pile holds `dropped`. + + The builder uses no name that osrlib 2.9.0 lacks, so the 2.9.0 fixture writer runs it too. + """ + game = GameSession.new(build_party(), _adventure(kept + dropped), seed=SEED) + assert game.execute(EnterDungeon(dungeon_id="priory")).accepted + 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] + holders = { + valuable.instance_id: member.id for member in game.party.members for valuable in member.inventory.valuables + } + assert len(holders) == len(kept) + len(dropped), "precondition: the party carries every placed piece" + for spec in dropped: + instance_id = _placed(game, spec).instance_id + result = game.execute(DropItems(character_id=holders[instance_id], item_ids=(instance_id,))) + assert result.accepted, [rejection.code for rejection in result.rejections] + return game + + +def _with_pieces(pack: list[ValuableInstance], pile: list[ValuableInstance]) -> GameSession: + """A session in the nave whose first member carries `pack` and whose known pile on the nave's cell holds `pile`, + each piece built by hand, so a test can give a piece any name and phrase.""" + game = GameSession.new(build_party(), _adventure(()), seed=SEED) + assert game.execute(EnterDungeon(dungeon_id="priory")).accepted + game.party.members[0].inventory.valuables.extend(pack) + game.dungeon_state.piles[NAVE] = DropPile(valuables=pile) + view = _player_view(game) + shown = {valuable["instance_id"] for sheet in view.party for valuable in sheet.inventory["valuables"]} + assert {piece.instance_id for piece in pack} <= shown, "precondition: the view shows the pack" + assert NAVE in view.piles, "precondition: the nave's pile is known" + return game + + +def _piece(number: int, name: str, phrase: str = "", kind: str = "jewellery") -> ValuableInstance: + return ValuableInstance(instance_id=f"valuable-{number:04d}", kind=kind, name=name, phrase=phrase, value_gp=100) + + +def _expected(game: GameSession, phrases: dict[ValuableSpec, str]) -> dict[str, str]: + return {_placed(game, spec).instance_id: phrase for spec, phrase in phrases.items()} + + +# ---------------------------------------------------------------------- the made phrase + + +MADE = [ + # A name with no article starts with a consonant: "a", and its first letter is lowered. + ("Silver altar candlestick", "a silver altar candlestick"), + ("Moonstone", "a moonstone"), + # "y" isn't a vowel. + ("Yellow topaz", "a yellow topaz"), + # A name that already starts in lowercase gets the article alone. + ("garnet", "a garnet"), + # A vowel takes "an". Only the first letter is lowered, so a capital later in the name stays. + ("Eye of Ossor", "an eye of Ossor"), + ("Opal of the Lower Chapel", "an opal of the Lower Chapel"), + ("Ivory comb", "an ivory comb"), + ("Aquamarine", "an aquamarine"), + # "u" is a vowel, so the rule gives "an". An author who wants "a" sets the phrase. + ("Unicorn-horn cup", "an unicorn-horn cup"), + # A proper name gets the rule's phrase too, which reads wrong. That's what `phrase` is for. + ("Ossor's Eye", "an ossor's Eye"), + # A first word of "the", "a", or "an" keeps the name's words, with that word lowered, in any case. + ("The abbot's seal ring", "the abbot's seal ring"), + ("the prior's chain", "the prior's chain"), + ("THE ABBOT'S SEAL", "the ABBOT'S SEAL"), + ("A ring of drowned silver", "a ring of drowned silver"), + ("An amber tear", "an amber tear"), + ("AN Onyx Idol", "an Onyx Idol"), + # The article must be the whole first word: "Theodric's" and "Annulet" only start with one. + ("Theodric's torc", "a theodric's torc"), + ("Annulet of jet", "an annulet of jet"), + # A vowel with an accent is a vowel, and a consonant with one isn't. + ("\u00c9meraude du prieur", "an \u00e9meraude du prieur"), + ("\u00d6l-lamp of horn", "an \u00f6l-lamp of horn"), + ("\u00c7intamani stone", "a \u00e7intamani stone"), + # The first character is lowered, whatever it is, and the article follows the first letter only when it's first. + ("'Lucky' ring", "a 'Lucky' ring"), +] + + +@pytest.mark.parametrize(("name", "phrase"), MADE, ids=[name for name, _ in MADE]) +def test_a_piece_with_no_phrase_has_the_phrase_made_from_its_name(name, phrase): + """The same piece's phrase, made by the rule, in a member's pack and in a known pile.""" + game = _with_pieces([_piece(101, name)], [_piece(102, name)]) + + view = _player_view(game) + + assert view.valuable_phrases == {"valuable-0101": phrase, "valuable-0102": phrase} + assert view.valuable_names == {"valuable-0101": name, "valuable-0102": name} + + +@pytest.mark.parametrize( + ("name", "phrase"), + [ + ("Ossor's Eye", "Ossor's Eye"), + ("Prior's chain of office", "the Prior's chain of office"), + # The phrase is used as written, so a capital the author gave it stays. + ("Silver altar candlestick", "A silver altar candlestick"), + ("Moonstone", "the moonstone of the lower chapel"), + ], +) +def test_a_piece_with_a_phrase_has_it_as_written(name, phrase): + game = _with_pieces([_piece(101, name, phrase)], [_piece(102, name, phrase)]) + + view = _player_view(game) + + assert view.valuable_phrases == {"valuable-0101": phrase, "valuable-0102": phrase} + + +def test_spaces_around_a_name_or_a_phrase_dont_count(): + """The view shows a name and a phrase without the whitespace around them, and judges whether a piece has a name + of its own without it. So a gem named `" Gem "` is a rolled gem's lookalike, with a key in neither map, and a + pile's `items` show each piece's name trimmed. The pieces themselves keep what their author wrote.""" + pieces = [ + (" The ring of Hael ", "", "jewellery"), + ("\tSilver ewer\n", "", "jewellery"), + (" Moonstone ", " the Moonstone ", "gem"), + (" Gem ", "", "gem"), + (" Jewellery\t", " a tarnished brooch ", "jewellery"), + ] + pack = [_piece(101 + n, name, phrase, kind) for n, (name, phrase, kind) in enumerate(pieces)] + pile = [_piece(201 + n, name, phrase, kind) for n, (name, phrase, kind) in enumerate(pieces)] + game = _with_pieces(pack, pile) + + view = _player_view(game) + + names = ["The ring of Hael", "Silver ewer", "Moonstone"] + phrases = ["the ring of Hael", "a silver ewer", "the Moonstone"] + assert view.valuable_names == { + f"valuable-{base + n:04d}": name for base in (101, 201) for n, name in enumerate(names) + } + assert view.valuable_phrases == { + f"valuable-{base + n:04d}": phrase for base in (101, 201) for n, phrase in enumerate(phrases) + } + assert view.piles[NAVE].items == (*names, "Gem", "Jewellery") + assert [piece.name for piece in game.party.members[0].inventory.valuables] == [name for name, _, _ in pieces] + + +@pytest.mark.parametrize("blank", ["", " ", "\t", " \n\t "]) +def test_a_phrase_of_whitespace_alone_counts_as_empty(blank): + """As `SpellMode.display_name` treats a label of whitespace alone. "Star" takes "a", first letter lowered.""" + game = _with_pieces([_piece(101, "Star of the lower chapel", blank)], []) + + assert _player_view(game).valuable_phrases == {"valuable-0101": "a star of the lower chapel"} + + +def test_the_keys_are_exactly_the_keys_of_valuable_names(): + """Every variant, in a member's pack and in a known pile. + + The variants are a named piece with no phrase, one with a phrase, one with a phrase of whitespace alone, and, with + no name of their own, an empty name with and without a phrase, and the rolled name of each kind with and without a + phrase. Only the first three are keys, in both maps, in both places. + """ + variants = [ + ("Silver altar candlestick", "", "jewellery", True), + ("Ossor's Eye", "Ossor's Eye", "gem", True), + ("Star of the lower chapel", " ", "gem", True), + ("", "a cloudy opal", "gem", False), + ("", "", "jewellery", False), + ("Gem", "a gem of the lower chapel", "gem", False), + ("Gem", "", "gem", False), + ("Jewellery", "a tarnished brooch", "jewellery", False), + ("Jewellery", "", "jewellery", False), + ] + pack = [_piece(100 + n, name, phrase, kind) for n, (name, phrase, kind, _) in enumerate(variants)] + pile = [_piece(200 + n, name, phrase, kind) for n, (name, phrase, kind, _) in enumerate(variants)] + game = _with_pieces(pack, pile) + + view = _player_view(game) + + keyed = {f"valuable-{base + n:04d}" for base in (100, 200) for n, (*_, has_name) in enumerate(variants) if has_name} + assert set(view.valuable_names) == keyed + assert set(view.valuable_phrases) == keyed + assert view.valuable_phrases == { + f"valuable-{base + n:04d}": phrase + for base in (100, 200) + for n, phrase in enumerate(["a silver altar candlestick", "Ossor's Eye", "a star of the lower chapel"]) + } + + +@pytest.mark.parametrize("blank", [" ", "\t", " \n\t "]) +def test_a_name_of_whitespace_alone_is_no_name_of_its_own(blank): + """A piece whose name is only whitespace has no name of its own, like a piece whose name is empty (issue #355). + + It is a key in neither map, with or without a phrase, in a pack and in a pile, and the pile's `items` show its + kind, as they do for a piece with an empty name. + """ + pack = [_piece(101, blank, kind="gem"), _piece(102, blank, "a cloudy opal", kind="gem")] + pile = [_piece(201, blank), _piece(202, blank, "a tarnished brooch")] + game = _with_pieces(pack, pile) + + view = _player_view(game) + + assert view.valuable_names == {} + assert view.valuable_phrases == {} + assert [view.item_names[f"valuable-{n:04d}"] for n in (101, 102, 201, 202)] == [ + "gem", + "gem", + "piece of jewellery", + "piece of jewellery", + ] + assert view.piles[NAVE].items == ("jewellery", "jewellery") + + +# ---------------------------------------------------------------------- the haul + + +def test_taking_a_placed_piece_copies_its_phrase(): + """The session copies each spec's `phrase` to the piece it makes, as it copies `name`, whitespace and all. The + inventory's `valuables` show it as they show `name`, and the view has the phrase of each named piece, carried + and dropped.""" + game = hauled(NEW_KEPT, NEW_DROPPED) + + for spec in NEW_KEPT + NEW_DROPPED: + assert _placed(game, spec).phrase == spec.phrase, spec.name + view = _player_view(game) + shown = {valuable["instance_id"]: valuable for sheet in view.party for valuable in sheet.inventory["valuables"]} + for spec in NEW_KEPT: + entry = shown[_placed(game, spec).instance_id] + assert (entry["name"], entry["phrase"]) == (spec.name, spec.phrase) + assert view.valuable_phrases == _expected(game, NEW_PHRASES) + assert set(view.valuable_phrases) == set(view.valuable_names) + + +def test_a_session_restored_from_a_save_has_the_same_phrases(): + game = hauled(NEW_KEPT, NEW_DROPPED) + + loaded = load_game(json.loads(json.dumps(save_game(game)))) + + for spec in NEW_KEPT + NEW_DROPPED: + assert _placed(loaded, spec).phrase == spec.phrase, spec.name + assert _player_view(loaded).valuable_phrases == _player_view(game).valuable_phrases == _expected(game, NEW_PHRASES) + + +def test_an_adventure_document_keeps_a_phrase(): + """A guard: an author's phrase survives the adventure document's JSON round trip.""" + adventure = _adventure(NEW_KEPT + NEW_DROPPED) + + restored = Adventure.model_validate_json(adventure.model_dump_json()) + + (reliquary, *_) = restored.dungeons[0].levels[0].areas[0].features + assert [spec.phrase for spec in reliquary.valuables] == [spec.phrase for spec in NEW_KEPT + NEW_DROPPED] + + +def test_a_piece_the_party_cant_see_has_no_phrase_in_the_view(): + """A guard: 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 phrase is anywhere in the view.""" + game = hauled(NEW_KEPT, NEW_DROPPED) + game.dungeon_state.piles[TOMB] = DropPile(valuables=[CROWN]) + + view = _player_view(game) + + assert CROWN.instance_id not in view.valuable_phrases + blob = view.model_dump_json() + for hidden in ("mitre", "crown"): + assert hidden not in blob.lower(), hidden + + +# ---------------------------------------------------------------------- what osrlib 2.9.0 wrote + + +def test_a_save_from_osrlib_2_9_0_gives_a_phrase_for_every_named_piece(): + """A 2.9.0 save's pieces have no phrase, so each named piece's phrase is made from its name, and the keys are the + keys of `valuable_names`. The whole view of the loaded save is the view of the same state built now.""" + document = json.loads(SAVE_2_9_0.read_text(encoding="utf-8")) + assert document["engine_version"] == "2.9.0" + + loaded = load_game(document) + + game = hauled(OLD_KEPT, OLD_DROPPED) + assert all(piece.phrase == "" for piece in _pieces(loaded)) + view = _player_view(loaded) + assert set(view.valuable_names) == set(_expected(game, OLD_PHRASES)), "precondition: the named pieces" + assert view.valuable_phrases == _expected(game, OLD_PHRASES) + assert set(view.valuable_phrases) == set(view.valuable_names) + assert view == _player_view(game) + + +def test_a_player_view_from_osrlib_2_9_0_validates_with_no_phrases(): + """A guard: a client that stored a `PlayerView` osrlib 2.9.0 built, like a feed entry, can still read it. The + view has `valuable_names` and no `valuable_phrases`, and it validates with the map empty.""" + document = json.loads(VIEW_2_9_0.read_text(encoding="utf-8")) + assert "valuable_phrases" not in document + assert document["valuable_names"], "precondition: the stored view names some pieces" + + view = PlayerView.model_validate(document) + + assert view.valuable_phrases == {} + assert view.valuable_names == document["valuable_names"] + assert set(view.valuable_names) == { + _placed(hauled(OLD_KEPT, OLD_DROPPED), spec).instance_id for spec in OLD_PHRASES + } + + +# ---------------------------------------------------------------------- the docs + + +def _description(model: type, field: str) -> str: + return model.model_json_schema()["properties"][field]["description"] + + +def test_the_docstrings_send_a_sentence_to_valuable_phrases(): + """Each place that told a client to show a valuable's name in a sentence names `valuable_phrases` instead.""" + guidance = { + "PlayerView.valuable_names": _description(PlayerView, "valuable_names"), + "PlayerView.item_names": _description(PlayerView, "item_names"), + "PileItemView": PileItemView.__doc__ or "", + } + for place, text in guidance.items(): + assert "valuable_phrases" in text, place + assert "Sam takes Prior's chain of office" not in text, place + + +def test_the_guides_and_the_changelog_describe_the_phrases(): + root = Path(__file__).parent.parent + views_guide = (root / "docs" / "guides" / "views-and-visibility.md").read_text(encoding="utf-8") + authoring_guide = (root / "docs" / "guides" / "authoring-custom-content.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 "(#354)" in line] + + assert "valuable_phrases" in views_guide + assert "Sam takes Prior's chain of office" not in views_guide + assert "ValuableSpec.phrase" in authoring_guide or "`phrase`" in authoring_guide + (bullet,) = (line for line in bullets if "valuable_phrases" in line) + assert "phrase" in bullet.replace("valuable_phrases", "")