osrlib 2.8.0__tar.gz → 2.9.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.8.0 → osrlib-2.9.0}/PKG-INFO +1 -1
- {osrlib-2.8.0 → osrlib-2.9.0}/pyproject.toml +1 -1
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/character.py +179 -25
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/ruleset.py +42 -10
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/spells.py +72 -8
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/treasure.py +8 -3
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_spells.py +38 -2
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/views.py +106 -8
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/spells.json +164 -15
- {osrlib-2.8.0 → osrlib-2.9.0}/LICENSE +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/LICENSE-OGL.md +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/README.md +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/__init__.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/__init__.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/_descriptions.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/abilities.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/alignment.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/classes.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/clock.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/combat.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/creature.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/dice.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/effects.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/events.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/frozen.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/items.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/monsters.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/npc.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/rng.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/tables.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/core/validation.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/__init__.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_arrival.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_doors.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_feature_handles.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_gating.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_hauling.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_items.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_light.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_magic_items.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_movement.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_odometer.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_party_location.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_party_members.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_search.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_town.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/_treasure.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/adventure.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/battle.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/commands.py +1 -1
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/content_pack.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/dungeon.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/encounter.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/events.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/exploration.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/gates.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/interpreter.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/narrative.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/party.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/quests.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/session.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/stocking.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/crawl/triggers.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/LICENSE-OGL.md +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/__init__.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/abilities.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/classes.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/combat_tables.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/encounter_tables.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/equipment.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/languages.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/magic_items.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/monsters.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/data/treasure.json +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/errors.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/messages.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/persistence.py +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/py.typed +0 -0
- {osrlib-2.8.0 → osrlib-2.9.0}/src/osrlib/versioning.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "osrlib"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.9.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
|
|
@@ -20,6 +20,8 @@ To create a character one step at a time while a player makes the choices, call
|
|
|
20
20
|
in the order the SRD gives for creating a character:
|
|
21
21
|
|
|
22
22
|
1. [`roll_ability_scores`][osrlib.core.character.roll_ability_scores] rolls the six ability scores.
|
|
23
|
+
The roll's [`sub_par`][osrlib.core.character.AbilityScoreRolls.sub_par] says whether they are sub-par,
|
|
24
|
+
so that a referee may let the player discard the character and start again.
|
|
23
25
|
2. [`validate_class_choice`][osrlib.core.character.validate_class_choice] checks the scores against
|
|
24
26
|
the class the player picks.
|
|
25
27
|
3. [`validate_adjustment`][osrlib.core.abilities.validate_adjustment] and
|
|
@@ -86,9 +88,9 @@ print(party.members[0].name, party.members[0].max_hp, party.members[0].armour_cl
|
|
|
86
88
|
"""
|
|
87
89
|
|
|
88
90
|
from collections.abc import Mapping, Sequence
|
|
89
|
-
from typing import Final
|
|
91
|
+
from typing import Final, Literal
|
|
90
92
|
|
|
91
|
-
from pydantic import ConfigDict, Field, field_validator, model_validator
|
|
93
|
+
from pydantic import ConfigDict, Field, computed_field, field_validator, model_validator
|
|
92
94
|
|
|
93
95
|
from osrlib.core.abilities import (
|
|
94
96
|
AbilityAdjustment,
|
|
@@ -140,6 +142,7 @@ __all__ = [
|
|
|
140
142
|
"roll_ability_scores",
|
|
141
143
|
"roll_hit_points",
|
|
142
144
|
"roll_starting_gold",
|
|
145
|
+
"scores_are_sub_par",
|
|
143
146
|
"validate_class_choice",
|
|
144
147
|
"validate_extra_languages",
|
|
145
148
|
"validate_starting_spells",
|
|
@@ -972,18 +975,61 @@ class AbilityScoreRolls(_Model):
|
|
|
972
975
|
|
|
973
976
|
[`roll_ability_scores`][osrlib.core.character.roll_ability_scores] returns one, and
|
|
974
977
|
[`create_character`][osrlib.core.character.create_character] includes one in its result. Pass
|
|
975
|
-
`scores` to [`validate_class_choice`][osrlib.core.character.validate_class_choice]
|
|
978
|
+
`scores` to [`validate_class_choice`][osrlib.core.character.validate_class_choice], and read
|
|
979
|
+
`sub_par` to find out whether a referee may let the player start again. Frozen.
|
|
976
980
|
"""
|
|
977
981
|
|
|
978
982
|
model_config = ConfigDict(frozen=True)
|
|
979
983
|
|
|
980
984
|
scores: dict[AbilityScore, int]
|
|
981
|
-
"""The total of each ability's three dice, keyed by [`AbilityScore`][osrlib.core.abilities.AbilityScore].
|
|
982
|
-
abilities are present, each from 3 to 18.
|
|
985
|
+
"""The total of each ability's three counted dice, keyed by [`AbilityScore`][osrlib.core.abilities.AbilityScore].
|
|
986
|
+
All six abilities are present, each from 3 to 18.
|
|
983
987
|
"""
|
|
984
988
|
|
|
985
989
|
rolls: dict[AbilityScore, tuple[int, int, int]]
|
|
986
|
-
"""The three d6 results
|
|
990
|
+
"""The three d6 results that count towards each score, keyed the same way, in the order they were thrown.
|
|
991
|
+
|
|
992
|
+
Each score is the sum of its three dice. With the `"4d6_drop_lowest"` method, the die dropped
|
|
993
|
+
from an ability's four is in `dropped` instead, and the other three keep their order here.
|
|
994
|
+
"""
|
|
995
|
+
|
|
996
|
+
dropped: dict[AbilityScore, int] = {}
|
|
997
|
+
"""The die that didn't count towards each score, keyed the same way.
|
|
998
|
+
|
|
999
|
+
A `"4d6_drop_lowest"` roll has an entry for all six abilities: the lowest of the four dice, or the
|
|
1000
|
+
first of them thrown when two or more tie for lowest. A `"3d6"` roll drops nothing, so this is
|
|
1001
|
+
empty, and so is a roll that osrlib 2.8.0 or earlier recorded. Read an ability with no entry as one
|
|
1002
|
+
with no die dropped. To show all four dice of an ability, show its three `rolls` and this die.
|
|
1003
|
+
"""
|
|
1004
|
+
|
|
1005
|
+
@field_validator("scores")
|
|
1006
|
+
@classmethod
|
|
1007
|
+
def _all_six_scores_in_range(cls, value: dict[AbilityScore, int]) -> dict[AbilityScore, int]:
|
|
1008
|
+
_check_scores(value)
|
|
1009
|
+
return value
|
|
1010
|
+
|
|
1011
|
+
@computed_field
|
|
1012
|
+
@property
|
|
1013
|
+
def sub_par(self) -> bool:
|
|
1014
|
+
"""Whether `scores` are sub-par, so that a referee may let the player discard the character and start again.
|
|
1015
|
+
|
|
1016
|
+
The SRD's "Sub-Par Characters" rule says: "If you roll a character with very poor ability scores—for example an
|
|
1017
|
+
8 or less in every score or an extremely low rating in more than one ability—the referee may allow you to
|
|
1018
|
+
discard the character and start again." It's true when every score is 8 or less, or when two or more scores
|
|
1019
|
+
are 5 or less, as [`scores_are_sub_par`][osrlib.core.character.scores_are_sub_par] decides.
|
|
1020
|
+
|
|
1021
|
+
The value is computed from `scores` each time you read it, so it's right for a roll that osrlib 2.8.0 or
|
|
1022
|
+
earlier recorded too. It's in `model_dump()` and in the JSON, so a client that receives the roll as a document
|
|
1023
|
+
can read it there. When you parse a document, a `sub_par` key in it is ignored.
|
|
1024
|
+
|
|
1025
|
+
It answers for the scores as rolled, before the adjustment step, so the `ability_rolls` of a
|
|
1026
|
+
[`CharacterCreationResult`][osrlib.core.character.CharacterCreationResult] says whether the character was
|
|
1027
|
+
sub-par as rolled, whatever the adjustment changed afterwards. With the `"4d6_drop_lowest"` method, it's
|
|
1028
|
+
decided by the three dice that count. osrlib only reports it. Whether the referee allows the discard is your
|
|
1029
|
+
game's choice, so [`Ruleset`][osrlib.core.ruleset.Ruleset] has no flag for it, and
|
|
1030
|
+
[`create_character`][osrlib.core.character.create_character] never refuses or rerolls sub-par scores.
|
|
1031
|
+
"""
|
|
1032
|
+
return scores_are_sub_par(self.scores)
|
|
987
1033
|
|
|
988
1034
|
|
|
989
1035
|
class HitPointRoll(_Model):
|
|
@@ -1000,11 +1046,23 @@ class HitPointRoll(_Model):
|
|
|
1000
1046
|
"""Every die result, before the CON modifier, in the order thrown.
|
|
1001
1047
|
|
|
1002
1048
|
With the `hp_reroll_at_first_level` option of [`Ruleset`][osrlib.core.ruleset.Ruleset] on, the 1s and 2s that were
|
|
1003
|
-
thrown again are here too, and the last entry is the die that counts. Otherwise there's one entry.
|
|
1049
|
+
thrown again are here too, and the last entry is the die that counts. Otherwise there's one entry. The
|
|
1050
|
+
`max_hp_at_first_level` option doesn't change what's thrown, so with both options on, the 1s and 2s set aside and
|
|
1051
|
+
the last die are all here, and `maximized` says the hit points come from the die's size instead.
|
|
1004
1052
|
"""
|
|
1005
1053
|
|
|
1006
1054
|
hit_points: int = Field(ge=1)
|
|
1007
|
-
"""The hit points the character starts with
|
|
1055
|
+
"""The hit points the character starts with, and at least 1.
|
|
1056
|
+
|
|
1057
|
+
They're the last die plus the CON modifier, or with `maximized` true, the hit die's size plus the CON modifier.
|
|
1058
|
+
"""
|
|
1059
|
+
|
|
1060
|
+
maximized: bool = False
|
|
1061
|
+
"""Whether the hit die counted as its maximum, because `max_hp_at_first_level` was on in the ruleset.
|
|
1062
|
+
|
|
1063
|
+
When it's true, `hit_points` is the die's size plus the CON modifier, whatever the last entry of `rolls` shows, so
|
|
1064
|
+
a client can say why. It's false for a roll that osrlib 2.8.0 or earlier recorded.
|
|
1065
|
+
"""
|
|
1008
1066
|
|
|
1009
1067
|
|
|
1010
1068
|
class CharacterCreationResult(_Model):
|
|
@@ -1035,8 +1093,8 @@ class CharacterCreationResult(_Model):
|
|
|
1035
1093
|
"""
|
|
1036
1094
|
|
|
1037
1095
|
|
|
1038
|
-
def roll_ability_scores(stream: RngStream) -> AbilityScoreRolls:
|
|
1039
|
-
"""Roll
|
|
1096
|
+
def roll_ability_scores(stream: RngStream, *, method: Literal["3d6", "4d6_drop_lowest"] = "3d6") -> AbilityScoreRolls:
|
|
1097
|
+
"""Roll the six ability scores, in the SRD's order: STR, INT, WIS, DEX, CON, CHA.
|
|
1040
1098
|
|
|
1041
1099
|
This is the first step of creating a character one step at a time. Show the result to the
|
|
1042
1100
|
player, then pass the scores to
|
|
@@ -1046,16 +1104,31 @@ def roll_ability_scores(stream: RngStream) -> AbilityScoreRolls:
|
|
|
1046
1104
|
and apply it with [`apply_adjustment`][osrlib.core.abilities.apply_adjustment].
|
|
1047
1105
|
|
|
1048
1106
|
Call [`create_character`][osrlib.core.character.create_character] instead when the choices are
|
|
1049
|
-
already known and you want only the finished character.
|
|
1107
|
+
already known and you want only the finished character. It passes the `ability_score_method` of
|
|
1108
|
+
its ruleset as `method`.
|
|
1050
1109
|
|
|
1051
|
-
|
|
1110
|
+
With `"3d6"`, the SRD's method, each ability throws three d6 and the score is their sum. With
|
|
1111
|
+
`"4d6_drop_lowest"`, a house rule that the SRD doesn't print, each ability throws four d6 and the
|
|
1112
|
+
lowest one doesn't count. When two or more of the four tie for lowest, the first of them thrown is
|
|
1113
|
+
the one dropped. The result's `rolls` keeps the three dice that count, in the order thrown, and
|
|
1114
|
+
`dropped` has the one that doesn't.
|
|
1115
|
+
|
|
1116
|
+
The same stream at the same position and the same method always give the same six scores.
|
|
1052
1117
|
|
|
1053
1118
|
Args:
|
|
1054
1119
|
stream: The stream to draw from, usually `streams.get(CHARACTER_CREATION_STREAM)`. It
|
|
1055
|
-
advances by 18 dice
|
|
1120
|
+
advances by 18 dice with `"3d6"` and by 24 with `"4d6_drop_lowest"`, all of them for
|
|
1121
|
+
STR before any for INT, and so on.
|
|
1122
|
+
method: How to roll each score: `"3d6"` or `"4d6_drop_lowest"`. Store it beside a seed if
|
|
1123
|
+
you roll the same scores again later, because the two methods give different scores from
|
|
1124
|
+
the same stream.
|
|
1056
1125
|
|
|
1057
1126
|
Returns:
|
|
1058
|
-
The six scores
|
|
1127
|
+
The six scores, the three dice that count towards each, and any die dropped.
|
|
1128
|
+
|
|
1129
|
+
Raises:
|
|
1130
|
+
ValueError: If `method` is neither `"3d6"` nor `"4d6_drop_lowest"`. The function checks it
|
|
1131
|
+
before the first draw, so the stream doesn't advance.
|
|
1059
1132
|
|
|
1060
1133
|
Examples:
|
|
1061
1134
|
```python
|
|
@@ -1068,13 +1141,79 @@ def roll_ability_scores(stream: RngStream) -> AbilityScoreRolls:
|
|
|
1068
1141
|
# {'str': 14, 'int': 6, 'wis': 9, 'dex': 10, 'con': 11, 'cha': 11}
|
|
1069
1142
|
```
|
|
1070
1143
|
"""
|
|
1144
|
+
if method not in ("3d6", "4d6_drop_lowest"):
|
|
1145
|
+
raise ValueError(f"unknown ability score method {method!r}: use '3d6' or '4d6_drop_lowest'")
|
|
1071
1146
|
scores: dict[AbilityScore, int] = {}
|
|
1072
1147
|
rolls: dict[AbilityScore, tuple[int, int, int]] = {}
|
|
1148
|
+
dropped: dict[AbilityScore, int] = {}
|
|
1073
1149
|
for ability in ABILITY_ROLL_ORDER:
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1150
|
+
if method == "3d6":
|
|
1151
|
+
thrown = list(roll("3d6", stream).rolls)
|
|
1152
|
+
else:
|
|
1153
|
+
thrown = list(roll("4d6", stream).rolls)
|
|
1154
|
+
# `index` finds the first of the lowest dice thrown, so a tie drops the earliest one.
|
|
1155
|
+
dropped[ability] = thrown.pop(thrown.index(min(thrown)))
|
|
1156
|
+
scores[ability] = sum(thrown)
|
|
1157
|
+
rolls[ability] = (thrown[0], thrown[1], thrown[2])
|
|
1158
|
+
return AbilityScoreRolls(scores=scores, rolls=rolls, dropped=dropped)
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
def scores_are_sub_par(scores: Mapping[AbilityScore, int]) -> bool:
|
|
1162
|
+
"""Say whether a set of ability scores as rolled is sub-par, so that a referee may let the player start again.
|
|
1163
|
+
|
|
1164
|
+
The SRD's "Sub-Par Characters" rule says: "If you roll a character with very poor ability scores—for example an
|
|
1165
|
+
8 or less in every score or an extremely low rating in more than one ability—the referee may allow you to
|
|
1166
|
+
discard the character and start again." osrlib reads it as two tests, and the scores are sub-par when either
|
|
1167
|
+
one holds:
|
|
1168
|
+
|
|
1169
|
+
- Every score is 8 or less, the SRD's own example.
|
|
1170
|
+
- Two or more scores are 5 or less. The SRD leaves "an extremely low rating" to the referee, so osrlib fixes it
|
|
1171
|
+
at 5 or less. Every ability's table in the SRD has a row boundary between 6 and 5: at 5 or less, STR's melee
|
|
1172
|
+
adjustment, WIS's and CON's, and DEX's armour class and missile adjustments are -2 or worse, INT leaves the
|
|
1173
|
+
character illiterate, CHA allows fewer retainers with lower loyalty, and a prime requisite costs 20% of the
|
|
1174
|
+
experience instead of 10%.
|
|
1175
|
+
|
|
1176
|
+
Pass the scores as rolled, before any adjustment, which are the `scores` of the
|
|
1177
|
+
[`AbilityScoreRolls`][osrlib.core.character.AbilityScoreRolls] that
|
|
1178
|
+
[`roll_ability_scores`][osrlib.core.character.roll_ability_scores] returns. That roll's
|
|
1179
|
+
[`sub_par`][osrlib.core.character.AbilityScoreRolls.sub_par] gives the same answer, so you need this function
|
|
1180
|
+
only for scores you have on their own.
|
|
1181
|
+
|
|
1182
|
+
osrlib only reports the fact. Whether the referee allows the discard is your game's choice, so
|
|
1183
|
+
[`Ruleset`][osrlib.core.ruleset.Ruleset] has no flag for it, and
|
|
1184
|
+
[`create_character`][osrlib.core.character.create_character] never refuses or rerolls sub-par scores. To start
|
|
1185
|
+
again, roll new scores from the same stream, and the new roll continues where the last one stopped.
|
|
1186
|
+
|
|
1187
|
+
The function draws nothing and doesn't change `scores`.
|
|
1188
|
+
|
|
1189
|
+
Args:
|
|
1190
|
+
scores: The six scores, keyed by [`AbilityScore`][osrlib.core.abilities.AbilityScore], each from 3 to 18.
|
|
1191
|
+
|
|
1192
|
+
Returns:
|
|
1193
|
+
`True` when every score is 8 or less, or two or more are 5 or less, and `False` otherwise.
|
|
1194
|
+
|
|
1195
|
+
Raises:
|
|
1196
|
+
ValueError: If `scores` is missing one of the six abilities, or has a score below 3 or above 18.
|
|
1197
|
+
|
|
1198
|
+
Examples:
|
|
1199
|
+
```python
|
|
1200
|
+
from osrlib.core.abilities import AbilityScore
|
|
1201
|
+
from osrlib.core.character import scores_are_sub_par
|
|
1202
|
+
|
|
1203
|
+
scores = dict.fromkeys(AbilityScore, 12)
|
|
1204
|
+
scores[AbilityScore.STR] = 4
|
|
1205
|
+
print(scores_are_sub_par(scores))
|
|
1206
|
+
# False
|
|
1207
|
+
scores[AbilityScore.CHA] = 5
|
|
1208
|
+
print(scores_are_sub_par(scores))
|
|
1209
|
+
# True
|
|
1210
|
+
print(scores_are_sub_par(dict.fromkeys(AbilityScore, 8)))
|
|
1211
|
+
# True
|
|
1212
|
+
```
|
|
1213
|
+
"""
|
|
1214
|
+
_check_scores(dict(scores))
|
|
1215
|
+
values = [scores[ability] for ability in AbilityScore]
|
|
1216
|
+
return all(value <= 8 for value in values) or sum(value <= 5 for value in values) >= 2
|
|
1078
1217
|
|
|
1079
1218
|
|
|
1080
1219
|
def validate_class_choice(scores: dict[AbilityScore, int], definition: ClassDefinition) -> list[Rejection]:
|
|
@@ -1149,11 +1288,17 @@ def roll_hit_points(
|
|
|
1149
1288
|
again until it shows 3 or more. The test is on the die before the CON modifier, and the result
|
|
1150
1289
|
includes every throw.
|
|
1151
1290
|
|
|
1291
|
+
With `max_hp_at_first_level` on, a house rule that the SRD doesn't print, the hit points are the
|
|
1292
|
+
die's size plus the CON modifier, and at least 1, and the result's `maximized` is true. The
|
|
1293
|
+
function still throws exactly the dice it throws with the option off, so the stream ends in the
|
|
1294
|
+
same place, and `hp_reroll_at_first_level` changes only what `rolls` lists, never the hit points.
|
|
1295
|
+
|
|
1152
1296
|
Args:
|
|
1153
1297
|
definition: The character's class. Its first-level progression row gives the hit die.
|
|
1154
1298
|
con_modifier: The CON hit point modifier for the final scores. It may be negative, and the
|
|
1155
1299
|
hit points are at least 1 either way.
|
|
1156
|
-
ruleset: The ruleset in play, read for the `hp_reroll_at_first_level`
|
|
1300
|
+
ruleset: The ruleset in play, read for the `hp_reroll_at_first_level` and
|
|
1301
|
+
`max_hp_at_first_level` options.
|
|
1157
1302
|
stream: The stream to draw from, usually `streams.get(CHARACTER_CREATION_STREAM)`.
|
|
1158
1303
|
|
|
1159
1304
|
Returns:
|
|
@@ -1169,12 +1314,12 @@ def roll_hit_points(
|
|
|
1169
1314
|
fighter = load_classes().get("fighter")
|
|
1170
1315
|
stream = RngStreams(master_seed=7).get(CHARACTER_CREATION_STREAM)
|
|
1171
1316
|
print(roll_hit_points(fighter, 0, Ruleset(), stream))
|
|
1172
|
-
# rolls=(2,) hit_points=2
|
|
1317
|
+
# rolls=(2,) hit_points=2 maximized=False
|
|
1173
1318
|
|
|
1174
1319
|
rerolling = Ruleset(hp_reroll_at_first_level=True)
|
|
1175
1320
|
stream = RngStreams(master_seed=7).get(CHARACTER_CREATION_STREAM)
|
|
1176
1321
|
print(roll_hit_points(fighter, 0, rerolling, stream))
|
|
1177
|
-
# rolls=(2, 8) hit_points=8
|
|
1322
|
+
# rolls=(2, 8) hit_points=8 maximized=False
|
|
1178
1323
|
```
|
|
1179
1324
|
"""
|
|
1180
1325
|
die = definition.row(1).hit_dice.die
|
|
@@ -1182,7 +1327,14 @@ def roll_hit_points(
|
|
|
1182
1327
|
if ruleset.hp_reroll_at_first_level:
|
|
1183
1328
|
while rolls[-1] <= 2:
|
|
1184
1329
|
rolls.append(stream.randbelow(die) + 1)
|
|
1185
|
-
|
|
1330
|
+
# The maximum replaces only the counted value, after every die has been thrown, so the draws are
|
|
1331
|
+
# the same with the option on or off.
|
|
1332
|
+
counted = die if ruleset.max_hp_at_first_level else rolls[-1]
|
|
1333
|
+
return HitPointRoll(
|
|
1334
|
+
rolls=tuple(rolls),
|
|
1335
|
+
hit_points=max(1, counted + con_modifier),
|
|
1336
|
+
maximized=ruleset.max_hp_at_first_level,
|
|
1337
|
+
)
|
|
1186
1338
|
|
|
1187
1339
|
|
|
1188
1340
|
def validate_extra_languages(definition: ClassDefinition, int_score: int, choices: Sequence[str]) -> list[Rejection]:
|
|
@@ -1493,8 +1645,10 @@ def create_character(
|
|
|
1493
1645
|
index](https://mmacy.github.io/osrlib-python/reference/content-ids/classes/). For a class
|
|
1494
1646
|
you wrote, it's the `id` of `custom_class`.
|
|
1495
1647
|
alignment: Lawful, neutral, or chaotic.
|
|
1496
|
-
ruleset: The ruleset in play.
|
|
1497
|
-
showing 1 or 2 is thrown
|
|
1648
|
+
ruleset: The ruleset in play. Its `ability_score_method` sets how the scores are rolled.
|
|
1649
|
+
When its `hp_reroll_at_first_level` flag is on, a hit die showing 1 or 2 is thrown
|
|
1650
|
+
again. When its `max_hp_at_first_level` flag is on, the hit die counts as its maximum,
|
|
1651
|
+
and the dice thrown, and so the gold roll after them, stay the same.
|
|
1498
1652
|
stream: The stream for the creation draws, usually
|
|
1499
1653
|
`streams.get(`[`CHARACTER_CREATION_STREAM`][osrlib.core.character.CHARACTER_CREATION_STREAM]`)`.
|
|
1500
1654
|
custom_class: The definition of a class you wrote, or `None` to play a class osrlib
|
|
@@ -1594,7 +1748,7 @@ def create_character(
|
|
|
1594
1748
|
# `validate_purchase` refuses it.
|
|
1595
1749
|
covered = sum(template.cost_gp * lots for template, lots in bought if lots > 0)
|
|
1596
1750
|
_outfit(Inventory(purse=CoinPurse(gp=covered)), definition, bought, equip_ids)
|
|
1597
|
-
ability_rolls = roll_ability_scores(stream)
|
|
1751
|
+
ability_rolls = roll_ability_scores(stream, method=ruleset.ability_score_method)
|
|
1598
1752
|
choice_rejections = validate_class_choice(ability_rolls.scores, definition)
|
|
1599
1753
|
if choice_rejections:
|
|
1600
1754
|
raise ValueError(f"illegal class choice: {[rejection.code for rejection in choice_rejections]}")
|
|
@@ -8,14 +8,16 @@ uses one ruleset from start to finish. The rules functions read its flags on eve
|
|
|
8
8
|
call, so there's no setup step. A save contains the ruleset, so a loaded game uses the
|
|
9
9
|
rules it began with.
|
|
10
10
|
|
|
11
|
-
`Ruleset()` with no arguments gives you the SRD rules as written. Each flag is
|
|
12
|
-
|
|
13
|
-
its default procedure. An adaptation is a default osrlib chooses for a decision that
|
|
14
|
-
tabletop game leaves to a human referee. A program that runs without a referee has to
|
|
15
|
-
make that decision.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
`Ruleset()` with no arguments gives you the SRD rules as written. Each flag is an optional
|
|
12
|
+
rule, an adaptation, or a house rule. An optional rule is an alternative the SRD prints
|
|
13
|
+
beside its default procedure. An adaptation is a default osrlib chooses for a decision that
|
|
14
|
+
the tabletop game leaves to a human referee. A program that runs without a referee has to
|
|
15
|
+
make that decision. A house rule changes a procedure in a way the SRD doesn't print, and
|
|
16
|
+
it's off unless you turn it on.
|
|
17
|
+
Three flags pick among alternatives instead of switching one behavior on and off: the two
|
|
18
|
+
enum flags, [`EncumbranceMode`][osrlib.core.ruleset.EncumbranceMode] and
|
|
19
|
+
[`XpAwardTiming`][osrlib.core.ruleset.XpAwardTiming], and the string flag
|
|
20
|
+
`ability_score_method`.
|
|
19
21
|
|
|
20
22
|
Each flag is a field of [`Ruleset`][osrlib.core.ruleset.Ruleset], documented there and in
|
|
21
23
|
[the ruleset options guide](https://mmacy.github.io/osrlib-python/guides/ruleset-options/)
|
|
@@ -44,6 +46,8 @@ assert house_rules.variable_weapon_damage is True
|
|
|
44
46
|
# Code reads every flag here. Don't add a flag before the code that reads it exists.
|
|
45
47
|
# Adding a flag with a default doesn't require a schema_version bump.
|
|
46
48
|
|
|
49
|
+
from typing import Literal
|
|
50
|
+
|
|
47
51
|
from pydantic import ConfigDict
|
|
48
52
|
|
|
49
53
|
from osrlib.core._descriptions import _StrEnum
|
|
@@ -124,10 +128,11 @@ class Ruleset(_Model):
|
|
|
124
128
|
unknown field name raises a pydantic `ValidationError`, so a misspelled flag fails
|
|
125
129
|
instead of doing nothing.
|
|
126
130
|
|
|
127
|
-
Each flag is one of
|
|
131
|
+
Each flag is one of three kinds. An optional rule is an alternative the SRD prints
|
|
128
132
|
beside its standard procedure, and osrlib's default is the book's. An adaptation is a
|
|
129
133
|
default osrlib supplies where the tabletop game leaves the decision to a human
|
|
130
|
-
referee.
|
|
134
|
+
referee. A house rule is a change the SRD doesn't print, and its default is the SRD's
|
|
135
|
+
procedure. [The adaptations register](https://mmacy.github.io/osrlib-python/adaptations/)
|
|
131
136
|
gives the reasoning behind each one.
|
|
132
137
|
|
|
133
138
|
Examples:
|
|
@@ -153,6 +158,33 @@ class Ruleset(_Model):
|
|
|
153
158
|
that modifier.
|
|
154
159
|
"""
|
|
155
160
|
|
|
161
|
+
max_hp_at_first_level: bool = False
|
|
162
|
+
"""Count a first-level character's hit die as its maximum. A house rule, off by default.
|
|
163
|
+
|
|
164
|
+
The SRD doesn't print this rule. Its character creation has you roll the class's hit die. Turn
|
|
165
|
+
the flag on and a first-level character's hit points are the hit die's size plus the CON
|
|
166
|
+
modifier, and at least 1, so a fighter with CON 7 starts with 8 - 1 = 7.
|
|
167
|
+
[`roll_hit_points`][osrlib.core.character.roll_hit_points] still throws the dice it throws with
|
|
168
|
+
the flag off, so the creation stream ends in the same place and the starting gold roll after it is
|
|
169
|
+
the same. With `hp_reroll_at_first_level` also on, a die showing 1 or 2 is still thrown again and
|
|
170
|
+
[`HitPointRoll.rolls`][osrlib.core.character.HitPointRoll.rolls] lists every die, but the
|
|
171
|
+
reroll can't change the hit points. The flag affects only the hit points rolled at character
|
|
172
|
+
creation. [`level_up`][osrlib.core.classes.level_up] rolls each later level's hit die as usual.
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
ability_score_method: Literal["3d6", "4d6_drop_lowest"] = "3d6"
|
|
176
|
+
"""How a new character's ability scores are rolled. `"3d6"` by default, the SRD's method.
|
|
177
|
+
|
|
178
|
+
`"4d6_drop_lowest"` is a house rule, not an SRD rule. With it, each ability throws four d6 and
|
|
179
|
+
the lowest die doesn't count, so the score is the sum of the other three, from 3 to 18.
|
|
180
|
+
[`create_character`][osrlib.core.character.create_character] passes the method to
|
|
181
|
+
[`roll_ability_scores`][osrlib.core.character.roll_ability_scores], and the result lists the
|
|
182
|
+
dropped die of each ability in
|
|
183
|
+
[`AbilityScoreRolls.dropped`][osrlib.core.character.AbilityScoreRolls.dropped]. The method
|
|
184
|
+
affects only the characters you create. The NPC adventurers that encounters generate always
|
|
185
|
+
roll 3d6.
|
|
186
|
+
"""
|
|
187
|
+
|
|
156
188
|
encumbrance: EncumbranceMode = EncumbranceMode.BASIC
|
|
157
189
|
"""Which system tracks carried weight and sets movement rate. Basic by default.
|
|
158
190
|
|
|
@@ -723,6 +723,7 @@ class SpellMode(_Model):
|
|
|
723
723
|
|
|
724
724
|
blind = light.mode("blind")
|
|
725
725
|
assert blind.save is not None # the target may save against being blinded
|
|
726
|
+
assert blind.display_name == "Blind a creature" # the label a cast dialog shows
|
|
726
727
|
assert blind.prose.startswith("Blinding a creature:")
|
|
727
728
|
```
|
|
728
729
|
"""
|
|
@@ -734,7 +735,28 @@ class SpellMode(_Model):
|
|
|
734
735
|
|
|
735
736
|
Pass it as `mode` to [`cast_spell`][osrlib.core.spells.cast_spell] and
|
|
736
737
|
[`validate_cast`][osrlib.core.spells.validate_cast]. A spell with a single usage still has a
|
|
737
|
-
mode, like *fire ball*'s `"damage"`.
|
|
738
|
+
mode, like *fire ball*'s `"damage"`. To show a mode to a player, use `display_name`.
|
|
739
|
+
"""
|
|
740
|
+
|
|
741
|
+
display_name: str = ""
|
|
742
|
+
"""A short label for the mode, like `"Blind a creature"`. Show it where a player chooses one of a form's modes.
|
|
743
|
+
|
|
744
|
+
The label says what the caster does, as an instruction in sentence case with no closing punctuation:
|
|
745
|
+
`"Conjure light"`, `"Cancel darkness"`, and `"Hold a group"`. In the built-in catalog, no two modes of one
|
|
746
|
+
form have the same label, in the normal form or in the reverse, so a cast dialog can list a form's
|
|
747
|
+
modes by label alone. A built-in label comes from the lead-in that the OSE SRD prints before the
|
|
748
|
+
usage, like "Blinding a creature:". A mode whose page prints no lead-in, or a lead-in that names a
|
|
749
|
+
situation rather than an action, like *bless*'s "Battle:", has a label written for it from the
|
|
750
|
+
page's words, like `"Bless allies in battle"` and the reverse of *light*'s `"Conjure darkness"`.
|
|
751
|
+
|
|
752
|
+
When you write a mode and leave the label out, or give one that is empty or only spaces, the
|
|
753
|
+
mode gets a label made from its key: each run of underscores becomes one space, the spaces at
|
|
754
|
+
either end are dropped, and the first letter becomes a capital, so `"darken"` is labelled
|
|
755
|
+
`"Darken"` and `"kill_green_slime"` is labelled `"Kill green slime"`. A key made only of
|
|
756
|
+
underscores is its own label, so a label is never empty. A spell you wrote for an earlier osrlib
|
|
757
|
+
loads this way, with a label on every mode. A spell with a single mode has nothing to choose
|
|
758
|
+
between, so the built-in catalog gives that mode the label from its key too, like *fire ball*'s
|
|
759
|
+
`"Damage"`. For a form with one mode, show the spell's name and not the mode's label.
|
|
738
760
|
"""
|
|
739
761
|
|
|
740
762
|
targeting: TargetingSpec | None = None
|
|
@@ -761,8 +783,31 @@ class SpellMode(_Model):
|
|
|
761
783
|
"""The SRD text for this usage.
|
|
762
784
|
|
|
763
785
|
Show it to the player. For a manual mode, it's all the information osrlib has about the result.
|
|
786
|
+
In the built-in catalog, no two modes of one form have the same prose. Where the page describes
|
|
787
|
+
several usages in one passage, like the reverse of *light*, each mode's prose is the part of
|
|
788
|
+
the passage that covers that usage, and the whole passage is the form's own prose, such as
|
|
789
|
+
[`ReversedForm.prose`][osrlib.core.spells.ReversedForm.prose].
|
|
764
790
|
"""
|
|
765
791
|
|
|
792
|
+
@model_validator(mode="before")
|
|
793
|
+
@classmethod
|
|
794
|
+
def _label_from_key(cls, data: object) -> object:
|
|
795
|
+
if not isinstance(data, dict):
|
|
796
|
+
return data
|
|
797
|
+
label = data.get("display_name")
|
|
798
|
+
if label is not None and not (isinstance(label, str) and not label.strip()):
|
|
799
|
+
return data
|
|
800
|
+
key = data.get("key")
|
|
801
|
+
if not isinstance(key, str):
|
|
802
|
+
return data
|
|
803
|
+
words = " ".join(part for part in key.split("_") if part).strip()
|
|
804
|
+
if not words:
|
|
805
|
+
return {**data, "display_name": key}
|
|
806
|
+
capital = words[0].upper()
|
|
807
|
+
if len(capital) == 1:
|
|
808
|
+
words = capital + words[1:]
|
|
809
|
+
return {**data, "display_name": words}
|
|
810
|
+
|
|
766
811
|
@model_validator(mode="after")
|
|
767
812
|
def _automated_modes_carry_structure(self) -> SpellMode:
|
|
768
813
|
if self.manual:
|
|
@@ -820,7 +865,11 @@ class ReversedForm(_Model):
|
|
|
820
865
|
"""
|
|
821
866
|
|
|
822
867
|
prose: str = ""
|
|
823
|
-
"""The SRD text for the reverse.
|
|
868
|
+
"""The SRD text for the reverse, all of it.
|
|
869
|
+
|
|
870
|
+
Each of the reverse's `modes` has the part of this text that covers that mode as its own
|
|
871
|
+
[`prose`][osrlib.core.spells.SpellMode.prose].
|
|
872
|
+
"""
|
|
824
873
|
|
|
825
874
|
modes: tuple[SpellMode, ...] = Field(min_length=1)
|
|
826
875
|
"""One [`SpellMode`][osrlib.core.spells.SpellMode] per castable usage of the reverse, at least one, each with a
|
|
@@ -974,7 +1023,8 @@ class SpellTemplate(_Model):
|
|
|
974
1023
|
|
|
975
1024
|
Use this when you know which usage you want, to read its targeting, its save, or its prose
|
|
976
1025
|
before you cast it. To offer a player a choice instead, iterate
|
|
977
|
-
[`modes`][osrlib.core.spells.SpellTemplate.modes] and show each mode's `
|
|
1026
|
+
[`modes`][osrlib.core.spells.SpellTemplate.modes] and show each mode's `display_name`, with its
|
|
1027
|
+
`prose` for the details. The key you
|
|
978
1028
|
pass here is the same string casting takes as its `mode` argument.
|
|
979
1029
|
|
|
980
1030
|
Args:
|
|
@@ -1384,9 +1434,7 @@ def memorize_spells(
|
|
|
1384
1434
|
"""
|
|
1385
1435
|
profile = caster_profile(definition)
|
|
1386
1436
|
if profile is None:
|
|
1387
|
-
return MemorizationResult(
|
|
1388
|
-
rejections=(Rejection(code="magic.memorize.not_a_caster", params={"class": definition.id}),)
|
|
1389
|
-
)
|
|
1437
|
+
return MemorizationResult(rejections=(_not_a_caster(definition),))
|
|
1390
1438
|
rejections: list[Rejection] = []
|
|
1391
1439
|
counts: dict[int, int] = {}
|
|
1392
1440
|
for selection in selections:
|
|
@@ -1420,6 +1468,22 @@ def memorize_spells(
|
|
|
1420
1468
|
return MemorizationResult(events=(event,))
|
|
1421
1469
|
|
|
1422
1470
|
|
|
1471
|
+
def _not_a_caster(definition: ClassDefinition) -> Rejection:
|
|
1472
|
+
"""Return the refusal of a preparation for a class that casts nothing, for which `caster_profile` is None."""
|
|
1473
|
+
return Rejection(code="magic.memorize.not_a_caster", params={"class": definition.id})
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
def _reverses_at(profile: CasterProfile) -> Literal["memorize", "cast"]:
|
|
1477
|
+
"""Return when a caster of this kind chooses the form of a spell that reverses.
|
|
1478
|
+
|
|
1479
|
+
An arcane caster chooses it when memorizing, so `memorize_spells` takes a reversed selection and a cast must match
|
|
1480
|
+
the copy's form. A divine caster chooses it when casting, so `memorize_spells` refuses a reversed selection with
|
|
1481
|
+
`magic.memorize.divine_reverses_at_cast` and a cast matches any copy of the spell. It's the member view's
|
|
1482
|
+
`reverses_at`.
|
|
1483
|
+
"""
|
|
1484
|
+
return "cast" if profile.kind == "divine" else "memorize"
|
|
1485
|
+
|
|
1486
|
+
|
|
1423
1487
|
def _slot_count(slots: Sequence[int], spell_level: int) -> int:
|
|
1424
1488
|
"""Return a progression row's slot count at a spell level, which is 0 past the end of the row."""
|
|
1425
1489
|
return slots[spell_level - 1] if spell_level <= len(slots) else 0
|
|
@@ -1437,7 +1501,7 @@ def _selection_rejection(
|
|
|
1437
1501
|
return Rejection(
|
|
1438
1502
|
code="magic.memorize.wrong_list", params={"spell": selection.spell_id, "list": template.spell_list}
|
|
1439
1503
|
)
|
|
1440
|
-
if profile
|
|
1504
|
+
if _reverses_at(profile) == "cast" and selection.reversed:
|
|
1441
1505
|
return Rejection(code="magic.memorize.divine_reverses_at_cast", params={"spell": selection.spell_id})
|
|
1442
1506
|
if profile.kind == "arcane":
|
|
1443
1507
|
if selection.spell_id not in getattr(caster, "spell_book", ()):
|
|
@@ -1996,7 +2060,7 @@ def _memorized_index(caster: Any, spell: SpellTemplate, reversed: bool, profile:
|
|
|
1996
2060
|
for index, copy in enumerate(getattr(caster, "memorized_spells", ())):
|
|
1997
2061
|
if copy.spell_id != spell.id:
|
|
1998
2062
|
continue
|
|
1999
|
-
if profile
|
|
2063
|
+
if _reverses_at(profile) == "cast" or copy.reversed == reversed:
|
|
2000
2064
|
return index
|
|
2001
2065
|
return None
|
|
2002
2066
|
|
|
@@ -897,6 +897,13 @@ def _int_param(params: Mapping[str, Any], key: str, default: int = 0) -> int:
|
|
|
897
897
|
return int(params.get(key, default))
|
|
898
898
|
|
|
899
899
|
|
|
900
|
+
_ROLLED_VALUABLE_NAMES: dict[str, str] = {"gem": "Gem", "jewellery": "Jewellery"}
|
|
901
|
+
"""The plain name that `_generate_valuable` gives a rolled piece of each kind, which is no name of the piece's own.
|
|
902
|
+
|
|
903
|
+
The player view's `valuable_names` leaves out a piece whose name is the one here, so the view and the generator use the
|
|
904
|
+
same names."""
|
|
905
|
+
|
|
906
|
+
|
|
900
907
|
def _generate_valuable(
|
|
901
908
|
kind: Literal["gem", "jewellery"], *, stream: RngStream, allocator: Any
|
|
902
909
|
) -> osrlib.core.items.ValuableInstance:
|
|
@@ -906,14 +913,12 @@ def _generate_valuable(
|
|
|
906
913
|
weights = {row.id: row.weight_coins for row in load_equipment().treasure_weights}
|
|
907
914
|
if kind == "gem":
|
|
908
915
|
value = load_treasure_tables().gems.value_for_roll(stream.randbelow(20) + 1)
|
|
909
|
-
name = "Gem"
|
|
910
916
|
else:
|
|
911
917
|
value = roll(load_treasure_tables().gems.jewellery_dice, stream).total
|
|
912
|
-
name = "Jewellery"
|
|
913
918
|
return osrlib.core.items.ValuableInstance(
|
|
914
919
|
instance_id=allocator.allocate("valuable"),
|
|
915
920
|
kind=kind,
|
|
916
|
-
name=
|
|
921
|
+
name=_ROLLED_VALUABLE_NAMES[kind],
|
|
917
922
|
value_gp=value,
|
|
918
923
|
weight_coins=weights[kind],
|
|
919
924
|
)
|