osrlib 2.6.0__tar.gz → 2.7.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.
- {osrlib-2.6.0 → osrlib-2.7.0}/PKG-INFO +1 -1
- {osrlib-2.6.0 → osrlib-2.7.0}/pyproject.toml +1 -1
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/_descriptions.py +71 -5
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/character.py +36 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/classes.py +8 -4
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/events.py +50 -20
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/frozen.py +5 -3
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/items.py +8 -8
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/monsters.py +9 -3
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/npc.py +8 -6
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/ruleset.py +18 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/tables.py +11 -10
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_hauling.py +2 -1
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_items.py +5 -1
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_magic_items.py +52 -24
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_treasure.py +1 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/adventure.py +4 -3
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/battle.py +477 -99
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/commands.py +231 -71
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/content_pack.py +1 -1
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/encounter.py +21 -8
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/events.py +178 -16
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/session.py +30 -13
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/views.py +197 -41
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/messages.py +159 -92
- {osrlib-2.6.0 → osrlib-2.7.0}/LICENSE +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/LICENSE-OGL.md +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/README.md +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/__init__.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/__init__.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/abilities.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/alignment.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/clock.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/combat.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/creature.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/dice.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/effects.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/rng.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/spells.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/treasure.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/core/validation.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/__init__.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_arrival.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_doors.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_feature_handles.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_gating.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_light.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_movement.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_odometer.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_party_location.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_party_members.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_search.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_spells.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/_town.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/dungeon.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/exploration.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/gates.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/interpreter.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/narrative.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/party.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/quests.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/stocking.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/crawl/triggers.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/LICENSE-OGL.md +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/__init__.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/abilities.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/classes.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/combat_tables.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/encounter_tables.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/equipment.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/languages.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/magic_items.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/monsters.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/spells.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/data/treasure.json +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/errors.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/persistence.py +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/py.typed +0 -0
- {osrlib-2.6.0 → osrlib-2.7.0}/src/osrlib/versioning.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "osrlib"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.7.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
|
|
11
|
-
whose `__get_pydantic_json_schema__`
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
1023
|
-
`streams.get(`[`EXPLORATION_STREAM`][osrlib.crawl.session.EXPLORATION_STREAM]`)
|
|
1024
|
-
|
|
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.
|
|
@@ -1145,16 +1145,22 @@ class SpellDisruptedEvent(Event):
|
|
|
1145
1145
|
|
|
1146
1146
|
|
|
1147
1147
|
class DeclarationFizzledEvent(Event):
|
|
1148
|
-
"""A declared
|
|
1148
|
+
"""A declared item use, hand-over, turning, or melee attack failed before it took effect.
|
|
1149
1149
|
|
|
1150
1150
|
A [`GameSession`][osrlib.crawl.session.GameSession] reports it during a battle round. At the start of each
|
|
1151
1151
|
round, every party member declares an action in a
|
|
1152
1152
|
[`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
|
|
1154
|
-
and turnings take effect. A
|
|
1155
|
-
each one resolves, the session checks it again. If a check the
|
|
1156
|
-
now fails, the declaration fizzles. Something earlier in the
|
|
1157
|
-
wand was aimed at left the battle.
|
|
1153
|
+
Device uses, potions, hand-overs, and turnings resolve in the round's magic phase, the step in which the
|
|
1154
|
+
party's spells, item uses, and turnings take effect. A device is a wand, a staff, or a rod. A staff's strike
|
|
1155
|
+
is the exception, described below. Just before each one resolves, the session checks it again. If a check the
|
|
1156
|
+
declaration passed at the start of the round now fails, the declaration fizzles. Something earlier in the
|
|
1157
|
+
round caused the failure. For example, the group a wand was aimed at left the battle.
|
|
1158
|
+
|
|
1159
|
+
A potion that one member gives another to drink fizzles with the code `magic.potion.fizzled` when the drinker
|
|
1160
|
+
died or turned to stone, or the two members no longer stand within 5' of each other. A potion the carrier
|
|
1161
|
+
drinks never fizzles. A `give_item` hand-over fizzles with the code `battle.give.fizzled` when the recipient
|
|
1162
|
+
can no longer act, or the two members no longer stand within 5' of each other. Either event has the item in
|
|
1163
|
+
`item_id` and the member it was for in `target_id`.
|
|
1158
1164
|
|
|
1159
1165
|
A melee attack fizzles when the party's melee step comes and the attack has nothing left to strike, or the
|
|
1160
1166
|
member stands in the wrong place. The session judges a melee attack before the round starts, as if every move the
|
|
@@ -1174,40 +1180,57 @@ class DeclarationFizzledEvent(Event):
|
|
|
1174
1180
|
strike's group ran out of the battle, or a quicker member killed the last monster in it that the member could
|
|
1175
1181
|
see.
|
|
1176
1182
|
|
|
1177
|
-
The event's `actor_id` is the member who declared the action, `item_id` is the device,
|
|
1178
|
-
|
|
1183
|
+
The event's `actor_id` is the member who declared the action, `item_id` is the device, the potion, or the item
|
|
1184
|
+
handed over, `target_id` is the member a potion or a hand-over was for, `group_id` is the group a melee attack
|
|
1185
|
+
was aimed at, and `reason` is the rejection code of the check that failed.
|
|
1179
1186
|
|
|
1180
|
-
A fizzled declaration spends nothing. The device wasn't used, so it keeps its charge and isn't
|
|
1181
|
-
the player the action failed, and that the device still has its charge. A
|
|
1182
|
-
|
|
1183
|
-
the
|
|
1184
|
-
|
|
1187
|
+
A fizzled declaration spends nothing and draws nothing. The device wasn't used, so it keeps its charge and isn't
|
|
1188
|
+
identified. Tell the player the action failed, and that the device still has its charge. A potion that fizzles
|
|
1189
|
+
stays with the member who carries it and isn't identified, and an item that wasn't handed over stays with the
|
|
1190
|
+
giver. A fizzled melee attack makes no attack roll, so tell the player why the member didn't swing. When a cast
|
|
1191
|
+
or a scroll read fizzles, the session reports a [`SpellDisruptedEvent`][osrlib.core.events.SpellDisruptedEvent]
|
|
1192
|
+
instead, because the spell is lost.
|
|
1185
1193
|
"""
|
|
1186
1194
|
|
|
1187
1195
|
allowed_codes: ClassVar[frozenset[str]] = frozenset(
|
|
1188
|
-
{
|
|
1196
|
+
{
|
|
1197
|
+
"magic.device.fizzled",
|
|
1198
|
+
"magic.potion.fizzled",
|
|
1199
|
+
"magic.turning.fizzled",
|
|
1200
|
+
"battle.give.fizzled",
|
|
1201
|
+
"battle.melee.fizzled",
|
|
1202
|
+
}
|
|
1189
1203
|
)
|
|
1190
|
-
"""The
|
|
1191
|
-
turning,
|
|
1204
|
+
"""The five codes: `magic.device.fizzled` for a wand, staff, or rod use, `magic.potion.fizzled` for a potion
|
|
1205
|
+
given to another member, `magic.turning.fizzled` for a turning, `battle.give.fizzled` for a hand-over, and
|
|
1206
|
+
`battle.melee.fizzled` for a melee attack."""
|
|
1192
1207
|
|
|
1193
1208
|
event_type: Literal["declaration_fizzled"] = "declaration_fizzled"
|
|
1194
1209
|
"""The fixed string that identifies this event class in a serialized event."""
|
|
1195
1210
|
|
|
1196
1211
|
code: str
|
|
1197
|
-
"""Which declaration fizzled: `magic.device.fizzled`, `magic.
|
|
1212
|
+
"""Which declaration fizzled: `magic.device.fizzled`, `magic.potion.fizzled`, `magic.turning.fizzled`,
|
|
1213
|
+
`battle.give.fizzled`, or `battle.melee.fizzled`."""
|
|
1198
1214
|
|
|
1199
1215
|
visibility: Visibility = Visibility.PLAYER
|
|
1200
1216
|
"""Player visibility: everyone sees the action fail."""
|
|
1201
1217
|
|
|
1202
1218
|
actor_id: str
|
|
1203
|
-
"""The entity id of the member who declared the device use, the turning, or the
|
|
1219
|
+
"""The entity id of the member who declared the device use, the potion, the hand-over, the turning, or the
|
|
1220
|
+
melee attack."""
|
|
1204
1221
|
|
|
1205
1222
|
item_id: str | None = None
|
|
1206
|
-
"""
|
|
1223
|
+
"""The item the declaration's `item_id` gave, on a `magic.device.fizzled`, a `magic.potion.fizzled`, or a
|
|
1224
|
+
`battle.give.fizzled` event: a device's or a potion's instance id, or the id of the item a hand-over moves.
|
|
1207
1225
|
|
|
1208
|
-
The player already used this id, so it reveals nothing about
|
|
1226
|
+
The player already used this id, so it reveals nothing about an item that isn't identified. It's `None` on a
|
|
1209
1227
|
`magic.turning.fizzled` or a `battle.melee.fizzled` event."""
|
|
1210
1228
|
|
|
1229
|
+
target_id: str | None = None
|
|
1230
|
+
"""On a `magic.potion.fizzled` or a `battle.give.fizzled` event, the id of the member the potion or the item
|
|
1231
|
+
was for, the one id in the declaration's `targets`. It's `None` on the other codes, and on an event from a log
|
|
1232
|
+
written before the field existed."""
|
|
1233
|
+
|
|
1211
1234
|
group_id: str | None = None
|
|
1212
1235
|
"""On a `battle.melee.fizzled` event, the id of the group the melee attack was aimed at, as the declaration's
|
|
1213
1236
|
`target_group_id` gave it. It's `None` on the other codes."""
|
|
@@ -1229,6 +1252,13 @@ class DeclarationFizzledEvent(Event):
|
|
|
1229
1252
|
the member can see is left in the group a melee attack was aimed at, for example because the party's missiles
|
|
1230
1253
|
or spells killed them earlier in the round. A melee attack gets this code wherever the member stands, whether
|
|
1231
1254
|
or not the member closed, because the session checks for a target before it checks the member's position.
|
|
1255
|
+
- `items.use.target_cannot_drink`: the member a potion was for died or turned to stone earlier in the round.
|
|
1256
|
+
- `session.command.member_incapacitated`: the member a hand-over was for can no longer act, for example
|
|
1257
|
+
because the member died or fell asleep earlier in the round.
|
|
1258
|
+
- `battle.declaration.member_out_of_reach`: the two members of a potion, a hand-over, or a staff of healing's
|
|
1259
|
+
touch no longer stand within 5' of each other.
|
|
1260
|
+
- `items.use.target_cannot_be_healed` and `items.use.target_healed_today`: the creature a staff of healing
|
|
1261
|
+
was to touch died or turned to stone, or the staff already healed it today.
|
|
1232
1262
|
|
|
1233
1263
|
Match on it as you match on the code of a [`Rejection`][osrlib.core.validation.Rejection].
|
|
1234
1264
|
[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
|
|
263
|
-
|
|
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)
|
|
@@ -1571,8 +1571,8 @@ class MagicItemCatalog(_Model):
|
|
|
1571
1571
|
[`ScrollSpellLevelTable`][osrlib.core.items.ScrollSpellLevelTable].
|
|
1572
1572
|
"""
|
|
1573
1573
|
sentient_swords: SentientSwordTables
|
|
1574
|
-
"""The tables for rolling up a sentient sword.
|
|
1575
|
-
"""
|
|
1574
|
+
"""The tables for rolling up a sentient sword.
|
|
1575
|
+
See [`SentientSwordTables`][osrlib.core.items.SentientSwordTables]."""
|
|
1576
1576
|
|
|
1577
1577
|
@model_validator(mode="after")
|
|
1578
1578
|
def _ids_unique_and_rows_resolve(self) -> MagicItemCatalog:
|
|
@@ -1694,8 +1694,8 @@ class SwordSentience(_Model):
|
|
|
1694
1694
|
extraordinary_powers: tuple[str, ...] = ()
|
|
1695
1695
|
"""The ids of its extraordinary powers, the ones that do things. Look them up the same way."""
|
|
1696
1696
|
special_purpose: str | None = None
|
|
1697
|
-
"""What the sword was made to do, for example `"chaotic_creatures"`, or `None` for a sword with no special
|
|
1698
|
-
"""
|
|
1697
|
+
"""What the sword was made to do, for example `"chaotic_creatures"`, or `None` for a sword with no special
|
|
1698
|
+
purpose."""
|
|
1699
1699
|
|
|
1700
1700
|
|
|
1701
1701
|
class MagicItemInstance(_Model):
|
|
@@ -1900,8 +1900,8 @@ class GeneratedTreasure(_Model):
|
|
|
1900
1900
|
valuables: tuple[ValuableInstance, ...] = ()
|
|
1901
1901
|
"""The gems and jewellery. See [`ValuableInstance`][osrlib.core.items.ValuableInstance]."""
|
|
1902
1902
|
magic_items: tuple[MagicItemInstance, ...] = ()
|
|
1903
|
-
"""The magic items, already rolled up as instances.
|
|
1904
|
-
"""
|
|
1903
|
+
"""The magic items, already rolled up as instances.
|
|
1904
|
+
See [`MagicItemInstance`][osrlib.core.items.MagicItemInstance]."""
|
|
1905
1905
|
|
|
1906
1906
|
|
|
1907
1907
|
class CoinPurse(_Model):
|
|
@@ -2083,8 +2083,8 @@ class Inventory(_Model):
|
|
|
2083
2083
|
model_config = ConfigDict(validate_assignment=True)
|
|
2084
2084
|
|
|
2085
2085
|
items: list[AnyInstance] = []
|
|
2086
|
-
"""What is carried but not in use, in the order it was acquired.
|
|
2087
|
-
"""
|
|
2086
|
+
"""What is carried but not in use, in the order it was acquired.
|
|
2087
|
+
See [`AnyInstance`][osrlib.core.items.AnyInstance]."""
|
|
2088
2088
|
purse: CoinPurse = CoinPurse()
|
|
2089
2089
|
"""The coins. See [`CoinPurse`][osrlib.core.items.CoinPurse]."""
|
|
2090
2090
|
valuables: list[ValuableInstance] = []
|
|
@@ -842,7 +842,10 @@ class MonsterTemplate(_Model):
|
|
|
842
842
|
[`MonsterCatalog.family`][osrlib.core.monsters.MonsterCatalog.family] to get every form.
|
|
843
843
|
|
|
844
844
|
A creature with one form is a family of one, and its family id is its `id`. A template you write that
|
|
845
|
-
leaves this out gets its `id` too.
|
|
845
|
+
leaves this out gets its `id` too. The player view shows the family id to the players, so a template
|
|
846
|
+
that disguises one creature as another, like a doppelganger the players see as a goblin, sets this to
|
|
847
|
+
the family the players should see, `"goblin"`. The players also see the template's `display_name`
|
|
848
|
+
and its `categories`.
|
|
846
849
|
"""
|
|
847
850
|
|
|
848
851
|
page: str
|
|
@@ -879,8 +882,8 @@ class MonsterTemplate(_Model):
|
|
|
879
882
|
"""The dice its hit points are rolled on. See [`MonsterHitDice`][osrlib.core.monsters.MonsterHitDice]."""
|
|
880
883
|
|
|
881
884
|
attacks: tuple[AttackRoutine, ...] = ()
|
|
882
|
-
"""The sets of attacks it can make, one set per round.
|
|
883
|
-
"""
|
|
885
|
+
"""The sets of attacks it can make, one set per round.
|
|
886
|
+
See [`AttackRoutine`][osrlib.core.monsters.AttackRoutine]."""
|
|
884
887
|
|
|
885
888
|
thac0: int = Field(ge=2, le=20)
|
|
886
889
|
"""Its THAC0 ("to hit armour class 0"): the d20 roll it needs to hit armour class 0 under descending armour class.
|
|
@@ -941,6 +944,9 @@ class MonsterTemplate(_Model):
|
|
|
941
944
|
|
|
942
945
|
Spells and turning check these. *Hold person* affects a monster only when it has `"person"`, and
|
|
943
946
|
turning affects only `"undead"`.
|
|
947
|
+
|
|
948
|
+
The player view shows them to the players, in
|
|
949
|
+
[`EncounterGroupView.categories`][osrlib.crawl.views.EncounterGroupView.categories].
|
|
944
950
|
"""
|
|
945
951
|
|
|
946
952
|
overrides_applied: tuple[str, ...] = ()
|
|
@@ -74,7 +74,7 @@ from pydantic import ConfigDict
|
|
|
74
74
|
|
|
75
75
|
from osrlib.core.abilities import AbilityScore
|
|
76
76
|
from osrlib.core.alignment import Alignment
|
|
77
|
-
from osrlib.core.character import Character, roll_ability_scores
|
|
77
|
+
from osrlib.core.character import Character, _armour_as_tested, roll_ability_scores
|
|
78
78
|
from osrlib.core.classes import ClassDefinition, level_up
|
|
79
79
|
from osrlib.core.dice import roll
|
|
80
80
|
from osrlib.core.frozen import _Model
|
|
@@ -281,9 +281,11 @@ def _item_usable(member: Character, definition: ClassDefinition, instance: Magic
|
|
|
281
281
|
def _maybe_equip_upgrade(member: Character, definition: ClassDefinition, instance: MagicItemInstance) -> None:
|
|
282
282
|
"""Equip a rolled weapon or piece of armour when it beats the one from the kit.
|
|
283
283
|
|
|
284
|
-
Better means a
|
|
285
|
-
mundane weapon.
|
|
286
|
-
|
|
284
|
+
Better means a lower armour class for armour and shields, or any enchantment at all over a
|
|
285
|
+
mundane weapon. An NPC knows no more than a player does, so it compares the armour class that
|
|
286
|
+
every test shows, which `osrlib.core.character._armour_as_tested` returns. A cursed shield or
|
|
287
|
+
suit tests as though it were a +1, which is what it appears to be, so the NPC equips it wherever
|
|
288
|
+
it would equip that +1, and the curse comes out in play.
|
|
287
289
|
"""
|
|
288
290
|
template = magic_item_template(instance)
|
|
289
291
|
inventory = member.inventory
|
|
@@ -294,13 +296,13 @@ def _maybe_equip_upgrade(member: Character, definition: ClassDefinition, instanc
|
|
|
294
296
|
return
|
|
295
297
|
if template.category != "armour":
|
|
296
298
|
return
|
|
297
|
-
before = member.armour_class
|
|
299
|
+
before = _armour_as_tested(member).armour_class
|
|
298
300
|
slot = "shield" if (instance.base_item_id or template.base_item_id) == "shield" else "worn_armour"
|
|
299
301
|
previous = getattr(inventory, slot)
|
|
300
302
|
if validate_equip(definition, instance, inventory):
|
|
301
303
|
return
|
|
302
304
|
equip(inventory, definition, instance)
|
|
303
|
-
if member.armour_class >= before:
|
|
305
|
+
if _armour_as_tested(member).armour_class >= before:
|
|
304
306
|
# Not better: put things back the way they were.
|
|
305
307
|
from osrlib.core.items import unequip
|
|
306
308
|
|
|
@@ -275,3 +275,21 @@ class Ruleset(_Model):
|
|
|
275
275
|
party can, and the trap still gets its 2-in-6 chance to spring when someone takes the
|
|
276
276
|
treasure.
|
|
277
277
|
"""
|
|
278
|
+
|
|
279
|
+
back_stab_needs_both_skills: bool = True
|
|
280
|
+
"""Require both of a hiding thief's skill rolls for a back-stab. An adaptation, on by default.
|
|
281
|
+
|
|
282
|
+
A thief can hide during a battle with a `hide` declaration and then back-stab from hiding, as
|
|
283
|
+
[`BattleDeclaration.back_stab`][osrlib.crawl.commands.BattleDeclaration.back_stab] describes.
|
|
284
|
+
The session rolls the thief's hide in shadows skill when the hide resolves, and move silently
|
|
285
|
+
when the back-stab comes up. With the flag on, the attack is a back-stab only when both rolls
|
|
286
|
+
passed. Turn it off and either roll passing is enough. The session makes both rolls under
|
|
287
|
+
either setting, so the flag changes no draw. The monsters' choice of targets reads the hide in
|
|
288
|
+
shadows roll alone under either setting.
|
|
289
|
+
|
|
290
|
+
The SRD says hide in shadows "Requires the thief to be motionless—attacking or moving while
|
|
291
|
+
hiding is not possible", and that with move silently "A thief may attempt to sneak past
|
|
292
|
+
enemies unnoticed". Neither setting is the rules as written.
|
|
293
|
+
[The adaptations register](https://mmacy.github.io/osrlib-python/adaptations/) has the
|
|
294
|
+
reasoning.
|
|
295
|
+
"""
|
|
@@ -839,16 +839,17 @@ class NpcPartyComposition(_Model):
|
|
|
839
839
|
roll its `count_dice` with [`roll`][osrlib.core.dice.roll], and pass the total as `count`
|
|
840
840
|
to [`generate_npc_party`][osrlib.core.npc.generate_npc_party].
|
|
841
841
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
842
|
+
Examples:
|
|
843
|
+
```python
|
|
844
|
+
from osrlib.core.dice import roll
|
|
845
|
+
from osrlib.core.rng import RngStreams
|
|
846
|
+
from osrlib.data import load_encounter_tables
|
|
847
|
+
|
|
848
|
+
stream = RngStreams(master_seed=3).get("encounter")
|
|
849
|
+
composition = next(entry for entry in load_encounter_tables().npc_compositions if entry.kind == "basic")
|
|
850
|
+
size = roll(composition.count_dice, stream).total
|
|
851
|
+
assert 5 <= size <= 8
|
|
852
|
+
```
|
|
852
853
|
"""
|
|
853
854
|
|
|
854
855
|
model_config = ConfigDict(frozen=True)
|
|
@@ -429,6 +429,7 @@ def _distribute_haul(session, carriers, haul: DropPile) -> tuple[list[Event], Dr
|
|
|
429
429
|
character_id=member.id,
|
|
430
430
|
item_ids=tuple(taken_ids[index]),
|
|
431
431
|
coins_gp_value=taken_coins.value_gp,
|
|
432
|
+
coins=taken_coins,
|
|
432
433
|
origin="treasure",
|
|
433
434
|
)
|
|
434
435
|
)
|
|
@@ -475,7 +476,7 @@ def _leave_behind(session, leftovers: DropPile) -> list[Event]:
|
|
|
475
476
|
if not (leftovers.items or leftovers.valuables or leftovers.magic_items or leftovers.coins.total_coins):
|
|
476
477
|
return []
|
|
477
478
|
item_ids = _add_to_pile(session, leftovers)
|
|
478
|
-
return [ItemsLeftBehindEvent(item_ids=item_ids, coins_gp_value=leftovers.coins.value_gp)]
|
|
479
|
+
return [ItemsLeftBehindEvent(item_ids=item_ids, coins_gp_value=leftovers.coins.value_gp, coins=leftovers.coins)]
|
|
479
480
|
|
|
480
481
|
|
|
481
482
|
def _take_haul(session, carriers, haul: DropPile) -> list[Event]:
|
|
@@ -129,6 +129,7 @@ def _apply_give(session, giver, recipient, item_ids: tuple[str, ...], coins: Coi
|
|
|
129
129
|
recipient_id=recipient.id,
|
|
130
130
|
item_ids=tuple(item_ids),
|
|
131
131
|
coins_gp_value=coins.value_gp,
|
|
132
|
+
coins=coins,
|
|
132
133
|
)
|
|
133
134
|
)
|
|
134
135
|
return events
|
|
@@ -163,7 +164,10 @@ def _apply_drop(session, member, command: DropItems, *, to_pile: bool) -> list[E
|
|
|
163
164
|
_add_to_pile(session, goods)
|
|
164
165
|
return [
|
|
165
166
|
ItemsDroppedEvent(
|
|
166
|
-
character_id=member.id,
|
|
167
|
+
character_id=member.id,
|
|
168
|
+
item_ids=tuple(command.item_ids),
|
|
169
|
+
coins_gp_value=command.coins.value_gp,
|
|
170
|
+
coins=command.coins,
|
|
167
171
|
)
|
|
168
172
|
]
|
|
169
173
|
|