osrlib 2.6.0__tar.gz → 2.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. {osrlib-2.6.0 → osrlib-2.8.0}/PKG-INFO +1 -1
  2. {osrlib-2.6.0 → osrlib-2.8.0}/pyproject.toml +1 -1
  3. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/_descriptions.py +71 -5
  4. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/character.py +36 -0
  5. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/classes.py +8 -4
  6. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/combat.py +6 -2
  7. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/events.py +55 -21
  8. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/frozen.py +5 -3
  9. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/items.py +279 -9
  10. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/monsters.py +9 -3
  11. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/npc.py +8 -6
  12. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/ruleset.py +18 -0
  13. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/spells.py +123 -41
  14. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/tables.py +11 -10
  15. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_feature_handles.py +52 -0
  16. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_hauling.py +2 -1
  17. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_items.py +5 -1
  18. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_magic_items.py +74 -34
  19. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_party_members.py +41 -1
  20. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_spells.py +42 -10
  21. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_treasure.py +1 -0
  22. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/adventure.py +4 -3
  23. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/battle.py +562 -114
  24. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/commands.py +317 -101
  25. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/content_pack.py +1 -1
  26. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/dungeon.py +40 -8
  27. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/encounter.py +21 -8
  28. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/events.py +192 -16
  29. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/session.py +80 -14
  30. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/views.py +639 -114
  31. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/equipment.json +174 -18
  32. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/magic_items.json +336 -2
  33. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/messages.py +159 -92
  34. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/persistence.py +8 -1
  35. {osrlib-2.6.0 → osrlib-2.8.0}/LICENSE +0 -0
  36. {osrlib-2.6.0 → osrlib-2.8.0}/LICENSE-OGL.md +0 -0
  37. {osrlib-2.6.0 → osrlib-2.8.0}/README.md +0 -0
  38. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/__init__.py +0 -0
  39. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/__init__.py +0 -0
  40. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/abilities.py +0 -0
  41. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/alignment.py +0 -0
  42. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/clock.py +0 -0
  43. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/creature.py +0 -0
  44. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/dice.py +0 -0
  45. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/effects.py +0 -0
  46. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/rng.py +0 -0
  47. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/treasure.py +0 -0
  48. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/core/validation.py +0 -0
  49. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/__init__.py +0 -0
  50. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_arrival.py +0 -0
  51. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_doors.py +0 -0
  52. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_gating.py +0 -0
  53. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_light.py +0 -0
  54. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_movement.py +0 -0
  55. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_odometer.py +0 -0
  56. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_party_location.py +0 -0
  57. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_search.py +0 -0
  58. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/_town.py +0 -0
  59. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/exploration.py +0 -0
  60. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/gates.py +0 -0
  61. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/interpreter.py +0 -0
  62. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/narrative.py +0 -0
  63. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/party.py +0 -0
  64. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/quests.py +0 -0
  65. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/stocking.py +0 -0
  66. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/crawl/triggers.py +0 -0
  67. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/LICENSE-OGL.md +0 -0
  68. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/__init__.py +0 -0
  69. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/abilities.json +0 -0
  70. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/classes.json +0 -0
  71. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/combat_tables.json +0 -0
  72. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/encounter_tables.json +0 -0
  73. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/languages.json +0 -0
  74. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/monsters.json +0 -0
  75. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/spells.json +0 -0
  76. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/data/treasure.json +0 -0
  77. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/errors.py +0 -0
  78. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/py.typed +0 -0
  79. {osrlib-2.6.0 → osrlib-2.8.0}/src/osrlib/versioning.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osrlib
3
- Version: 2.6.0
3
+ Version: 2.8.0
4
4
  Summary: B/X (1981 Basic/Expert) tabletop RPG rules engine for turn-based dungeon crawlers
5
5
  Keywords: basic-expert,bx,dungeon-crawler,game-engine,osr,rpg,srd,ttrpg
