osrlib 2.7.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.
Files changed (79) hide show
  1. {osrlib-2.7.0 → osrlib-2.9.0}/PKG-INFO +1 -1
  2. {osrlib-2.7.0 → osrlib-2.9.0}/pyproject.toml +1 -1
  3. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/character.py +179 -25
  4. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/combat.py +6 -2
  5. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/events.py +5 -1
  6. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/items.py +271 -1
  7. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/ruleset.py +42 -10
  8. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/spells.py +194 -48
  9. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/treasure.py +8 -3
  10. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_feature_handles.py +52 -0
  11. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_magic_items.py +25 -13
  12. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_party_members.py +41 -1
  13. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_spells.py +80 -12
  14. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/battle.py +91 -21
  15. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/commands.py +87 -31
  16. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/dungeon.py +40 -8
  17. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/events.py +14 -0
  18. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/session.py +56 -7
  19. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/views.py +562 -95
  20. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/equipment.json +174 -18
  21. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/magic_items.json +336 -2
  22. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/spells.json +164 -15
  23. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/persistence.py +8 -1
  24. {osrlib-2.7.0 → osrlib-2.9.0}/LICENSE +0 -0
  25. {osrlib-2.7.0 → osrlib-2.9.0}/LICENSE-OGL.md +0 -0
  26. {osrlib-2.7.0 → osrlib-2.9.0}/README.md +0 -0
  27. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/__init__.py +0 -0
  28. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/__init__.py +0 -0
  29. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/_descriptions.py +0 -0
  30. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/abilities.py +0 -0
  31. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/alignment.py +0 -0
  32. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/classes.py +0 -0
  33. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/clock.py +0 -0
  34. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/creature.py +0 -0
  35. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/dice.py +0 -0
  36. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/effects.py +0 -0
  37. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/frozen.py +0 -0
  38. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/monsters.py +0 -0
  39. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/npc.py +0 -0
  40. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/rng.py +0 -0
  41. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/tables.py +0 -0
  42. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/core/validation.py +0 -0
  43. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/__init__.py +0 -0
  44. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_arrival.py +0 -0
  45. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_doors.py +0 -0
  46. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_gating.py +0 -0
  47. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_hauling.py +0 -0
  48. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_items.py +0 -0
  49. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_light.py +0 -0
  50. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_movement.py +0 -0
  51. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_odometer.py +0 -0
  52. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_party_location.py +0 -0
  53. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_search.py +0 -0
  54. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_town.py +0 -0
  55. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/_treasure.py +0 -0
  56. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/adventure.py +0 -0
  57. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/content_pack.py +0 -0
  58. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/encounter.py +0 -0
  59. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/exploration.py +0 -0
  60. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/gates.py +0 -0
  61. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/interpreter.py +0 -0
  62. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/narrative.py +0 -0
  63. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/party.py +0 -0
  64. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/quests.py +0 -0
  65. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/stocking.py +0 -0
  66. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/crawl/triggers.py +0 -0
  67. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/LICENSE-OGL.md +0 -0
  68. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/__init__.py +0 -0
  69. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/abilities.json +0 -0
  70. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/classes.json +0 -0
  71. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/combat_tables.json +0 -0
  72. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/encounter_tables.json +0 -0
  73. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/languages.json +0 -0
  74. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/monsters.json +0 -0
  75. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/data/treasure.json +0 -0
  76. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/errors.py +0 -0
  77. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/messages.py +0 -0
  78. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/py.typed +0 -0
  79. {osrlib-2.7.0 → osrlib-2.9.0}/src/osrlib/versioning.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osrlib
3
- Version: 2.7.0
3
+ Version: 2.9.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.7.0"
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]. Frozen.
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]. All six
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 behind each score, keyed the same way, in the order they were rolled."""
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: the last die plus the CON modifier, and at least 1."""
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 3d6 for each of the six abilities, in the SRD's order: STR, INT, WIS, DEX, CON, CHA.
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
- The same stream at the same position always gives the same six scores.
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 and the three dice behind each.
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
- result = roll("3d6", stream)
1075
- scores[ability] = result.total
1076
- rolls[ability] = (result.rolls[0], result.rolls[1], result.rolls[2])
1077
- return AbilityScoreRolls(scores=scores, rolls=rolls)
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` option.
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
- return HitPointRoll(rolls=tuple(rolls), hit_points=max(1, rolls[-1] + con_modifier))
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. When its `hp_reroll_at_first_level` flag is on, a hit die
1497
- showing 1 or 2 is thrown again.
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]}")
@@ -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,