diff --git a/CHANGELOG.md b/CHANGELOG.md index 64aac844..8ccfa332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - [`RefereeView.feature_handles`][osrlib.crawl.views.RefereeView.feature_handles] maps each feature's save reference to the player handle the player view shows for it, for every authored feature and every generated cache, including a lair cache the players can't see yet (#318). A referee tool can use it to show a referee the feature the players see, and to send the same `feature_id` they do. The player-handle key stays out of both views. The session derives the five fields from state a save already contains, so a 2.7.0 save loads with them filled in, every new field has a default, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4. - [`FeatureSpec.referee_notes`][osrlib.crawl.dungeon.FeatureSpec.referee_notes] is a new string field for what the referee reads about a feature and the players never do, such as what a cache holds or how its trap is hidden (#318). osrlib never reads it, no event includes it, and no rule depends on it. It's in the adventure document, so a save and [`RefereeView.adventure`][osrlib.crawl.views.RefereeView.adventure] have it, but the player view doesn't include it. It defaults to an empty string, so an adventure document written before this release loads unchanged, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4. - [`EncounterView.can_back_stab`][osrlib.crawl.views.EncounterView.can_back_stab] lists the members who can declare an `attack` with [`back_stab`][osrlib.crawl.commands.BattleDeclaration.back_stab] this round: those whose class has the `back_stab` ability, in the party's free round or while they're hiding (#319). The session never refuses a back-stab by a member in it with `battle.declaration.back_stab_no_ability` or `battle.declaration.back_stab_target_aware`, and always refuses one by any other declarer with one of them, because the list comes from the same checks. So a client no longer needs to combine the class catalog, `party_free_round`, and `hiding`, and the list is also correct for a custom class, which isn't in the catalog. [`BattleRoundPreview.can_hide`][osrlib.crawl.battle.BattleRoundPreview.can_hide] and [`BattleRoundPreview.can_back_stab`][osrlib.crawl.battle.BattleRoundPreview.can_back_stab] give the two lists beside the declarations planned so far, judging each member as if the `hide` or the back-stab took the place of their own planned declaration. So another member's planned fighting withdrawal can take a thief out of `can_hide`, and another member's planned `close` can put one in it. A preview with no planned move gives the view's lists. Building the lists takes no draw, and each new field has an empty default, so a view or a preview from 2.7.0 still parses. +- Every equipment and magic item template has a `display_name` and a `display_name_plural`, what to call one unit and two or more in a sentence, such as `"vial of holy water"` and `"vials of holy water"` for the gear printed as `Holy water (vial)` (#316). They're on [`WeaponTemplate`][osrlib.core.items.WeaponTemplate], [`ArmourTemplate`][osrlib.core.items.ArmourTemplate], [`GearTemplate`][osrlib.core.items.GearTemplate], [`AmmunitionTemplate`][osrlib.core.items.AmmunitionTemplate], and [`MagicItemTemplate`][osrlib.core.items.MagicItemTemplate]. Each name refers to the unit that an instance's `quantity` counts, not to a lot from the price list, so `Torches (6)` is `"torch"` and `Arrows +1 (3d10 arrows)` is `"arrow +1"`. The SRD compiler fills them for the built-in catalogs. A template you write that leaves them out gets its `name`, and a plural with the regular English ending on the word that names the item, the last word before the first `of`, `with`, or `vs` in any case, a comma, a bonus such as `+1`, a closing Roman numeral, or an opening parenthesis, or the last word of a name with none of them. So `"Idol of the drowned saint"` becomes `"Idols of the drowned saint"`, `"Staff Of Power"` becomes `"Staves Of Power"`, and spaces after the word stay after the ending. Every compiled plural follows the same rule. An adventure document from 2.7.0 still loads. +- [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] and [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] name every item whose id the view shows, keyed by that id: a mundane stack's catalog id, and a magic item's or a valuable's instance id, in a member's inventory or a known pile (#316). A mundane stack, carried or in a pile, is named from the session's catalog, [`GameSession.effective_equipment`][osrlib.crawl.session.GameSession.effective_equipment], so an item the adventure bundles is named, and a stack from a 2.7.0 save or party document, which embeds a template without display names, is named as a new stack is. A carried stack whose id the catalog lacks, such as an item another adventure bundled, is named from the template it embeds. An unidentified magic item is named by its masked name without the article, like `"potion"` or `"shield with a faint aura"`, so a cursed item has the names of the item it passes for, and the view never includes its template id. An identified item is named by its template's display names, under its instance id, and under its template id while a member carries it, because a pile shows a magic item by its instance id alone. A gem is `"gem"` and a piece of jewellery `"piece of jewellery"`. Before, a client with only the view and the events couldn't word "The party finds 2 vials of holy water". +- [`PileView.contents`][osrlib.crawl.views.PileView.contents] gives each thing in a pile as a [`PileItemView`][osrlib.crawl.views.PileItemView], with the id that the events use for it and its count, in the order of `items` (#316). A client reads `"holy_water"` and 2 there where `items` has `"holy_water×2"`. `items` doesn't change. +- [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] has two new fields, `display_name` and `display_name_plural`, the identified item's display names, like `"potion of healing"` (#316). A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, but the event does. An event recorded before this release has empty names. Every field this release adds has a default, so a 2.7.0 save, view, or event still parses, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4. +- The gear in a save or a party document that osrlib 2.7.0 wrote takes the display names of the session's catalog (#316). Its embedded templates have no display names, so they validate with the defaults from the price-list `name`, like `"Holy water (vial)"`. When a session starts, when [`load_game`][osrlib.persistence.load_game] restores one, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, each template that a party member's or an NPC adventurer's stack embeds takes the `display_name` and `display_name_plural` of the catalog's template with the same id, with the `overrides_applied` entries that name those two fields. So holy water from a 2.7.0 save reads `"vial of holy water"` in `MemberView.inventory`, in the referee view, and in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], and the next save writes those names. Nothing else in the template changes, a template whose id the catalog lacks keeps its names, `AddMember`'s logged character keeps the templates it arrived with, and loading a save draws nothing. ### Fixed - The docstrings of [`FeatureSpec.description`][osrlib.crawl.dungeon.FeatureSpec.description] and [`MapFeatureView.description`][osrlib.crawl.views.MapFeatureView.description], and the guide to authoring custom content, say who reads a feature's description (#318). Since 2.6.0, the player view shows a cache's authored description as soon as the cache comes into view, before anyone opens it and after the party empties it. Before 2.6.0, only a referee read that text, but neither the 2.6.0 changelog nor the docstring, which called it "Text to show when the party finds the feature", said that the players now read it. If you wrote an adventure before 2.6.0, check each cache's description for its contents, the identity of a magic item the players see masked, and a trap the party hasn't found. Leave in `description` what the party sees from outside the cache, and move the rest: the contents to the cache's `item_ids`, `magic_item_ids`, `coins`, and `valuables`, the trap to its `trap`, and what only the referee reads to the new `referee_notes`. - The docstrings of [`FeatureSpec.id`][osrlib.crawl.dungeon.FeatureSpec.id] and of the `feature_id` field of [`TakeTreasure`][osrlib.crawl.commands.TakeTreasure], [`InspectTreasure`][osrlib.crawl.commands.InspectTreasure], and [`RemoveTreasureTrap`][osrlib.crawl.commands.RemoveTreasureTrap] say that both forms of feature id stay supported, the `feature:` handle from [`MapFeatureView.id`][osrlib.crawl.views.MapFeatureView.id] and the raw id (#318). A player client sends the handle, because the player view lists only handles, and a referee tool can send the raw id. Both forms resolve against the same features, the ones the party can reach where it stands, so a raw id reaches only the features that a handle reaches and reveals nothing more. Before, the docstrings called the raw id a form that current callers could still pass for compatibility, and didn't say what it could reach. - Outside a battle, [`CastSpell`][osrlib.crawl.commands.CastSpell] and [`UseItem`][osrlib.crawl.commands.UseItem] refuse a target that isn't a party member and isn't a creature in a group of the open encounter that hasn't fled (#317). The refusal is the one an id that matches nothing gets, `magic.cast.unknown_target` for a spell or a scroll and `items.use.unknown_target` for a staff of healing, with the same params, and it costs no draw, no time, and no state. Before, the session accepted as a target any creature still in `session.registry()`, so after the referee's `EndEncounter` a magic-user's *magic missile* at `monster-0001` damaged a goblin that the player view no longer listed. A monster or an NPC adventurer of an encounter that has ended, a monster of a group that fled, and a monster spawned into no encounter now get the unknown id's answer, alive or dead. A party member is still a target in any state, so *raise dead* and *stone to flesh* work as before. The fix also changes two related rejections. A scroll read at a dead creature of the open encounter gets `magic.cast.unknown_target`, as a `cast` declaration in a battle does, where before the spell landed on the corpse. A staff of healing declared in a battle at a dead creature of an encounter that has ended gets `items.use.unknown_target`, where before it got `items.use.target_cannot_be_healed`, which told you the creature was dead. A refused scroll read also no longer adds the `magic` stream to the session's saved RNG state. A command log recorded on 2.7.0 that holds such a command no longer replays, because the command is now refused. A session with no such command draws exactly as before on every stream. +- [`EquipmentDestroyedEvent`][osrlib.core.events.EquipmentDestroyedEvent], which the players see, names an unidentified magic item by its masked name, like `"a sword with a faint aura"`, the `display` the inventory showed for it (#316). Before, it named the item by its true name, like `"Sword +1"`, so a breath weapon that killed a member told the players what the member's unidentified items were. +- The masked `display` of an unidentified enchanted arm in [`MemberView.inventory`][osrlib.crawl.views.MemberView.inventory] and [`PileView.items`][osrlib.crawl.views.PileView.items] is built from one unit of the mundane item underneath it, its display name with "a" or "an" (#316). Enchanted arrows read `"an arrow with a faint aura"`, where they read `"a arrows (quiver of 20) with a faint aura"`, enchanted crossbow bolts read `"a crossbow bolt with a faint aura"`, where they read `"a crossbow bolts (case of 30) with a faint aura"`, enchanted chainmail reads `"a suit of chainmail with a faint aura"`, where it read `"a chainmail with a faint aura"`, and enchanted armour with no mundane armour recorded reads `"a suit of armour with a faint aura"`, where it read `"a arm with a faint aura"`. Enchanted leather and plate mail read `"a suit of leather armour with a faint aura"` and `"a suit of plate mail with a faint aura"`, where they read `"a leather with a faint aura"` and `"a plate mail with a faint aura"`. Enchanted silver tipped arrows read `"a silver tipped arrow with a faint aura"`, where they read `"a silver tipped arrow (1) with a faint aura"`, and enchanted sling stones read `"a sling stone with a faint aura"`, where they read `"a sling stones with a faint aura"`. The shield, sword, dagger, staff, and other weapon strings don't change. A front end that matches on the changed strings needs updating. ## [2.7.0] - 2026-11-25 diff --git a/docs/adaptations.md b/docs/adaptations.md index d4f81b69..0493b606 100644 --- a/docs/adaptations.md +++ b/docs/adaptations.md @@ -153,6 +153,18 @@ Ammunition compiles with a weight of 0. The ammunition table has no weight colum Sling stones cost 0 and are bought one at a time. The table entry for their cost reads `Free`, so osrlib sets the cost to 0 and the purchase lot to 1. Locked by `test_srd_data.py::TestEquipmentData`. +### Item display names name the unit the session counts + +The SRD prints item names for a price list or a treasure table, like `Torches (6)`, `Holy water (vial)`, and `Arrows +1 (3d10 arrows)`, so they name a lot and have no plural. Every compiled equipment and magic item template also has a `display_name` for one unit in a sentence and a `display_name_plural` for two or more. The compiler writes them by these rules: + +- The display name is the printed name with a trailing parenthesis dropped, in lowercase. A word printed all in capitals keeps its capitals, because it's an abbreviation or a Roman numeral: "potion of ESP", "treasure map II". +- It names one of the units that the item's `quantity` counts, not a lot. The compiler drops the plural ending from ammunition, so `Arrows (quiver of 20)` is "arrow" and `Arrows +1` is "arrow +1". Gear sold in a lot or as a substance is named by the unit or the container the SRD's descriptions give, so `Torches (6)` is "torch", `Holy water (vial)` is "vial of holy water", and `Oil (1 flask)` is "flask of oil". Those names come from `overrides/equipment.json`, with a reason for each. +- Body armour is a suit, "suit of chainmail" and "suit of armour +1", and the SRD's `Leather` is "suit of leather armour". Boots and gauntlets are a pair, "pair of boots of speed". The drums of panic and the elven cloak and boots are each a set. +- A spell scroll keeps its spell count, "spell scroll with 3 spells". The compiler moves a label after a colon to the front, so `Elemental Summoning Device: Air` is "air elemental summoning device", except a treasure map's numeral, which stays at the end. +- The plural ending goes on the word that names the item, before any `of`, `with`, `vs`, comma, bonus, numeral, or opening parenthesis, so the plurals read "vials of holy water", "swords +1, +3 vs undead", and "treasure maps II". The ending is the regular English one, except that "staff" becomes "staves". + +A template you write without the fields gets its `name`, and a plural by the same rule, which counts `of`, `with`, and `vs` in any case, because an author often writes a name in title case. So "Idol of the drowned saint" becomes "Idols of the drowned saint", and "Staff Of Power" becomes "Staves Of Power". `osrlib.core.items` has the one implementation of the rule, which the compiler imports, so every compiled plural is the one the rule gives. Locked by `test_item_display_names.py`. + ### INT-granted languages come from the Other Languages table and may not duplicate natives A character with high INT picks extra languages from the twenty Other Languages, and can't pick a language their class already speaks. So a dwarf can't spend an INT language on Dwarvish. @@ -1650,7 +1662,7 @@ Locked by `test_srd_data.py` and the `test_magic_items.py` census. ### Magic items enter play unidentified, identify on first meaningful use, and curses stick -A magic item shows a generic name until it's identified: an enchanted weapon or armour is "a {base} with a faint aura", and a miscellaneous item is "a curious device". An item is identified by any of these: +A magic item shows a generic name until it's identified. An enchanted weapon, piece of ammunition, suit of armour, or shield is named after one unit of the mundane item underneath it, "a {base} with a faint aura", like "an arrow with a faint aura" or "a suit of chainmail with a faint aura", and a suit of enchanted armour whose mundane armour isn't recorded is "a suit of armour with a faint aura". A miscellaneous item is "a curious device". The player view's `item_names` and `EquipmentDestroyedEvent` name an unidentified item the same way, so a cursed item reads as the item it passes for. An item is identified by any of these: - Its first meaningful use. - The referee's `IdentifyItem`. diff --git a/docs/front-ends/fastapi-pattern.md b/docs/front-ends/fastapi-pattern.md index a355cc3c..47ba6403 100644 --- a/docs/front-ends/fastapi-pattern.md +++ b/docs/front-ends/fastapi-pattern.md @@ -176,7 +176,7 @@ except SaveVersionError: --8<-- "examples/fastapi_crawler/app.py:player-view" ``` -[`PlayerView`][osrlib.crawl.views.PlayerView] allowlists only fields safe for an untrusted client: explored and lit dungeon cells, entered areas, known features and transitions, public character sheets, masked descriptions for unidentified magic items, 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, masked descriptions for unidentified magic items, display names for every item the view shows (`item_names` and `item_names_plural`), the id and count of each thing in a known pile (`PileView.contents`), encounter groups without monster hit points, `journal` entries, and active `quests` with their revealed objectives. Pass each known [`MapFeatureView.id`][osrlib.crawl.views.MapFeatureView.id] back in a treasure command's `feature_id`. [`PlayerView.features_here`][osrlib.crawl.views.PlayerView.features_here] lists the handles the treasure commands accept from where the party stands, and [`MapFeatureView.emptied`][osrlib.crawl.views.MapFeatureView.emptied] marks an authored cache the party has emptied, so the client can draw that cache opened and stop offering it. Unexplored geometry, raw ids in the feature list, cache contents, undiscovered secret doors and traps, transition destinations, monster stats, `flags`, narrator `guidance`, the player-handle key, and RNG state are excluded from the model (see [Views and visibility](../guides/views-and-visibility.md)). `PlayerView.emptied_caches` can contain a fully qualified raw feature id after the party empties that cache. 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 e4ef9cd3..b179db41 100644 --- a/docs/guides/authoring-custom-content.md +++ b/docs/guides/authoring-custom-content.md @@ -657,6 +657,8 @@ Unlike spells, monsters, and items, custom classes are stored on each character Add custom [`WeaponTemplate`][osrlib.core.items.WeaponTemplate], [`ArmourTemplate`][osrlib.core.items.ArmourTemplate], [`GearTemplate`][osrlib.core.items.GearTemplate], and [`AmmunitionTemplate`][osrlib.core.items.AmmunitionTemplate] instances (discriminated by `item_type`) to `Adventure.items`. [`GameSession.effective_equipment`][osrlib.crawl.session.GameSession.effective_equipment] unions `load_equipment()` with `Adventure.items`, resolving bundled IDs in treasure caches (`FeatureSpec.item_ids`), [`GrantItem`][osrlib.crawl.commands.GrantItem], and dropped item piles. Once acquired, [`ItemInstance`][osrlib.core.items.ItemInstance] embeds its template for equipping, encumbrance, combat, item transfers, saves, and replay. +You can also set what the players call a bundled item in a sentence. Set [`display_name`][osrlib.core.items.GearTemplate.display_name] to what to call one, in lowercase with no article, like `"idol of the drowned saint"`, and [`display_name_plural`][osrlib.core.items.GearTemplate.display_name_plural] to what to call two or more. [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] and [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] give them to the players' client. A template that leaves `display_name` out gets its `name`, and one that leaves `display_name_plural` out gets the display name with the regular English ending on the word that names the item, the last word before the first `of`, `with`, or `vs` in any case, a comma, a bonus such as `+1`, a closing Roman numeral, or an opening parenthesis, or the last word of a name with none of them. So `"idol of the drowned saint"` gets `"idols of the drowned saint"`, and `"Staff Of Power"` gets `"Staves Of Power"`. Set the plural yourself when the name is already plural, such as `"Torches (6)"`, or when the plural is irregular. + [`validate_adventure`][osrlib.crawl.adventure.validate_adventure] requires every bundled item ID to be unique across `Adventure.items`, the built-in equipment catalog ([the equipment id index][equipment-index]), and the built-in magic-item catalog (treasure encumbrance row IDs such as `coin`, `gem`, and `jewellery` do not count as item IDs): ```python @@ -672,8 +674,17 @@ from osrlib.crawl.party import Party from osrlib.crawl.session import GameSession from osrlib.data import load_equipment, load_monsters -# The quest object: a gear item with no shop price, carried like any other kit. -TEMPLE_IDOL = GearTemplate.model_validate({"id": "temple_idol", "name": "Idol of the drowned saint", "cost_gp": 0}) +# The quest object: a gear item with no shop price, carried like any other kit. Its +# display names are what the players' client shows in a sentence. +TEMPLE_IDOL = GearTemplate.model_validate( + { + "id": "temple_idol", + "name": "Idol of the drowned saint", + "cost_gp": 0, + "display_name": "idol of the drowned saint", + "display_name_plural": "idols of the drowned saint", + } +) # The saint's own arms and armour: each kind is the model its built-in list is made # of, so a weapon carries damage and qualities, body armour both AC formats and its @@ -703,6 +714,10 @@ BLESSED_STONES = AmmunitionTemplate.model_validate( {"id": "blessed_stones", "name": "Blessed sling stones", "cost_gp": 0, "lot_size": 20} ) +# A template written without display names gets its name, and the plural ending on the +# word that names the item. +assert (DROWNED_BLADE.display_name, DROWNED_BLADE.display_name_plural) == ("Drowned blade", "Drowned blades") + # Bundle them: the adventure document carries the templates, and a cache places # them by id like any built-in item. BUNDLED_IDS = ("temple_idol", "drowned_blade", "saints_scale", "blessed_stones") diff --git a/docs/guides/views-and-visibility.md b/docs/guides/views-and-visibility.md index 8591f8bc..01f90cf0 100644 --- a/docs/guides/views-and-visibility.md +++ b/docs/guides/views-and-visibility.md @@ -34,13 +34,15 @@ Each party member appears in `PlayerView.party` as a [`MemberView`][osrlib.crawl A member's spell book and memorized spells name each spell by id, and so does the `kind` of a spell's effect in `PlayerView.effects`. Show the names in [`PlayerView.spell_names`][osrlib.crawl.views.PlayerView.spell_names], keyed by those ids, and the names of reversed forms, like *darkness* for *light*, in [`PlayerView.reversed_spell_names`][osrlib.crawl.views.PlayerView.reversed_spell_names]. The view reads both from the session's catalog, so a spell the adventure bundles has its name there too. Neither includes a spell that is absent from the rest of the view, like one on a scroll. +Items work the same way. An inventory identifies a mundane stack by its template's catalog id, like `"holy_water"`, and a magic item or a gem or piece of jewellery by its instance id, like `"magic-item-0003"`, and the item events use the same ids. Show the names in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], a noun phrase for one with no article, like `"vial of holy water"`, and in [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] for a count, so you can word "The party finds 2 vials of holy water". Both have a key for each item id that the inventories and the known piles show, and only for those ids. A mundane stack, carried or in a pile, is named as the session's catalog names it, so an item the adventure bundles has its name there too. The session gives the template each carried stack embeds the catalog's display names when it starts, when a save loads, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, so a stack from a 2.7.0 save, whose template has no display names, shows the catalog's names in `inventory` too, and the next save writes them. A carried stack whose id the catalog lacks, such as an item another adventure bundled, keeps the names its template has. A valuable is named by its kind, `"gem"` or `"piece of jewellery"`, whereas the inventory's `valuables` contain the piece's name and value. A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, and the [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] contains its names instead. + 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: - **Armour class**: `armour_class` and `armour_class_ascending` reflect worn magic armour or shields immediately, because a magic item works when it's worn, while `inventory` still displays a masked description such as `"a shield with a faint aura"`. A cursed shield or suit of armour is the exception. The OSE SRD says every test shows it as enchanted with a +1 bonus until it's used in deadly combat, so until the session reveals the curse, the player view counts it as the +1 item it tests as. An unarmoured fighter with an unidentified cursed shield -2 reads AC 7, as with a shield +1, while the monsters roll against the real AC 10. The real number appears when the curse is revealed, the first time the member is attacked in a battle or when a referee sends `IdentifyItem`. [`Character.armour_class`][osrlib.core.character.Character.armour_class] and the referee view always have the real number. - **Strength overrides**: Items that set Strength (such as gauntlets of ogre power setting STR 18, or a cursed ring of weakness setting STR 3) update [`effective_strength`][osrlib.crawl.views.MemberView.effective_strength], `melee_modifier`, and `open_doors_chance`, while `scores["str"]` preserves the rolled score. Display both `scores["str"]` and `effective_strength` if you want players to see the item's effect. - **Timed effects**: Temporary spell and potion modifiers appear in [`PlayerView.effects`][osrlib.crawl.views.PlayerView.effects] rather than in `MemberView` stat totals. Each entry includes its remaining duration, except for potions, whose duration a B/X referee tracks secretly, so `PlayerView` reports it as unknown. -In `MemberView.inventory`, unidentified magic items use a category description from [`MagicItemCategory`][osrlib.core.items.MagicItemCategory] instead of their true name, bonus, curse state, or template ID. When an unidentified item's display string names a weapon, such as an enchanted blade (`"a sword with a faint aura"`) or a magic staff (`"a staff"`), its inventory dict also includes the base weapon's `qualities` and (when applicable) `missile_ranges` so your UI can distinguish melee from missile attacks without revealing the enchantment. Non-weapon categories, such as `"a wand"`, omit both keys. +In `MemberView.inventory`, unidentified magic items use a category description from [`MagicItemCategory`][osrlib.core.items.MagicItemCategory] instead of their true name, bonus, curse state, or template ID. An enchanted weapon, piece of ammunition, suit of armour, or shield is named after one unit of the mundane item underneath it, so enchanted arrows display as `"an arrow with a faint aura"`, enchanted chainmail as `"a suit of chainmail with a faint aura"`, and enchanted armour with no recorded mundane armour displays as `"a suit of armour with a faint aura"`. `PlayerView.item_names` names an unidentified item by the same description without the article, like `"arrow with a faint aura"`, so a cursed item and the item it passes for read the same there too. When an unidentified item's display string names a weapon, such as an enchanted blade (`"a sword with a faint aura"`) or a magic staff (`"a staff"`), its inventory dict also includes the base weapon's `qualities` and (when applicable) `missile_ranges` so your UI can distinguish melee from missile attacks without revealing the enchantment. Non-weapon categories, such as `"a wand"`, omit both keys. ## Render maps, encounters, and battle positions @@ -48,7 +50,7 @@ In `MemberView.inventory`, unidentified magic items use a category description f Each level also reports the authored areas the party entered, with only walked area cells. An entered area's `trap_state` is `"found"` or `"sprung"` once the party has found or sprung the room's trap, and `None` before, so a room whose trap the party hasn't met looks like a room without one. When areas overlap, the first area in the level's list owns the shared cell and only that owner can enter through it. A known custom feature or treasure cache appears as a [`MapFeatureView`][osrlib.crawl.views.MapFeatureView] on its visible cell. An area-bound feature appears after the party enters that area, and a construction trick appears only after search marks it in `found_tricks`. An explicit feature on a shared cell belongs to the owning area only. Use the feature's opaque `id` in `feature_id`; the feature list never exposes the authored or generated raw id. The fields list the safe kind, description, location, area id after entry, trap state (`"found"`, `"sprung"`, or `"removed"`), and `emptied`, which is true for an authored treasure cache the party has emptied. They never include cache contents, trap or trigger mechanics, destinations, gates, or an unannounced secret. An emptied cache stays in the list under the same `id`, so you can draw it opened, but `TakeTreasure` refuses it with `exploration.feature.emptied`. The description is the author's [`FeatureSpec.description`][osrlib.crawl.dungeon.FeatureSpec.description], written for the players, and the feature's [`referee_notes`][osrlib.crawl.dungeon.FeatureSpec.referee_notes] never appear in the player view. [Describe a treasure cache for the players](authoring-custom-content.md#describe-a-treasure-cache-for-the-players) shows how to write each field. -Generated area caches appear after their cells become known. The session removes a generated cache when the party takes it, so the cache leaves the list. A generated cache's `area_id` names the area that owns its cell once the party has entered that area. A generated lair cache stays out of the view and refuses feature commands until the party resolves the area's keyed encounter. [`TransitionView`][osrlib.crawl.views.TransitionView] exposes the kind and safe position of each transition on a known cell, but not its destination or gate. `ExploredLevelView.entrance` appears only when the party knows the entrance cell, and `PlayerView.can_travel_to_town` is true only when the party can issue [`TravelToTown`][osrlib.crawl.commands.TravelToTown] from there. Known dropped piles stay in `PlayerView.piles`. +Generated area caches appear after their cells become known. The session removes a generated cache when the party takes it, so the cache leaves the list. A generated cache's `area_id` names the area that owns its cell once the party has entered that area. A generated lair cache stays out of the view and refuses feature commands until the party resolves the area's keyed encounter. [`TransitionView`][osrlib.crawl.views.TransitionView] exposes the kind and safe position of each transition on a known cell, but not its destination or gate. `ExploredLevelView.entrance` appears only when the party knows the entrance cell, and `PlayerView.can_travel_to_town` is true only when the party can issue [`TravelToTown`][osrlib.crawl.commands.TravelToTown] from there. Known dropped piles stay in `PlayerView.piles`. Each [`PileView`][osrlib.crawl.views.PileView] lists its things twice, in the same order: `items` as display strings like `"holy_water×2"`, and `contents` as [`PileItemView`][osrlib.crawl.views.PileItemView] entries with the id and the count, which you name from `PlayerView.item_names`. `PlayerView.features_here` lists the handles that [`TakeTreasure`][osrlib.crawl.commands.TakeTreasure], [`InspectTreasure`][osrlib.crawl.commands.InspectTreasure], and [`RemoveTreasureTrap`][osrlib.crawl.commands.RemoveTreasureTrap] accept from where the party stands, in the order of the level's `features`. The session resolves a command's `feature_id` against the same caches, so offer those handles rather than working out reach yourself. The list is empty unless the session is exploring. To tell whether a listed cache is emptied, read its `MapFeatureView.emptied`. `RemoveTreasureTrap` accepts a listed cache only when its `trap_state` is `"found"`, and it refuses any other with `exploration.feature.unknown`, so its answer doesn't say whether a cache is trapped. diff --git a/docs/spec.md b/docs/spec.md index 824e6380..057e444b 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 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. 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/combat.py b/src/osrlib/core/combat.py index 9d984435..94f3403a 100644 --- a/src/osrlib/core/combat.py +++ b/src/osrlib/core/combat.py @@ -173,7 +173,9 @@ MissileRanges, WeaponQuality, WeaponTemplate, + _masked_names, _shield_ac_parts, + _with_article, equipped_item_modifiers, magic_item_template, ) @@ -2099,7 +2101,8 @@ def destroy_equipment( items that save stay in the inventory's `items` list, no longer equipped. The saving throws report no events of their own. The function returns one [`EquipmentDestroyedEvent`][osrlib.core.events.EquipmentDestroyedEvent], which lists - the items destroyed and the items saved. In a + the items destroyed and the items saved. It names an unidentified magic item by its masked + name, like `"a sword with a faint aura"`, because the players see the event. In a [`GameSession`][osrlib.crawl.session.GameSession], that event's page says where a dead party member's saved items go. @@ -2176,7 +2179,8 @@ def destroy_equipment( if save_stream.randbelow(20) + 1 + best_bonus >= required: saved.append(instance) continue - destroyed.append(template.name) + # The event has player visibility, so an unidentified item is named as the inventory shows it. + destroyed.append(template.name if instance.identified else _with_article(_masked_names(instance)[0])) else: destroyed.append(instance.template.name) inventory.items = list(saved) diff --git a/src/osrlib/core/events.py b/src/osrlib/core/events.py index 1ddf19ea..b63e6829 100644 --- a/src/osrlib/core/events.py +++ b/src/osrlib/core/events.py @@ -849,7 +849,11 @@ class EquipmentDestroyedEvent(Event): """The entity id of the victim.""" item_names: tuple[str, ...] - """The display names of the items that were destroyed.""" + """The names of the items that were destroyed, as the players know them: a mundane item's + `name`, like `"Torches (6)"`, an identified magic item's `name`, and an unidentified magic item's + masked name, like `"a sword with a faint aura"`, the `display` that + [`MemberView.inventory`][osrlib.crawl.views.MemberView.inventory] showed for it. The event has + player visibility, so it never names an unidentified item by its true name.""" saved_items: tuple[str, ...] = () """The instance ids of the magic items that passed their save and still exist. Empty when none survived, diff --git a/src/osrlib/core/items.py b/src/osrlib/core/items.py index 9e294e35..9675dd6c 100644 --- a/src/osrlib/core/items.py +++ b/src/osrlib/core/items.py @@ -88,10 +88,11 @@ ``` """ +import re from collections.abc import Mapping from typing import TYPE_CHECKING, Annotated, Any, Literal -from pydantic import ConfigDict, Field, field_validator, model_validator +from pydantic import ConfigDict, Field, ValidationInfo, field_validator, model_validator import osrlib.core from osrlib.core._descriptions import _StrEnum @@ -99,6 +100,7 @@ from osrlib.core.dice import parse from osrlib.core.effects import ModifierSpec from osrlib.core.frozen import FrozenMap, _Model +from osrlib.core.monsters import _regular_plural from osrlib.core.rng import RngStream from osrlib.core.ruleset import EncumbranceMode, Ruleset from osrlib.core.treasure import MagicItemType, TreasureEntry @@ -361,6 +363,42 @@ def _check_missile_ranges(qualities: tuple[WeaponQuality, ...], missile_ranges: raise ValueError("missile ranges are present exactly when the missile quality is") +_IRREGULAR_PLURALS = {"staff": "staves"} +"""The plural of every word that names an item and doesn't take the regular English ending.""" + +_HEAD_NOUN_END = re.compile(r" (?i:of|with|vs) |, | [+-]\d| (?=[IVX]+$)| \(") +"""Where the words that name an item end and the words that qualify it begin: `of`, `with`, or `vs` in any case, a +comma, a bonus like `+1`, a closing Roman numeral, or an opening parenthesis.""" + +_LAST_WORD = re.compile(r"(?P.*?)(?P\S+)(?P\s*)") +"""The words before the last word, the last word, and any whitespace after it.""" + + +def _item_plural(name: str) -> str: + """Return the plural of an item's display name, with the ending on the word that names the item. + + That word is the last one before the first match of `_HEAD_NOUN_END`, or the last word of a name with no match, so + `"vial of holy water"` becomes `"vials of holy water"`, `"Staff Of Power"` becomes `"Staves Of Power"`, and + `"Lantern (hooded)"` becomes `"Lanterns (hooded)"`. It takes the ending of `_regular_plural`, unless + `_IRREGULAR_PLURALS` lists it, and keeps its capital, so `"Staff of the Magi"` becomes `"Staves of the Magi"`. + The ending goes straight on the word, and any whitespace after the word stays after the ending, so a name with + two spaces before its `of` keeps them after the ending. The SRD compiler writes the plural of every built-in + template with this function, and a template written without a plural gets it from this function too. + """ + end = _HEAD_NOUN_END.search(name) + head, tail = (name[: end.start()], name[end.start() :]) if end else (name, "") + match = _LAST_WORD.fullmatch(head) + if match is None: + return name + noun = match["noun"] + irregular = _IRREGULAR_PLURALS.get(noun.lower()) + if irregular is None: + noun = _regular_plural(noun) + else: + noun = irregular.capitalize() if noun[:1].isupper() else irregular + return match["words"] + noun + match["space"] + tail + + class WeaponTemplate(_Model): """A mundane weapon, from the SRD's weapon table. @@ -383,6 +421,29 @@ class WeaponTemplate(_Model): """ name: str """The display name, for example `"Sword"`.""" + display_name: str = Field(default="", validate_default=True) + """What to call one of these weapons in a sentence, like `"sword"` or `"two-handed sword"`. + + It's lowercase unless a word is a proper noun or an abbreviation, and it has no article, so put a number or an + article in front of it: "a sword", "2 swords". + [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] gives it to the players' client. + + A template you write that leaves it out gets its `name`. + """ + display_name_plural: str = Field(default="", validate_default=True) + """What to call two or more of these weapons, like `"swords"` or `"staves"`. + + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] gives it to the players' client. A + template you write that leaves it out gets `display_name` with the regular English ending on the word that names the + item: the last word before the first `of`, `with`, or `vs`, a comma, a bonus like `+1`, a closing Roman numeral, or + an opening parenthesis, or the last word when the name has none of them. So `"Idol of the drowned saint"` becomes + `"Idols of the drowned saint"`, and `"Lantern (hooded)"` becomes `"Lanterns (hooded)"`. The ending is `s`, or `es` + after `s`, `x`, `z`, `ch`, or `sh`, or `ies` in place of a `y` that follows a consonant, and `staff` becomes + `staves` with its capital kept, so `"Staff of the Magi"` becomes `"Staves of the Magi"`. The connecting words count + in any case, so `"Staff Of Power"` becomes `"Staves Of Power"`, and any spaces after the word stay after the ending. + The compiled plural of every built-in template follows the same rule. Set it yourself when the name is already + plural, like `"Torches (6)"`, or when the plural is irregular. + """ cost_gp: int = Field(ge=0) """The listed price in gold pieces, for one weapon.""" weight_coins: int = Field(ge=0) @@ -404,6 +465,16 @@ class WeaponTemplate(_Model): osrlib doesn't read it during play. """ + @field_validator("display_name") + @classmethod + def _display_name_defaults_to_name(cls, value: str, info: ValidationInfo) -> str: + return value or info.data.get("name", "") + + @field_validator("display_name_plural") + @classmethod + def _plural_defaults_to_regular_ending(cls, value: str, info: ValidationInfo) -> str: + return value or _item_plural(info.data.get("display_name", "")) + @field_validator("damage") @classmethod def _damage_must_parse(cls, value: str) -> str: @@ -445,6 +516,29 @@ class ArmourTemplate(_Model): index](https://mmacy.github.io/osrlib-python/reference/content-ids/equipment/).""" name: str """The display name.""" + display_name: str = Field(default="", validate_default=True) + """What to call one of these in a sentence, like `"shield"` or `"suit of chainmail"`. + + Body armour is named as a suit, so a count reads "2 suits of chainmail". It's lowercase unless a + word is a proper noun or an abbreviation, and it has no article, so put a number or an article in + front of it. [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] gives it to the players' client. + + A template you write that leaves it out gets its `name`. + """ + display_name_plural: str = Field(default="", validate_default=True) + """What to call two or more of these, like `"shields"` or `"suits of chainmail"`. + + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] gives it to the players' client. A + template you write that leaves it out gets `display_name` with the regular English ending on the word that names the + item: the last word before the first `of`, `with`, or `vs`, a comma, a bonus like `+1`, a closing Roman numeral, or + an opening parenthesis, or the last word when the name has none of them. So `"Idol of the drowned saint"` becomes + `"Idols of the drowned saint"`, and `"Lantern (hooded)"` becomes `"Lanterns (hooded)"`. The ending is `s`, or `es` + after `s`, `x`, `z`, `ch`, or `sh`, or `ies` in place of a `y` that follows a consonant, and `staff` becomes + `staves` with its capital kept, so `"Staff of the Magi"` becomes `"Staves of the Magi"`. The connecting words count + in any case, so `"Staff Of Power"` becomes `"Staves Of Power"`, and any spaces after the word stay after the ending. + The compiled plural of every built-in template follows the same rule. Set it yourself when the name is already + plural, like `"Torches (6)"`, or when the plural is irregular. + """ cost_gp: int = Field(ge=0) """The listed price in gold pieces.""" weight_coins: int = Field(ge=0) @@ -466,6 +560,16 @@ class ArmourTemplate(_Model): osrlib doesn't read it during play. """ + @field_validator("display_name") + @classmethod + def _display_name_defaults_to_name(cls, value: str, info: ValidationInfo) -> str: + return value or info.data.get("name", "") + + @field_validator("display_name_plural") + @classmethod + def _plural_defaults_to_regular_ending(cls, value: str, info: ValidationInfo) -> str: + return value or _item_plural(info.data.get("display_name", "")) + @model_validator(mode="after") def _body_armour_or_shield(self) -> ArmourTemplate: body_fields = (self.ac is not None, self.ac_ascending is not None, self.category is not None) @@ -553,6 +657,32 @@ class GearTemplate(_Model): """The display name as the price list prints it, which includes the lot size for gear sold in lots: `"Torches (6)"`, `"Iron spikes (12)"`. """ + display_name: str = Field(default="", validate_default=True) + """What to call one unit of this gear in a sentence, like `"torch"` or `"vial of holy water"`. + + It names one of the units that [`ItemInstance.quantity`][osrlib.core.items.ItemInstance.quantity] + counts, not a lot from the price list, so `"Torches (6)"` is `"torch"`, and a stack of six reads + "6 torches". Where the price list names a substance, it names the container or the measure the + session counts: `"vial of holy water"`, `"flask of oil"`, `"pint of wine"`. It's lowercase unless a + word is a proper noun or an abbreviation, and it has no article, so put a number or an article in + front of it. [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] gives it to the players' client. + + A template you write that leaves it out gets its `name`. + """ + display_name_plural: str = Field(default="", validate_default=True) + """What to call two or more units, like `"torches"` or `"vials of holy water"`. + + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] gives it to the players' client. A + template you write that leaves it out gets `display_name` with the regular English ending on the word that names the + item: the last word before the first `of`, `with`, or `vs`, a comma, a bonus like `+1`, a closing Roman numeral, or + an opening parenthesis, or the last word when the name has none of them. So `"Idol of the drowned saint"` becomes + `"Idols of the drowned saint"`, and `"Lantern (hooded)"` becomes `"Lanterns (hooded)"`. The ending is `s`, or `es` + after `s`, `x`, `z`, `ch`, or `sh`, or `ies` in place of a `y` that follows a consonant, and `staff` becomes + `staves` with its capital kept, so `"Staff of the Magi"` becomes `"Staves of the Magi"`. The connecting words count + in any case, so `"Staff Of Power"` becomes `"Staves Of Power"`, and any spaces after the word stay after the ending. + The compiled plural of every built-in template follows the same rule. Set it yourself when the name is already + plural, like `"Torches (6)"`, or when the plural is irregular. + """ cost_gp: int = Field(ge=0) """The listed price in gold pieces, for one lot.""" lot_size: int = Field(default=1, ge=1) @@ -576,6 +706,16 @@ class GearTemplate(_Model): osrlib doesn't read it during play. """ + @field_validator("display_name") + @classmethod + def _display_name_defaults_to_name(cls, value: str, info: ValidationInfo) -> str: + return value or info.data.get("name", "") + + @field_validator("display_name_plural") + @classmethod + def _plural_defaults_to_regular_ending(cls, value: str, info: ValidationInfo) -> str: + return value or _item_plural(info.data.get("display_name", "")) + class AmmunitionTemplate(_Model): """Ammunition for a missile weapon: arrows, quarrels, sling stones. @@ -596,6 +736,30 @@ class AmmunitionTemplate(_Model): [the equipment id index](https://mmacy.github.io/osrlib-python/reference/content-ids/equipment/).""" name: str """The display name as the price list prints it, which includes the lot: `"Arrows (quiver of 20)"`.""" + display_name: str = Field(default="", validate_default=True) + """What to call one unit of this ammunition in a sentence, like `"arrow"` or `"crossbow bolt"`. + + It names one of the units that [`ItemInstance.quantity`][osrlib.core.items.ItemInstance.quantity] + counts, not the lot, so `"Arrows (quiver of 20)"` is `"arrow"`, and a full quiver reads "20 arrows". + It's lowercase unless a word is a proper noun or an abbreviation, and it has no article. + [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] gives it to the players' client. + + A template you write that leaves it out gets its `name`. + """ + display_name_plural: str = Field(default="", validate_default=True) + """What to call two or more units, like `"arrows"` or `"crossbow bolts"`. + + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] gives it to the players' client. A + template you write that leaves it out gets `display_name` with the regular English ending on the word that names the + item: the last word before the first `of`, `with`, or `vs`, a comma, a bonus like `+1`, a closing Roman numeral, or + an opening parenthesis, or the last word when the name has none of them. So `"Idol of the drowned saint"` becomes + `"Idols of the drowned saint"`, and `"Lantern (hooded)"` becomes `"Lanterns (hooded)"`. The ending is `s`, or `es` + after `s`, `x`, `z`, `ch`, or `sh`, or `ies` in place of a `y` that follows a consonant, and `staff` becomes + `staves` with its capital kept, so `"Staff of the Magi"` becomes `"Staves of the Magi"`. The connecting words count + in any case, so `"Staff Of Power"` becomes `"Staves Of Power"`, and any spaces after the word stay after the ending. + The compiled plural of every built-in template follows the same rule. Set it yourself when the name is already + plural, like `"Torches (6)"`, or when the plural is irregular. + """ cost_gp: int = Field(ge=0) """The listed price in gold pieces, for one lot. 0 for sling stones.""" lot_size: int = Field(default=1, ge=1) @@ -613,6 +777,16 @@ class AmmunitionTemplate(_Model): osrlib doesn't read it during play. """ + @field_validator("display_name") + @classmethod + def _display_name_defaults_to_name(cls, value: str, info: ValidationInfo) -> str: + return value or info.data.get("name", "") + + @field_validator("display_name_plural") + @classmethod + def _plural_defaults_to_regular_ending(cls, value: str, info: ValidationInfo) -> str: + return value or _item_plural(info.data.get("display_name", "")) + ItemTemplate = Annotated[ WeaponTemplate | ArmourTemplate | GearTemplate | AmmunitionTemplate, @@ -957,6 +1131,36 @@ class MagicItemTemplate(_Model): index](https://mmacy.github.io/osrlib-python/reference/content-ids/magic-items/).""" name: str """The display name. Show this only once the instance is identified.""" + display_name: str = Field(default="", validate_default=True) + """What to call one of these items in a sentence once the party knows what it is, like + `"potion of healing"` or `"sword +1"`. + + It's lowercase unless a word is a proper noun or an abbreviation, like the `ESP` of + `"potion of ESP"`, and it has no article, so put a number or an article in front of it. For + enchanted ammunition it names one of the units that + [`MagicItemInstance.quantity`][osrlib.core.items.MagicItemInstance.quantity] counts, so + `"Arrows +1 (3d10 arrows)"` is `"arrow +1"`. Footwear and gloves are named as a pair, like + `"pair of boots of speed"`, so a count reads "2 pairs of boots of speed". + + Like `name`, show it only once the instance is identified. Until then, + [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] names the item by its masked name. + + A template you construct yourself that leaves it out gets its `name`. + """ + display_name_plural: str = Field(default="", validate_default=True) + """What to call two or more of these items, like `"potions of healing"` or `"swords +1"`. + + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] gives it to the players' client. A + template you construct yourself that leaves it out gets `display_name` with the regular English ending on the word + that names the item: the last word before the first `of`, `with`, or `vs`, a comma, a bonus like `+1`, a closing + Roman numeral, or an opening parenthesis, or the last word when the name has none of them. So `"Idol of the drowned + saint"` becomes `"Idols of the drowned saint"`, and `"Lantern (hooded)"` becomes `"Lanterns (hooded)"`. The ending + is `s`, or `es` after `s`, `x`, `z`, `ch`, or `sh`, or `ies` in place of a `y` that follows a consonant, and `staff` + becomes `staves` with its capital kept, so `"Staff of the Magi"` becomes `"Staves of the Magi"`. The connecting + words count in any case, so `"Staff Of Power"` becomes `"Staves Of Power"`, and any spaces after the word stay after + the ending. The compiled plural of every built-in template follows the same rule. Set it yourself when the name is + already plural, like `"Torches (6)"`, or when the plural is irregular. + """ category: MagicItemCategory """What kind of item it is. See [`MagicItemCategory`][osrlib.core.items.MagicItemCategory].""" base_item_id: str | None = None @@ -1027,6 +1231,16 @@ class MagicItemTemplate(_Model): osrlib doesn't read it during play. """ + @field_validator("display_name") + @classmethod + def _display_name_defaults_to_name(cls, value: str, info: ValidationInfo) -> str: + return value or info.data.get("name", "") + + @field_validator("display_name_plural") + @classmethod + def _plural_defaults_to_regular_ending(cls, value: str, info: ValidationInfo) -> str: + return value or _item_plural(info.data.get("display_name", "")) + @field_validator("charges_dice", "quantity_dice") @classmethod def _dice_must_parse(cls, value: str | None) -> str | None: @@ -1783,6 +1997,16 @@ class ItemInstance(_Model): """The item itself, one of the four equipment templates. See [`ItemTemplate`][osrlib.core.items.ItemTemplate]. The whole template is embedded rather than referenced by id, so an instance of an item an adventure bundled stays readable without that adventure. + + A session gives an embedded template the display names of the template its catalog, + [`GameSession.effective_equipment`][osrlib.crawl.session.GameSession.effective_equipment], has under the same id. + It does this to every stack a party member or an NPC adventurer carries when the session starts, when + [`load_game`][osrlib.persistence.load_game] restores it, and when [`AddMember`][osrlib.crawl.commands.AddMember] + adds a member. Only `display_name` and `display_name_plural` change, with the entries of `overrides_applied` that + name those two fields, which record where the names came from. The rest of the template is rules data that travels + with the character. So a stack from a save or a party document that osrlib 2.7.0 wrote, whose + template has no display names, is named as the catalog names it, in the views and in the next save. A template + whose id the catalog doesn't have, like an item another adventure bundled, keeps the names it has. """ quantity: int = Field(default=1, ge=1) """How many units the stack contains, counting individual items rather than lots: buying one lot of torches gives @@ -2275,6 +2499,52 @@ def magic_item_template(instance: MagicItemInstance) -> MagicItemTemplate: return load_magic_items().get(instance.template_id) +_MASKED_CATEGORY_NAMES = { + MagicItemCategory.POTION: ("potion", "potions"), + MagicItemCategory.SCROLL: ("scroll", "scrolls"), + MagicItemCategory.RING: ("ring", "rings"), + MagicItemCategory.WAND: ("wand", "wands"), + MagicItemCategory.STAFF: ("staff", "staves"), + MagicItemCategory.ROD: ("rod", "rods"), + MagicItemCategory.MISC: ("curious device", "curious devices"), +} +"""What the players call an unidentified item of each category that isn't an enchanted arm.""" + + +def _masked_names(instance: MagicItemInstance) -> tuple[str, str]: + """Return what the players call an unidentified magic item, for one and for two or more, with no article. + + An item whose category has a name in `_MASKED_CATEGORY_NAMES` gets that name, like `"potion"`. An enchanted + weapon, piece of ammunition, suit of armour, or shield is named after one unit of the mundane item underneath it, + its `display_name` followed by "with a faint aura", the concession made because *detect magic* exists: `"arrow + with a faint aura"`, `"suit of chainmail with a faint aura"`. A suit of enchanted armour with no mundane item + recorded is `"suit of armour with a faint aura"`. + + The name depends on the category and the base alone, so a cursed item has the names of the item it passes for, + and neither the bonus nor the curse shows. + """ + from osrlib.data import load_equipment + + template = magic_item_template(instance) + category_names = _MASKED_CATEGORY_NAMES.get(template.category) + if category_names is not None: + return category_names + base_id = instance.base_item_id or template.base_item_id + if base_id is not None: + base = load_equipment().get(base_id) + singular, plural = base.display_name, base.display_name_plural + elif template.category is MagicItemCategory.ARMOUR: + singular, plural = "suit of armour", "suits of armour" + else: + singular, plural = "weapon", "weapons" + return f"{singular} with a faint aura", f"{plural} with a faint aura" + + +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}" + + def _shield_ac_parts(shield: AnyInstance | None, *, ascending: bool) -> tuple[int | None, int]: """Return the armour class a shield sets, or None, and the bonus the shield adds to armour class. diff --git a/src/osrlib/crawl/_magic_items.py b/src/osrlib/crawl/_magic_items.py index 4d700d9f..5a45ab34 100644 --- a/src/osrlib/crawl/_magic_items.py +++ b/src/osrlib/crawl/_magic_items.py @@ -42,7 +42,14 @@ def _identify_item_events(session, member, instance: MagicItemInstance) -> list: events: list[Event] = [] if not instance.identified: instance.identified = True - events.append(ItemIdentifiedEvent(instance_id=instance.instance_id, template_id=instance.template_id)) + events.append( + ItemIdentifiedEvent( + instance_id=instance.instance_id, + template_id=instance.template_id, + display_name=template.display_name, + display_name_plural=template.display_name_plural, + ) + ) if template.cursed and not instance.cursed_revealed: instance.cursed_revealed = True events.append( diff --git a/src/osrlib/crawl/commands.py b/src/osrlib/crawl/commands.py index d5040c30..8e7d59d1 100644 --- a/src/osrlib/crawl/commands.py +++ b/src/osrlib/crawl/commands.py @@ -3751,7 +3751,10 @@ class AddMember(Command): needs `id` set to `None`, no conditions or stat modifiers, and no magic items or valuables. Constructing the command copies the character. A change you make to your object afterwards doesn't reach the command, and the command log records the - character as you sent it.""" + character as you sent it. The member who joins gets the display names of the session's catalog + on each item template the character's stacks embed, as + [`ItemInstance.template`][osrlib.core.items.ItemInstance.template] describes, while the + command keeps the templates it arrived with.""" @field_validator("character", mode="after") @classmethod diff --git a/src/osrlib/crawl/events.py b/src/osrlib/crawl/events.py index c8d9ace3..e26448ad 100644 --- a/src/osrlib/crawl/events.py +++ b/src/osrlib/crawl/events.py @@ -1794,6 +1794,20 @@ class ItemIdentifiedEvent(Event): """The session-scoped id of the item, the same id the earlier events contained.""" template_id: str """What it turned out to be, as its magic item catalog id.""" + display_name: str = "" + """What to call the item now that the party knows it, the template's + [`display_name`][osrlib.core.items.MagicItemTemplate.display_name], like `"potion of healing"`. + + It's here because the command that identifies an item can also use it up, like a potion drunk + before the party knew what it was. Then no view names it by its true name, because the view built + after the command no longer shows the item and the view from before showed it masked. When the + item is still carried, the view's + [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] has the same name under + `instance_id` and `template_id`.""" + display_name_plural: str = "" + """What to call two or more of the item, the template's + [`display_name_plural`][osrlib.core.items.MagicItemTemplate.display_name_plural], like + `"potions of healing"`.""" class CurseRevealedEvent(Event): diff --git a/src/osrlib/crawl/session.py b/src/osrlib/crawl/session.py index 754f7beb..0403ebd9 100644 --- a/src/osrlib/crawl/session.py +++ b/src/osrlib/crawl/session.py @@ -444,6 +444,45 @@ def worst(self) -> int: return max(self.food_days, self.water_days) +_ITEM_NAME_FIELDS = ("display_name", "display_name_plural") + + +def _take_catalog_item_names(catalog: EquipmentCatalog, character: Character) -> None: + """Give each item template the character's stacks embed the display names of the catalog's template with its id. + + A save or a party document from osrlib 2.7.0 embeds templates without display names, so each one validated with + the defaults from its price-list `name`. The two names come from the catalog, with the entries of + `overrides_applied` that name them, which record where the names came from. The rest of the template is rules data + that travels with the character and doesn't change, and a template whose id the catalog lacks keeps its names. + The call draws nothing, and calling it again changes nothing. + """ + templates = { + template.id: template for template in (*catalog.weapons, *catalog.armour, *catalog.gear, *catalog.ammunition) + } + for instance in character.inventory.all_instances(): + if not isinstance(instance, ItemInstance): + continue + source = templates.get(instance.template.id) + if source is None: + continue + embedded = instance.template + kept = tuple(entry for entry in embedded.overrides_applied if entry not in _ITEM_NAME_FIELDS) + overrides = (*kept, *(entry for entry in source.overrides_applied if entry in _ITEM_NAME_FIELDS)) + unchanged = ( + embedded.display_name == source.display_name + and embedded.display_name_plural == source.display_name_plural + and set(embedded.overrides_applied) == set(overrides) + ) + if not unchanged: + instance.template = embedded.model_copy( + update={ + "display_name": source.display_name, + "display_name_plural": source.display_name_plural, + "overrides_applied": overrides, + } + ) + + def _member_id(member: Character) -> str: """Return a member's session id, which every member in a session has.""" if member.id is None: @@ -680,6 +719,8 @@ def __init__( if lines := item_conflicts.lines("item"): raise ContentValidationError("adventure bundles colliding item ids:\n" + "\n".join(lines)) self._equipment_catalog = equipment + for member in party.members: + _take_catalog_item_names(equipment, member) spells, spell_conflicts = _effective_spells(adventure, load_spells()) if lines := spell_conflicts.lines("spell"): raise ContentValidationError("adventure bundles colliding spell ids:\n" + "\n".join(lines)) @@ -2461,6 +2502,7 @@ def _handle_add_member(session: GameSession, command: AddMember) -> tuple[list[R return [Rejection(code="party.add.carries_instances", params={"name": character.name, "item": carried[0]})], [] # The command keeps the character as it arrived, so the log replays the same addition. member = character.model_copy(deep=True) + _take_catalog_item_names(session.effective_equipment, member) taken = {existing.id for existing in session.party.members} member.id = session.allocator.allocate("character") while member.id in taken: diff --git a/src/osrlib/crawl/views.py b/src/osrlib/crawl/views.py index ba13403e..b69d44a1 100644 --- a/src/osrlib/crawl/views.py +++ b/src/osrlib/crawl/views.py @@ -109,6 +109,7 @@ ``` """ +from collections.abc import Iterable from copy import deepcopy from typing import Literal @@ -120,7 +121,15 @@ from osrlib.core.effects import Condition, EffectsLedger, has_condition from osrlib.core.events import Event from osrlib.core.frozen import _Model -from osrlib.core.items import Coins, MagicItemCategory, MagicItemInstance, magic_item_template +from osrlib.core.items import ( + _MASKED_CATEGORY_NAMES, + Coins, + MagicItemCategory, + MagicItemInstance, + _masked_names, + _with_article, + magic_item_template, +) from osrlib.core.monsters import IdAllocator, MonsterInstance, _regular_plural from osrlib.core.ruleset import Ruleset from osrlib.crawl._feature_handles import ( @@ -136,7 +145,16 @@ from osrlib.crawl.adventure import Adventure from osrlib.crawl.battle import BattleState from osrlib.crawl.commands import Command, SessionMode -from osrlib.crawl.dungeon import Direction, DungeonState, EdgeKind, PartyLocation, Position, cell_ref, edge_ref +from osrlib.crawl.dungeon import ( + Direction, + DropPile, + DungeonState, + EdgeKind, + PartyLocation, + Position, + cell_ref, + edge_ref, +) from osrlib.crawl.encounter import EncounterState, _member_kind from osrlib.crawl.exploration import EXHAUSTED_KIND, FATIGUE_KIND, HEALING_SERVICES from osrlib.crawl.party import Party @@ -161,6 +179,7 @@ "MemberEffectView", "MemberView", "ObjectiveView", + "PileItemView", "PileView", "PlayerView", "QuestView", @@ -234,17 +253,23 @@ class too.""" `worn_armour`, `shield`, `wielded`, and `rings`. Mundane items appear as the inventory serializes them. - A magic item is masked until it's identified. An unidentified one has a `display` name in - place of its true name, like `"a potion"`, or `"a dagger with a faint aura"` for a magic - weapon. When the display name refers to a weapon, the entry also has the `qualities` of that - plain weapon, as an identified one does, so you can tell a melee attack from a missile - attack without revealing the weapon's bonus or curse. It has a `missile_ranges` key only - when the rules give the weapon ranges, so on a sword the key is absent rather than empty. - Every magic staff displays as `"a staff"` and has the staff's `qualities`. Any other item - whose display name comes from its category, like `"a wand"`, has neither key, because its - display name doesn't refer to a weapon. An identified item - shows its `name`, its `template_id`, and whether a curse has been revealed. Charges never - appear.""" + A magic item is masked until it's identified. An unidentified one has a `display` name in place of its true + name, like `"a potion"`, or `"a dagger with a faint aura"` for a magic weapon. An enchanted weapon, suit of + armour, or shield is named after one unit of the mundane item underneath it, its + [`display_name`][osrlib.core.items.WeaponTemplate.display_name] with an article, so enchanted arrows display as + `"an arrow with a faint aura"` and enchanted chainmail as `"a suit of chainmail with a faint aura"`. A suit of + enchanted armour with no mundane item recorded displays as `"a suit of armour with a faint aura"`. When the + display name refers to a weapon, the entry also has the `qualities` of that plain weapon, as an identified one + does, so you can tell a melee attack from a missile attack without revealing the weapon's bonus or curse. It has + a `missile_ranges` key only when the rules give the weapon ranges, so on a sword the key is absent rather than + empty. Every magic staff displays as `"a staff"` and has the staff's `qualities`. Any other item whose display + name comes from its category, like `"a wand"`, has neither key, because its display name doesn't refer to a + weapon. An identified item shows its `name`, its `template_id`, and whether a curse has been revealed. Charges + never appear. + + To name an item in a sentence, look up the id it has here in + [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names]: a mundane item's + `template.id`, and a magic item's or a valuable's `instance_id`.""" memorized_spells: tuple[dict, ...] """The prepared spells, one dumped [`MemorizedSpell`][osrlib.core.spells.MemorizedSpell] per copy, in memorization @@ -436,6 +461,27 @@ class EdgeView(_Model): a door.""" +class PileItemView(_Model): + """One thing in a dropped pile, by the id the events name it by, with its count. + + You get these from [`PileView.contents`][osrlib.crawl.views.PileView.contents]. Look `item_id` up + in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names] and + [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] to name it. + """ + + model_config = ConfigDict(frozen=True) + + item_id: str + """The catalog id of a mundane stack, like `"holy_water"`, or the instance id of a magic item, + like `"magic-item-0003"`, or of a gem or piece of jewellery, like `"valuable-0007"`. It's the form + of id that [`ItemsDroppedEvent.item_ids`][osrlib.crawl.events.ItemsDroppedEvent.item_ids] and the + other item events use, and an unidentified magic item's template id never appears here.""" + quantity: int = 1 + """How many units: the size of a mundane stack, the + [`quantity`][osrlib.core.items.MagicItemInstance.quantity] of a magic item, which is more than 1 + only for enchanted ammunition, and always 1 for a gem or piece of jewellery.""" + + class PileView(_Model): """A known dropped pile in explored space. @@ -455,6 +501,14 @@ class PileView(_Model): """The pile's coins, as their value in whole gold pieces, rounded down.""" coins: Coins = Coins() """The pile's coins by denomination, so a pile of copper alone isn't mistaken for an empty one.""" + contents: tuple[PileItemView, ...] = () + """One entry per thing in the pile, in the order of `items`, each with the id the events name + it by and its count. + + A mundane stack has its catalog id, so a client reads `"holy_water"` and 2 here where `items` has + the string `"holy_water×2"`. A magic item and a valuable have their instance ids. Name each entry + from [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], which has a key for + every id here.""" class DungeonNameView(_Model): @@ -1093,6 +1147,59 @@ class PlayerView(_Model): [`memorized_spells`][osrlib.crawl.views.MemberView.memorized_spells]. A divine caster prepares the normal form and chooses the form when casting, so every memorized copy of a reversible spell can be cast either way. To offer that choice, show both names.""" + item_names: dict[str, str] = {} + """What to call one of each item whose id the view shows, keyed by that id, like + `{"torch": "torch", "holy_water": "vial of holy water", "magic-item-0003": "potion"}`. Show these + names, not the ids, and put a number or an article in front of one: "a torch". To word a count, + like "6 torches", use `item_names_plural`. + + An item id appears in the view in four forms, and each is a key here: + + - The catalog id of a mundane stack, like `"holy_water"`, in a member's + [`inventory`][osrlib.crawl.views.MemberView.inventory] and in a pile's + [`contents`][osrlib.crawl.views.PileView.contents]. For a stack a member carries, its name is + the [`display_name`][osrlib.core.items.GearTemplate.display_name] of the template the stack + embeds, which the session gives the display names of the template its catalog, + [`GameSession.effective_equipment`][osrlib.crawl.session.GameSession.effective_equipment], has + under that id, as [`ItemInstance.template`][osrlib.core.items.ItemInstance.template] says. So a + stack from a save or a party document that osrlib 2.7.0 wrote is named as the catalog names it, + and the name here matches the stack's template in `inventory`. A bundled id can't shadow a + built-in one, because a session refuses an adventure whose bundled id collides with a built-in + id. A carried stack whose id the catalog doesn't have, like an item another adventure bundled, + keeps the names its template has. For a pile, the name comes from the catalog, and a pile's + catalog id that the catalog doesn't have has no entry. + - The instance id of a magic item, like `"magic-item-0003"`, in an inventory and in a pile. + Until the party identifies the item, its name is the masked name the inventory shows, without + the article: `"potion"`, `"curious device"`, or `"shield with a faint aura"`. So a cursed item + and the item it passes for have the same name, and the name tells nothing the inventory + doesn't. Once the item is identified, its name is the + [`display_name`][osrlib.core.items.MagicItemTemplate.display_name] of its template in the magic + item catalog, like `"potion of healing"`. + - The template id of an identified magic item, like `"potion_of_healing"`, which the inventory + shows once the item is identified, with the same name. A pile shows a magic item by its + instance id alone, identified or not, so an identified item's template id is a key only while + a member carries it. An unidentified item's template id is never a key. + - The instance id of a gem or a piece of jewellery, like `"valuable-0007"`. Its name is its kind, + `"gem"` or `"piece of jewellery"`. The players see everything else about it from the moment + they take it, its own name and its value in gold pieces included, in the inventory's + `valuables`. + + 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 + item the command left in a member's pack or in a pile the view shows is a key in the view you + build after the command. An item the command used up, sold, or left behind on a trail is a key + in the view from before it. An item that is identified and used up in the same command, like a + potion drunk before the party knew it, has its true name on the + [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent].""" + item_names_plural: dict[str, str] = {} + """What to call two or more of each item in `item_names`, with the same keys, like + `{"torch": "torches", "holy_water": "vials of holy water", "magic-item-0003": "potions"}`. + + Each value is the plural of the name in `item_names`: the template's + [`display_name_plural`][osrlib.core.items.GearTemplate.display_name_plural], the plural of a + masked name, like `"shields with a faint aura"`, or `"gems"` or `"pieces of jewellery"`. Use it + with a count from a pile's [`contents`][osrlib.crawl.views.PileView.contents], an inventory + entry's `quantity`, or the ids an event repeats, one per unit: "2 vials of holy water".""" fatigued: bool """Whether any member is fatigued.""" exhausted: bool @@ -1308,29 +1415,18 @@ class RefereeView(_Model): The session removes a generated cache when the party takes it, and its entry leaves with it.""" -_MASKED_CATEGORY_NAMES = { - MagicItemCategory.POTION: "a potion", - MagicItemCategory.SCROLL: "a scroll", - MagicItemCategory.RING: "a ring", - MagicItemCategory.WAND: "a wand", - MagicItemCategory.STAFF: "a staff", - MagicItemCategory.ROD: "a rod", - MagicItemCategory.MISC: "a curious device", -} - - def _masked_magic_item(instance: MagicItemInstance) -> dict: """One magic item as the player sees it, masked until identified. - An unidentified item shows its category display name, and an enchanted arm shows its - base instead, as in "a sword with a faint aura", the concession made because *detect - magic* exists. A display string built from that base weapon already includes the weapon's name, - so the unidentified item also shows the `qualities` of the mundane weapon underneath - it, exactly as an identified one does, and its `missile_ranges` when the rules give that - weapon ranges. A weapon with no printed ranges, a sword among them, gets the `qualities` key - and no `missile_ranges` key at all. Every magic staff reads "a staff", and every one is a - mundane staff underneath, so the display is the name of the weapon and every staff shows the - staff's `qualities`. A wand or other item whose display comes from its category shows + An unidentified item shows its category display name, and an enchanted arm shows one unit of + its base instead, as in "a sword with a faint aura" or "an arrow with a faint aura", the + concession made because *detect magic* exists. A display string built from that base weapon + already includes the weapon's name, so the unidentified item also shows the `qualities` of + the mundane weapon underneath it, exactly as an identified one does, and its `missile_ranges` + when the rules give that weapon ranges. A weapon with no printed ranges, a sword among them, + gets the `qualities` key and no `missile_ranges` key at all. Every magic staff reads "a + staff", and every one is a mundane staff underneath, so the display is the name of the weapon + and every staff shows the staff's `qualities`. A wand or other item whose display comes from its category shows neither field, because the display isn't the name of a weapon and the fields would single the item out among the items that show the same string. @@ -1344,7 +1440,6 @@ def _masked_magic_item(instance: MagicItemInstance) -> dict: level, because by the rules as written charges are undiscoverable. """ from osrlib.core.combat import attack_facet - from osrlib.data import load_equipment template = magic_item_template(instance) facet = attack_facet(instance) @@ -1359,12 +1454,8 @@ def _masked_magic_item(instance: MagicItemInstance) -> dict: "cursed": instance.cursed_revealed, } else: - display = _MASKED_CATEGORY_NAMES.get(template.category) - if display is None: - base_id = instance.base_item_id or template.base_item_id - base_name = load_equipment().get(base_id).name.lower() if base_id is not None else "arm" - display = f"a {base_name} with a faint aura" - elif template.category is not MagicItemCategory.STAFF: + display = _with_article(_masked_names(instance)[0]) + if template.category in _MASKED_CATEGORY_NAMES and template.category is not MagicItemCategory.STAFF: # The display came from the category table, not the base weapon, so # attaching weapon facts here would single this one item out among the items in its # category that show the same string. "A staff" is the name of the weapon under every staff. @@ -1483,24 +1574,8 @@ def build_player_view(session) -> PlayerView: explored = tuple(_explored_levels(session)) features_here = _features_here_view(session, explored) visible_refs = _visible_cell_refs(session) - piles = { - ref: PileView( - items=tuple( - ( - *(f"{entry.item_id}×{entry.quantity}" for entry in pile.items), - *( - str(_masked_magic_item(item).get("name", _masked_magic_item(item).get("display"))) - for item in pile.magic_items - ), - *(valuable.name or valuable.kind for valuable in pile.valuables), - ) - ), - coins_gp_value=pile.coins.value_gp, - coins=pile.coins, - ) - for ref, pile in session.dungeon_state.piles.items() - if ref in visible_refs - } + known_piles = {ref: pile for ref, pile in session.dungeon_state.piles.items() if ref in visible_refs} + piles = {ref: _pile_view(pile) for ref, pile in known_piles.items()} fatigued = any(session.ledger.active_on(member.id, FATIGUE_KIND) for member in session.party.members) exhausted = any(session.ledger.active_on(member.id, EXHAUSTED_KIND) for member in session.party.members) deprivation = { @@ -1509,6 +1584,7 @@ def build_player_view(session) -> PlayerView: if state.worst > 0 } spell_names, reversed_spell_names = _spell_names(session, members, effects) + item_names, item_names_plural = _item_names(session, known_piles.values()) return PlayerView( adventure_name=session.adventure.name, adventure_description=session.adventure.description, @@ -1532,6 +1608,8 @@ def build_player_view(session) -> PlayerView: effects=effects, spell_names=spell_names, reversed_spell_names=reversed_spell_names, + item_names=item_names, + item_names_plural=item_names_plural, fatigued=fatigued, exhausted=exhausted, deprivation=deprivation, @@ -1562,6 +1640,77 @@ def _spell_names(session, members, effects) -> tuple[dict[str, str], dict[str, s return names, reversed_names +def _pile_view(pile: DropPile) -> PileView: + """One known pile as the players see it, with each entry's display string and its id and count.""" + magic_items = [_masked_magic_item(item) for item in pile.magic_items] + return 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), + ), + coins_gp_value=pile.coins.value_gp, + coins=pile.coins, + contents=( + *(PileItemView(item_id=entry.item_id, quantity=entry.quantity) for entry in pile.items), + *(PileItemView(item_id=item.instance_id, quantity=item.quantity) for item in pile.magic_items), + *(PileItemView(item_id=valuable.instance_id) for valuable in pile.valuables), + ), + ) + + +_VALUABLE_NAMES = {"gem": ("gem", "gems"), "jewellery": ("piece of jewellery", "pieces of jewellery")} +"""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]]: + # 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 + # item keeps its mask, and a template id is a key only for an identified item a member carries, because a + # pile shows a magic item by its instance id alone. + names: dict[str, str] = {} + plurals: dict[str, str] = {} + equipment = session.effective_equipment + catalog = { + template.id: template + for template in (*equipment.weapons, *equipment.armour, *equipment.gear, *equipment.ammunition) + } + + def add(item_id: str, singular: str, plural: str) -> None: + if item_id not in names: + names[item_id] = singular + plurals[item_id] = plural + + def add_magic_item(instance: MagicItemInstance, *, carried: bool) -> None: + if instance.identified: + template = magic_item_template(instance) + add(instance.instance_id, template.display_name, template.display_name_plural) + if carried: + add(instance.template_id, template.display_name, template.display_name_plural) + else: + add(instance.instance_id, *_masked_names(instance)) + + for member in session.party.members: + for instance in member.inventory.all_instances(): + if isinstance(instance, MagicItemInstance): + add_magic_item(instance, carried=True) + else: + add(instance.template.id, instance.template.display_name, instance.template.display_name_plural) + for valuable in member.inventory.valuables: + add(valuable.instance_id, *_VALUABLE_NAMES[valuable.kind]) + for pile in piles: + for entry in pile.items: + template = catalog.get(entry.item_id) + if template is not None: + add(entry.item_id, template.display_name, template.display_name_plural) + for instance in pile.magic_items: + add_magic_item(instance, carried=False) + for valuable in pile.valuables: + add(valuable.instance_id, *_VALUABLE_NAMES[valuable.kind]) + return names, plurals + + def _quest_views(session): """The active quests, in document order, each with its revealed objectives. diff --git a/src/osrlib/data/equipment.json b/src/osrlib/data/equipment.json index f923fb27..20faade9 100644 --- a/src/osrlib/data/equipment.json +++ b/src/osrlib/data/equipment.json @@ -11,6 +11,8 @@ "ammunition": [ { "cost_gp": 5, + "display_name": "arrow", + "display_name_plural": "arrows", "id": "arrows", "item_type": "ammunition", "lot_size": 20, @@ -21,6 +23,8 @@ }, { "cost_gp": 10, + "display_name": "crossbow bolt", + "display_name_plural": "crossbow bolts", "id": "crossbow_bolts", "item_type": "ammunition", "lot_size": 30, @@ -31,6 +35,8 @@ }, { "cost_gp": 5, + "display_name": "silver tipped arrow", + "display_name_plural": "silver tipped arrows", "id": "silver_tipped_arrow", "item_type": "ammunition", "lot_size": 1, @@ -41,6 +47,8 @@ }, { "cost_gp": 0, + "display_name": "sling stone", + "display_name_plural": "sling stones", "id": "sling_stones", "item_type": "ammunition", "lot_size": 1, @@ -57,6 +65,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 40, + "display_name": "suit of chainmail", + "display_name_plural": "suits of chainmail", "id": "chainmail", "item_type": "armour", "name": "Chainmail", @@ -69,10 +79,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 }, { @@ -81,6 +96,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 60, + "display_name": "suit of plate mail", + "display_name_plural": "suits of plate mail", "id": "plate_mail", "item_type": "armour", "name": "Plate mail", @@ -93,6 +110,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -105,6 +124,8 @@ "capacity_coins": 400, "combat": null, "cost_gp": 5, + "display_name": "backpack", + "display_name_plural": "backpacks", "id": "backpack", "item_type": "gear", "lot_size": 1, @@ -116,6 +137,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 10, + "display_name": "crowbar", + "display_name_plural": "crowbars", "id": "crowbar", "item_type": "gear", "lot_size": 1, @@ -127,17 +150,24 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "bulb of garlic", + "display_name_plural": "bulbs of garlic", "id": "garlic", "item_type": "gear", "lot_size": 1, "name": "Garlic", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 25, + "display_name": "grappling hook", + "display_name_plural": "grappling hooks", "id": "grappling_hook", "item_type": "gear", "lot_size": 1, @@ -149,17 +179,24 @@ "capacity_coins": null, "combat": null, "cost_gp": 2, + "display_name": "small hammer", + "display_name_plural": "small hammers", "id": "hammer", "item_type": "gear", "lot_size": 1, "name": "Hammer (small)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 25, + "display_name": "holy symbol", + "display_name_plural": "holy symbols", "id": "holy_symbol", "item_type": "gear", "lot_size": 1, @@ -191,22 +228,32 @@ ] }, "cost_gp": 25, + "display_name": "vial of holy water", + "display_name_plural": "vials of holy water", "id": "holy_water", "item_type": "gear", "lot_size": 1, "name": "Holy water (vial)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "iron spike", + "display_name_plural": "iron spikes", "id": "iron_spikes", "item_type": "gear", "lot_size": 12, "name": "Iron spikes (12)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "wedges_doors": true } @@ -215,6 +262,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 10, + "display_name": "lantern", + "display_name_plural": "lanterns", "id": "lantern", "item_type": "gear", "lot_size": 1, @@ -230,11 +279,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "hand mirror", + "display_name_plural": "hand mirrors", "id": "mirror", "item_type": "gear", "lot_size": 1, "name": "Mirror (hand-sized, steel)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { @@ -261,11 +315,16 @@ ] }, "cost_gp": 2, + "display_name": "flask of oil", + "display_name_plural": "flasks of oil", "id": "oil_flask", "item_type": "gear", "lot_size": 1, "name": "Oil (1 flask)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "fuels_lantern": true } @@ -274,22 +333,32 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "10’ pole", + "display_name_plural": "10’ poles", "id": "pole", "item_type": "gear", "lot_size": 1, "name": "Pole (10’ long, wooden)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 15, + "display_name": "iron ration", + "display_name_plural": "iron rations", "id": "rations_iron", "item_type": "gear", "lot_size": 7, "name": "Rations (iron, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -298,11 +367,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -311,55 +385,80 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "50’ coil of rope", + "display_name_plural": "50’ coils of rope", "id": "rope", "item_type": "gear", "lot_size": 1, "name": "Rope (50’)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": 600, "combat": null, "cost_gp": 2, + "display_name": "large sack", + "display_name_plural": "large sacks", "id": "sack_large", "item_type": "gear", "lot_size": 1, "name": "Sack (large)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": 200, "combat": null, "cost_gp": 1, + "display_name": "small sack", + "display_name_plural": "small sacks", "id": "sack_small", "item_type": "gear", "lot_size": 1, "name": "Sack (small)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 3, + "display_name": "set of stakes and mallet", + "display_name_plural": "sets of stakes and mallet", "id": "stakes_and_mallet", "item_type": "gear", "lot_size": 1, "name": "Stakes (3) and mallet", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 25, + "display_name": "set of thieves’ tools", + "display_name_plural": "sets of thieves’ tools", "id": "thieves_tools", "item_type": "gear", "lot_size": 1, "name": "Thieves’ tools", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "required_for": "open_locks" } @@ -368,6 +467,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 3, + "display_name": "tinder box", + "display_name_plural": "tinder boxes", "id": "tinder_box", "item_type": "gear", "lot_size": 1, @@ -387,11 +488,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -402,6 +508,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -415,22 +523,32 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "pint of wine", + "display_name_plural": "pints of wine", "id": "wine", "item_type": "gear", "lot_size": 2, "name": "Wine (2 pints)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} }, { "capacity_coins": null, "combat": null, "cost_gp": 10, + "display_name": "bunch of wolfsbane", + "display_name_plural": "bunches of wolfsbane", "id": "wolfsbane", "item_type": "gear", "lot_size": 1, "name": "Wolfsbane (1 bunch)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} } ], @@ -472,6 +590,8 @@ { "cost_gp": 7, "damage": "1d8", + "display_name": "battle axe", + "display_name_plural": "battle axes", "id": "battle_axe", "item_type": "weapon", "material": "standard", @@ -488,6 +608,8 @@ { "cost_gp": 3, "damage": "1d4", + "display_name": "club", + "display_name_plural": "clubs", "id": "club", "item_type": "weapon", "material": "standard", @@ -503,6 +625,8 @@ { "cost_gp": 30, "damage": "1d6", + "display_name": "crossbow", + "display_name_plural": "crossbows", "id": "crossbow", "item_type": "weapon", "material": "standard", @@ -533,6 +657,8 @@ { "cost_gp": 3, "damage": "1d4", + "display_name": "dagger", + "display_name_plural": "daggers", "id": "dagger", "item_type": "weapon", "material": "standard", @@ -561,6 +687,8 @@ { "cost_gp": 4, "damage": "1d6", + "display_name": "hand axe", + "display_name_plural": "hand axes", "id": "hand_axe", "item_type": "weapon", "material": "standard", @@ -589,6 +717,8 @@ { "cost_gp": 1, "damage": "1d4", + "display_name": "javelin", + "display_name_plural": "javelins", "id": "javelin", "item_type": "weapon", "material": "standard", @@ -616,6 +746,8 @@ { "cost_gp": 5, "damage": "1d6", + "display_name": "lance", + "display_name_plural": "lances", "id": "lance", "item_type": "weapon", "material": "standard", @@ -631,6 +763,8 @@ { "cost_gp": 40, "damage": "1d6", + "display_name": "long bow", + "display_name_plural": "long bows", "id": "long_bow", "item_type": "weapon", "material": "standard", @@ -659,6 +793,8 @@ { "cost_gp": 5, "damage": "1d6", + "display_name": "mace", + "display_name_plural": "maces", "id": "mace", "item_type": "weapon", "material": "standard", @@ -674,6 +810,8 @@ { "cost_gp": 7, "damage": "1d10", + "display_name": "pole arm", + "display_name_plural": "pole arms", "id": "pole_arm", "item_type": "weapon", "material": "standard", @@ -691,6 +829,8 @@ { "cost_gp": 25, "damage": "1d6", + "display_name": "short bow", + "display_name_plural": "short bows", "id": "short_bow", "item_type": "weapon", "material": "standard", @@ -719,6 +859,8 @@ { "cost_gp": 7, "damage": "1d6", + "display_name": "short sword", + "display_name_plural": "short swords", "id": "short_sword", "item_type": "weapon", "material": "standard", @@ -733,6 +875,8 @@ { "cost_gp": 30, "damage": "1d4", + "display_name": "silver dagger", + "display_name_plural": "silver daggers", "id": "silver_dagger", "item_type": "weapon", "material": "silver", @@ -761,6 +905,8 @@ { "cost_gp": 2, "damage": "1d4", + "display_name": "sling", + "display_name_plural": "slings", "id": "sling", "item_type": "weapon", "material": "standard", @@ -789,6 +935,8 @@ { "cost_gp": 3, "damage": "1d6", + "display_name": "spear", + "display_name_plural": "spears", "id": "spear", "item_type": "weapon", "material": "standard", @@ -818,6 +966,8 @@ { "cost_gp": 2, "damage": "1d4", + "display_name": "staff", + "display_name_plural": "staves", "id": "staff", "item_type": "weapon", "material": "standard", @@ -835,6 +985,8 @@ { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -849,6 +1001,8 @@ { "cost_gp": 15, "damage": "1d10", + "display_name": "two-handed sword", + "display_name_plural": "two-handed swords", "id": "two_handed_sword", "item_type": "weapon", "material": "standard", @@ -865,6 +1019,8 @@ { "cost_gp": 5, "damage": "1d6", + "display_name": "war hammer", + "display_name_plural": "war hammers", "id": "war_hammer", "item_type": "weapon", "material": "standard", diff --git a/src/osrlib/data/magic_items.json b/src/osrlib/data/magic_items.json index de66c7ee..e0947673 100644 --- a/src/osrlib/data/magic_items.json +++ b/src/osrlib/data/magic_items.json @@ -133,6 +133,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "amulet of protection against scrying", + "display_name_plural": "amulets of protection against scrying", "effect": null, "hoard_recipe": [], "id": "amulet_of_protection_against_scrying", @@ -167,6 +169,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "suit of armour +1", + "display_name_plural": "suits of armour +1", "effect": null, "hoard_recipe": [], "id": "armour_plus_1", @@ -198,6 +202,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "suit of armour +2", + "display_name_plural": "suits of armour +2", "effect": null, "hoard_recipe": [], "id": "armour_plus_2", @@ -229,6 +235,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "suit of armour +3", + "display_name_plural": "suits of armour +3", "effect": null, "hoard_recipe": [], "id": "armour_plus_3", @@ -260,6 +268,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "arrow +1", + "display_name_plural": "arrows +1", "effect": null, "hoard_recipe": [], "id": "arrows_plus_1", @@ -291,6 +301,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "arrow +2", + "display_name_plural": "arrows +2", "effect": null, "hoard_recipe": [], "id": "arrows_plus_2", @@ -322,6 +334,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "axe +1", + "display_name_plural": "axes +1", "effect": null, "hoard_recipe": [], "id": "axe_plus_1", @@ -353,6 +367,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "axe +2", + "display_name_plural": "axes +2", "effect": null, "hoard_recipe": [], "id": "axe_plus_2", @@ -384,6 +400,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "bag of devouring", + "display_name_plural": "bags of devouring", "effect": null, "hoard_recipe": [], "id": "bag_of_devouring", @@ -418,6 +436,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "bag of holding", + "display_name_plural": "bags of holding", "effect": null, "hoard_recipe": [], "id": "bag_of_holding", @@ -456,6 +476,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "pair of boots of levitation", + "display_name_plural": "pairs of boots of levitation", "effect": null, "hoard_recipe": [], "id": "boots_of_levitation", @@ -492,6 +514,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "pair of boots of speed", + "display_name_plural": "pairs of boots of speed", "effect": null, "hoard_recipe": [], "id": "boots_of_speed", @@ -526,6 +550,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "pair of boots of travelling and leaping", + "display_name_plural": "pairs of boots of travelling and leaping", "effect": null, "hoard_recipe": [], "id": "boots_of_travelling_and_leaping", @@ -560,6 +586,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "bow +1", + "display_name_plural": "bows +1", "effect": null, "hoard_recipe": [], "id": "bow_plus_1", @@ -591,6 +619,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "broom of flying", + "display_name_plural": "brooms of flying", "effect": null, "hoard_recipe": [], "id": "broom_of_flying", @@ -625,6 +655,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "crossbow bolt +1", + "display_name_plural": "crossbow bolts +1", "effect": null, "hoard_recipe": [], "id": "crossbow_bolts_plus_1", @@ -656,6 +688,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "crossbow bolt +2", + "display_name_plural": "crossbow bolts +2", "effect": null, "hoard_recipe": [], "id": "crossbow_bolts_plus_2", @@ -687,6 +721,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "crystal ball", + "display_name_plural": "crystal balls", "effect": null, "hoard_recipe": [], "id": "crystal_ball", @@ -728,6 +764,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "crystal ball with clairaudience", + "display_name_plural": "crystal balls with clairaudience", "effect": null, "hoard_recipe": [], "id": "crystal_ball_with_clairaudience", @@ -760,6 +798,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "crystal ball with ESP", + "display_name_plural": "crystal balls with ESP", "effect": null, "hoard_recipe": [], "id": "crystal_ball_with_esp", @@ -795,6 +835,8 @@ "cursed": true, "curses": [], "damage_bonus": 0, + "display_name": "suit of cursed armour, AC 9 [10]", + "display_name_plural": "suits of cursed armour, AC 9 [10]", "effect": null, "hoard_recipe": [], "id": "cursed_armour_ac_9", @@ -828,6 +870,8 @@ "cursed": true, "curses": [], "damage_bonus": 0, + "display_name": "suit of cursed armour -1", + "display_name_plural": "suits of cursed armour -1", "effect": null, "hoard_recipe": [], "id": "cursed_armour_minus_1", @@ -861,6 +905,8 @@ "cursed": true, "curses": [], "damage_bonus": 0, + "display_name": "suit of cursed armour -2", + "display_name_plural": "suits of cursed armour -2", "effect": null, "hoard_recipe": [], "id": "cursed_armour_minus_2", @@ -931,6 +977,8 @@ } ], "damage_bonus": 0, + "display_name": "cursed scroll", + "display_name_plural": "cursed scrolls", "effect": null, "hoard_recipe": [], "id": "cursed_scroll", @@ -962,6 +1010,8 @@ "cursed": true, "curses": [], "damage_bonus": 0, + "display_name": "cursed shield, AC 9 [10]", + "display_name_plural": "cursed shields, AC 9 [10]", "effect": null, "hoard_recipe": [], "id": "cursed_shield_ac_9", @@ -995,6 +1045,8 @@ "cursed": true, "curses": [], "damage_bonus": 0, + "display_name": "cursed shield -2", + "display_name_plural": "cursed shields -2", "effect": null, "hoard_recipe": [], "id": "cursed_shield_minus_2", @@ -1028,6 +1080,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "dagger +1", + "display_name_plural": "daggers +1", "effect": null, "hoard_recipe": [], "id": "dagger_plus_1", @@ -1059,6 +1113,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "dagger +2, +3 vs orcs, goblins, and kobolds", + "display_name_plural": "daggers +2, +3 vs orcs, goblins, and kobolds", "effect": null, "hoard_recipe": [], "id": "dagger_plus_2_plus_3_vs_orcs_goblins_and_kobolds", @@ -1101,6 +1157,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "displacer cloak", + "display_name_plural": "displacer cloaks", "effect": { "condition": null, "damage_dice": null, @@ -1176,6 +1234,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "set of drums of panic", + "display_name_plural": "sets of drums of panic", "effect": null, "hoard_recipe": [], "id": "drums_of_panic", @@ -1188,7 +1248,10 @@ "Activating: Unless an item’s description states otherwise, it may be used any number of times per day and is activated by concentration." ], "name": "Drums of Panic", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {}, "quantity_dice": null, "usable_by": { @@ -1211,6 +1274,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "efreeti bottle", + "display_name_plural": "efreeti bottles", "effect": null, "hoard_recipe": [], "id": "efreeti_bottle", @@ -1246,6 +1311,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "air elemental summoning device", + "display_name_plural": "air elemental summoning devices", "effect": null, "hoard_recipe": [], "id": "elemental_summoning_device_air", @@ -1288,6 +1355,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "earth elemental summoning device", + "display_name_plural": "earth elemental summoning devices", "effect": null, "hoard_recipe": [], "id": "elemental_summoning_device_earth", @@ -1330,6 +1399,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "fire elemental summoning device", + "display_name_plural": "fire elemental summoning devices", "effect": null, "hoard_recipe": [], "id": "elemental_summoning_device_fire", @@ -1372,6 +1443,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "water elemental summoning device", + "display_name_plural": "water elemental summoning devices", "effect": null, "hoard_recipe": [], "id": "elemental_summoning_device_water", @@ -1414,6 +1487,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "set of elven cloak and boots", + "display_name_plural": "sets of elven cloak and boots", "effect": null, "hoard_recipe": [], "id": "elven_cloak_and_boots", @@ -1426,7 +1501,10 @@ "Activating: Unless an item’s description states otherwise, it may be used any number of times per day and is activated by concentration." ], "name": "Elven Cloak and Boots", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {}, "quantity_dice": null, "usable_by": { @@ -1449,6 +1527,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "flying carpet", + "display_name_plural": "flying carpets", "effect": null, "hoard_recipe": [], "id": "flying_carpet", @@ -1484,6 +1564,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "pair of gauntlets of ogre power", + "display_name_plural": "pairs of gauntlets of ogre power", "effect": { "condition": null, "damage_dice": null, @@ -1549,6 +1631,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "girdle of giant strength", + "display_name_plural": "girdles of giant strength", "effect": { "condition": null, "damage_dice": null, @@ -1602,6 +1686,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "helm of alignment changing", + "display_name_plural": "helms of alignment changing", "effect": null, "hoard_recipe": [], "id": "helm_of_alignment_changing", @@ -1637,6 +1723,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "helm of reading languages and magic", + "display_name_plural": "helms of reading languages and magic", "effect": null, "hoard_recipe": [], "id": "helm_of_reading_languages_and_magic", @@ -1672,6 +1760,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "helm of telepathy", + "display_name_plural": "helms of telepathy", "effect": null, "hoard_recipe": [], "id": "helm_of_telepathy", @@ -1710,6 +1800,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "helm of teleportation", + "display_name_plural": "helms of teleportation", "effect": null, "hoard_recipe": [], "id": "helm_of_teleportation", @@ -1747,6 +1839,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "horn of blasting", + "display_name_plural": "horns of blasting", "effect": null, "hoard_recipe": [], "id": "horn_of_blasting", @@ -1783,6 +1877,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "mace +1", + "display_name_plural": "maces +1", "effect": null, "hoard_recipe": [], "id": "mace_plus_1", @@ -1814,6 +1910,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "mace +2", + "display_name_plural": "maces +2", "effect": null, "hoard_recipe": [], "id": "mace_plus_2", @@ -1845,6 +1943,8 @@ "cursed": false, "curses": [], "damage_bonus": 3, + "display_name": "mace +3", + "display_name_plural": "maces +3", "effect": null, "hoard_recipe": [], "id": "mace_plus_3", @@ -1876,6 +1976,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "medallion of ESP 30’", + "display_name_plural": "medallions of ESP 30’", "effect": null, "hoard_recipe": [], "id": "medallion_of_esp_30", @@ -1912,6 +2014,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "medallion of ESP 90’", + "display_name_plural": "medallions of ESP 90’", "effect": null, "hoard_recipe": [], "id": "medallion_of_esp_90", @@ -1944,6 +2048,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "mirror of life trapping", + "display_name_plural": "mirrors of life trapping", "effect": null, "hoard_recipe": [], "id": "mirror_of_life_trapping", @@ -1981,6 +2087,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of clairaudience", + "display_name_plural": "potions of clairaudience", "effect": null, "hoard_recipe": [], "id": "potion_of_clairaudience", @@ -2017,6 +2125,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of clairvoyance", + "display_name_plural": "potions of clairvoyance", "effect": null, "hoard_recipe": [], "id": "potion_of_clairvoyance", @@ -2053,6 +2163,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of control animal", + "display_name_plural": "potions of control animal", "effect": null, "hoard_recipe": [], "id": "potion_of_control_animal", @@ -2090,6 +2202,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of control dragon", + "display_name_plural": "potions of control dragon", "effect": null, "hoard_recipe": [], "id": "potion_of_control_dragon", @@ -2130,6 +2244,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of control giant", + "display_name_plural": "potions of control giant", "effect": null, "hoard_recipe": [], "id": "potion_of_control_giant", @@ -2168,6 +2284,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of control human", + "display_name_plural": "potions of control human", "effect": null, "hoard_recipe": [], "id": "potion_of_control_human", @@ -2209,6 +2327,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of control plant", + "display_name_plural": "potions of control plant", "effect": null, "hoard_recipe": [], "id": "potion_of_control_plant", @@ -2248,6 +2368,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of control undead", + "display_name_plural": "potions of control undead", "effect": null, "hoard_recipe": [], "id": "potion_of_control_undead", @@ -2287,6 +2409,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of delusion", + "display_name_plural": "potions of delusion", "effect": null, "hoard_recipe": [], "id": "potion_of_delusion", @@ -2323,6 +2447,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of diminution", + "display_name_plural": "potions of diminution", "effect": null, "hoard_recipe": [], "id": "potion_of_diminution", @@ -2360,6 +2486,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of ESP", + "display_name_plural": "potions of ESP", "effect": null, "hoard_recipe": [], "id": "potion_of_esp", @@ -2394,6 +2522,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of fire resistance", + "display_name_plural": "potions of fire resistance", "effect": { "condition": null, "damage_dice": null, @@ -2470,6 +2600,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of flying", + "display_name_plural": "potions of flying", "effect": null, "hoard_recipe": [], "id": "potion_of_flying", @@ -2506,6 +2638,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of gaseous form", + "display_name_plural": "potions of gaseous form", "effect": null, "hoard_recipe": [], "id": "potion_of_gaseous_form", @@ -2544,6 +2678,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of giant strength", + "display_name_plural": "potions of giant strength", "effect": { "condition": null, "damage_dice": null, @@ -2610,6 +2746,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of growth", + "display_name_plural": "potions of growth", "effect": { "condition": null, "damage_dice": null, @@ -2674,6 +2812,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of healing", + "display_name_plural": "potions of healing", "effect": { "condition": null, "damage_dice": null, @@ -2729,6 +2869,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of heroism", + "display_name_plural": "potions of heroism", "effect": null, "hoard_recipe": [], "id": "potion_of_heroism", @@ -2770,6 +2912,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of invisibility", + "display_name_plural": "potions of invisibility", "effect": { "condition": "invisible", "damage_dice": null, @@ -2823,6 +2967,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of invulnerability", + "display_name_plural": "potions of invulnerability", "effect": { "condition": null, "damage_dice": null, @@ -2900,6 +3046,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of levitation", + "display_name_plural": "potions of levitation", "effect": null, "hoard_recipe": [], "id": "potion_of_levitation", @@ -2937,6 +3085,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of longevity", + "display_name_plural": "potions of longevity", "effect": null, "hoard_recipe": [], "id": "potion_of_longevity", @@ -2971,6 +3121,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of poison", + "display_name_plural": "potions of poison", "effect": { "condition": null, "damage_dice": null, @@ -3025,6 +3177,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of polymorph self", + "display_name_plural": "potions of polymorph self", "effect": null, "hoard_recipe": [], "id": "potion_of_polymorph_self", @@ -3059,6 +3213,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of speed", + "display_name_plural": "potions of speed", "effect": { "condition": null, "damage_dice": null, @@ -3116,6 +3272,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "potion of treasure finding", + "display_name_plural": "potions of treasure finding", "effect": null, "hoard_recipe": [], "id": "potion_of_treasure_finding", @@ -3155,6 +3313,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of controlling animals", + "display_name_plural": "rings of controlling animals", "effect": null, "hoard_recipe": [], "id": "ring_of_controlling_animals", @@ -3195,6 +3355,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of controlling humans", + "display_name_plural": "rings of controlling humans", "effect": null, "hoard_recipe": [], "id": "ring_of_controlling_humans", @@ -3234,6 +3396,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of controlling plants", + "display_name_plural": "rings of controlling plants", "effect": null, "hoard_recipe": [], "id": "ring_of_controlling_plants", @@ -3272,6 +3436,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of delusion", + "display_name_plural": "rings of delusion", "effect": null, "hoard_recipe": [], "id": "ring_of_delusion", @@ -3308,6 +3474,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of djinni summoning", + "display_name_plural": "rings of djinni summoning", "effect": null, "hoard_recipe": [], "id": "ring_of_djinni_summoning", @@ -3345,6 +3513,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of fire resistance", + "display_name_plural": "rings of fire resistance", "effect": { "condition": null, "damage_dice": null, @@ -3419,6 +3589,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of invisibility", + "display_name_plural": "rings of invisibility", "effect": null, "hoard_recipe": [], "id": "ring_of_invisibility", @@ -3455,6 +3627,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of protection", + "display_name_plural": "rings of protection", "effect": { "condition": null, "damage_dice": null, @@ -3518,6 +3692,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of protection, 5’ radius", + "display_name_plural": "rings of protection, 5’ radius", "effect": { "condition": null, "damage_dice": null, @@ -3584,6 +3760,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of regeneration", + "display_name_plural": "rings of regeneration", "effect": { "condition": null, "damage_dice": null, @@ -3645,6 +3823,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of spell storing", + "display_name_plural": "rings of spell storing", "effect": null, "hoard_recipe": [], "id": "ring_of_spell_storing", @@ -3685,6 +3865,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of spell turning", + "display_name_plural": "rings of spell turning", "effect": null, "hoard_recipe": [], "id": "ring_of_spell_turning", @@ -3720,6 +3902,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of telekinesis", + "display_name_plural": "rings of telekinesis", "effect": null, "hoard_recipe": [], "id": "ring_of_telekinesis", @@ -3758,6 +3942,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of water walking", + "display_name_plural": "rings of water walking", "effect": null, "hoard_recipe": [], "id": "ring_of_water_walking", @@ -3792,6 +3978,8 @@ "cursed": true, "curses": [], "damage_bonus": 0, + "display_name": "ring of weakness", + "display_name_plural": "rings of weakness", "effect": { "condition": null, "damage_dice": null, @@ -3848,6 +4036,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of wishes", + "display_name_plural": "rings of wishes", "effect": null, "hoard_recipe": [], "id": "ring_of_wishes", @@ -3883,6 +4073,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "ring of x-ray vision", + "display_name_plural": "rings of x-ray vision", "effect": null, "hoard_recipe": [], "id": "ring_of_x_ray_vision", @@ -3923,6 +4115,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "rod of cancellation", + "display_name_plural": "rods of cancellation", "effect": null, "hoard_recipe": [], "id": "rod_of_cancellation", @@ -3959,6 +4153,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "rope of climbing", + "display_name_plural": "ropes of climbing", "effect": null, "hoard_recipe": [], "id": "rope_of_climbing", @@ -3994,6 +4190,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "scarab of protection", + "display_name_plural": "scarabs of protection", "effect": null, "hoard_recipe": [], "id": "scarab_of_protection", @@ -4029,6 +4227,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "scroll of protection from elementals", + "display_name_plural": "scrolls of protection from elementals", "effect": { "condition": null, "damage_dice": null, @@ -4101,6 +4301,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "scroll of protection from lycanthropes", + "display_name_plural": "scrolls of protection from lycanthropes", "effect": { "condition": null, "damage_dice": null, @@ -4171,6 +4373,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "scroll of protection from magic", + "display_name_plural": "scrolls of protection from magic", "effect": null, "hoard_recipe": [], "id": "scroll_of_protection_from_magic", @@ -4209,6 +4413,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "scroll of protection from undead", + "display_name_plural": "scrolls of protection from undead", "effect": { "condition": null, "damage_dice": null, @@ -4274,6 +4480,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "shield +1", + "display_name_plural": "shields +1", "effect": null, "hoard_recipe": [], "id": "shield_plus_1", @@ -4305,6 +4513,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "shield +2", + "display_name_plural": "shields +2", "effect": null, "hoard_recipe": [], "id": "shield_plus_2", @@ -4336,6 +4546,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "shield +3", + "display_name_plural": "shields +3", "effect": null, "hoard_recipe": [], "id": "shield_plus_3", @@ -4367,6 +4579,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sling +1", + "display_name_plural": "slings +1", "effect": null, "hoard_recipe": [], "id": "sling_plus_1", @@ -4398,6 +4612,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "spear +1", + "display_name_plural": "spears +1", "effect": null, "hoard_recipe": [], "id": "spear_plus_1", @@ -4429,6 +4645,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "spear +2", + "display_name_plural": "spears +2", "effect": null, "hoard_recipe": [], "id": "spear_plus_2", @@ -4460,6 +4678,8 @@ "cursed": false, "curses": [], "damage_bonus": 3, + "display_name": "spear +3", + "display_name_plural": "spears +3", "effect": null, "hoard_recipe": [], "id": "spear_plus_3", @@ -4491,6 +4711,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "spell scroll with 1 spell", + "display_name_plural": "spell scrolls with 1 spell", "effect": null, "hoard_recipe": [], "id": "spell_scroll_1", @@ -4530,6 +4752,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "spell scroll with 2 spells", + "display_name_plural": "spell scrolls with 2 spells", "effect": null, "hoard_recipe": [], "id": "spell_scroll_2", @@ -4569,6 +4793,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "spell scroll with 3 spells", + "display_name_plural": "spell scrolls with 3 spells", "effect": null, "hoard_recipe": [], "id": "spell_scroll_3", @@ -4608,6 +4834,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "spell scroll with 5 spells", + "display_name_plural": "spell scrolls with 5 spells", "effect": null, "hoard_recipe": [], "id": "spell_scroll_5", @@ -4647,6 +4875,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "spell scroll with 7 spells", + "display_name_plural": "spell scrolls with 7 spells", "effect": null, "hoard_recipe": [], "id": "spell_scroll_7", @@ -4686,6 +4916,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "staff of commanding", + "display_name_plural": "staves of commanding", "effect": null, "hoard_recipe": [], "id": "staff_of_commanding", @@ -4735,6 +4967,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "staff of healing", + "display_name_plural": "staves of healing", "effect": { "condition": null, "damage_dice": null, @@ -4791,6 +5025,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "staff of power", + "display_name_plural": "staves of power", "effect": { "condition": null, "damage_dice": "2d6", @@ -4850,6 +5086,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "staff of snakes", + "display_name_plural": "staves of snakes", "effect": null, "hoard_recipe": [], "id": "staff_of_snakes", @@ -4892,6 +5130,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "staff of striking", + "display_name_plural": "staves of striking", "effect": { "condition": null, "damage_dice": "2d6", @@ -4948,6 +5188,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "staff of withering", + "display_name_plural": "staves of withering", "effect": null, "hoard_recipe": [], "id": "staff_of_withering", @@ -4986,6 +5228,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "staff of wizardry", + "display_name_plural": "staves of wizardry", "effect": { "condition": null, "damage_dice": "2d6", @@ -5049,6 +5293,8 @@ "cursed": true, "curses": [], "damage_bonus": -1, + "display_name": "sword -1, cursed", + "display_name_plural": "swords -1, cursed", "effect": null, "hoard_recipe": [], "id": "sword_minus_1_cursed", @@ -5077,6 +5323,8 @@ "cursed": true, "curses": [], "damage_bonus": -2, + "display_name": "sword -2, cursed", + "display_name_plural": "swords -2, cursed", "effect": null, "hoard_recipe": [], "id": "sword_minus_2_cursed", @@ -5105,6 +5353,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1", + "display_name_plural": "swords +1", "effect": null, "hoard_recipe": [], "id": "sword_plus_1", @@ -5137,6 +5387,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, energy drain", + "display_name_plural": "swords +1, energy drain", "effect": { "condition": null, "damage_dice": null, @@ -5193,6 +5445,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, flaming", + "display_name_plural": "swords +1, flaming", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_flaming", @@ -5235,6 +5489,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, light", + "display_name_plural": "swords +1, light", "effect": { "condition": null, "damage_dice": null, @@ -5286,6 +5542,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, locate objects", + "display_name_plural": "swords +1, locate objects", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_locate_objects", @@ -5321,6 +5579,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, +2 vs lycanthropes", + "display_name_plural": "swords +1, +2 vs lycanthropes", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_plus_2_vs_lycanthropes", @@ -5367,6 +5627,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, +2 vs spell users", + "display_name_plural": "swords +1, +2 vs spell users", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_plus_2_vs_spell_users", @@ -5416,6 +5678,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, +3 vs dragons", + "display_name_plural": "swords +1, +3 vs dragons", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_plus_3_vs_dragons", @@ -5464,6 +5728,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, +3 vs enchanted creatures", + "display_name_plural": "swords +1, +3 vs enchanted creatures", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_plus_3_vs_enchanted_creatures", @@ -5505,6 +5771,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, +3 vs regenerating creatures", + "display_name_plural": "swords +1, +3 vs regenerating creatures", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_plus_3_vs_regenerating_creatures", @@ -5550,6 +5818,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, +3 vs undead", + "display_name_plural": "swords +1, +3 vs undead", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_plus_3_vs_undead", @@ -5591,6 +5861,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "sword +1, wishes", + "display_name_plural": "swords +1, wishes", "effect": null, "hoard_recipe": [], "id": "sword_plus_1_wishes", @@ -5628,6 +5900,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "sword +2", + "display_name_plural": "swords +2", "effect": null, "hoard_recipe": [], "id": "sword_plus_2", @@ -5660,6 +5934,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "sword +2, charm person", + "display_name_plural": "swords +2, charm person", "effect": null, "hoard_recipe": [], "id": "sword_plus_2_charm_person", @@ -5695,6 +5971,8 @@ "cursed": false, "curses": [], "damage_bonus": 3, + "display_name": "sword +3", + "display_name_plural": "swords +3", "effect": null, "hoard_recipe": [], "id": "sword_plus_3", @@ -5727,6 +6005,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map I", + "display_name_plural": "treasure maps I", "effect": null, "hoard_recipe": [ { @@ -5778,6 +6058,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map II", + "display_name_plural": "treasure maps II", "effect": null, "hoard_recipe": [ { @@ -5828,6 +6110,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map III", + "display_name_plural": "treasure maps III", "effect": null, "hoard_recipe": [ { @@ -5879,6 +6163,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map IV", + "display_name_plural": "treasure maps IV", "effect": null, "hoard_recipe": [ { @@ -5932,6 +6218,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map IX", + "display_name_plural": "treasure maps IX", "effect": null, "hoard_recipe": [ { @@ -5978,6 +6266,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map V", + "display_name_plural": "treasure maps V", "effect": null, "hoard_recipe": [ { @@ -6046,6 +6336,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map VI", + "display_name_plural": "treasure maps VI", "effect": null, "hoard_recipe": [ { @@ -6131,6 +6423,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map VII", + "display_name_plural": "treasure maps VII", "effect": null, "hoard_recipe": [ { @@ -6189,6 +6483,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map VIII", + "display_name_plural": "treasure maps VIII", "effect": null, "hoard_recipe": [ { @@ -6235,6 +6531,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map X", + "display_name_plural": "treasure maps X", "effect": null, "hoard_recipe": [ { @@ -6296,6 +6594,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map XI", + "display_name_plural": "treasure maps XI", "effect": null, "hoard_recipe": [ { @@ -6349,6 +6649,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "treasure map XII", + "display_name_plural": "treasure maps XII", "effect": null, "hoard_recipe": [ { @@ -6395,6 +6697,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of cold", + "display_name_plural": "wands of cold", "effect": { "condition": null, "damage_dice": "6d6", @@ -6449,6 +6753,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of enemy detection", + "display_name_plural": "wands of enemy detection", "effect": null, "hoard_recipe": [], "id": "wand_of_enemy_detection", @@ -6484,6 +6790,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of fear", + "display_name_plural": "wands of fear", "effect": { "condition": "afraid", "damage_dice": null, @@ -6540,6 +6848,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of fire balls", + "display_name_plural": "wands of fire balls", "effect": { "condition": null, "damage_dice": "6d6", @@ -6594,6 +6904,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of illusion", + "display_name_plural": "wands of illusion", "effect": null, "hoard_recipe": [], "id": "wand_of_illusion", @@ -6628,6 +6940,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of lightning bolts", + "display_name_plural": "wands of lightning bolts", "effect": { "condition": null, "damage_dice": "6d6", @@ -6684,6 +6998,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of magic detection", + "display_name_plural": "wands of magic detection", "effect": null, "hoard_recipe": [], "id": "wand_of_magic_detection", @@ -6719,6 +7035,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of metal detection", + "display_name_plural": "wands of metal detection", "effect": null, "hoard_recipe": [], "id": "wand_of_metal_detection", @@ -6755,6 +7073,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of negation", + "display_name_plural": "wands of negation", "effect": null, "hoard_recipe": [], "id": "wand_of_negation", @@ -6791,6 +7111,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of paralysation", + "display_name_plural": "wands of paralysation", "effect": { "condition": "paralysed", "damage_dice": null, @@ -6847,6 +7169,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of polymorph", + "display_name_plural": "wands of polymorph", "effect": null, "hoard_recipe": [], "id": "wand_of_polymorph", @@ -6881,6 +7205,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of secret door detection", + "display_name_plural": "wands of secret door detection", "effect": null, "hoard_recipe": [], "id": "wand_of_secret_door_detection", @@ -6914,6 +7240,8 @@ "cursed": false, "curses": [], "damage_bonus": 0, + "display_name": "wand of trap detection", + "display_name_plural": "wands of trap detection", "effect": null, "hoard_recipe": [], "id": "wand_of_trap_detection", @@ -6947,6 +7275,8 @@ "cursed": false, "curses": [], "damage_bonus": 1, + "display_name": "war hammer +1", + "display_name_plural": "war hammers +1", "effect": null, "hoard_recipe": [], "id": "war_hammer_plus_1", @@ -6978,6 +7308,8 @@ "cursed": false, "curses": [], "damage_bonus": 2, + "display_name": "war hammer +2", + "display_name_plural": "war hammers +2", "effect": null, "hoard_recipe": [], "id": "war_hammer_plus_2", @@ -7009,6 +7341,8 @@ "cursed": false, "curses": [], "damage_bonus": 3, + "display_name": "war hammer +3, dwarven thrower", + "display_name_plural": "war hammers +3, dwarven thrower", "effect": null, "hoard_recipe": [], "id": "war_hammer_plus_3_dwarven_thrower", diff --git a/src/osrlib/persistence.py b/src/osrlib/persistence.py index 75fff3a4..19a3c383 100644 --- a/src/osrlib/persistence.py +++ b/src/osrlib/persistence.py @@ -128,6 +128,7 @@ GameSession, JournalEntry, QuestState, + _take_catalog_item_names, ) from osrlib.errors import ContentValidationError, ReplayVersionError from osrlib.versioning import SCHEMA_VERSION, check_document, engine_version, stamp_document @@ -470,7 +471,11 @@ def load_game(document: Mapping[str, object]) -> GameSession: You don't need to do anything for an older save. The call checks the document, then upgrades a copy of the payload through [`MIGRATIONS`][osrlib.persistence.MIGRATIONS], one schema version at a time, before it rebuilds anything. The call doesn't change `document`, - and the restored session shares nothing with it. + and the restored session shares nothing with it. Each item template that a party member's or + an NPC adventurer's stack embeds takes the display names of the session's catalog, as + [`ItemInstance.template`][osrlib.core.items.ItemInstance.template] describes, so the gear in a + save that osrlib 2.7.0 wrote is named as a new session names it, and the next save writes those + names. A save that this osrlib wrote loads to a session that saves the same document again. A newer osrlib can add event types and message codes within the same schema version. The call keeps an event as a dict when this osrlib doesn't define its type, or defines the type @@ -552,6 +557,8 @@ def load_game(document: Mapping[str, object]) -> GameSession: if npc.id is None: raise ContentValidationError("an NPC in the save carries no id") session.npcs[npc.id] = npc + for npc in session.npcs.values(): + _take_catalog_item_names(session.effective_equipment, npc) session.flags = dict(payload["flags"]) # Both blocks are newer than schema version 3 and load with empty defaults, so an # older save restores unchanged, and the session records them from then on. diff --git a/tests/goldens/phase1_party.json b/tests/goldens/phase1_party.json index e13ac790..675ef702 100644 --- a/tests/goldens/phase1_party.json +++ b/tests/goldens/phase1_party.json @@ -1,5 +1,5 @@ { - "engine_version": "2.0.1", + "engine_version": "2.7.0", "kind": "party", "payload": { "characters": [ @@ -27,11 +27,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -57,6 +62,8 @@ "template": { "cost_gp": 5, "damage": "1d6", + "display_name": "mace", + "display_name_plural": "maces", "id": "mace", "item_type": "weapon", "material": "standard", @@ -80,10 +87,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -124,11 +136,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "iron spike", + "display_name_plural": "iron spikes", "id": "iron_spikes", "item_type": "gear", "lot_size": 12, "name": "Iron spikes (12)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "wedges_doors": true } @@ -147,11 +164,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -177,6 +199,8 @@ "template": { "cost_gp": 5, "damage": "1d6", + "display_name": "war hammer", + "display_name_plural": "war hammers", "id": "war_hammer", "item_type": "weapon", "material": "standard", @@ -200,10 +224,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -254,6 +283,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -276,10 +307,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -332,6 +368,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -354,10 +392,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -399,6 +442,8 @@ "quantity": 1, "template": { "cost_gp": 0, + "display_name": "sling stone", + "display_name_plural": "sling stones", "id": "sling_stones", "item_type": "ammunition", "lot_size": 1, @@ -415,11 +460,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -443,6 +493,8 @@ "template": { "cost_gp": 2, "damage": "1d4", + "display_name": "sling", + "display_name_plural": "slings", "id": "sling", "item_type": "weapon", "material": "standard", @@ -479,10 +531,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -543,11 +600,16 @@ ] }, "cost_gp": 2, + "display_name": "flask of oil", + "display_name_plural": "flasks of oil", "id": "oil_flask", "item_type": "gear", "lot_size": 1, "name": "Oil (1 flask)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "fuels_lantern": true } @@ -566,11 +628,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -585,11 +652,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -602,6 +674,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -630,6 +704,8 @@ "template": { "cost_gp": 3, "damage": "1d4", + "display_name": "dagger", + "display_name_plural": "daggers", "id": "dagger", "item_type": "weapon", "material": "standard", @@ -699,11 +775,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "50’ coil of rope", + "display_name_plural": "50’ coils of rope", "id": "rope", "item_type": "gear", "lot_size": 1, "name": "Rope (50’)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": {} } }, @@ -720,11 +801,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -750,6 +836,8 @@ "template": { "cost_gp": 3, "damage": "1d4", + "display_name": "dagger", + "display_name_plural": "daggers", "id": "dagger", "item_type": "weapon", "material": "standard", @@ -786,10 +874,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } diff --git a/tests/goldens/phase5_milestone.json b/tests/goldens/phase5_milestone.json index 9a4b2996..5988af28 100644 --- a/tests/goldens/phase5_milestone.json +++ b/tests/goldens/phase5_milestone.json @@ -3778,7 +3778,7 @@ "master_seed": 39, "mode": "victory", "party_document": { - "engine_version": "2.6.0", + "engine_version": "2.7.0", "kind": "party", "payload": { "characters": [ @@ -3810,6 +3810,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -3825,6 +3827,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -3847,6 +3851,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 40, + "display_name": "suit of chainmail", + "display_name_plural": "suits of chainmail", "id": "chainmail", "item_type": "armour", "name": "Chainmail", @@ -3901,6 +3907,8 @@ "template": { "cost_gp": 5, "damage": "1d6", + "display_name": "mace", + "display_name_plural": "maces", "id": "mace", "item_type": "weapon", "material": "standard", @@ -3924,6 +3932,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 40, + "display_name": "suit of chainmail", + "display_name_plural": "suits of chainmail", "id": "chainmail", "item_type": "armour", "name": "Chainmail", @@ -3978,6 +3988,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -4000,10 +4012,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -4054,6 +4071,8 @@ "template": { "cost_gp": 3, "damage": "1d4", + "display_name": "dagger", + "display_name_plural": "daggers", "id": "dagger", "item_type": "weapon", "material": "standard", diff --git a/tests/goldens/phase5_npc_parties.json b/tests/goldens/phase5_npc_parties.json index b3199426..300b2851 100644 --- a/tests/goldens/phase5_npc_parties.json +++ b/tests/goldens/phase5_npc_parties.json @@ -19,6 +19,8 @@ "quantity": 1, "template": { "cost_gp": 0, + "display_name": "sling stone", + "display_name_plural": "sling stones", "id": "sling_stones", "item_type": "ammunition", "lot_size": 1, @@ -35,11 +37,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -52,6 +59,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -75,11 +84,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -105,6 +119,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -120,6 +136,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -138,6 +156,8 @@ "template": { "cost_gp": 2, "damage": "1d4", + "display_name": "sling", + "display_name_plural": "slings", "id": "sling", "item_type": "weapon", "material": "standard", @@ -174,10 +194,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -220,6 +245,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -234,11 +261,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -251,6 +283,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -274,11 +308,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -304,6 +343,8 @@ "template": { "cost_gp": 7, "damage": "1d8", + "display_name": "battle axe", + "display_name_plural": "battle axes", "id": "battle_axe", "item_type": "weapon", "material": "standard", @@ -328,6 +369,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 40, + "display_name": "suit of chainmail", + "display_name_plural": "suits of chainmail", "id": "chainmail", "item_type": "armour", "name": "Chainmail", @@ -372,11 +415,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 25, + "display_name": "set of thieves’ tools", + "display_name_plural": "sets of thieves’ tools", "id": "thieves_tools", "item_type": "gear", "lot_size": 1, "name": "Thieves’ tools", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "required_for": "open_locks" } @@ -389,11 +437,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -406,6 +459,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -429,11 +484,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -459,6 +519,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -481,10 +543,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -527,6 +594,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -541,11 +610,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -558,6 +632,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -581,11 +657,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -611,6 +692,8 @@ "template": { "cost_gp": 7, "damage": "1d8", + "display_name": "battle axe", + "display_name_plural": "battle axes", "id": "battle_axe", "item_type": "weapon", "material": "standard", @@ -635,6 +718,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 40, + "display_name": "suit of chainmail", + "display_name_plural": "suits of chainmail", "id": "chainmail", "item_type": "armour", "name": "Chainmail", @@ -677,6 +762,8 @@ "quantity": 20, "template": { "cost_gp": 5, + "display_name": "arrow", + "display_name_plural": "arrows", "id": "arrows", "item_type": "ammunition", "lot_size": 20, @@ -693,11 +780,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -710,6 +802,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -733,11 +827,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -763,6 +862,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -781,6 +882,8 @@ "template": { "cost_gp": 40, "damage": "1d6", + "display_name": "long bow", + "display_name_plural": "long bows", "id": "long_bow", "item_type": "weapon", "material": "standard", @@ -817,6 +920,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 40, + "display_name": "suit of chainmail", + "display_name_plural": "suits of chainmail", "id": "chainmail", "item_type": "armour", "name": "Chainmail", @@ -907,11 +1012,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -924,6 +1034,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -947,11 +1059,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -980,6 +1097,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -1040,6 +1159,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -1062,6 +1183,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 60, + "display_name": "suit of plate mail", + "display_name_plural": "suits of plate mail", "id": "plate_mail", "item_type": "armour", "name": "Plate mail", @@ -1104,6 +1227,8 @@ "quantity": 1, "template": { "cost_gp": 0, + "display_name": "sling stone", + "display_name_plural": "sling stones", "id": "sling_stones", "item_type": "ammunition", "lot_size": 1, @@ -1120,11 +1245,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -1137,6 +1267,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -1160,11 +1292,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -1181,6 +1318,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -1229,6 +1368,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -1247,6 +1388,8 @@ "template": { "cost_gp": 2, "damage": "1d4", + "display_name": "sling", + "display_name_plural": "slings", "id": "sling", "item_type": "weapon", "material": "standard", @@ -1283,10 +1426,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -1325,6 +1473,8 @@ "quantity": 1, "template": { "cost_gp": 0, + "display_name": "sling stone", + "display_name_plural": "sling stones", "id": "sling_stones", "item_type": "ammunition", "lot_size": 1, @@ -1341,11 +1491,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -1358,6 +1513,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -1381,11 +1538,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -1423,6 +1585,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -1438,6 +1602,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -1456,6 +1622,8 @@ "template": { "cost_gp": 2, "damage": "1d4", + "display_name": "sling", + "display_name_plural": "slings", "id": "sling", "item_type": "weapon", "material": "standard", @@ -1520,10 +1688,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -1564,11 +1737,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 25, + "display_name": "set of thieves’ tools", + "display_name_plural": "sets of thieves’ tools", "id": "thieves_tools", "item_type": "gear", "lot_size": 1, "name": "Thieves’ tools", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "required_for": "open_locks" } @@ -1581,11 +1759,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -1598,6 +1781,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -1621,11 +1806,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -1651,6 +1841,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -1673,10 +1865,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -1717,11 +1914,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -1734,6 +1936,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -1757,11 +1961,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -1811,6 +2020,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -1826,6 +2037,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -1860,6 +2073,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 60, + "display_name": "suit of plate mail", + "display_name_plural": "suits of plate mail", "id": "plate_mail", "item_type": "armour", "name": "Plate mail", @@ -1904,11 +2119,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 25, + "display_name": "set of thieves’ tools", + "display_name_plural": "sets of thieves’ tools", "id": "thieves_tools", "item_type": "gear", "lot_size": 1, "name": "Thieves’ tools", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "required_for": "open_locks" } @@ -1921,11 +2141,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -1938,6 +2163,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -1961,11 +2188,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -1991,6 +2223,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -2025,10 +2259,15 @@ "ac_bonus": null, "category": "light", "cost_gp": 20, + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour", "id": "leather", "item_type": "armour", "name": "Leather", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "weight_coins": 200 } } @@ -2069,11 +2308,16 @@ "capacity_coins": null, "combat": null, "cost_gp": 5, + "display_name": "standard ration", + "display_name_plural": "standard rations", "id": "rations_standard", "item_type": "gear", "lot_size": 7, "name": "Rations (standard, 7 days)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "ration": true } @@ -2086,6 +2330,8 @@ "capacity_coins": null, "combat": null, "cost_gp": 1, + "display_name": "waterskin", + "display_name_plural": "waterskins", "id": "waterskin", "item_type": "gear", "lot_size": 1, @@ -2109,11 +2355,16 @@ ] }, "cost_gp": 1, + "display_name": "torch", + "display_name_plural": "torches", "id": "torch", "item_type": "gear", "lot_size": 6, "name": "Torches (6)", - "overrides_applied": [], + "overrides_applied": [ + "display_name", + "display_name_plural" + ], "params": { "brightness": "flame", "burn_turns": 6, @@ -2139,6 +2390,8 @@ "ac_bonus": 1, "category": null, "cost_gp": 10, + "display_name": "shield", + "display_name_plural": "shields", "id": "shield", "item_type": "armour", "name": "Shield", @@ -2154,6 +2407,8 @@ "template": { "cost_gp": 10, "damage": "1d8", + "display_name": "sword", + "display_name_plural": "swords", "id": "sword", "item_type": "weapon", "material": "standard", @@ -2176,6 +2431,8 @@ "ac_bonus": null, "category": "heavy", "cost_gp": 60, + "display_name": "suit of plate mail", + "display_name_plural": "suits of plate mail", "id": "plate_mail", "item_type": "armour", "name": "Plate mail", diff --git a/tests/saves/view_item_names_2.7.0.json b/tests/saves/view_item_names_2.7.0.json new file mode 100644 index 00000000..438909ed --- /dev/null +++ b/tests/saves/view_item_names_2.7.0.json @@ -0,0 +1,850 @@ +{ + "engine_version": "2.7.0", + "kind": "save", + "payload": { + "adventure": { + "description": "", + "dungeons": [ + { + "id": "shrine", + "levels": [ + { + "areas": [], + "edges": {}, + "entrance": [ + 0, + 0 + ], + "features": [], + "guidance": "", + "height": 1, + "number": 1, + "transitions": [], + "wandering": { + "chance_in_six": 1, + "interval_turns": 2, + "table": null + }, + "width": 1 + } + ], + "name": "The Shrine" + } + ], + "hooks": [], + "items": [ + { + "capacity_coins": null, + "combat": null, + "cost_gp": 0, + "id": "temple_idol", + "item_type": "gear", + "lot_size": 1, + "name": "Idol of the drowned saint", + "overrides_applied": [], + "params": {} + } + ], + "monsters": [], + "name": "The Drowned Saint", + "party": null, + "quests": [], + "spells": [], + "town": { + "description": "", + "healing_prices": {}, + "name": "Threshold", + "services": [], + "travel_turns": { + "shrine": 1 + } + }, + "triggers": [] + }, + "allocator": { + "counters": { + "character": 4, + "magic-item": 1 + } + }, + "battle": null, + "clock_rounds": 60, + "command_log": [ + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "holy_water", + "quantity": 2, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "torch", + "quantity": 6, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "sword", + "quantity": 1, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "chainmail", + "quantity": 1, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "arrows", + "quantity": 20, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "short_bow", + "quantity": 1, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "temple_idol", + "quantity": 2, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "oil_flask", + "quantity": 2, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "grant_item", + "item_id": "potion_of_healing", + "quantity": 1, + "source": null + }, + { + "character_id": "character-0001", + "command_type": "equip_item", + "item_id": "sword", + "source": null + }, + { + "character_id": "character-0001", + "command_type": "equip_item", + "item_id": "chainmail", + "source": null + }, + { + "command_type": "enter_dungeon", + "dungeon_id": "shrine", + "source": null + }, + { + "character_id": "character-0001", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "command_type": "drop_items", + "item_ids": [ + "oil_flask", + "oil_flask", + "temple_idol" + ], + "source": null + } + ], + "death_records": {}, + "defeated_monsters": [], + "deprivation": {}, + "dungeon_state": { + "doors": {}, + "emptied_caches": [], + "explored": { + "shrine:1": [ + [ + 0, + 0 + ] + ] + }, + "found_traps": [], + "found_tricks": [], + "generated_caches": {}, + "generated_lair_hoards": [], + "generated_treasure_areas": [], + "inspect_attempts": {}, + "listen_attempts": {}, + "location": { + "dungeon_id": "shrine", + "facing": "north", + "kind": "dungeon", + "level_number": 1, + "position": [ + 0, + 0 + ] + }, + "lock_failures": {}, + "piles": { + "cell:shrine:1:0,0": { + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "items": [ + { + "item_id": "oil_flask", + "quantity": 2 + }, + { + "item_id": "temple_idol", + "quantity": 1 + } + ], + "magic_items": [], + "valuables": [] + } + }, + "removal_attempts": {}, + "removed_traps": [], + "resolved_encounters": [], + "search_attempts": {}, + "seen": {}, + "sprung_traps": [] + }, + "encounter": null, + "event_log": [ + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "holy_water", + "holy_water" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "torch", + "torch", + "torch", + "torch", + "torch", + "torch" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "sword" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "chainmail" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows", + "arrows" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "short_bow" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "temple_idol", + "temple_idol" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "oil_flask", + "oil_flask" + ], + "origin": "grant", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.acquired", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "item_acquired", + "item_ids": [ + "magic-item-0001" + ], + "origin": "grant", + "visibility": "player" + }, + { + "code": "exploration.location.entered", + "dungeon_id": null, + "event_type": "location_entered", + "level_number": 1, + "location_id": "shrine", + "location_kind": "dungeon", + "narrative": null, + "transition_ref": null, + "via": "entrance", + "visibility": "player" + }, + { + "character_id": "character-0001", + "code": "exploration.item.dropped", + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "coins_gp_value": 0, + "event_type": "items_dropped", + "item_ids": [ + "oil_flask", + "oil_flask", + "temple_idol" + ], + "visibility": "player" + } + ], + "exploration": { + "alerted_areas": [], + "heard_areas": [], + "last_prepared_sleep": {}, + "noise_since_check": false, + "odometer_thirds": 0, + "provisions_day": 0, + "sleep_count": 0, + "turns_since_rest": 0, + "wandering_counter": 0 + }, + "fired_triggers": [], + "flags": {}, + "journal": [], + "ledger": { + "effects": [] + }, + "listener_state": {}, + "master_seed": 5, + "mode": "exploring", + "monsters": [], + "npcs": [], + "party": { + "members": [ + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0001", + "inventory": { + "items": [ + { + "instance_type": "item", + "quantity": 2, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d8", + "missile_ranges": { + "long": { + "max_feet": 50, + "min_feet": 31 + }, + "medium": { + "max_feet": 30, + "min_feet": 11 + }, + "short": { + "max_feet": 10, + "min_feet": 5 + } + }, + "qualities": [ + "missile", + "splash" + ] + }, + "cost_gp": 25, + "id": "holy_water", + "item_type": "gear", + "lot_size": 1, + "name": "Holy water (vial)", + "overrides_applied": [], + "params": {} + } + }, + { + "instance_type": "item", + "quantity": 6, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d4", + "missile_ranges": null, + "qualities": [ + "melee" + ] + }, + "cost_gp": 1, + "id": "torch", + "item_type": "gear", + "lot_size": 6, + "name": "Torches (6)", + "overrides_applied": [], + "params": { + "brightness": "flame", + "burn_turns": 6, + "light_radius_feet": 30 + } + } + }, + { + "instance_type": "item", + "quantity": 20, + "template": { + "cost_gp": 5, + "id": "arrows", + "item_type": "ammunition", + "lot_size": 20, + "material": "standard", + "name": "Arrows (quiver of 20)", + "overrides_applied": [], + "weight_coins": 0 + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 25, + "damage": "1d6", + "id": "short_bow", + "item_type": "weapon", + "material": "standard", + "missile_ranges": { + "long": { + "max_feet": 150, + "min_feet": 101 + }, + "medium": { + "max_feet": 100, + "min_feet": 51 + }, + "short": { + "max_feet": 50, + "min_feet": 5 + } + }, + "name": "Short bow", + "overrides_applied": [], + "qualities": [ + "missile", + "two_handed" + ], + "weight_coins": 30 + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 0, + "id": "temple_idol", + "item_type": "gear", + "lot_size": 1, + "name": "Idol of the drowned saint", + "overrides_applied": [], + "params": {} + } + }, + { + "base_item_id": null, + "charges_remaining": null, + "cursed_revealed": false, + "identified": false, + "instance_id": "magic-item-0001", + "instance_type": "magic_item", + "quantity": 1, + "sentience": null, + "state": {}, + "template_id": "potion_of_healing" + } + ], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [ + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 10, + "damage": "1d8", + "id": "sword", + "item_type": "weapon", + "material": "standard", + "missile_ranges": null, + "name": "Sword", + "overrides_applied": [], + "qualities": [ + "melee" + ], + "weight_coins": 60 + } + } + ], + "worn_armour": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": 5, + "ac_ascending": 14, + "ac_bonus": null, + "category": "heavy", + "cost_gp": 40, + "id": "chainmail", + "item_type": "armour", + "name": "Chainmail", + "overrides_applied": [], + "weight_coins": 400 + } + } + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Brakk", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "thief", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0002", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Sable", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0003", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Wynn", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 13 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0004", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Elara", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [ + "sleep" + ], + "stat_modifiers": [], + "xp": 0 + } + ] + }, + "quests": {}, + "rng_streams": { + "effects": { + "inc": 83995303103106262482337783037166368733, + "state": 170194833506817835568259385413023180433 + }, + "treasure": { + "inc": 53476702257389784988669638314557571929, + "state": 310646460157342966311778912749120787293 + } + }, + "ruleset": { + "aoe_friendly_fire": true, + "back_stab_needs_both_skills": true, + "deprivation_penalties": false, + "encumbrance": "basic", + "failed_trap_removal_springs": true, + "formation_width_limit": true, + "hd5_counts_as_magical": false, + "hp_reroll_at_first_level": false, + "individual_initiative": false, + "magic_item_death_save": true, + "thac0_arithmetic": false, + "variable_weapon_damage": true, + "weapon_reload": false, + "xp_award_timing": "on_return" + }, + "treasure_snapshot_cp": 0 + }, + "schema_version": 4 +} diff --git a/tests/saves/view_item_names_npcs_2.7.0.json b/tests/saves/view_item_names_npcs_2.7.0.json new file mode 100644 index 00000000..7e403fdd --- /dev/null +++ b/tests/saves/view_item_names_npcs_2.7.0.json @@ -0,0 +1,1150 @@ +{ + "engine_version": "2.7.0", + "kind": "save", + "payload": { + "adventure": { + "description": "", + "dungeons": [ + { + "id": "crypt", + "levels": [ + { + "areas": [], + "edges": {}, + "entrance": [ + 0, + 0 + ], + "features": [], + "guidance": "", + "height": 1, + "number": 1, + "transitions": [], + "wandering": { + "chance_in_six": 0, + "interval_turns": 2, + "table": null + }, + "width": 1 + } + ], + "name": "Crypt" + } + ], + "hooks": [], + "items": [], + "monsters": [], + "name": "The Rival Band", + "party": null, + "quests": [], + "spells": [], + "town": { + "description": "", + "healing_prices": {}, + "name": "Threshold", + "services": [], + "travel_turns": { + "crypt": 1 + } + }, + "triggers": [] + }, + "allocator": { + "counters": { + "character": 4, + "group": 1, + "npc": 4 + } + }, + "battle": { + "advance_feet": {}, + "arrived_round": {}, + "concentration": {}, + "fired_last_round": [], + "hiding": {}, + "melee_engagements": {}, + "monsters_hold_rounds": 0, + "morale": { + "passed": {} + }, + "morale_acted": {}, + "round": 1, + "started_round": 60 + }, + "clock_rounds": 61, + "command_log": [ + { + "command_type": "enter_dungeon", + "dungeon_id": "crypt", + "source": null + }, + { + "command_type": "spawn_npc_party", + "count_dice": null, + "count_fixed": 4, + "distance_feet": 60, + "party_kind": "basic", + "source": null + } + ], + "death_records": {}, + "defeated_monsters": [], + "deprivation": {}, + "dungeon_state": { + "doors": {}, + "emptied_caches": [], + "explored": { + "crypt:1": [ + [ + 0, + 0 + ] + ] + }, + "found_traps": [], + "found_tricks": [], + "generated_caches": {}, + "generated_lair_hoards": [], + "generated_treasure_areas": [], + "inspect_attempts": {}, + "listen_attempts": {}, + "location": { + "dungeon_id": "crypt", + "facing": "north", + "kind": "dungeon", + "level_number": 1, + "position": [ + 0, + 0 + ] + }, + "lock_failures": {}, + "piles": {}, + "removal_attempts": {}, + "removed_traps": [], + "resolved_encounters": [], + "search_attempts": {}, + "seen": {}, + "sprung_traps": [] + }, + "encounter": { + "area_ref": null, + "evading": false, + "groups": [ + { + "distance_feet": 40, + "fled": false, + "fleeing": false, + "group_treasure": { + "coins": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 49 + }, + "magic_items": [], + "valuables": [] + }, + "id": "group-0001", + "label": "adventurer", + "label_plural": "adventurers", + "member_treasure": {}, + "monster_ids": [ + "npc-0001", + "npc-0002", + "npc-0003", + "npc-0004" + ] + } + ], + "hostile_deadline": null, + "kind": "spawned", + "monsters_skip_rounds": 0, + "monsters_surprised": false, + "party_surprised": true, + "pursuit": null, + "round": 0, + "stance": "attacks", + "started_round": 60 + }, + "event_log": [ + { + "code": "exploration.location.entered", + "dungeon_id": null, + "event_type": "location_entered", + "level_number": 1, + "location_id": "crypt", + "location_kind": "dungeon", + "narrative": null, + "transition_ref": null, + "via": "entrance", + "visibility": "player" + }, + { + "alignment": "chaotic", + "class_ids": [ + "magic_user", + "cleric", + "fighter", + "fighter" + ], + "code": "encounter.npc_party.spawned", + "event_type": "npc_party_spawned", + "levels": [ + 1, + 1, + 1, + 2 + ], + "npc_ids": [ + "npc-0001", + "npc-0002", + "npc-0003", + "npc-0004" + ], + "party_kind": "basic", + "visibility": "referee" + }, + { + "code": "encounter.surprise.rolled", + "event_type": "surprise_rolled", + "roll": 5, + "side": "monsters", + "surprised": false, + "threshold": 2, + "visibility": "referee" + }, + { + "code": "encounter.surprise.rolled", + "event_type": "surprise_rolled", + "roll": 3, + "side": "party", + "surprised": true, + "threshold": 3, + "visibility": "referee" + }, + { + "code": "encounter.started", + "count": 4, + "distance_feet": 60, + "event_type": "encounter_started", + "group_counts": [ + 4 + ], + "group_labels": [ + "adventurer" + ], + "group_labels_plural": [ + "adventurers" + ], + "monster_name": "adventurer", + "monster_name_plural": "adventurers", + "monsters_surprised": false, + "party_surprised": true, + "visibility": "player" + }, + { + "code": "encounter.reaction.rolled", + "event_type": "reaction_rolled", + "modifier": 0, + "result": "attacks", + "roll": 2, + "total": 2, + "visibility": "referee" + }, + { + "code": "encounter.stance.changed", + "event_type": "stance_changed", + "stance": "attacks", + "visibility": "player" + }, + { + "code": "battle.started", + "event_type": "battle_started", + "visibility": "player" + }, + { + "attack_name": "Dagger", + "attacker_id": "npc-0001", + "back_stab": false, + "code": "combat.attack.hit", + "defender_ac": 9, + "defender_id": "character-0002", + "event_type": "attack_rolled", + "modifier": 0, + "natural": null, + "required": 10, + "roll": 17, + "total": 17, + "visibility": "player" + }, + { + "amount": 3, + "attacker_id": "npc-0001", + "code": "combat.damage.dealt", + "event_type": "damage_dealt", + "keys": [], + "non_regenerable": false, + "rolls": [ + 3 + ], + "target_id": "character-0002", + "visibility": "player" + }, + { + "code": "combat.state.hit_points", + "current_hp": 3, + "event_type": "hit_points_reported", + "max_hp": 6, + "target_id": "character-0002", + "visibility": "referee" + }, + { + "code": "battle.group.moved", + "distance_feet": 40, + "event_type": "group_moved", + "group_id": "group-0001", + "visibility": "player" + } + ], + "exploration": { + "alerted_areas": [], + "heard_areas": [], + "last_prepared_sleep": {}, + "noise_since_check": false, + "odometer_thirds": 0, + "provisions_day": 0, + "sleep_count": 0, + "turns_since_rest": 0, + "wandering_counter": 0 + }, + "fired_triggers": [], + "flags": {}, + "journal": [], + "ledger": { + "effects": [] + }, + "listener_state": {}, + "master_seed": 1, + "mode": "battle", + "monsters": [], + "npcs": [ + { + "alignment": "chaotic", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 3, + "custom_class": null, + "extra_languages": [], + "id": "npc-0001", + "inventory": { + "items": [ + { + "instance_type": "item", + "quantity": 7, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 5, + "id": "rations_standard", + "item_type": "gear", + "lot_size": 7, + "name": "Rations (standard, 7 days)", + "overrides_applied": [], + "params": { + "ration": true + } + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 1, + "id": "waterskin", + "item_type": "gear", + "lot_size": 1, + "name": "Waterskin", + "overrides_applied": [], + "params": { + "water_container": true + } + } + }, + { + "instance_type": "item", + "quantity": 6, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d4", + "missile_ranges": null, + "qualities": [ + "melee" + ] + }, + "cost_gp": 1, + "id": "torch", + "item_type": "gear", + "lot_size": 6, + "name": "Torches (6)", + "overrides_applied": [], + "params": { + "brightness": "flame", + "burn_turns": 6, + "light_radius_feet": 30 + } + } + } + ], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [ + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 3, + "damage": "1d4", + "id": "dagger", + "item_type": "weapon", + "material": "standard", + "missile_ranges": { + "long": { + "max_feet": 30, + "min_feet": 21 + }, + "medium": { + "max_feet": 20, + "min_feet": 11 + }, + "short": { + "max_feet": 10, + "min_feet": 5 + } + }, + "name": "Dagger", + "overrides_applied": [], + "qualities": [ + "melee", + "missile" + ], + "weight_coins": 10 + } + } + ], + "worn_armour": null + }, + "level": 1, + "max_hp": 3, + "memorized_spells": [ + { + "reversed": false, + "spell_id": "floating_disc" + } + ], + "name": "Magic-User adventurer 1", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 9, + "con": 9, + "dex": 11, + "int": 12, + "str": 15, + "wis": 12 + }, + "spell_book": [ + "floating_disc" + ], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "chaotic", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 5, + "custom_class": null, + "extra_languages": [], + "id": "npc-0002", + "inventory": { + "items": [ + { + "instance_type": "item", + "quantity": 7, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 5, + "id": "rations_standard", + "item_type": "gear", + "lot_size": 7, + "name": "Rations (standard, 7 days)", + "overrides_applied": [], + "params": { + "ration": true + } + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 1, + "id": "waterskin", + "item_type": "gear", + "lot_size": 1, + "name": "Waterskin", + "overrides_applied": [], + "params": { + "water_container": true + } + } + }, + { + "instance_type": "item", + "quantity": 6, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d4", + "missile_ranges": null, + "qualities": [ + "melee" + ] + }, + "cost_gp": 1, + "id": "torch", + "item_type": "gear", + "lot_size": 6, + "name": "Torches (6)", + "overrides_applied": [], + "params": { + "brightness": "flame", + "burn_turns": 6, + "light_radius_feet": 30 + } + } + } + ], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": null, + "ac_ascending": null, + "ac_bonus": 1, + "category": null, + "cost_gp": 10, + "id": "shield", + "item_type": "armour", + "name": "Shield", + "overrides_applied": [], + "weight_coins": 100 + } + }, + "valuables": [], + "wielded": [ + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 5, + "damage": "1d6", + "id": "mace", + "item_type": "weapon", + "material": "standard", + "missile_ranges": null, + "name": "Mace", + "overrides_applied": [], + "qualities": [ + "blunt", + "melee" + ], + "weight_coins": 30 + } + } + ], + "worn_armour": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": 5, + "ac_ascending": 14, + "ac_bonus": null, + "category": "heavy", + "cost_gp": 40, + "id": "chainmail", + "item_type": "armour", + "name": "Chainmail", + "overrides_applied": [], + "weight_coins": 400 + } + } + }, + "level": 1, + "max_hp": 5, + "memorized_spells": [], + "name": "Cleric adventurer 2", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 14, + "con": 11, + "dex": 12, + "int": 13, + "str": 11, + "wis": 8 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "chaotic", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "npc-0003", + "inventory": { + "items": [ + { + "instance_type": "item", + "quantity": 7, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 5, + "id": "rations_standard", + "item_type": "gear", + "lot_size": 7, + "name": "Rations (standard, 7 days)", + "overrides_applied": [], + "params": { + "ration": true + } + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 1, + "id": "waterskin", + "item_type": "gear", + "lot_size": 1, + "name": "Waterskin", + "overrides_applied": [], + "params": { + "water_container": true + } + } + }, + { + "instance_type": "item", + "quantity": 6, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d4", + "missile_ranges": null, + "qualities": [ + "melee" + ] + }, + "cost_gp": 1, + "id": "torch", + "item_type": "gear", + "lot_size": 6, + "name": "Torches (6)", + "overrides_applied": [], + "params": { + "brightness": "flame", + "burn_turns": 6, + "light_radius_feet": 30 + } + } + } + ], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": null, + "ac_ascending": null, + "ac_bonus": 1, + "category": null, + "cost_gp": 10, + "id": "shield", + "item_type": "armour", + "name": "Shield", + "overrides_applied": [], + "weight_coins": 100 + } + }, + "valuables": [], + "wielded": [ + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 10, + "damage": "1d8", + "id": "sword", + "item_type": "weapon", + "material": "standard", + "missile_ranges": null, + "name": "Sword", + "overrides_applied": [], + "qualities": [ + "melee" + ], + "weight_coins": 60 + } + } + ], + "worn_armour": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": 5, + "ac_ascending": 14, + "ac_bonus": null, + "category": "heavy", + "cost_gp": 40, + "id": "chainmail", + "item_type": "armour", + "name": "Chainmail", + "overrides_applied": [], + "weight_coins": 400 + } + } + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Fighter adventurer 3", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 6, + "con": 15, + "dex": 12, + "int": 9, + "str": 8, + "wis": 5 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "chaotic", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 8, + "custom_class": null, + "extra_languages": [], + "id": "npc-0004", + "inventory": { + "items": [ + { + "instance_type": "item", + "quantity": 7, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 5, + "id": "rations_standard", + "item_type": "gear", + "lot_size": 7, + "name": "Rations (standard, 7 days)", + "overrides_applied": [], + "params": { + "ration": true + } + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 1, + "id": "waterskin", + "item_type": "gear", + "lot_size": 1, + "name": "Waterskin", + "overrides_applied": [], + "params": { + "water_container": true + } + } + }, + { + "instance_type": "item", + "quantity": 6, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d4", + "missile_ranges": null, + "qualities": [ + "melee" + ] + }, + "cost_gp": 1, + "id": "torch", + "item_type": "gear", + "lot_size": 6, + "name": "Torches (6)", + "overrides_applied": [], + "params": { + "brightness": "flame", + "burn_turns": 6, + "light_radius_feet": 30 + } + } + } + ], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": null, + "ac_ascending": null, + "ac_bonus": 1, + "category": null, + "cost_gp": 10, + "id": "shield", + "item_type": "armour", + "name": "Shield", + "overrides_applied": [], + "weight_coins": 100 + } + }, + "valuables": [], + "wielded": [ + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 10, + "damage": "1d8", + "id": "sword", + "item_type": "weapon", + "material": "standard", + "missile_ranges": null, + "name": "Sword", + "overrides_applied": [], + "qualities": [ + "melee" + ], + "weight_coins": 60 + } + } + ], + "worn_armour": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": 5, + "ac_ascending": 14, + "ac_bonus": null, + "category": "heavy", + "cost_gp": 40, + "id": "chainmail", + "item_type": "armour", + "name": "Chainmail", + "overrides_applied": [], + "weight_coins": 400 + } + } + }, + "level": 2, + "max_hp": 8, + "memorized_spells": [], + "name": "Fighter adventurer 4", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 12, + "con": 7, + "dex": 11, + "int": 8, + "str": 16, + "wis": 9 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 2000 + } + ], + "party": { + "members": [ + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0001", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Brakk", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "thief", + "conditions": [], + "current_hp": 3, + "custom_class": null, + "extra_languages": [], + "id": "character-0002", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Sable", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0003", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Wynn", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 13 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0004", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Elara", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [ + "sleep" + ], + "stat_modifiers": [], + "xp": 0 + } + ] + }, + "quests": {}, + "rng_streams": { + "combat": { + "inc": 51974326853383236054174564158459888819, + "state": 180795397024793254201627794445874276412 + }, + "effects": { + "inc": 283453162651363138174751306997233822321, + "state": 82950419690610286897458899398562272993 + }, + "encounter": { + "inc": 89959186405662357923881332541411655931, + "state": 245600835435001370040161073915762547766 + }, + "monster_action": { + "inc": 216485260068944084833976769572152741595, + "state": 316252631387065876105645382272260252652 + }, + "npc_party": { + "inc": 6905548725317423460208538633085511011, + "state": 167557780833365036580802211511327935853 + }, + "treasure": { + "inc": 55149374389624700722747444595030452821, + "state": 119070280199547008720396439384068395895 + } + }, + "ruleset": { + "aoe_friendly_fire": true, + "back_stab_needs_both_skills": true, + "deprivation_penalties": false, + "encumbrance": "basic", + "failed_trap_removal_springs": true, + "formation_width_limit": true, + "hd5_counts_as_magical": false, + "hp_reroll_at_first_level": false, + "individual_initiative": false, + "magic_item_death_save": true, + "thac0_arithmetic": false, + "variable_weapon_damage": true, + "weapon_reload": false, + "xp_award_timing": "on_return" + }, + "treasure_snapshot_cp": 0 + }, + "schema_version": 4 +} diff --git a/tests/saves/view_item_names_party_2.7.0.json b/tests/saves/view_item_names_party_2.7.0.json new file mode 100644 index 00000000..fd3c8940 --- /dev/null +++ b/tests/saves/view_item_names_party_2.7.0.json @@ -0,0 +1,384 @@ +{ + "engine_version": "2.7.0", + "kind": "party", + "payload": { + "characters": [ + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0001", + "inventory": { + "items": [ + { + "instance_type": "item", + "quantity": 2, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d8", + "missile_ranges": { + "long": { + "max_feet": 50, + "min_feet": 31 + }, + "medium": { + "max_feet": 30, + "min_feet": 11 + }, + "short": { + "max_feet": 10, + "min_feet": 5 + } + }, + "qualities": [ + "missile", + "splash" + ] + }, + "cost_gp": 25, + "id": "holy_water", + "item_type": "gear", + "lot_size": 1, + "name": "Holy water (vial)", + "overrides_applied": [], + "params": {} + } + }, + { + "instance_type": "item", + "quantity": 6, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d4", + "missile_ranges": null, + "qualities": [ + "melee" + ] + }, + "cost_gp": 1, + "id": "torch", + "item_type": "gear", + "lot_size": 6, + "name": "Torches (6)", + "overrides_applied": [], + "params": { + "brightness": "flame", + "burn_turns": 6, + "light_radius_feet": 30 + } + } + }, + { + "instance_type": "item", + "quantity": 20, + "template": { + "cost_gp": 5, + "id": "arrows", + "item_type": "ammunition", + "lot_size": 20, + "material": "standard", + "name": "Arrows (quiver of 20)", + "overrides_applied": [], + "weight_coins": 0 + } + }, + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 25, + "damage": "1d6", + "id": "short_bow", + "item_type": "weapon", + "material": "standard", + "missile_ranges": { + "long": { + "max_feet": 150, + "min_feet": 101 + }, + "medium": { + "max_feet": 100, + "min_feet": 51 + }, + "short": { + "max_feet": 50, + "min_feet": 5 + } + }, + "name": "Short bow", + "overrides_applied": [], + "qualities": [ + "missile", + "two_handed" + ], + "weight_coins": 30 + } + }, + { + "instance_type": "item", + "quantity": 2, + "template": { + "capacity_coins": null, + "combat": null, + "cost_gp": 0, + "id": "temple_idol", + "item_type": "gear", + "lot_size": 1, + "name": "Idol of the drowned saint", + "overrides_applied": [], + "params": {} + } + }, + { + "instance_type": "item", + "quantity": 2, + "template": { + "capacity_coins": null, + "combat": { + "damage": "1d8", + "missile_ranges": { + "long": { + "max_feet": 50, + "min_feet": 31 + }, + "medium": { + "max_feet": 30, + "min_feet": 11 + }, + "short": { + "max_feet": 10, + "min_feet": 5 + } + }, + "qualities": [ + "missile", + "splash" + ] + }, + "cost_gp": 2, + "id": "oil_flask", + "item_type": "gear", + "lot_size": 1, + "name": "Oil (1 flask)", + "overrides_applied": [], + "params": { + "fuels_lantern": true + } + } + }, + { + "base_item_id": null, + "charges_remaining": null, + "cursed_revealed": false, + "identified": false, + "instance_id": "magic-item-0001", + "instance_type": "magic_item", + "quantity": 1, + "sentience": null, + "state": {}, + "template_id": "potion_of_healing" + } + ], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [ + { + "instance_type": "item", + "quantity": 1, + "template": { + "cost_gp": 10, + "damage": "1d8", + "id": "sword", + "item_type": "weapon", + "material": "standard", + "missile_ranges": null, + "name": "Sword", + "overrides_applied": [], + "qualities": [ + "melee" + ], + "weight_coins": 60 + } + } + ], + "worn_armour": { + "instance_type": "item", + "quantity": 1, + "template": { + "ac": 5, + "ac_ascending": 14, + "ac_bonus": null, + "category": "heavy", + "cost_gp": 40, + "id": "chainmail", + "item_type": "armour", + "name": "Chainmail", + "overrides_applied": [], + "weight_coins": 400 + } + } + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Brakk", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "thief", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0002", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Sable", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "cleric", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0003", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Wynn", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 13 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 0 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 6, + "custom_class": null, + "extra_languages": [], + "id": "character-0004", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 1, + "max_hp": 6, + "memorized_spells": [], + "name": "Elara", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 11, + "con": 11, + "dex": 11, + "int": 11, + "str": 11, + "wis": 11 + }, + "spell_book": [ + "sleep" + ], + "stat_modifiers": [], + "xp": 0 + } + ] + }, + "schema_version": 4 +} diff --git a/tests/test_embedded_item_names.py b/tests/test_embedded_item_names.py new file mode 100644 index 00000000..4a559e17 --- /dev/null +++ b/tests/test_embedded_item_names.py @@ -0,0 +1,270 @@ +"""An embedded item template takes its display names from the session's catalog (issue #316, part 3). + +An `ItemInstance` embeds its whole template, and `MemberView.inventory`, the referee view, and a save dump it whole. +A save or a party document that osrlib 2.7.0 wrote embeds templates without `display_name` and +`display_name_plural`, so validation gives them the defaults from the price-list `name`: "Holy water (vial)" where a +new session has "vial of holy water". The session gives every embedded template whose id its catalog has the +catalog template's two names, when it starts, when a save loads, and when `AddMember` adds a member. Nothing else in +the template changes, because the rest is rules data that travels with the character. A template whose id the +catalog lacks keeps the names it has. + +`tests/test_view_features.py::test_a_save_written_by_2_7_0_loads_with_the_new_fields` is the guard from another +chunk: the player view of a loaded 2.7.0 save equals the view of the same state built fresh. +""" + +import json +from pathlib import Path + +import pytest +from pydantic import TypeAdapter + +from crawl_fixtures import build_party +from osrlib.core.character import Character, party_from_document +from osrlib.core.events import Visibility +from osrlib.core.items import GearTemplate, ItemInstance, ItemTemplate +from osrlib.crawl.adventure import Adventure, TownSpec +from osrlib.crawl.commands import AddMember, GrantItem +from osrlib.crawl.dungeon import DungeonSpec, LevelSpec +from osrlib.crawl.party import Party +from osrlib.crawl.session import GameSession +from osrlib.crawl.views import PlayerView, RefereeView +from osrlib.data import load_equipment +from osrlib.persistence import load_game, save_game +from test_view_item_names import CATALOG_NAMES, PARTY_2_7_0, SAVE_2_7_0, UNNAMED_IDOL, _adventure, _embedded_templates + +NPCS_2_7_0 = Path(__file__).parent / "saves" / "view_item_names_npcs_2.7.0.json" +"""A save that osrlib 2.7.0 wrote, kept as it wrote it, in which a basic NPC party of four has attacked the party. + +The NPCs carry chainmail, a dagger, a mace, standard rations, a shield, a sword, torches, and a waterskin, each +embedding a template with no display names. +""" + +WRITTEN_IDOL = ("idol of the drowned saint", "idols of the drowned saint") +"""The names `_adventure()`'s bundled idol has, which its author wrote.""" + +CARRIED_IN_SAVE = ("holy_water", "torch", "arrows", "short_bow", "chainmail", "sword", "temple_idol") +"""The stacks the fighter carries in the 2.7.0 save. The two flasks of oil lie in the pile.""" + +TEMPLATE = TypeAdapter(ItemTemplate) +NAME_FIELDS = ("display_name", "display_name_plural") + + +def _load(path: Path) -> GameSession: + return load_game(json.loads(path.read_text(encoding="utf-8"))) + + +def _party_from_2_7_0() -> Party: + return Party(members=party_from_document(json.loads(PARTY_2_7_0.read_text(encoding="utf-8")))) + + +def _empty_crypt() -> Adventure: + """An adventure that bundles nothing, so its catalog has no `temple_idol`.""" + level = LevelSpec(number=1, width=1, height=1, entrance=(0, 0)) + return Adventure( + name="An Empty Crypt", + town=TownSpec(name="Threshold"), + dungeons=(DungeonSpec(id="crypt", name="Crypt", levels=(level,)),), + ) + + +def _names(templates) -> dict[str, tuple[str, str]]: + """Each template's id with its two names, from dumped templates. A repeated id must have the same names.""" + names: dict[str, tuple[str, str]] = {} + for template in templates: + pair = (template["display_name"], template["display_name_plural"]) + assert names.setdefault(template["id"], pair) == pair, template["id"] + return names + + +def _player_templates(view: PlayerView) -> list[dict]: + return [template for member in view.party for template in _embedded_templates(member.inventory)] + + +def _referee_templates(view: RefereeView) -> list[dict]: + members = [*view.party.members, *view.npcs] + return [ + template for member in members for template in _embedded_templates(member.inventory.model_dump(mode="json")) + ] + + +def _without_names(templates: list[dict]) -> list[str]: + """The templates without their names, as sorted JSON, so the order a document walks them in doesn't matter. + + The names are the two fields and the entries of `overrides_applied` that name them, which record that the + compiler took a name from `tools/srd_compile/overrides/`. Those entries describe the names, so they travel with + them: a fresh session's torch has them, and a torch loaded from 2.7.0 must have the same view. + """ + stripped = [] + for template in templates: + kept = {key: value for key, value in template.items() if key not in NAME_FIELDS} + kept["overrides_applied"] = [entry for entry in template["overrides_applied"] if entry not in NAME_FIELDS] + stripped.append(kept) + return sorted(json.dumps(template, sort_keys=True) for template in stripped) + + +# ---------------------------------------------------------------------- a 2.7.0 save + + +def test_a_2_7_0_save_embeds_the_catalogs_names_in_every_carried_stack(): + """The inventory dump, the referee view, and the next save all carry the catalog's names. + + The save's adventure bundles the idol with no names, so the catalog's idol has the defaults, and the carried idol + takes those. + """ + game = _load(SAVE_2_7_0) + expected = {item_id: CATALOG_NAMES.get(item_id, UNNAMED_IDOL) for item_id in CARRIED_IN_SAVE} + + player = game.view(Visibility.PLAYER) + referee = game.view(Visibility.REFEREE) + assert isinstance(player, PlayerView) and isinstance(referee, RefereeView) + + assert _names(_player_templates(player)) == expected + assert _names(_referee_templates(referee)) == expected + assert _names(_embedded_templates(save_game(game))) == expected + + +def test_a_2_7_0_save_gives_npc_adventurers_the_catalogs_names(): + """An NPC's gear is in the referee view and the save, and it takes the catalog's names too.""" + game = _load(NPCS_2_7_0) + catalog = load_equipment() + + referee = game.view(Visibility.REFEREE) + assert isinstance(referee, RefereeView) + + npc_templates = [ + template for npc in referee.npcs for template in _embedded_templates(npc.inventory.model_dump(mode="json")) + ] + names = _names(npc_templates) + assert set(names) == {"chainmail", "dagger", "mace", "rations_standard", "shield", "sword", "torch", "waterskin"} + assert names == { + item_id: (catalog.get(item_id).display_name, catalog.get(item_id).display_name_plural) for item_id in names + } + assert names["torch"] == ("torch", "torches") + assert names["rations_standard"] == ("standard ration", "standard rations") + assert _names(_embedded_templates(save_game(game)["payload"]["npcs"])) == names + + +@pytest.mark.parametrize( + "path", + [pytest.param(SAVE_2_7_0, id="party"), pytest.param(NPCS_2_7_0, id="npcs")], +) +def test_loading_a_2_7_0_save_changes_only_the_two_names_of_an_embedded_template(path: Path): + """Every embedded template, read as this osrlib reads it, is the same before and after but for its names.""" + document = json.loads(path.read_text(encoding="utf-8")) + before = [TEMPLATE.validate_python(template).model_dump(mode="json") for template in _embedded_templates(document)] + + after = _embedded_templates(save_game(load_game(document))) + + assert len(after) == len(before) + assert _without_names(after) == _without_names(before) + assert _names(after) != _names(before) + + +def test_loading_a_2_7_0_save_draws_nothing_and_keeps_the_logs(): + """The names are no rule and no draw: the streams, the command log, and the event log come back as they were.""" + document = json.loads(SAVE_2_7_0.read_text(encoding="utf-8")) + + again = save_game(load_game(document))["payload"] + + for key in ("rng_streams", "command_log", "event_log", "clock_rounds", "allocator"): + assert again[key] == document["payload"][key], key + + +# ---------------------------------------------------------------------- a 2.7.0 party document + + +def test_a_2_7_0_party_document_takes_the_adventures_names_for_its_bundled_item(): + """A new session of an adventure whose idol has written names: the carried idol takes them.""" + game = GameSession.new(_party_from_2_7_0(), _adventure(), seed=5) + expected = {**CATALOG_NAMES, "temple_idol": WRITTEN_IDOL} + + player = game.view(Visibility.PLAYER) + assert isinstance(player, PlayerView) + + assert _names(_player_templates(player)) == expected + assert _names(_embedded_templates(save_game(game)["payload"]["party"])) == expected + + +def test_a_2_7_0_party_documents_bundled_item_keeps_its_names_without_the_adventure(): + """The same party in an adventure that bundles no idol: the idol keeps the defaults its template has.""" + game = GameSession.new(_party_from_2_7_0(), _empty_crypt(), seed=5) + + player = game.view(Visibility.PLAYER) + assert isinstance(player, PlayerView) + + assert _names(_player_templates(player)) == {**CATALOG_NAMES, "temple_idol": UNNAMED_IDOL} + + +def test_a_new_session_changes_only_the_names_of_a_template_the_catalog_has(): + """A torch of the fighter's own, with the catalog's id but its own rules data, keeps all but its names.""" + party = build_party() + old_torch = GearTemplate.model_validate( + { + "id": "torch", + "name": "Old torch", + "cost_gp": 3, + "params": {"burn_turns": 2, "light_radius_feet": 10}, + "display_name": "old torch", + "display_name_plural": "old torches", + } + ) + party.members[0].inventory.items.append(ItemInstance(template=old_torch, quantity=2)) + + game = GameSession.new(party, _empty_crypt(), seed=5) + + (stack,) = game.party.members[0].inventory.items + assert isinstance(stack, ItemInstance) + assert (stack.template.display_name, stack.template.display_name_plural) == ("torch", "torches") + assert _without_names([stack.template.model_dump(mode="json")]) == _without_names( + [old_torch.model_dump(mode="json")] + ) + catalog_torch = load_equipment().get("torch") + assert stack.template.overrides_applied == tuple( + entry for entry in catalog_torch.overrides_applied if entry in NAME_FIELDS + ) + assert stack.quantity == 2 + + +def test_a_member_added_from_a_2_7_0_document_takes_the_catalogs_names(): + """`AddMember` with the 2.7.0 fighter, given no id and none of the magic items a joining member can't carry. + + The member who joins has the catalog's names, and the command log keeps the character as it arrived. + """ + document = json.loads(PARTY_2_7_0.read_text(encoding="utf-8")) + fighter = next(member for member in document["payload"]["characters"] if member["id"] == "character-0001") + fighter = {**fighter, "id": None} + fighter["inventory"]["items"] = [ + entry for entry in fighter["inventory"]["items"] if entry["instance_type"] != "magic_item" + ] + game = GameSession.new(build_party(), _adventure(), seed=5) + + added = game.execute(AddMember(character=Character.model_validate(fighter))) + assert added.accepted, [rejection.code for rejection in added.rejections] + + joined = game.party.members[-1] + templates = _embedded_templates(joined.inventory.model_dump(mode="json")) + assert _names(templates) == {**CATALOG_NAMES, "temple_idol": WRITTEN_IDOL} + logged = _embedded_templates(game.command_log[-1].character.inventory.model_dump(mode="json")) + assert _names(logged)["holy_water"][0] == "Holy water (vial)" + + +# ---------------------------------------------------------------------- a save this osrlib writes + + +def test_a_save_written_now_loads_to_the_same_save(): + """A session of current documents, a bundled item and a torch of the fighter's own included, re-saves unchanged. + + This holds before the chunk's change too, and it must keep holding after it. + """ + party = build_party() + party.members[0].inventory.items.append( + ItemInstance( + template=GearTemplate.model_validate({"id": "torch", "name": "Old torch", "cost_gp": 3}), quantity=2 + ) + ) + game = GameSession.new(party, _adventure(), seed=5) + for item_id in ("holy_water", "chainmail", "arrows", "temple_idol", "potion_of_healing"): + assert game.execute(GrantItem(character_id="character-0001", item_id=item_id)).accepted + document = json.loads(json.dumps(save_game(game))) + + assert json.loads(json.dumps(save_game(load_game(document)))) == document diff --git a/tests/test_item_display_names.py b/tests/test_item_display_names.py new file mode 100644 index 00000000..e63e9103 --- /dev/null +++ b/tests/test_item_display_names.py @@ -0,0 +1,375 @@ +"""Every item template has a name for one unit in a sentence and a name for two or more (issue #316, part 3). + +A remote front end words a count, like "The party finds 2 vials of holy water", from the player view and the events +alone. The templates' `name` is the price list's label, like `"Holy water (vial)"` or `"Torches (6)"`, which names a +lot and has no plural, so a client can't build that sentence from it. `display_name` and `display_name_plural` are +the words a sentence needs, as `MonsterTemplate.display_name` and `display_name_plural` are for monsters, and +`PlayerView.item_names` carries them to the client. + +The unit is the one the session counts. `ItemInstance.quantity` counts individual items, not lots, so the OSE SRD's +"Torches (6)" is six units of `"torch"`, "Iron spikes (12)" twelve of `"iron spike"`, "Wine (2 pints)" two of +`"pint of wine"`, and "Rations (iron, 7 days)" seven of `"iron ration"`. The SRD's gear descriptions name the +containers: "Holy water: Water blessed by a holy person, stored in a special vial" and "Oil flask: A flask of oil +fuels a lantern", so a unit of holy water is a vial and a unit of oil a flask. +""" + +import pytest + +from osrlib.core.items import AmmunitionTemplate, ArmourTemplate, GearTemplate, MagicItemTemplate, WeaponTemplate +from osrlib.crawl.adventure import Adventure, TownSpec +from osrlib.crawl.dungeon import DungeonSpec, LevelSpec +from osrlib.data import load_equipment, load_magic_items + +MUNDANE = { + # Gear. A lot from the price list becomes one unit, and a substance becomes its container or measure. + "backpack": ("backpack", "backpacks"), + "crowbar": ("crowbar", "crowbars"), + "garlic": ("bulb of garlic", "bulbs of garlic"), + "grappling_hook": ("grappling hook", "grappling hooks"), + "hammer": ("small hammer", "small hammers"), + "holy_symbol": ("holy symbol", "holy symbols"), + "holy_water": ("vial of holy water", "vials of holy water"), + "iron_spikes": ("iron spike", "iron spikes"), + "lantern": ("lantern", "lanterns"), + "mirror": ("hand mirror", "hand mirrors"), + "oil_flask": ("flask of oil", "flasks of oil"), + "pole": ("10’ pole", "10’ poles"), + "rations_iron": ("iron ration", "iron rations"), + "rations_standard": ("standard ration", "standard rations"), + "rope": ("50’ coil of rope", "50’ coils of rope"), + "sack_large": ("large sack", "large sacks"), + "sack_small": ("small sack", "small sacks"), + "stakes_and_mallet": ("set of stakes and mallet", "sets of stakes and mallet"), + "thieves_tools": ("set of thieves’ tools", "sets of thieves’ tools"), + "tinder_box": ("tinder box", "tinder boxes"), + "torch": ("torch", "torches"), + "waterskin": ("waterskin", "waterskins"), + "wine": ("pint of wine", "pints of wine"), + "wolfsbane": ("bunch of wolfsbane", "bunches of wolfsbane"), + # Ammunition: one arrow, not the quiver of 20. + "arrows": ("arrow", "arrows"), + "crossbow_bolts": ("crossbow bolt", "crossbow bolts"), + "silver_tipped_arrow": ("silver tipped arrow", "silver tipped arrows"), + "sling_stones": ("sling stone", "sling stones"), + # Weapons: the printed name in lowercase, with the regular plural except for the staff. + "battle_axe": ("battle axe", "battle axes"), + "club": ("club", "clubs"), + "crossbow": ("crossbow", "crossbows"), + "dagger": ("dagger", "daggers"), + "hand_axe": ("hand axe", "hand axes"), + "javelin": ("javelin", "javelins"), + "lance": ("lance", "lances"), + "long_bow": ("long bow", "long bows"), + "mace": ("mace", "maces"), + "pole_arm": ("pole arm", "pole arms"), + "short_bow": ("short bow", "short bows"), + "short_sword": ("short sword", "short swords"), + "silver_dagger": ("silver dagger", "silver daggers"), + "sling": ("sling", "slings"), + "spear": ("spear", "spears"), + "staff": ("staff", "staves"), + "sword": ("sword", "swords"), + "two_handed_sword": ("two-handed sword", "two-handed swords"), + "war_hammer": ("war hammer", "war hammers"), + # Armour: body armour is a suit, and the SRD's "Leather" is leather armour. + "chainmail": ("suit of chainmail", "suits of chainmail"), + "leather": ("suit of leather armour", "suits of leather armour"), + "plate_mail": ("suit of plate mail", "suits of plate mail"), + "shield": ("shield", "shields"), +} +"""The display names of every compiled equipment template, keyed by catalog id.""" + +MAGIC = { + "potion_of_healing": ("potion of healing", "potions of healing"), + # An abbreviation keeps its capitals. + "potion_of_esp": ("potion of ESP", "potions of ESP"), + "ring_of_protection": ("ring of protection", "rings of protection"), + "wand_of_cold": ("wand of cold", "wands of cold"), + # The ending goes on the word that names the item, and "staff" has the plural the mundane staff has. + "staff_of_healing": ("staff of healing", "staves of healing"), + "bag_of_holding": ("bag of holding", "bags of holding"), + "boots_of_speed": ("pair of boots of speed", "pairs of boots of speed"), + "gauntlets_of_ogre_power": ("pair of gauntlets of ogre power", "pairs of gauntlets of ogre power"), + "sword_plus_1": ("sword +1", "swords +1"), + "sword_plus_1_plus_3_vs_undead": ("sword +1, +3 vs undead", "swords +1, +3 vs undead"), + "sword_minus_1_cursed": ("sword -1, cursed", "swords -1, cursed"), + "shield_plus_1": ("shield +1", "shields +1"), + "armour_plus_1": ("suit of armour +1", "suits of armour +1"), + "cursed_armour_ac_9": ("suit of cursed armour, AC 9 [10]", "suits of cursed armour, AC 9 [10]"), + # Enchanted ammunition names one unit, which MagicItemInstance.quantity counts, not the generated count. + "arrows_plus_1": ("arrow +1", "arrows +1"), + "crossbow_bolts_plus_2": ("crossbow bolt +2", "crossbow bolts +2"), + # A spell scroll keeps how many spells it holds, which its printed name gives in a parenthesis. + "spell_scroll_1": ("spell scroll with 1 spell", "spell scrolls with 1 spell"), + "spell_scroll_3": ("spell scroll with 3 spells", "spell scrolls with 3 spells"), + # A treasure map's Roman numeral keeps its capitals. + "treasure_map_ii": ("treasure map II", "treasure maps II"), +} +"""The display names of a sample of compiled magic item templates, keyed by catalog id.""" + + +def _equipment() -> dict: + catalog = load_equipment() + return { + template.id: template for template in (*catalog.weapons, *catalog.armour, *catalog.gear, *catalog.ammunition) + } + + +def test_the_table_covers_every_compiled_equipment_template(): + """A template the compiler adds needs its names in `MUNDANE`, so this table stays the whole catalog.""" + assert set(_equipment()) == set(MUNDANE) + + +@pytest.mark.parametrize(("item_id", "names"), sorted(MUNDANE.items())) +def test_each_compiled_equipment_template_has_its_display_names(item_id: str, names: tuple[str, str]): + template = _equipment()[item_id] + + assert (template.display_name, template.display_name_plural) == names + + +@pytest.mark.parametrize(("item_id", "names"), sorted(MAGIC.items())) +def test_a_compiled_magic_item_template_has_its_display_names(item_id: str, names: tuple[str, str]): + template = load_magic_items().get(item_id) + + assert (template.display_name, template.display_name_plural) == names + + +def test_every_compiled_magic_item_has_display_names_a_sentence_can_use(): + """Each one is filled, starts in lowercase, drops the printed parenthesis, and has a distinct plural.""" + for template in load_magic_items().items: + singular, plural = template.display_name, template.display_name_plural + assert singular and plural, template.id + assert not singular[0].isupper(), (template.id, singular) + assert "(" not in singular and "(" not in plural, (template.id, singular) + assert singular != plural, (template.id, singular) + + +BLADE = { + "id": "blade", + "name": "Drowned blade", + "cost_gp": 0, + "weight_coins": 60, + "damage": "1d8", + "qualities": ("melee",), +} +"""The fields a weapon template needs besides its names.""" + + +@pytest.mark.parametrize( + ("template", "names"), + [ + # A template written without the fields gets its name, and the regular ending on the word that names the + # item: the last word before " of ", " with ", " vs ", a comma, a bonus, a closing Roman numeral, or an + # opening parenthesis, or the last word when the name has none. + pytest.param( + GearTemplate.model_validate({"id": "crypt_key", "name": "Crypt key", "cost_gp": 0}), + ("Crypt key", "Crypt keys"), + id="gear", + ), + pytest.param( + GearTemplate.model_validate({"id": "compass", "name": "Brass compass", "cost_gp": 0}), + ("Brass compass", "Brass compasses"), + id="gear_es", + ), + pytest.param( + AmmunitionTemplate.model_validate({"id": "dart", "name": "Barbed dart", "cost_gp": 0}), + ("Barbed dart", "Barbed darts"), + id="ammunition", + ), + pytest.param( + WeaponTemplate.model_validate( + { + "id": "blade", + "name": "Drowned blade", + "cost_gp": 0, + "weight_coins": 60, + "damage": "1d8", + "qualities": ("melee",), + } + ), + ("Drowned blade", "Drowned blades"), + id="weapon", + ), + pytest.param( + ArmourTemplate.model_validate( + { + "id": "scale", + "name": "Saint's scale", + "cost_gp": 0, + "weight_coins": 300, + "ac": 6, + "ac_ascending": 13, + "category": "light", + } + ), + ("Saint's scale", "Saint's scales"), + id="armour", + ), + pytest.param( + MagicItemTemplate.model_validate({"id": "orb", "name": "Gleaming orb", "category": "misc"}), + ("Gleaming orb", "Gleaming orbs"), + id="magic_item", + ), + # A consonant before the y: "ies". + pytest.param( + GearTemplate.model_validate({"id": "reliquary", "name": "Reliquary", "cost_gp": 0}), + ("Reliquary", "Reliquaries"), + id="gear_ies", + ), + # A name written for one keeps a plural written for two or more. This holds before the chunk too. + pytest.param( + GearTemplate.model_validate( + { + "id": "lamp_oil", + "name": "Lamp oil", + "cost_gp": 0, + "display_name": "jar of lamp oil", + "display_name_plural": "jars of lamp oil", + } + ), + ("jar of lamp oil", "jars of lamp oil"), + id="written", + ), + # A plural left out of a written name follows the written name. + pytest.param( + GearTemplate.model_validate( + {"id": "idol", "name": "Idol of the drowned saint", "cost_gp": 0, "display_name": "jade idol"} + ), + ("jade idol", "jade idols"), + id="written_singular", + ), + pytest.param( + GearTemplate.model_validate({"id": "idol", "name": "Idol of the drowned saint", "cost_gp": 0}), + ("Idol of the drowned saint", "Idols of the drowned saint"), + id="of", + ), + # "staff" becomes "staves", as the compiler makes it, and keeps its capital. + pytest.param( + WeaponTemplate.model_validate({**BLADE, "id": "magi_staff", "name": "Staff of the Magi"}), + ("Staff of the Magi", "Staves of the Magi"), + id="staff_of", + ), + pytest.param( + WeaponTemplate.model_validate({**BLADE, "id": "oaken_staff", "name": "Oaken staff"}), + ("Oaken staff", "Oaken staves"), + id="staff_last", + ), + pytest.param( + GearTemplate.model_validate({"id": "hooded_lantern", "name": "Lantern (hooded)", "cost_gp": 0}), + ("Lantern (hooded)", "Lanterns (hooded)"), + id="parenthesis", + ), + pytest.param( + GearTemplate.model_validate({"id": "blue_lamp", "name": "Lamp with a blue flame", "cost_gp": 0}), + ("Lamp with a blue flame", "Lamps with a blue flame"), + id="with", + ), + pytest.param( + GearTemplate.model_validate({"id": "silver_ring", "name": "Ring, silver", "cost_gp": 0}), + ("Ring, silver", "Rings, silver"), + id="comma", + ), + pytest.param( + GearTemplate.model_validate({"id": "ward", "name": "Charm vs evil", "cost_gp": 0}), + ("Charm vs evil", "Charms vs evil"), + id="vs", + ), + pytest.param( + GearTemplate.model_validate({"id": "map_iv", "name": "Map fragment IV", "cost_gp": 0}), + ("Map fragment IV", "Map fragments IV"), + id="numeral", + ), + pytest.param( + MagicItemTemplate.model_validate({"id": "seeing_orb", "name": "Orb of Seeing", "category": "misc"}), + ("Orb of Seeing", "Orbs of Seeing"), + id="magic_item_of", + ), + # An author often writes a name in title case, so "Of" and "With" mark the head noun as "of" and "with" do. + pytest.param( + MagicItemTemplate.model_validate({"id": "power_staff", "name": "Staff Of Power", "category": "staff"}), + ("Staff Of Power", "Staves Of Power"), + id="title_case_of", + ), + pytest.param( + GearTemplate.model_validate({"id": "gem_lamp", "name": "Lamp With A Gem", "cost_gp": 0}), + ("Lamp With A Gem", "Lamps With A Gem"), + id="title_case_with", + ), + # A doubled space in a written name doesn't put a space before the ending. + pytest.param( + GearTemplate.model_validate({"id": "rock_box", "name": "Box of rocks", "cost_gp": 0}), + ("Box of rocks", "Boxes of rocks"), + id="doubled_space", + ), + ], +) +def test_a_template_you_write_without_the_fields_gets_them(template, names: tuple[str, str]): + assert (template.display_name, template.display_name_plural) == names + + +def test_a_bundled_items_display_names_survive_the_adventure_document(): + """An adventure document round-trips the names its author wrote, and one written without them still loads.""" + idol = GearTemplate.model_validate( + { + "id": "temple_idol", + "name": "Idol of the drowned saint", + "cost_gp": 0, + "display_name": "idol of the drowned saint", + "display_name_plural": "idols of the drowned saint", + } + ) + key = GearTemplate.model_validate({"id": "crypt_key", "name": "Crypt key", "cost_gp": 0}) + level = LevelSpec(number=1, width=1, height=1, entrance=(0, 0)) + adventure = Adventure( + name="A", + town=TownSpec(name="Threshold"), + dungeons=(DungeonSpec(id="crypt", name="Crypt", levels=(level,)),), + items=(idol, key), + ) + + document = adventure.model_dump(mode="json") + for item in document["items"]: + if item["id"] == "crypt_key": + del item["display_name"], item["display_name_plural"] + loaded = Adventure.model_validate(document) + + names = {item.id: (item.display_name, item.display_name_plural) for item in loaded.items} + assert names == { + "temple_idol": ("idol of the drowned saint", "idols of the drowned saint"), + "crypt_key": ("Crypt key", "Crypt keys"), + } + + +def test_a_written_name_that_is_already_plural_keeps_its_parenthesis_last(): + """An author's `"Torches (6)"` takes the ending on `"Torches"`, before the parenthesis, never after it. + + The rule can't tell that `"Torches"` is already plural, so it adds the ending a word in "s" takes. The template + docstrings tell an author to set the plural of such a name. What this pins is where the ending goes: the plural + isn't `"Torches (6)s"`, and the lot stays at the end. + """ + template = GearTemplate.model_validate({"id": "torch_bundle", "name": "Torches (6)", "cost_gp": 1}) + + assert template.display_name == "Torches (6)" + assert template.display_name_plural.endswith(" (6)") + assert not template.display_name_plural.endswith(")s") + + +def test_every_compiled_plural_is_the_default_plural_of_its_display_name(): + """The compiler and a template written without a plural follow one rule. + + Each compiled template, rebuilt with its `display_name` and without its plural, gets its compiled plural back. + No compiled template differs, because every plural an override in `tools/srd_compile/overrides/` sets is the + one the rule gives. + """ + catalog = load_equipment() + templates = (*catalog.weapons, *catalog.armour, *catalog.gear, *catalog.ammunition, *load_magic_items().items) + differs = {} + for template in templates: + document = template.model_dump() + del document["display_name_plural"] + rebuilt = type(template).model_validate(document) + if rebuilt.display_name_plural != template.display_name_plural: + differs[template.id] = (rebuilt.display_name_plural, template.display_name_plural) + + assert len(templates) == 51 + 164 + assert differs == {} diff --git a/tests/test_view_item_names.py b/tests/test_view_item_names.py new file mode 100644 index 00000000..97792357 --- /dev/null +++ b/tests/test_view_item_names.py @@ -0,0 +1,767 @@ +"""The player view names every item whose id it shows (issue #316, part 3). + +A remote front end builds its screens from `PlayerView` and the player-visible events alone. The view shows items by +id: a catalog id like `"holy_water"` for a mundane stack, an instance id like `"magic-item-0003"` for a magic item, +and an instance id like `"valuable-0007"` for a gem or piece of jewellery. A pile shows strings like +`"holy_water×2"`. `PlayerView.item_names` and `item_names_plural` carry a singular and a plural for every one of +those ids, read from the template a stack embeds or the session's catalog, so an item the adventure bundles is named. +`PileView.contents` gives each pile entry's id and count beside the strings. + +A masked item keeps its mask. Until the party identifies a magic item, its name is the masked name the inventory +shows, without the article, so a cursed item and the item it passes for read the same. The OSE SRD's Armour and +Shields page says "All types of tests indicate that a cursed shield or suit of armour is enchanted with a +1 bonus", +which is why `tests/test_unrevealed_curse_view.py` pins a cursed shield to the view of a shield +1. +""" + +import json +from pathlib import Path + +import pytest + +from crawl_fixtures import build_party +from osrlib.core.character import party_from_document +from osrlib.core.events import Visibility +from osrlib.core.items import GearTemplate, MagicItemInstance, ValuableInstance +from osrlib.crawl.adventure import Adventure, TownSpec +from osrlib.crawl.commands import DropItems, EnterDungeon, GrantItem, IdentifyItem, TakeTreasure, UseItem +from osrlib.crawl.dungeon import AreaSpec, DungeonSpec, FeatureSpec, LevelSpec, ValuableSpec +from osrlib.crawl.events import ItemAcquiredEvent, ItemIdentifiedEvent, ItemsDroppedEvent +from osrlib.crawl.party import Party +from osrlib.crawl.session import GameSession +from osrlib.crawl.views import PileItemView, PlayerView +from osrlib.data import load_equipment, load_magic_items +from osrlib.persistence import load_game +from test_loot_and_traps import breath_kill + +FIGHTER = "character-0001" + +TEMPLE_IDOL = GearTemplate.model_validate( + { + "id": "temple_idol", + "name": "Idol of the drowned saint", + "cost_gp": 0, + "display_name": "idol of the drowned saint", + "display_name_plural": "idols of the drowned saint", + } +) +"""A bundled item with names its author wrote. `load_equipment()` has no `temple_idol`.""" + +SEAL_RING = ValuableSpec(kind="jewellery", name="The abbot's seal ring", value_gp=900) +PLAIN_GEM = ValuableSpec(kind="gem", value_gp=50) + + +def _adventure() -> Adventure: + """One cell, the entrance, in an area whose cache holds gear, a bundled item, a potion, and two valuables.""" + vault = FeatureSpec( + id="reliquary", + kind="treasure_cache", + description="A lead-lined reliquary.", + cell=(0, 0), + item_ids=("holy_water", "holy_water", "temple_idol"), + magic_item_ids=("potion_of_healing",), + valuables=(SEAL_RING, PLAIN_GEM), + ) + level = LevelSpec( + number=1, + width=1, + height=1, + entrance=(0, 0), + areas=(AreaSpec(id="vault", name="Vault", cells=((0, 0),), features=(vault,)),), + ) + return Adventure( + name="The Drowned Saint", + town=TownSpec(name="Threshold", travel_turns={"shrine": 1}), + dungeons=(DungeonSpec(id="shrine", name="The Shrine", levels=(level,)),), + items=(TEMPLE_IDOL,), + ) + + +def _player_view(game: GameSession) -> PlayerView: + view = game.view(Visibility.PLAYER) + assert isinstance(view, PlayerView) + return view + + +def _looted() -> tuple[GameSession, list[ItemAcquiredEvent]]: + """The stock party enters the shrine and empties the reliquary. Returns the session and the acquisitions.""" + game = GameSession.new(build_party(), _adventure(), seed=5) + assert game.execute(EnterDungeon(dungeon_id="shrine")).accepted + (feature,) = _player_view(game).explored[0].features + taken = game.execute(TakeTreasure(feature_id=feature.id)) + assert taken.accepted, [rejection.code for rejection in taken.rejections] + acquired = [event for event in taken.events if isinstance(event, ItemAcquiredEvent)] + assert acquired, "precondition: the party took the reliquary's contents" + return game, acquired + + +def _ids_of(acquired: list[ItemAcquiredEvent]) -> tuple[str, str, str]: + """The potion's and the two valuables' instance ids, in the order potion, seal ring, gem.""" + ids = [item_id for event in acquired for item_id in event.item_ids] + potion = next(item_id for item_id in ids if item_id.startswith("magic-item-")) + valuables = [item_id for item_id in ids if item_id.startswith("valuable-")] + assert len(valuables) == 2 + seal_ring, gem = sorted(valuables) + return potion, seal_ring, gem + + +def _holders(game: GameSession, item_id: str) -> list[str]: + """Every member who carries `item_id`, once per unit, as a catalog id or an instance id.""" + held = [] + for member in game.party.members: + for instance in member.inventory.all_instances(): + if isinstance(instance, MagicItemInstance): + if instance.instance_id == item_id: + held.append(member.id) + elif instance.template.id == item_id: + held.extend([member.id] * instance.quantity) + held.extend(member.id for valuable in member.inventory.valuables if valuable.instance_id == item_id) + return held + + +def _drop_everything(game: GameSession, order: list[str]) -> list[ItemsDroppedEvent]: + """Each holder drops each unit of the ids in `order`, in that order, onto the party's cell.""" + dropped = [] + for item_id in order: + for member_id in _holders(game, item_id): + result = game.execute(DropItems(character_id=member_id, item_ids=(item_id,))) + assert result.accepted, [rejection.code for rejection in result.rejections] + dropped += [event for event in result.events if isinstance(event, ItemsDroppedEvent)] + return dropped + + +def _shown_ids(view: PlayerView) -> set[str]: + """Every item id the view shows, read from the inventories and from the piles' contents.""" + shown: set[str] = set() + for member in view.party: + inventory = member.inventory + entries = [*inventory["items"], *inventory["wielded"], *inventory["rings"]] + entries += [entry for entry in (inventory["worn_armour"], inventory["shield"]) if entry is not None] + for entry in entries: + if entry["instance_type"] == "magic_item": + shown.add(entry["instance_id"]) + if entry["identified"]: + shown.add(entry["template_id"]) + else: + shown.add(entry["template"]["id"]) + shown.update(valuable["instance_id"] for valuable in inventory["valuables"]) + for pile in view.piles.values(): + shown.update(entry.item_id for entry in pile.contents) + return shown + + +# ---------------------------------------------------------------------- what the party carries + + +def test_every_item_a_member_carries_is_named_singular_and_plural(): + """The reliquary's contents, spread across the party's packs. + + Holy water is named from the template the stack embeds, the bundled idol with the names its author wrote, the + unidentified potion by its masked name, and each valuable by its kind. The seal ring's own name stays in the + inventory's `valuables`. + """ + game, acquired = _looted() + potion, seal_ring, gem = _ids_of(acquired) + view = _player_view(game) + + assert view.item_names == { + "holy_water": "vial of holy water", + "temple_idol": "idol of the drowned saint", + potion: "potion", + seal_ring: "piece of jewellery", + gem: "gem", + } + assert view.item_names_plural == { + "holy_water": "vials of holy water", + "temple_idol": "idols of the drowned saint", + potion: "potions", + seal_ring: "pieces of jewellery", + gem: "gems", + } + + +def test_every_id_an_acquisition_names_is_a_key_in_the_view_after_it(): + """`ItemAcquiredEvent.item_ids` repeats a catalog id once per unit, and each id is named after the command.""" + game, acquired = _looted() + view = _player_view(game) + + for event in acquired: + for item_id in event.item_ids: + assert item_id in view.item_names and item_id in view.item_names_plural, item_id + assert sum(event.item_ids.count("holy_water") for event in acquired) == 2 + + +def test_the_view_names_exactly_the_ids_it_shows(): + """Every key is an id the inventories or the piles' contents show, and every such id is a key. + + The state holds an identified magic item in each place: a ring of protection the fighter carries, which shows + its template id, and the reliquary's potion, identified and then dropped, which a pile shows by its instance id + alone. Without the identified potion in the pile, a view that keyed a pile item's template id would pass. + """ + game, acquired = _looted() + potion, _, _ = _ids_of(acquired) + ring = _granted(game, "ring_of_protection") + for instance_id in (ring, potion): + holder = _holders(game, instance_id)[0] + identified = game.execute(IdentifyItem(character_id=holder, item_id=instance_id)) + assert identified.accepted, [rejection.code for rejection in identified.rejections] + _drop_everything(game, ["holy_water", potion]) + view = _player_view(game) + + assert "ring_of_protection" in _shown_ids(view) + assert potion in _shown_ids(view) and "potion_of_healing" not in _shown_ids(view) + assert set(view.item_names) == _shown_ids(view) + assert set(view.item_names_plural) == set(view.item_names) + + +def test_an_identified_item_in_a_pile_is_named_by_its_instance_id_alone(): + """A wand of cold, identified and then dropped in the dungeon. + + The pile shows it by its instance id and its true name, never its template id, so `wand_of_cold` is no key. + """ + game = _town() + instance_id = _granted(game, "wand_of_cold") + assert game.execute(IdentifyItem(character_id=FIGHTER, item_id=instance_id)).accepted + assert game.execute(EnterDungeon(dungeon_id="shrine")).accepted + dropped = game.execute(DropItems(character_id=FIGHTER, item_ids=(instance_id,))) + assert dropped.accepted, [rejection.code for rejection in dropped.rejections] + + view = _player_view(game) + + (pile,) = view.piles.values() + assert pile.contents == (PileItemView(item_id=instance_id, quantity=1),) + assert view.item_names == {instance_id: "wand of cold"} + assert view.item_names_plural == {instance_id: "wands of cold"} + + +def test_a_party_that_carries_nothing_has_no_item_names(): + """The stock party starts with empty packs. This holds before the chunk too.""" + game = GameSession.new(build_party(), _adventure(), seed=5) + + view = _player_view(game) + + assert view.item_names == {} + assert view.item_names_plural == {} + + +# ---------------------------------------------------------------------- what lies in a pile + + +def test_a_piles_contents_give_each_entrys_id_and_count_beside_the_strings(): + """The whole haul dropped on the party's cell. The strings stay as they were, and `contents` follows their order. + + The pile lists mundane stacks, then magic items, then valuables. The two vials merge into one stack of 2 whoever + dropped them, and the valuables keep the order they were dropped in. + """ + game, acquired = _looted() + potion, seal_ring, gem = _ids_of(acquired) + dropped = _drop_everything(game, ["holy_water", "temple_idol", potion, seal_ring, gem]) + view = _player_view(game) + + (pile,) = view.piles.values() + assert pile.items == ("holy_water×2", "temple_idol×1", "a potion", "The abbot's seal ring", "gem") + assert pile.contents == ( + PileItemView(item_id="holy_water", quantity=2), + PileItemView(item_id="temple_idol", quantity=1), + PileItemView(item_id=potion, quantity=1), + PileItemView(item_id=seal_ring, quantity=1), + PileItemView(item_id=gem, quantity=1), + ) + for event in dropped: + for item_id in event.item_ids: + assert item_id in view.item_names, item_id + + +def test_a_bundled_item_in_a_pile_is_named_from_the_sessions_catalog(): + """Nobody carries the idol once it's dropped, so its name comes from `effective_equipment`, not a pack.""" + game, acquired = _looted() + potion, seal_ring, gem = _ids_of(acquired) + _drop_everything(game, ["holy_water", "temple_idol", potion, seal_ring, gem]) + + view = _player_view(game) + + assert all(member.inventory["items"] == [] for member in view.party) + assert view.item_names == { + "holy_water": "vial of holy water", + "temple_idol": "idol of the drowned saint", + potion: "potion", + seal_ring: "piece of jewellery", + gem: "gem", + } + assert view.item_names_plural["temple_idol"] == "idols of the drowned saint" + + +# ---------------------------------------------------------------------- masked and identified magic items + + +def _granted(game: GameSession, item_id: str, member_id: str = FIGHTER) -> str: + result = game.execute(GrantItem(character_id=member_id, item_id=item_id)) + assert result.accepted, [rejection.code for rejection in result.rejections] + (instance_id,) = next(event.item_ids for event in result.events if isinstance(event, ItemAcquiredEvent)) + return instance_id + + +def _town() -> GameSession: + return GameSession.new(build_party(), _adventure(), seed=5) + + +def _entry(view: PlayerView, instance_id: str, member_id: str = FIGHTER) -> dict: + (member,) = (member for member in view.party if member.id == member_id) + return next(entry for entry in member.inventory["items"] if entry.get("instance_id") == instance_id) + + +@pytest.mark.parametrize( + ("template_id", "names"), + [ + pytest.param("potion_of_healing", ("potion", "potions"), id="potion"), + pytest.param("spell_scroll_1", ("scroll", "scrolls"), id="scroll"), + pytest.param("ring_of_protection", ("ring", "rings"), id="ring"), + pytest.param("wand_of_cold", ("wand", "wands"), id="wand"), + pytest.param("staff_of_healing", ("staff", "staves"), id="staff"), + pytest.param("rod_of_cancellation", ("rod", "rods"), id="rod"), + pytest.param("bag_of_holding", ("curious device", "curious devices"), id="misc"), + ], +) +def test_an_unidentified_item_is_named_by_its_category_mask(template_id: str, names: tuple[str, str]): + """The mask is the inventory's `display` without its article, and the template id stays out of the view.""" + game = _town() + instance_id = _granted(game, template_id) + + view = _player_view(game) + + assert (view.item_names[instance_id], view.item_names_plural[instance_id]) == names + assert _entry(view, instance_id)["display"] == f"a {names[0]}" + assert template_id not in view.model_dump_json() + + +def test_an_unidentified_items_true_name_never_reaches_the_view(): + """Neither the potion's catalog id nor its true name, in either case, appears anywhere in the view.""" + game = _town() + _granted(game, "potion_of_healing") + + blob = _player_view(game).model_dump_json() + + for hidden in ("potion_of_healing", "Potion of Healing", "potion of healing", "potions of healing"): + assert hidden not in blob + assert '"potion"' in blob + + +@pytest.mark.parametrize( + ("cursed", "lookalike", "base", "names"), + [ + pytest.param( + "cursed_shield_minus_2", + "shield_plus_1", + None, + ("shield with a faint aura", "shields with a faint aura"), + id="shield_minus_2", + ), + pytest.param( + "cursed_shield_ac_9", + "shield_plus_1", + None, + ("shield with a faint aura", "shields with a faint aura"), + id="shield_ac_9", + ), + pytest.param( + "cursed_armour_minus_1", + "armour_plus_1", + "chainmail", + ("suit of chainmail with a faint aura", "suits of chainmail with a faint aura"), + id="armour_minus_1", + ), + pytest.param( + "cursed_armour_ac_9", + "armour_plus_1", + "plate_mail", + ("suit of plate mail with a faint aura", "suits of plate mail with a faint aura"), + id="armour_ac_9", + ), + ], +) +def test_a_cursed_item_and_its_lookalike_have_the_same_names(cursed, lookalike, base, names): + """Two sessions that differ only in which of the pair the fighter got show the same names for it.""" + views = [] + for template_id in (cursed, lookalike): + game = _town() + instance_id = _granted(game, template_id) + if base is not None: + instance = game.member(FIGHTER).inventory.magic_item(instance_id) + assert instance is not None + instance.base_item_id = base + views.append((instance_id, _player_view(game))) + + (cursed_id, cursed_view), (lookalike_id, lookalike_view) = views + assert cursed_id == lookalike_id + assert cursed_view.item_names == lookalike_view.item_names == {cursed_id: names[0]} + assert cursed_view.item_names_plural == lookalike_view.item_names_plural == {cursed_id: names[1]} + assert cursed not in cursed_view.model_dump_json() + + +@pytest.mark.parametrize( + ("template_id", "base", "display", "names"), + [ + # The base's display_name with an article: "an" before a vowel. Today it reads "a arrows (quiver of 20) ...". + pytest.param( + "arrows_plus_1", + "arrows", + "an arrow with a faint aura", + ("arrow with a faint aura", "arrows with a faint aura"), + id="arrows", + ), + pytest.param( + "crossbow_bolts_plus_2", + "crossbow_bolts", + "a crossbow bolt with a faint aura", + ("crossbow bolt with a faint aura", "crossbow bolts with a faint aura"), + id="crossbow_bolts", + ), + # Body armour is a suit. Today it reads "a chainmail with a faint aura". + pytest.param( + "armour_plus_1", + "chainmail", + "a suit of chainmail with a faint aura", + ("suit of chainmail with a faint aura", "suits of chainmail with a faint aura"), + id="chainmail", + ), + # A suit with no mundane item recorded. Today it reads "a arm with a faint aura". + pytest.param( + "armour_plus_1", + None, + "a suit of armour with a faint aura", + ("suit of armour with a faint aura", "suits of armour with a faint aura"), + id="no_base", + ), + # The names a single word gives are unchanged in `display`, and these two already hold. + pytest.param("shield_plus_1", "shield", "a shield with a faint aura", None, id="shield"), + pytest.param("dagger_plus_1", "dagger", "a dagger with a faint aura", None, id="dagger"), + ], +) +def test_an_enchanted_arm_is_named_after_one_unit_of_its_base(template_id, base, display, names): + """The mask names the mundane item underneath by its display_name, so a stack of arrows reads in units.""" + game = _town() + quantity = 13 if base in ("arrows", "crossbow_bolts") else 1 + instance = MagicItemInstance( + instance_id="magic-item-9001", template_id=template_id, base_item_id=base, quantity=quantity + ) + game.member(FIGHTER).inventory.items.append(instance) + + view = _player_view(game) + + assert _entry(view, "magic-item-9001")["display"] == display + if names is not None: + assert (view.item_names["magic-item-9001"], view.item_names_plural["magic-item-9001"]) == names + + +def test_an_identified_item_is_named_by_its_template_under_both_ids(): + """Once identified, the inventory shows the template id, and it and the instance id have the true names.""" + game = _town() + instance_id = _granted(game, "potion_of_healing") + identified = game.execute(IdentifyItem(character_id=FIGHTER, item_id=instance_id)) + assert identified.accepted, [rejection.code for rejection in identified.rejections] + + view = _player_view(game) + + assert _entry(view, instance_id)["template_id"] == "potion_of_healing" + assert view.item_names == {instance_id: "potion of healing", "potion_of_healing": "potion of healing"} + assert view.item_names_plural == {instance_id: "potions of healing", "potion_of_healing": "potions of healing"} + + +def test_the_identification_event_names_the_item(): + """`IdentifyItem` leaves the potion in the pack, and the event and the view give the same names.""" + game = _town() + instance_id = _granted(game, "potion_of_healing") + + result = game.execute(IdentifyItem(character_id=FIGHTER, item_id=instance_id)) + + (event,) = (event for event in result.events if isinstance(event, ItemIdentifiedEvent)) + assert (event.display_name, event.display_name_plural) == ("potion of healing", "potions of healing") + assert _player_view(game).item_names[instance_id] == event.display_name + + +def test_a_potion_identified_by_drinking_it_is_named_only_by_its_event(): + """Drinking an unidentified potion identifies it and uses it up in one command. + + The view before showed it masked, and the view after doesn't show it, so neither names `potion_of_healing`. The + identification event does. + """ + game = _town() + instance_id = _granted(game, "potion_of_healing") + assert game.execute(EnterDungeon(dungeon_id="shrine")).accepted + before = _player_view(game) + + result = game.execute(UseItem(character_id=FIGHTER, item_id=instance_id)) + assert result.accepted, [rejection.code for rejection in result.rejections] + + after = _player_view(game) + (event,) = (event for event in result.events if isinstance(event, ItemIdentifiedEvent)) + assert event.template_id == "potion_of_healing" + assert (event.display_name, event.display_name_plural) == ("potion of healing", "potions of healing") + assert before.item_names == {instance_id: "potion"} + assert "potion_of_healing" not in before.item_names and "potion_of_healing" not in after.item_names + assert instance_id not in after.item_names + + +# ---------------------------------------------------------------------- valuables + + +def test_a_valuable_is_named_by_its_kind_whatever_its_own_name(): + """A gem the treasure tables roll is named `"Gem"`, and a piece of jewellery can have any name an author gives it. + + Both are named by their kind, and the inventory keeps each one's own name and value, which the players see from + the moment they take it. + """ + game = _town() + valuables = game.member(FIGHTER).inventory.valuables + valuables.append(ValuableInstance(instance_id="valuable-9001", kind="gem", name="Gem", value_gp=50)) + valuables.append(ValuableInstance(instance_id="valuable-9002", kind="jewellery", name="Jewellery", value_gp=600)) + valuables.append( + ValuableInstance(instance_id="valuable-9003", kind="jewellery", name="The abbot's seal ring", value_gp=900) + ) + + view = _player_view(game) + + assert view.item_names == { + "valuable-9001": "gem", + "valuable-9002": "piece of jewellery", + "valuable-9003": "piece of jewellery", + } + assert view.item_names_plural == { + "valuable-9001": "gems", + "valuable-9002": "pieces of jewellery", + "valuable-9003": "pieces of jewellery", + } + (member,) = (member for member in view.party if member.id == FIGHTER) + assert [(entry["name"], entry["value_gp"]) for entry in member.inventory["valuables"]] == [ + ("Gem", 50), + ("Jewellery", 600), + ("The abbot's seal ring", 900), + ] + + +# ---------------------------------------------------------------------- destroyed equipment + + +def test_a_destroyed_unidentified_item_is_named_by_its_mask(): + """A hellhound's breath kills a member whose pack holds one unidentified Sword +1, which fails its save. + + `EquipmentDestroyedEvent` has player visibility, so it names the sword as the inventory showed it, "a sword with a + faint aura", not as "Sword +1". The sword's base is the mundane sword, so the mask is the sword's display name. + """ + _, _, event = breath_kill(need_saved=False) + + assert event.visibility is Visibility.PLAYER + assert event.item_names == ("a sword with a faint aura",) + + +# ---------------------------------------------------------------------- saves and parties from 2.7.0 + +SAVES = Path(__file__).parent / "saves" + +SAVE_2_7_0 = SAVES / "view_item_names_2.7.0.json" +"""A save that osrlib 2.7.0 wrote, before the templates had display names. It's kept as 2.7.0 wrote it. + +The adventure bundles `temple_idol`, named "Idol of the drowned saint", with no display names. The fighter carries +2 vials of holy water, 6 torches, 20 arrows, a short bow, an idol, and an unidentified potion of healing, and wears +chainmail and wields a sword. The party stands on the shrine's one cell, where the fighter dropped 2 flasks of oil +and the second idol. +""" + +PARTY_2_7_0 = SAVES / "view_item_names_party_2.7.0.json" +"""The same party as a party document that osrlib 2.7.0 wrote, in town, before the drop: the fighter also carries +the 2 flasks of oil and both idols.""" + +CATALOG_NAMES = { + "holy_water": ("vial of holy water", "vials of holy water"), + "torch": ("torch", "torches"), + "arrows": ("arrow", "arrows"), + "short_bow": ("short bow", "short bows"), + "chainmail": ("suit of chainmail", "suits of chainmail"), + "sword": ("sword", "swords"), + "oil_flask": ("flask of oil", "flasks of oil"), +} +"""The compiled catalog's names for the built-in items the fixtures hold, as `test_item_display_names.py` pins them.""" + +UNNAMED_IDOL = ("Idol of the drowned saint", "Idols of the drowned saint") +"""The names a template written without them gets: its `name`, and the ending on the word before " of ".""" + + +def _embedded_templates(document) -> list[dict]: + """Every template a document embeds in a mundane stack, wherever it sits.""" + found = [] + if isinstance(document, dict): + if document.get("instance_type") == "item": + found.append(document["template"]) + for value in document.values(): + found += _embedded_templates(value) + elif isinstance(document, list): + for value in document: + found += _embedded_templates(value) + return found + + +def _names(view: PlayerView) -> dict[str, tuple[str, str]]: + return {item_id: (view.item_names[item_id], view.item_names_plural.get(item_id, "")) for item_id in view.item_names} + + +def test_the_2_7_0_fixtures_embed_templates_without_display_names(): + """The precondition for the two tests below: osrlib 2.7.0 wrote them, so no embedded template has the fields.""" + for path in (SAVE_2_7_0, PARTY_2_7_0): + document = json.loads(path.read_text(encoding="utf-8")) + assert document["engine_version"] == "2.7.0" + templates = _embedded_templates(document) + assert {template["id"] for template in templates} >= {"holy_water", "torch", "chainmail", "temple_idol"} + assert all("display_name" not in template for template in templates) + + +def test_a_2_7_0_save_names_built_in_items_from_the_catalog(): + """Each carried stack is named by the session's catalog, never by the template the save embedded. + + Named from the embedded template, holy water would read "Holy water (vial)", with the plural + "Holy water (vial)s". The bundled idol has no display names in the save's adventure either, so the catalog's + template gets the defaults, and the carried idol and the one in the pile read the same. + """ + game = load_game(json.loads(SAVE_2_7_0.read_text(encoding="utf-8"))) + + view = _player_view(game) + + (pile,) = view.piles.values() + assert pile.contents == ( + PileItemView(item_id="oil_flask", quantity=2), + PileItemView(item_id="temple_idol", quantity=1), + ) + assert _names(view) == {**CATALOG_NAMES, "temple_idol": UNNAMED_IDOL, "magic-item-0001": ("potion", "potions")} + + +def test_a_2_7_0_party_document_starts_a_session_with_catalog_names(): + """The party document goes into a new session of an adventure whose idol has names its author wrote. + + The carried idol embeds 2.7.0's template, with no names, and the view names it as the catalog does. + """ + party = Party(members=party_from_document(json.loads(PARTY_2_7_0.read_text(encoding="utf-8")))) + game = GameSession.new(party, _adventure(), seed=5) + + view = _player_view(game) + + assert _names(view) == { + **CATALOG_NAMES, + "temple_idol": ("idol of the drowned saint", "idols of the drowned saint"), + "magic-item-0001": ("potion", "potions"), + } + + +def test_a_carried_item_the_catalog_lacks_is_named_from_its_embedded_template(): + """The same party in an adventure that bundles no idol: the catalog has no `temple_idol`. + + The view still names the carried idol, from the template it embeds, with the defaults a template written without + names gets. Every built-in item still comes from the catalog. + """ + party = Party(members=party_from_document(json.loads(PARTY_2_7_0.read_text(encoding="utf-8")))) + level = LevelSpec(number=1, width=1, height=1, entrance=(0, 0)) + adventure = Adventure( + name="An Empty Crypt", + town=TownSpec(name="Threshold"), + dungeons=(DungeonSpec(id="crypt", name="Crypt", levels=(level,)),), + ) + game = GameSession.new(party, adventure, seed=5) + + view = _player_view(game) + + assert _names(view) == {**CATALOG_NAMES, "temple_idol": UNNAMED_IDOL, "magic-item-0001": ("potion", "potions")} + + +# ---------------------------------------------------------------------- masks that changed from 2.7.0 + +MASKS_2_7_0_BY_BASE = { + None: "a arm with a faint aura", + "battle_axe": "a battle axe with a faint aura", + "club": "a club with a faint aura", + "crossbow": "a crossbow with a faint aura", + "dagger": "a dagger with a faint aura", + "hand_axe": "a hand axe with a faint aura", + "javelin": "a javelin with a faint aura", + "lance": "a lance with a faint aura", + "long_bow": "a long bow with a faint aura", + "mace": "a mace with a faint aura", + "pole_arm": "a pole arm with a faint aura", + "short_bow": "a short bow with a faint aura", + "short_sword": "a short sword with a faint aura", + "silver_dagger": "a silver dagger with a faint aura", + "sling": "a sling with a faint aura", + "spear": "a spear with a faint aura", + "staff": "a staff with a faint aura", + "sword": "a sword with a faint aura", + "two_handed_sword": "a two-handed sword with a faint aura", + "war_hammer": "a war hammer with a faint aura", + "chainmail": "a chainmail with a faint aura", + "leather": "a leather with a faint aura", + "plate_mail": "a plate mail with a faint aura", + "shield": "a shield with a faint aura", + "arrows": "a arrows (quiver of 20) with a faint aura", + "crossbow_bolts": "a crossbow bolts (case of 30) with a faint aura", + "silver_tipped_arrow": "a silver tipped arrow (1) with a faint aura", + "sling_stones": "a sling stones with a faint aura", +} +"""The `display` osrlib 2.7.0 gave an unidentified enchanted weapon, suit of armour, or shield, by its base item. + +The base is the instance's `base_item_id`, or the template's when the instance has none. Computed by running 2.7.0's +masking over every magic item of the armour, sword, and weapon categories with no base and with each mundane weapon, +armour, and ammunition id as its base: 1,433 instances in all, each giving the string its base gives here. +""" + +MASKS_2_7_0_BY_CATEGORY = { + "misc": "a curious device", + "potion": "a potion", + "ring": "a ring", + "rod": "a rod", + "scroll": "a scroll", + "staff": "a staff", + "wand": "a wand", +} +"""The `display` osrlib 2.7.0 gave every unidentified magic item of the other categories, whatever its base.""" + +CHANGED_MASKS = { + "a arm with a faint aura": "a suit of armour with a faint aura", + "a arrows (quiver of 20) with a faint aura": "an arrow with a faint aura", + "a chainmail with a faint aura": "a suit of chainmail with a faint aura", + "a crossbow bolts (case of 30) with a faint aura": "a crossbow bolt with a faint aura", + "a leather with a faint aura": "a suit of leather armour with a faint aura", + "a plate mail with a faint aura": "a suit of plate mail with a faint aura", + "a silver tipped arrow (1) with a faint aura": "a silver tipped arrow with a faint aura", + "a sling stones with a faint aura": "a sling stone with a faint aura", +} +"""Every 2.7.0 mask that reads differently now, and what it reads as. Every other mask is unchanged.""" + +ARM_CATEGORIES = ("armour", "sword", "weapon") + + +def test_the_masks_that_changed_from_2_7_0_are_exactly_these(): + """Every unidentified magic item, with every base an arm can have, shows the 2.7.0 mask or its replacement. + + The instances sit in one fighter's pack, and the test reads each `display` from the player view. + """ + equipment = load_equipment() + bases = [None, *(template.id for template in (*equipment.weapons, *equipment.armour, *equipment.ammunition))] + game = _town() + pack = game.member(FIGHTER).inventory.items + expected: dict[str, str] = {} + changed: dict[str, str] = {} + for template in load_magic_items().items: + arm = template.category.value in ARM_CATEGORIES + for base in bases if arm else [None]: + instance_id = f"magic-item-{len(expected) + 1:05d}" + pack.append(MagicItemInstance(instance_id=instance_id, template_id=template.id, base_item_id=base)) + if arm: + old = MASKS_2_7_0_BY_BASE[base or template.base_item_id] + else: + old = MASKS_2_7_0_BY_CATEGORY[template.category.value] + expected[instance_id] = CHANGED_MASKS.get(old, old) + if old in CHANGED_MASKS: + changed[old] = CHANGED_MASKS[old] + + view = _player_view(game) + + assert len(expected) == 1433 + (member,) = (member for member in view.party if member.id == FIGHTER) + shown = {entry["instance_id"]: entry["display"] for entry in member.inventory["items"]} + assert shown == expected + assert changed == CHANGED_MASKS diff --git a/tools/docs/gen_content_ids.py b/tools/docs/gen_content_ids.py index c31d5c98..bf630ae1 100644 --- a/tools/docs/gen_content_ids.py +++ b/tools/docs/gen_content_ids.py @@ -80,7 +80,8 @@ def _page(filename: str, title: str, loader_ref: str, intro: str): "equipment.md", "Equipment ids", "[`load_equipment`][osrlib.data.load_equipment]", - "Every mundane equipment id — weapons, armour, gear, and ammunition — with its display name.", + "Every mundane equipment id (weapons, armour, gear, and ammunition), with its name as the SRD's price list " + "prints it, and its display names, what a sentence calls one unit and two or more.", ) as page: catalog = data.load_equipment() for section_title, entries in ( @@ -90,18 +91,26 @@ def _page(filename: str, title: str, loader_ref: str, intro: str): ("Ammunition", catalog.ammunition), ): page.write(f"## {section_title}\n\n") - _table(page, ("Id", "Name"), [(f"`{e.id}`", e.name) for e in entries]) + _table( + page, + ("Id", "Name", "Display name", "Display name plural"), + [(f"`{e.id}`", e.name, e.display_name, e.display_name_plural) for e in entries], + ) with _page( "magic-items.md", "Magic item ids", "[`load_magic_items`][osrlib.data.load_magic_items]", - "Every magic item template id, with its display name and category.", + "Every magic item template id, with its name as the SRD prints it, its display names, what a sentence calls " + "one identified item and two or more, and its category.", ) as page: _table( page, - ("Id", "Name", "Category"), - [(f"`{i.id}`", i.name, f"`{i.category}`") for i in data.load_magic_items().items], + ("Id", "Name", "Display name", "Display name plural", "Category"), + [ + (f"`{i.id}`", i.name, i.display_name, i.display_name_plural, f"`{i.category}`") + for i in data.load_magic_items().items + ], ) with _page( diff --git a/tools/srd_compile/equipment.py b/tools/srd_compile/equipment.py index 5bde5f66..d0980f71 100644 --- a/tools/srd_compile/equipment.py +++ b/tools/srd_compile/equipment.py @@ -16,11 +16,21 @@ size 1; `Stakes (3) and mallet` is one kit item; the ammunition table has no weight column and compiles to weight 0 — per the SRD, missile weapon weights already include the ammunition and its container. + +Every entry gets the names a sentence uses for one unit and for two or more. The display name +is the printed name in lowercase with a trailing parenthesis dropped, and body armour is named +as a suit. Ammunition names one unit, so its plural ending goes too: `Arrows (quiver of 20)` is +"arrow". The plural comes from `osrlib.core.items._item_plural`, the rule a template written without a plural +follows too. Gear whose printed name is a lot or a substance, like +`Torches (6)` and `Holy water (vial)`, and the armour the SRD prints as `Leather`, get the name +of the unit the session counts from `overrides/equipment.json`. """ import re from pathlib import Path +from osrlib.core.items import _item_plural + from .pipetable import parse_range, section_prose, slugify, tables_after_heading SOURCE_PAGES = ("Weapons_and_Armour.md", "Adventuring_Gear.md", "Time%2C_Weight%2C_Movement.md") @@ -117,6 +127,13 @@ _MISSILE_PATTERN = re.compile(r"Missile \(([^)]*)\)") +TRAILING_PARENTHESIS = re.compile(r"\s*\([^)]*\)$") + + +def display_names(singular: str) -> dict[str, str]: + """Return an entry's `display_name` and `display_name_plural` fields for a display name.""" + return {"display_name": singular, "display_name_plural": _item_plural(singular)} + def _weapon_id(name: str) -> str: return name.lower().replace("-", "_").replace(" ", "_") @@ -181,6 +198,7 @@ def compile_equipment(srd_dir: Path) -> dict[str, object]: weapon: dict[str, object] = { "id": _weapon_id(name), "name": name, + **display_names(name.lower()), "cost_gp": _parse_cost(cost_cell), "weight_coins": int(weight_cell), "damage": damage, @@ -203,6 +221,7 @@ def compile_equipment(srd_dir: Path) -> dict[str, object]: { "id": ammunition_id, "name": name, + **display_names(TRAILING_PARENTHESIS.sub("", name).lower().removesuffix("s")), "cost_gp": _parse_cost(cost_cell), "lot_size": lot_size, "weight_coins": 0, @@ -223,7 +242,9 @@ def compile_equipment(srd_dir: Path) -> dict[str, object]: bonus_match = re.fullmatch(r"\+(\d+) bonus", ac_cell) if bonus_match: entry["ac_bonus"] = int(bonus_match[1]) + entry.update(display_names(name.lower())) else: + entry.update(display_names(f"suit of {name.lower()}")) ac_match = re.fullmatch(r"(\d+) \[(\d+)\]", ac_cell) if ac_match is None: raise ValueError(f"unparseable AC cell {ac_cell!r}") @@ -250,6 +271,7 @@ def compile_equipment(srd_dir: Path) -> dict[str, object]: entry = { "id": gear_id, "name": name, + **display_names(TRAILING_PARENTHESIS.sub("", name).lower()), "cost_gp": _parse_cost(cost_cell), "lot_size": _GEAR_LOT_SIZES.get(gear_id, 1), } diff --git a/tools/srd_compile/magic_items.py b/tools/srd_compile/magic_items.py index da1d1e76..4daaa8f5 100644 --- a/tools/srd_compile/magic_items.py +++ b/tools/srd_compile/magic_items.py @@ -41,12 +41,19 @@ exactly the Phase 5 wired census; everything else ships `manual`-tagged prose. `Helm_of_Telepathy.md` is truncated mid-sentence in the SRD dump — its description completes via `overrides/magic_items.json` with provenance. + +Every item gets the names a sentence uses for one and for two or more, from `display_names`. +The two items that are a set rather than one thing, the drums of panic and the elven cloak and +boots, get theirs from `overrides/magic_items.json`. """ import re from pathlib import Path from urllib.parse import quote +from osrlib.core.items import _item_plural + +from .equipment import TRAILING_PARENTHESIS from .pipetable import slugify, strip_emphasis, strip_links, tables_after_heading from .treasure import parse_treasure_segment @@ -600,6 +607,52 @@ def _apply_mechanics(template: dict[str, object]) -> None: template[key] = value +_SPELL_COUNT = re.compile(r"(?P.+) \((?P\d+ spells?)\)") +_ROMAN_NUMERAL = re.compile(r"[IVX]+") +_PAIRS = ("boots", "gauntlets") + + +def display_names(printed_name: str, category: str, base_item_id: str | None) -> dict[str, str]: + """Return an item's `display_name` and `display_name_plural` fields, from its printed name. + + The SRD prints names for a table, so the compiler rewrites them for a sentence: + + - A spell scroll's parenthesis says how many spells it holds, so it becomes a `with` phrase: + `Spell Scroll (1 spell)` is "spell scroll with 1 spell". Any other trailing parenthesis goes, + like the generated count in `Arrows +1 (3d10 arrows)`. + - A label after a colon moves to the front, `Elemental Summoning Device: Air` becoming "air + elemental summoning device", except a treasure map's Roman numeral, which stays at the end. + - Every word is lowercase, except a word printed all in capitals, which is an abbreviation or + a Roman numeral: "potion of ESP", "treasure map II". + - Enchanted ammunition names one unit, so `Arrows +1` is "arrow +1". + - Enchanted body armour is named as a suit, "suit of armour +1", and boots and gauntlets as a + pair, "pair of boots of speed". + + The plural comes from `osrlib.core.items._item_plural`. + + Args: + printed_name: The item's `name`, like `"Potion of Healing"`. + category: The item's category. + base_item_id: The mundane item the enchantment overlays, or `None`. + + Returns: + The two fields. + """ + spells = _SPELL_COUNT.fullmatch(printed_name) + name = f"{spells['name']} with {spells['count']}" if spells else TRAILING_PARENTHESIS.sub("", printed_name) + head, colon, label = name.partition(": ") + if colon: + name = f"{head} {label}" if _ROMAN_NUMERAL.fullmatch(label) else f"{label} {head}" + singular = " ".join(word if word.isupper() else word.lower() for word in name.split(" ")) + if base_item_id in _AMMUNITION_BASES: + singular = re.sub(r"s(?= [+-]\d)", "", singular, count=1) + if category == "armour" and base_item_id != "shield": + singular = f"suit of {singular}" + elif singular.startswith(_PAIRS): + singular = f"pair of {singular}" + return {"display_name": singular, "display_name_plural": _item_plural(singular)} + + def _template( item_id: str, name: str, @@ -609,9 +662,11 @@ def _template( weight_coins: int = 0, **fields: object, ) -> dict[str, object]: + base_item_id = fields.get("base_item_id") template: dict[str, object] = { "id": item_id, "name": name, + **display_names(name, category, base_item_id if isinstance(base_item_id, str) else None), "category": category, "manual": manual or [], "weight_coins": weight_coins, diff --git a/tools/srd_compile/overrides/equipment.json b/tools/srd_compile/overrides/equipment.json new file mode 100644 index 00000000..d4e5b24f --- /dev/null +++ b/tools/srd_compile/overrides/equipment.json @@ -0,0 +1,146 @@ +[ + { + "id": "garlic", + "reason": "The price list prints 'Garlic' with no unit, and one unit is a bulb.", + "set": { + "display_name": "bulb of garlic", + "display_name_plural": "bulbs of garlic" + } + }, + { + "id": "hammer", + "reason": "The price list prints 'Hammer (small)', so the size goes in front of the noun.", + "set": { + "display_name": "small hammer", + "display_name_plural": "small hammers" + } + }, + { + "id": "holy_water", + "reason": "Holy water is a substance, and the description says it is 'stored in a special vial', so a unit is a vial.", + "set": { + "display_name": "vial of holy water", + "display_name_plural": "vials of holy water" + } + }, + { + "id": "iron_spikes", + "reason": "'Iron spikes (12)' is a lot of 12, and the session counts single spikes.", + "set": { + "display_name": "iron spike", + "display_name_plural": "iron spikes" + } + }, + { + "id": "leather", + "reason": "The armour table prints the bare 'Leather', and the prose under it says 'Leather armour counts as light armour', so a suit is of leather armour.", + "set": { + "display_name": "suit of leather armour", + "display_name_plural": "suits of leather armour" + } + }, + { + "id": "mirror", + "reason": "The price list prints 'Mirror (hand-sized, steel)', so the display name keeps the size.", + "set": { + "display_name": "hand mirror", + "display_name_plural": "hand mirrors" + } + }, + { + "id": "oil_flask", + "reason": "'Oil (1 flask)' is a substance, and the description says 'A flask of oil fuels a lantern', so a unit is a flask.", + "set": { + "display_name": "flask of oil", + "display_name_plural": "flasks of oil" + } + }, + { + "id": "pole", + "reason": "The price list prints 'Pole (10’ long, wooden)', and the description heading is 'Pole, 10’'.", + "set": { + "display_name": "10’ pole", + "display_name_plural": "10’ poles" + } + }, + { + "id": "rations_iron", + "reason": "'Rations (iron, 7 days)' is a lot of 7, and the session counts one day's iron ration.", + "set": { + "display_name": "iron ration", + "display_name_plural": "iron rations" + } + }, + { + "id": "rations_standard", + "reason": "'Rations (standard, 7 days)' is a lot of 7, and the session counts one day's standard ration.", + "set": { + "display_name": "standard ration", + "display_name_plural": "standard rations" + } + }, + { + "id": "rope", + "reason": "Rope is a substance, and 'Rope (50’)' sells one 50’ length, which is a coil.", + "set": { + "display_name": "50’ coil of rope", + "display_name_plural": "50’ coils of rope" + } + }, + { + "id": "sack_large", + "reason": "The price list prints 'Sack (large)', so the size goes in front of the noun.", + "set": { + "display_name": "large sack", + "display_name_plural": "large sacks" + } + }, + { + "id": "sack_small", + "reason": "The price list prints 'Sack (small)', so the size goes in front of the noun.", + "set": { + "display_name": "small sack", + "display_name_plural": "small sacks" + } + }, + { + "id": "stakes_and_mallet", + "reason": "'Stakes (3) and mallet' is one kit, which the description calls 'A wooden mallet and three 18” long stakes'.", + "set": { + "display_name": "set of stakes and mallet", + "display_name_plural": "sets of stakes and mallet" + } + }, + { + "id": "thieves_tools", + "reason": "The description says 'A set of lock picking tools in a small case'.", + "set": { + "display_name": "set of thieves’ tools", + "display_name_plural": "sets of thieves’ tools" + } + }, + { + "id": "torch", + "reason": "'Torches (6)' is a lot of 6, and the session counts single torches.", + "set": { + "display_name": "torch", + "display_name_plural": "torches" + } + }, + { + "id": "wine", + "reason": "'Wine (2 pints)' is a substance sold in a lot of 2, and the session counts pints.", + "set": { + "display_name": "pint of wine", + "display_name_plural": "pints of wine" + } + }, + { + "id": "wolfsbane", + "reason": "'Wolfsbane (1 bunch)' is a herb, and a unit is a bunch.", + "set": { + "display_name": "bunch of wolfsbane", + "display_name_plural": "bunches of wolfsbane" + } + } +] diff --git a/tools/srd_compile/overrides/magic_items.json b/tools/srd_compile/overrides/magic_items.json index 65c83963..88012e19 100644 --- a/tools/srd_compile/overrides/magic_items.json +++ b/tools/srd_compile/overrides/magic_items.json @@ -5,5 +5,21 @@ "set": { "manual.4": "Bidirectional communication: The wearer may initiate bidirectional, telepathic communication, though the creature is not compelled to respond." } + }, + { + "id": "drums_of_panic", + "reason": "The page describes 'Large war drums', a single item made of several drums, so the display name calls it a set, which also gives it a plural that differs from the singular.", + "set": { + "display_name": "set of drums of panic", + "display_name_plural": "sets of drums of panic" + } + }, + { + "id": "elven_cloak_and_boots", + "reason": "The page describes 'A set of enchanted boots and a matching cloak', a single item made of two pieces, so the display name calls it a set.", + "set": { + "display_name": "set of elven cloak and boots", + "display_name_plural": "sets of elven cloak and boots" + } } ]