6
6
  Author: Marsh Macy
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "osrlib"
3
- version = "2.6.0"
3
+ version = "2.8.0"
4
4
  description = "B/X (1981 Basic/Expert) tabletop RPG rules engine for turn-based dungeon crawlers"
5
5
  readme = "README.md"
6
6
  # The wheel ships Open Game Content (osrlib/data/*.json and its LICENSE-OGL.md
@@ -7,9 +7,19 @@ the docstring of its field. To read the docstrings, `_describe` parses the sourc
7
7
  model and its base classes. It parses a module only when pydantic builds a schema, and only once, so importing osrlib
8
8
  parses nothing.
9
9
 
10
- Pydantic writes an enum's docstring as the description of the enum's schema. Every osrlib enum subclasses `_StrEnum`,
11
- whose `__get_pydantic_json_schema__` reduces the cross-references in that description each time pydantic builds the
12
- enum's schema.
10
+ Pydantic writes a model's or an enum's class docstring as the description of its schema. Every osrlib enum subclasses
11
+ `_StrEnum`, whose `__get_pydantic_json_schema__` rewrites that description each time pydantic builds the enum's schema,
12
+ as `_describe` does for a model. A program such as an OpenAPI viewer renders the description as CommonMark, which
13
+ doesn't recognize the Google-style sections of a docstring: it joins the lines under `Attributes:` into one paragraph
14
+ and shows an indented fence as an indented code block. The description is therefore the docstring's text before its
15
+ first section, followed by its `Modes:`, `Rejections:`, and `Events:` sections, which describe what a command does on
16
+ the wire. Each kept section is its label on a line of its own, a blank line, and its body moved to the left margin, so
17
+ its lists and paragraphs render as they do on the documentation site. The other sections, such as `Attributes:`,
18
+ `Raises:`, and `Examples:`, are left out, because each property has its own description and the rest describe Python
19
+ use. A kept section whose body is only whitespace is left out too, and a schema whose description the rule empties has
20
+ no `description` key, as the schema of a class with no docstring has none. A section starts at a line at the left margin
21
+ that is one or more words and a colon when the line after it is indented, so a sentence that ends with a colon and
22
+ introduces text at the left margin isn't a section. Field descriptions keep their whole docstring.
13
23
 
14
24
  A description reaches its reader as raw text, outside the documentation site, so `_describe` and `_StrEnum` reduce each
15
25
  mkdocstrings cross-reference, like ``[`MoveParty`][osrlib.crawl.commands.MoveParty]``, to its label, `` `MoveParty` ``.
@@ -23,6 +33,7 @@ import ast
23
33
  import inspect
24
34
  import re
25
35
  import sys
36
+ import textwrap
26
37
  from enum import StrEnum
27
38
  from functools import cache
28
39
  from itertools import pairwise
@@ -117,6 +128,61 @@ def _reduce(schema: dict[str, Any]) -> None:
117
128
  schema["description"] = _plain(description)
118
129
 
119
130
 
131
+ # A line that starts a docstring section when the line after it is indented: one or more words and a colon.
132
+ _LABEL = re.compile(r"[A-Z][A-Za-z ]*:")
133
+
134
+ # The sections a model's or an enum's description keeps, because they describe what a command does on the wire.
135
+ _KEPT = frozenset({"Modes", "Rejections", "Events"})
136
+
137
+
138
+ def _sectioned(description: str) -> str:
139
+ """Return a class docstring as CommonMark: its text before the first section, then its wire sections.
140
+
141
+ A section starts at a line at the left margin that matches `_LABEL` when the line after it is indented, and it
142
+ runs to the next section or to the end of the docstring. The `Modes:`, `Rejections:`, and `Events:` sections are
143
+ kept, in the docstring's order, each as its label on a line of its own, a blank line, and its body moved to the
144
+ left margin. A kept section whose body is only whitespace is left out, and so is every other section. A docstring
145
+ with no sections is returned whole. `_sectioned` reduces the cross-references in each part.
146
+
147
+ Args:
148
+ description: The class docstring as pydantic writes it, already cleaned by `inspect.cleandoc`.
149
+
150
+ Returns:
151
+ The description for the class's JSON Schema, which is empty when the docstring has nothing it keeps.
152
+ """
153
+ lines = description.split("\n")
154
+ lead: list[str] = []
155
+ sections: list[tuple[str, list[str]]] = []
156
+ for line, following in zip(lines, [*lines[1:], ""], strict=True):
157
+ if _LABEL.fullmatch(line) and following.startswith(" "):
158
+ sections.append((line.removesuffix(":"), []))
159
+ elif sections:
160
+ sections[-1][1].append(line)
161
+ else:
162
+ lead.append(line)
163
+ if not sections:
164
+ return _plain(description)
165
+ parts = [_plain("\n".join(lead)).rstrip()]
166
+ for label, body in sections:
167
+ text = _plain(textwrap.dedent("\n".join(body))).strip("\n")
168
+ if label in _KEPT and text.strip():
169
+ parts.append(f"{label}:\n\n{text}")
170
+ return "\n\n".join(part for part in parts if part)
171
+
172
+
173
+ def _reduce_class(schema: dict[str, Any]) -> None:
174
+ """Rewrite a model's or an enum's top-level `description` as `_sectioned` gives it.
175
+
176
+ When the rewritten description is empty, the schema has no `description` key, as the schema of a class with no
177
+ docstring has none.
178
+ """
179
+ if isinstance(description := schema.get("description"), str):
180
+ if text := _sectioned(description):
181
+ schema["description"] = text
182
+ else:
183
+ del schema["description"]
184
+
185
+
120
186
  def _property_name(name: str, info: FieldInfo, mode: JsonSchemaMode) -> str:
121
187
  """Return the name of a field's property in a schema that uses aliases, as pydantic chooses it.
122
188
 
@@ -151,7 +217,7 @@ def _describe(cls: type[BaseModel], json_schema: JsonSchemaValue, handler: GetJs
151
217
  reference to its definition.
152
218
  """
153
219
  schema = handler.resolve_ref_schema(json_schema)
154
- _reduce(schema)
220
+ _reduce_class(schema)
155
221
  fields = {name: name for name in cls.model_fields}
156
222
  # A property named for a field's alias belongs to that field, even when another field has the same name.
157
223
  fields.update({_property_name(name, info, handler.mode): name for name, info in cls.model_fields.items()})
@@ -177,5 +243,5 @@ class _StrEnum(StrEnum):
177
243
  pydantic builds the definitions of a larger schema.
178
244
  """
179
245
  json_schema = handler(schema)
180
- _reduce(handler.resolve_ref_schema(json_schema))
246
+ _reduce_class(handler.resolve_ref_schema(json_schema))
181
247
  return json_schema
@@ -109,8 +109,10 @@ from osrlib.core.items import (
109
109
  Inventory,
110
110
  ItemInstance,
111
111
  ItemTemplate,
112
+ MagicItemInstance,
112
113
  equip,
113
114
  equipped_item_modifiers,
115
+ magic_item_template,
114
116
  movement_rate_feet,
115
117
  purchase,
116
118
  validate_purchase,
@@ -809,6 +811,40 @@ class Character(_Model):
809
811
  raise ContentValidationError(f"character document payload failed validation: {error}") from error
810
812
 
811
813
 
814
+ _TESTS_AS: Final = {"shield": "shield_plus_1", "worn_armour": "armour_plus_1"}
815
+ """The +1 template that every test shows for a cursed item worn in each armour slot."""
816
+
817
+
818
+ def _armour_as_tested(member: Character) -> Character:
819
+ """Return the member as every test shows their armour, for an armour class that knows no more than a player does.
820
+
821
+ The OSE SRD says "All types of tests indicate that a cursed shield or suit of armour is enchanted with a +1
822
+ bonus. It is only when the armour is used in deadly combat that the curse is revealed." So in the copy this
823
+ returns, each worn cursed shield or suit that is unidentified and whose curse isn't revealed becomes a copy of
824
+ itself made from the +1 template, `shield_plus_1` or `armour_plus_1`, keeping its base item. Read
825
+ `armour_class` or `armour_class_ascending` from the copy for the number the item tests as. Everything else the
826
+ member wears counts as usual.
827
+
828
+ With nothing to mask, it returns the member itself. The copy is shallow and only read, so the member never
829
+ changes. The player view's armour class and the equipment choice of a generated NPC both read this, and the
830
+ attack rolls and every other rule read the member's real armour class.
831
+ """
832
+ inventory = member.inventory
833
+ masked = {}
834
+ for slot, lookalike in _TESTS_AS.items():
835
+ worn = getattr(inventory, slot)
836
+ if (
837
+ isinstance(worn, MagicItemInstance)
838
+ and not worn.identified
839
+ and not worn.cursed_revealed
840
+ and magic_item_template(worn).cursed
841
+ ):
842
+ masked[slot] = worn.model_copy(update={"template_id": lookalike})
843
+ if not masked:
844
+ return member
845
+ return member.model_copy(update={"inventory": inventory.model_copy(update=masked)})
846
+
847
+
812
848
  def party_to_document(characters: Sequence[Character]) -> dict[str, object]:
813
849
  """Return a group of characters as one JSON-ready document, stamped with its schema and engine versions.
814
850
 
@@ -999,7 +999,9 @@ def thief_skill_check(
999
999
  door, or picking a pocket. It rolls and returns the result, and does nothing else. It emits no
1000
1000
  events, and it doesn't decide what the players may see. If you show players only what their
1001
1001
  characters know, you decide what to reveal. In a session, the engine calls it and emits the
1002
- events for you when it resolves commands like [`PickLock`][osrlib.crawl.commands.PickLock].
1002
+ events for you when it resolves commands like [`PickLock`][osrlib.crawl.commands.PickLock], and
1003
+ when a thief hides and back-stabs in a battle round, as
1004
+ [`BattleDeclaration.back_stab`][osrlib.crawl.commands.BattleDeclaration.back_stab] describes.
1003
1005
 
1004
1006
  For a skill in [`PERCENTILE_THIEF_SKILLS`][osrlib.core.classes.PERCENTILE_THIEF_SKILLS], it
1005
1007
  rolls d%, and the check succeeds on a roll equal to or under the chance for the thief's level.
@@ -1019,9 +1021,11 @@ def thief_skill_check(
1019
1021
  `"hear_noise"`.
1020
1022
  modifier_pct: A percentage added to the chance before rolling. Make it negative to make
1021
1023
  the attempt harder. Ignored for `"hear_noise"`.
1022
- stream: The stream to draw from, usually the one a session uses for these checks,
1023
- `streams.get(`[`EXPLORATION_STREAM`][osrlib.crawl.session.EXPLORATION_STREAM]`)`.
1024
- It advances by one draw.
1024
+ stream: The stream to draw from. A session draws a thief check outside a battle from
1025
+ `streams.get(`[`EXPLORATION_STREAM`][osrlib.crawl.session.EXPLORATION_STREAM]`)`, and a
1026
+ battle's hide in shadows and move silently rolls from
1027
+ `streams.get(`[`COMBAT_STREAM`][osrlib.core.combat.COMBAT_STREAM]`)`. It advances by one
1028
+ draw.
1025
1029
 
1026
1030
  Returns:
1027
1031
  The roll, the chance it was checked against, and whether it succeeded.
@@ -173,7 +173,9 @@ from osrlib.core.items import (
173
173
  MissileRanges,
174
174
  WeaponQuality,
175
175
  WeaponTemplate,
176
+ _masked_names,
176
177
  _shield_ac_parts,
178
+ _with_article,
177
179
  equipped_item_modifiers,
178
180
  magic_item_template,
179
181
  )
@@ -2099,7 +2101,8 @@ def destroy_equipment(
2099
2101
  items that save stay in the inventory's `items` list, no longer equipped. The saving
2100
2102
  throws report no events of their own. The function returns one
2101
2103
  [`EquipmentDestroyedEvent`][osrlib.core.events.EquipmentDestroyedEvent], which lists
2102
- the items destroyed and the items saved. In a
2104
+ the items destroyed and the items saved. It names an unidentified magic item by its masked
2105
+ name, like `"a sword with a faint aura"`, because the players see the event. In a
2103
2106
  [`GameSession`][osrlib.crawl.session.GameSession], that event's page says where a dead
2104
2107
  party member's saved items go.
2105
2108
 
@@ -2176,7 +2179,8 @@ def destroy_equipment(
2176
2179
  if save_stream.randbelow(20) + 1 + best_bonus >= required:
2177
2180
  saved.append(instance)
2178
2181
  continue
2179
- destroyed.append(template.name)
2182
+ # The event has player visibility, so an unidentified item is named as the inventory shows it.
2183
+ destroyed.append(template.name if instance.identified else _with_article(_masked_names(instance)[0]))
2180
2184
  else:
2181
2185
  destroyed.append(instance.template.name)
2182
2186
  inventory.items = list(saved)
@@ -849,7 +849,11 @@ class EquipmentDestroyedEvent(Event):
849
849
  """The entity id of the victim."""
850
850
 
851
851
  item_names: tuple[str, ...]
852
- """The display names of the items that were destroyed."""
852
+ """The names of the items that were destroyed, as the players know them: a mundane item's
853
+ `name`, like `"Torches (6)"`, an identified magic item's `name`, and an unidentified magic item's
854
+ masked name, like `"a sword with a faint aura"`, the `display` that
855
+ [`MemberView.inventory`][osrlib.crawl.views.MemberView.inventory] showed for it. The event has
856
+ player visibility, so it never names an unidentified item by its true name."""
853
857
 
854
858
  saved_items: tuple[str, ...] = ()
855
859
  """The instance ids of the magic items that passed their save and still exist. Empty when none survived,
@@ -1145,16 +1149,22 @@ class SpellDisruptedEvent(Event):
1145
1149
 
1146
1150
 
1147
1151
  class DeclarationFizzledEvent(Event):
1148
- """A declared wand, staff, or rod use, a declared turning, or a declared melee attack failed before it took effect.
1152
+ """A declared item use, hand-over, turning, or melee attack failed before it took effect.
1149
1153
 
1150
1154
  A [`GameSession`][osrlib.crawl.session.GameSession] reports it during a battle round. At the start of each
1151
1155
  round, every party member declares an action in a
1152
1156
  [`BattleDeclaration`][osrlib.crawl.commands.BattleDeclaration]. A turning is a cleric's attempt to turn undead.
1153
- Device uses and turnings resolve in the round's magic phase, the step in which the party's spells, item uses,
1154
- and turnings take effect. A staff's strike is the exception, described below. Just before
1155
- each one resolves, the session checks it again. If a check the declaration passed at the start of the round
1156
- now fails, the declaration fizzles. Something earlier in the round caused the failure. For example, the group a
1157
- wand was aimed at left the battle.
1157
+ Device uses, potions, hand-overs, and turnings resolve in the round's magic phase, the step in which the
1158
+ party's spells, item uses, and turnings take effect. A device is a wand, a staff, or a rod. A staff's strike
1159
+ is the exception, described below. Just before each one resolves, the session checks it again. If a check the
1160
+ declaration passed at the start of the round now fails, the declaration fizzles. Something earlier in the
1161
+ round caused the failure. For example, the group a wand was aimed at left the battle.
1162
+
1163
+ A potion that one member gives another to drink fizzles with the code `magic.potion.fizzled` when the drinker
1164
+ died or turned to stone, or the two members no longer stand within 5' of each other. A potion the carrier
1165
+ drinks never fizzles. A `give_item` hand-over fizzles with the code `battle.give.fizzled` when the recipient
1166
+ can no longer act, or the two members no longer stand within 5' of each other. Either event has the item in
1167
+ `item_id` and the member it was for in `target_id`.
1158
1168
 
1159
1169
  A melee attack fizzles when the party's melee step comes and the attack has nothing left to strike, or the
1160
1170
  member stands in the wrong place. The session judges a melee attack before the round starts, as if every move the
@@ -1174,40 +1184,57 @@ class DeclarationFizzledEvent(Event):
1174
1184
  strike's group ran out of the battle, or a quicker member killed the last monster in it that the member could
1175
1185
  see.
1176
1186
 
1177
- The event's `actor_id` is the member who declared the action, `item_id` is the device, `group_id` is the group a
1178
- melee attack was aimed at, and `reason` is the rejection code of the check that failed.
1187
+ The event's `actor_id` is the member who declared the action, `item_id` is the device, the potion, or the item
1188
+ handed over, `target_id` is the member a potion or a hand-over was for, `group_id` is the group a melee attack
1189
+ was aimed at, and `reason` is the rejection code of the check that failed.
1179
1190
 
1180
- A fizzled declaration spends nothing. The device wasn't used, so it keeps its charge and isn't identified. Tell
1181
- the player the action failed, and that the device still has its charge. A fizzled melee attack makes no attack
1182
- roll, so tell the player why the member didn't swing. When a cast or a scroll read fizzles,
1183
- the session reports a [`SpellDisruptedEvent`][osrlib.core.events.SpellDisruptedEvent] instead, because the
1184
- spell is lost.
1191
+ A fizzled declaration spends nothing and draws nothing. The device wasn't used, so it keeps its charge and isn't
1192
+ identified. Tell the player the action failed, and that the device still has its charge. A potion that fizzles
1193
+ stays with the member who carries it and isn't identified, and an item that wasn't handed over stays with the
1194
+ giver. A fizzled melee attack makes no attack roll, so tell the player why the member didn't swing. When a cast
1195
+ or a scroll read fizzles, the session reports a [`SpellDisruptedEvent`][osrlib.core.events.SpellDisruptedEvent]
1196
+ instead, because the spell is lost.
1185
1197
  """
1186
1198
 
1187
1199
  allowed_codes: ClassVar[frozenset[str]] = frozenset(
1188
- {"magic.device.fizzled", "magic.turning.fizzled", "battle.melee.fizzled"}
1200
+ {
1201
+ "magic.device.fizzled",
1202
+ "magic.potion.fizzled",
1203
+ "magic.turning.fizzled",
1204
+ "battle.give.fizzled",
1205
+ "battle.melee.fizzled",
1206
+ }
1189
1207
  )
1190
- """The three codes: `magic.device.fizzled` for a wand, staff, or rod use, `magic.turning.fizzled` for a
1191
- turning, and `battle.melee.fizzled` for a melee attack."""
1208
+ """The five codes: `magic.device.fizzled` for a wand, staff, or rod use, `magic.potion.fizzled` for a potion
1209
+ given to another member, `magic.turning.fizzled` for a turning, `battle.give.fizzled` for a hand-over, and
1210
+ `battle.melee.fizzled` for a melee attack."""
1192
1211
 
1193
1212
  event_type: Literal["declaration_fizzled"] = "declaration_fizzled"
1194
1213
  """The fixed string that identifies this event class in a serialized event."""
1195
1214
 
1196
1215
  code: str
1197
- """Which declaration fizzled: `magic.device.fizzled`, `magic.turning.fizzled`, or `battle.melee.fizzled`."""
1216
+ """Which declaration fizzled: `magic.device.fizzled`, `magic.potion.fizzled`, `magic.turning.fizzled`,
1217
+ `battle.give.fizzled`, or `battle.melee.fizzled`."""
1198
1218
 
1199
1219
  visibility: Visibility = Visibility.PLAYER
1200
1220
  """Player visibility: everyone sees the action fail."""
1201
1221
 
1202
1222
  actor_id: str
1203
- """The entity id of the member who declared the device use, the turning, or the melee attack."""
1223
+ """The entity id of the member who declared the device use, the potion, the hand-over, the turning, or the
1224
+ melee attack."""
1204
1225
 
1205
1226
  item_id: str | None = None
1206
- """On a `magic.device.fizzled` event, the device's instance id, as the declaration's `item_id` gave it.
1227
+ """The item the declaration's `item_id` gave, on a `magic.device.fizzled`, a `magic.potion.fizzled`, or a
1228
+ `battle.give.fizzled` event: a device's or a potion's instance id, or the id of the item a hand-over moves.
1207
1229
 
1208
- The player already used this id, so it reveals nothing about a device that isn't identified. It's `None` on a
1230
+ The player already used this id, so it reveals nothing about an item that isn't identified. It's `None` on a
1209
1231
  `magic.turning.fizzled` or a `battle.melee.fizzled` event."""
1210
1232
 
1233
+ target_id: str | None = None
1234
+ """On a `magic.potion.fizzled` or a `battle.give.fizzled` event, the id of the member the potion or the item
1235
+ was for, the one id in the declaration's `targets`. It's `None` on the other codes, and on an event from a log
1236
+ written before the field existed."""
1237
+
1211
1238
  group_id: str | None = None
1212
1239
  """On a `battle.melee.fizzled` event, the id of the group the melee attack was aimed at, as the declaration's
1213
1240
  `target_group_id` gave it. It's `None` on the other codes."""
@@ -1229,6 +1256,13 @@ class DeclarationFizzledEvent(Event):
1229
1256
  the member can see is left in the group a melee attack was aimed at, for example because the party's missiles
1230
1257
  or spells killed them earlier in the round. A melee attack gets this code wherever the member stands, whether
1231
1258
  or not the member closed, because the session checks for a target before it checks the member's position.
1259
+ - `items.use.target_cannot_drink`: the member a potion was for died or turned to stone earlier in the round.
1260
+ - `session.command.member_incapacitated`: the member a hand-over was for can no longer act, for example
1261
+ because the member died or fell asleep earlier in the round.
1262
+ - `battle.declaration.member_out_of_reach`: the two members of a potion, a hand-over, or a staff of healing's
1263
+ touch no longer stand within 5' of each other.
1264
+ - `items.use.target_cannot_be_healed` and `items.use.target_healed_today`: the creature a staff of healing
1265
+ was to touch died or turned to stone, or the staff already healed it today.
1232
1266
 
1233
1267
  Match on it as you match on the code of a [`Rejection`][osrlib.core.validation.Rejection].
1234
1268
  [The rejection code reference][rejection-codes] explains each code.
@@ -218,7 +218,8 @@ class _Model(BaseModel):
218
218
  assigning a field enforces.
219
219
 
220
220
  The class also gives each model's JSON Schema a description for each field: the field's docstring, from the
221
- class or from the nearest base class that documents the field.
221
+ class or from the nearest base class that documents the field. The model's own description is the class
222
+ docstring's text before its first section, followed by its `Modes:`, `Rejections:`, and `Events:` sections.
222
223
  """
223
224
 
224
225
  def model_copy(self, *, update: Mapping[str, Any] | None = None, deep: bool = False) -> Self:
@@ -259,8 +260,9 @@ class _Model(BaseModel):
259
260
  Pydantic calls this each time it builds the model's JSON Schema, for `model_json_schema()` and for a
260
261
  `TypeAdapter`. It reduces each mkdocstrings cross-reference in a description to its label. When the model's
261
262
  module has no readable source, like one installed as bytecode alone, the schema doesn't have the field
262
- docstrings. It still has the descriptions that pydantic writes itself, like the model's docstring, a computed
263
- field's docstring, and a `Field(description=...)`.
263
+ docstrings. It still has the model's description, which the class docstring in the bytecode gives, so it's the
264
+ same as with the source. It also has the descriptions that pydantic writes itself, from a computed field's
265
+ docstring and from a `Field(description=...)`.
264
266
  """
265
267
  json_schema = handler(schema)
266
268
  _describe(cls, json_schema, handler)