diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a39e90..bd3eb0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ### Added - Two house rules for character creation, which the SRD doesn't print and `Ruleset()` leaves off (#341). [`Ruleset.ability_score_method`][osrlib.core.ruleset.Ruleset.ability_score_method] is `"3d6"` by default. With `"4d6_drop_lowest"`, [`create_character`][osrlib.core.character.create_character] throws four d6 for each ability and drops the lowest, the first of them thrown when two or more tie, and [`roll_ability_scores`][osrlib.core.character.roll_ability_scores] does the same when you pass the method to its new `method` keyword. [`AbilityScoreRolls.rolls`][osrlib.core.character.AbilityScoreRolls.rolls] keeps the three dice that count, and the new [`AbilityScoreRolls.dropped`][osrlib.core.character.AbilityScoreRolls.dropped] has the dropped die of each ability, so a client can show all four. The method draws 24 dice instead of 18, so the same seed gives a different character, and NPC adventurers always roll 3d6. With [`Ruleset.max_hp_at_first_level`][osrlib.core.ruleset.Ruleset.max_hp_at_first_level] on, a first-level character's hit points are the hit die's size plus the CON modifier, and at least 1, and the new [`HitPointRoll.maximized`][osrlib.core.character.HitPointRoll.maximized] is true. The hit die and any rerolls of `hp_reroll_at_first_level` are still thrown, so the starting gold is the same as with the flag off. `examples/rulesets/creation_house_rules.json` is a ruleset with both house rules on and every other field at its default, for a front end to copy. With both flags at their defaults, every draw and result is what 2.8.0 gave. A 2.8.0 save loads with both off, a 2.8.0 creation result parses with an empty `dropped` and a false `maximized`, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4. +- [`SpellMode.display_name`][osrlib.core.spells.SpellMode.display_name] is a short label for a mode, such as `"Blind a creature"`, for a client to show where a player chooses one of a form's modes, such as a cast dialog (#340). It says what the caster does, in sentence case with no closing punctuation, and in the built-in catalog no two modes of one form have the same label. Each built-in label comes from the lead-in that the OSE SRD prints before the usage, such as "Blinding a creature:". Where the page prints no lead-in, or one that names a situation such as *bless*'s "Battle:", the SRD compiler has a label written from the page's words, such as `"Bless allies in battle"`. A mode that leaves the label out, or gives one that is empty or only spaces, gets a label made from its key: each run of underscores becomes one space, the spaces at either end are dropped, and the first letter becomes a capital, so `"kill_green_slime"` is labelled `"Kill green slime"`. The one mode of a single-mode form is labelled the same way, such as *fire ball*'s `"Damage"`. As a result, a spell document, an adventure, or a save from 2.8.0 loads with a label on every mode, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4. + +### Changed + +- Each built-in mode of the reverses of *light* and *continual light*, of *charm monster*, and of *silence 15' radius* has the part of the SRD text that covers it as its [`prose`][osrlib.core.spells.SpellMode.prose], so no two modes of one form have the same prose (#340). Before, every mode of one of these forms had the whole passage. For example, the `blind` mode of *darkness*, the reverse of *light*, had "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell." and now has "Like light, it may alternatively be used to blind creatures." Each mode of *charm monster* has only its own alternative from the first sentence, and the `area` mode of *silence 15' radius* leaves out the "Casting upon a creature:" bullet. [`ReversedForm.prose`][osrlib.core.spells.ReversedForm.prose] still has the whole text of the reverse, and a spell that an adventure bundles keeps the prose its author wrote. ## [2.8.0] - 2026-11-25 diff --git a/docs/guides/authoring-custom-content.md b/docs/guides/authoring-custom-content.md index 330abf2..3ed3381 100644 --- a/docs/guides/authoring-custom-content.md +++ b/docs/guides/authoring-custom-content.md @@ -116,7 +116,7 @@ MEND_WOUNDS = SpellTemplate.model_validate( ) ``` -Each `SpellMode` defines a castable `key`, a `targeting` spec, an optional `save`, and either an automated `effect` (such as `"heal"` or `"damage"` with `params`) or `manual=True` with `prose` (which expends the memorized spell and emits the cast event so your front end can resolve the effect). Reversible spells also accept an optional [`ReversedForm`][osrlib.core.spells.ReversedForm] with its reversed name and modes, matching built-in spells such as `cure_light_wounds`. +Each `SpellMode` defines a castable `key`, an optional [`display_name`][osrlib.core.spells.SpellMode.display_name] that your front end shows where a player chooses one of a form's modes, a `targeting` spec, an optional `save`, and either an automated `effect` (such as `"heal"` or `"damage"` with `params`) or `manual=True` with `prose` (which expends the memorized spell and emits the cast event so your front end can resolve the effect). Reversible spells also accept an optional [`ReversedForm`][osrlib.core.spells.ReversedForm] with its reversed name and modes, matching built-in spells such as `cure_light_wounds`. A mode that leaves `display_name` out, or gives one that is empty or only spaces, gets a label made from its key: each run of underscores becomes one space and the first letter becomes a capital, so `"mend"` is labelled `"Mend"` and `"kill_green_slime"` is labelled `"Kill green slime"`. When a form has more than one mode, give each one a label that says what the caster does, such as `"Blind a creature"`, and give no two of them the same label, so a player can tell them apart. ## Validate custom class and spell catalogs diff --git a/src/osrlib/core/spells.py b/src/osrlib/core/spells.py index a8b2e17..d9dc0c2 100644 --- a/src/osrlib/core/spells.py +++ b/src/osrlib/core/spells.py @@ -723,6 +723,7 @@ class SpellMode(_Model): blind = light.mode("blind") assert blind.save is not None # the target may save against being blinded + assert blind.display_name == "Blind a creature" # the label a cast dialog shows assert blind.prose.startswith("Blinding a creature:") ``` """ @@ -734,7 +735,28 @@ class SpellMode(_Model): Pass it as `mode` to [`cast_spell`][osrlib.core.spells.cast_spell] and [`validate_cast`][osrlib.core.spells.validate_cast]. A spell with a single usage still has a - mode, like *fire ball*'s `"damage"`. + mode, like *fire ball*'s `"damage"`. To show a mode to a player, use `display_name`. + """ + + display_name: str = "" + """A short label for the mode, like `"Blind a creature"`. Show it where a player chooses one of a form's modes. + + The label says what the caster does, as an instruction in sentence case with no closing punctuation: + `"Conjure light"`, `"Cancel darkness"`, and `"Hold a group"`. In the built-in catalog, no two modes of one + form have the same label, in the normal form or in the reverse, so a cast dialog can list a form's + modes by label alone. A built-in label comes from the lead-in that the OSE SRD prints before the + usage, like "Blinding a creature:". A mode whose page prints no lead-in, or a lead-in that names a + situation rather than an action, like *bless*'s "Battle:", has a label written for it from the + page's words, like `"Bless allies in battle"` and the reverse of *light*'s `"Conjure darkness"`. + + When you write a mode and leave the label out, or give one that is empty or only spaces, the + mode gets a label made from its key: each run of underscores becomes one space, the spaces at + either end are dropped, and the first letter becomes a capital, so `"darken"` is labelled + `"Darken"` and `"kill_green_slime"` is labelled `"Kill green slime"`. A key made only of + underscores is its own label, so a label is never empty. A spell you wrote for an earlier osrlib + loads this way, with a label on every mode. A spell with a single mode has nothing to choose + between, so the built-in catalog gives that mode the label from its key too, like *fire ball*'s + `"Damage"`. For a form with one mode, show the spell's name and not the mode's label. """ targeting: TargetingSpec | None = None @@ -761,8 +783,31 @@ class SpellMode(_Model): """The SRD text for this usage. Show it to the player. For a manual mode, it's all the information osrlib has about the result. + In the built-in catalog, no two modes of one form have the same prose. Where the page describes + several usages in one passage, like the reverse of *light*, each mode's prose is the part of + the passage that covers that usage, and the whole passage is the form's own prose, such as + [`ReversedForm.prose`][osrlib.core.spells.ReversedForm.prose]. """ + @model_validator(mode="before") + @classmethod + def _label_from_key(cls, data: object) -> object: + if not isinstance(data, dict): + return data + label = data.get("display_name") + if label is not None and not (isinstance(label, str) and not label.strip()): + return data + key = data.get("key") + if not isinstance(key, str): + return data + words = " ".join(part for part in key.split("_") if part).strip() + if not words: + return {**data, "display_name": key} + capital = words[0].upper() + if len(capital) == 1: + words = capital + words[1:] + return {**data, "display_name": words} + @model_validator(mode="after") def _automated_modes_carry_structure(self) -> SpellMode: if self.manual: @@ -820,7 +865,11 @@ class ReversedForm(_Model): """ prose: str = "" - """The SRD text for the reverse.""" + """The SRD text for the reverse, all of it. + + Each of the reverse's `modes` has the part of this text that covers that mode as its own + [`prose`][osrlib.core.spells.SpellMode.prose]. + """ modes: tuple[SpellMode, ...] = Field(min_length=1) """One [`SpellMode`][osrlib.core.spells.SpellMode] per castable usage of the reverse, at least one, each with a @@ -974,7 +1023,8 @@ def mode(self, key: str, *, reversed: bool = False) -> SpellMode: Use this when you know which usage you want, to read its targeting, its save, or its prose before you cast it. To offer a player a choice instead, iterate - [`modes`][osrlib.core.spells.SpellTemplate.modes] and show each mode's `prose`. The key you + [`modes`][osrlib.core.spells.SpellTemplate.modes] and show each mode's `display_name`, with its + `prose` for the details. The key you pass here is the same string casting takes as its `mode` argument. Args: diff --git a/src/osrlib/data/spells.json b/src/osrlib/data/spells.json index 62a89c9..298ba4c 100644 --- a/src/osrlib/data/spells.json +++ b/src/osrlib/data/spells.json @@ -132,6 +132,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -169,6 +170,7 @@ "level": 6, "modes": [ { + "display_name": "Shell", "effect": { "condition": null, "cures_conditions": [], @@ -226,6 +228,7 @@ "level": 2, "modes": [ { + "display_name": "Bless allies in battle", "effect": { "condition": null, "cures_conditions": [], @@ -283,6 +286,7 @@ } }, { + "display_name": "Bless a ritual", "effect": null, "key": "ritual", "manual": true, @@ -304,6 +308,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Battle", "effect": { "condition": null, "cures_conditions": [], @@ -388,6 +393,7 @@ "level": 4, "modes": [ { + "display_name": "Charm an individual", "effect": { "condition": "charmed", "cures_conditions": [], @@ -402,7 +408,7 @@ }, "key": "individual", "manual": false, - "prose": "This spell places a charm upon either 3d6 creatures of 3 HD or less or a single creature of more than 3 HD. Each subject must make a save versus spells or be charmed as follows:\nFriendship: Charmed creatures regard the caster as a close friend and will come to the caster’s defence.\nCommands: If they share a language, the caster may give charmed creatures commands, which they will obey.\nSubject’s nature: Charmed creatures may resist commands that contradict their habits or alignment.\nSuicidal commands: Are always refused.\nRestrictions: Undead are not affected.\nDuration: The charm lasts indefinitely, but the subject is allowed to make further saves versus spells at intervals, depending on its INT score. If one of these saves succeeds, the spell ends.\nINT 3–8: New save once every month.\nINT 9–12: New save each week.\nINT 13–18: New save once every day.", + "prose": "This spell places a charm upon a single creature of more than 3 HD. Each subject must make a save versus spells or be charmed as follows:\nFriendship: Charmed creatures regard the caster as a close friend and will come to the caster’s defence.\nCommands: If they share a language, the caster may give charmed creatures commands, which they will obey.\nSubject’s nature: Charmed creatures may resist commands that contradict their habits or alignment.\nSuicidal commands: Are always refused.\nRestrictions: Undead are not affected.\nDuration: The charm lasts indefinitely, but the subject is allowed to make further saves versus spells at intervals, depending on its INT score. If one of these saves succeeds, the spell ends.\nINT 3–8: New save once every month.\nINT 9–12: New save each week.\nINT 13–18: New save once every day.", "save": { "category": "spells", "modifier": 0, @@ -420,6 +426,7 @@ } }, { + "display_name": "Charm a group", "effect": { "condition": "charmed", "cures_conditions": [], @@ -434,7 +441,7 @@ }, "key": "group", "manual": false, - "prose": "This spell places a charm upon either 3d6 creatures of 3 HD or less or a single creature of more than 3 HD. Each subject must make a save versus spells or be charmed as follows:\nFriendship: Charmed creatures regard the caster as a close friend and will come to the caster’s defence.\nCommands: If they share a language, the caster may give charmed creatures commands, which they will obey.\nSubject’s nature: Charmed creatures may resist commands that contradict their habits or alignment.\nSuicidal commands: Are always refused.\nRestrictions: Undead are not affected.\nDuration: The charm lasts indefinitely, but the subject is allowed to make further saves versus spells at intervals, depending on its INT score. If one of these saves succeeds, the spell ends.\nINT 3–8: New save once every month.\nINT 9–12: New save each week.\nINT 13–18: New save once every day.", + "prose": "This spell places a charm upon 3d6 creatures of 3 HD or less. Each subject must make a save versus spells or be charmed as follows:\nFriendship: Charmed creatures regard the caster as a close friend and will come to the caster’s defence.\nCommands: If they share a language, the caster may give charmed creatures commands, which they will obey.\nSubject’s nature: Charmed creatures may resist commands that contradict their habits or alignment.\nSuicidal commands: Are always refused.\nRestrictions: Undead are not affected.\nDuration: The charm lasts indefinitely, but the subject is allowed to make further saves versus spells at intervals, depending on its INT score. If one of these saves succeeds, the spell ends.\nINT 3–8: New save once every month.\nINT 9–12: New save each week.\nINT 13–18: New save once every day.", "save": { "category": "spells", "modifier": 0, @@ -481,6 +488,7 @@ "level": 1, "modes": [ { + "display_name": "Charm", "effect": { "condition": "charmed", "cures_conditions": [], @@ -543,6 +551,7 @@ "level": 3, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -580,6 +589,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -617,6 +627,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -654,6 +665,7 @@ "level": 4, "modes": [ { + "display_name": "Confuse", "effect": { "condition": "confused", "cures_conditions": [], @@ -725,6 +737,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -762,6 +775,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -799,6 +813,7 @@ "level": 3, "modes": [ { + "display_name": "Conjure light", "effect": { "condition": null, "cures_conditions": [], @@ -827,6 +842,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -855,6 +871,7 @@ } }, { + "display_name": "Cancel darkness", "effect": { "condition": null, "cures_conditions": [], @@ -894,6 +911,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Conjure darkness", "effect": { "condition": null, "cures_conditions": [], @@ -908,7 +926,7 @@ }, "key": "darken", "manual": false, - "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it. Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell.", + "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it.", "save": null, "targeting": { "count": null, @@ -922,6 +940,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -932,7 +951,7 @@ }, "key": "blind", "manual": false, - "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it. Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell.", + "prose": "Like continual light, it may alternatively be used to blind creatures.", "save": { "category": "spells", "modifier": 0, @@ -950,6 +969,7 @@ } }, { + "display_name": "Cancel light", "effect": { "condition": null, "cures_conditions": [], @@ -962,7 +982,7 @@ }, "key": "cancel", "manual": false, - "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it. Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell.", + "prose": "Like continual light, it may alternatively be used to dispel a continual light spell.", "save": null, "targeting": { "count": null, @@ -999,6 +1019,7 @@ "level": 2, "modes": [ { + "display_name": "Conjure light", "effect": { "condition": null, "cures_conditions": [], @@ -1027,6 +1048,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -1055,6 +1077,7 @@ } }, { + "display_name": "Cancel darkness", "effect": { "condition": null, "cures_conditions": [], @@ -1094,6 +1117,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Conjure darkness", "effect": { "condition": null, "cures_conditions": [], @@ -1108,7 +1132,7 @@ }, "key": "darken", "manual": false, - "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it. Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell.", + "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it.", "save": null, "targeting": { "count": null, @@ -1122,6 +1146,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -1132,7 +1157,7 @@ }, "key": "blind", "manual": false, - "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it. Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell.", + "prose": "Like continual light, it may alternatively be used to blind creatures.", "save": { "category": "spells", "modifier": 0, @@ -1150,6 +1175,7 @@ } }, { + "display_name": "Cancel light", "effect": { "condition": null, "cures_conditions": [], @@ -1162,7 +1188,7 @@ }, "key": "cancel", "manual": false, - "prose": "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. Light sources brought within the area of darkness do not illuminate it. Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell.", + "prose": "Like continual light, it may alternatively be used to dispel a continual light spell.", "save": null, "targeting": { "count": null, @@ -1199,6 +1225,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1236,6 +1263,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1273,6 +1301,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1310,6 +1339,7 @@ "level": 3, "modes": [ { + "display_name": "Cure a subject of any disease", "effect": { "condition": null, "cures_conditions": [ @@ -1336,6 +1366,7 @@ } }, { + "display_name": "Kill green slime", "effect": null, "key": "kill_green_slime", "manual": true, @@ -1357,6 +1388,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Afflict", "effect": { "condition": "diseased", "cures_conditions": [], @@ -1425,6 +1457,7 @@ "level": 1, "modes": [ { + "display_name": "Heal a living subject", "effect": { "condition": null, "cures_conditions": [], @@ -1451,6 +1484,7 @@ } }, { + "display_name": "Cure paralysis", "effect": { "condition": null, "cures_conditions": [ @@ -1490,6 +1524,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Harm", "effect": { "condition": null, "cures_conditions": [], @@ -1540,6 +1575,7 @@ "level": 4, "modes": [ { + "display_name": "Heal", "effect": { "condition": null, "cures_conditions": [], @@ -1579,6 +1615,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Harm", "effect": { "condition": null, "cures_conditions": [], @@ -1629,6 +1666,7 @@ "level": 6, "modes": [ { + "display_name": "Kill", "effect": { "condition": null, "cures_conditions": [], @@ -1690,6 +1728,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1727,6 +1766,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1764,6 +1804,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1801,6 +1842,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1838,6 +1880,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1875,6 +1918,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -1912,6 +1956,7 @@ "level": 6, "modes": [ { + "display_name": "Kill", "effect": { "condition": null, "cures_conditions": [], @@ -1972,6 +2017,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2009,6 +2055,7 @@ "level": 3, "modes": [ { + "display_name": "Dispel", "effect": { "condition": null, "cures_conditions": [], @@ -2066,6 +2113,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2103,6 +2151,7 @@ "level": 5, "modes": [ { + "display_name": "Feeblemind", "effect": { "condition": "feebleminded", "cures_conditions": [], @@ -2163,6 +2212,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2200,6 +2250,7 @@ "level": 3, "modes": [ { + "display_name": "Damage", "effect": { "condition": null, "cures_conditions": [], @@ -2262,6 +2313,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2299,6 +2351,7 @@ "level": 3, "modes": [ { + "display_name": "Grant", "effect": { "condition": null, "cures_conditions": [], @@ -2355,6 +2408,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2384,6 +2438,7 @@ }, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2415,6 +2470,7 @@ "level": 3, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2452,6 +2508,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2489,6 +2546,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2526,6 +2584,7 @@ "level": 3, "modes": [ { + "display_name": "Haste", "effect": { "condition": null, "cures_conditions": [], @@ -2585,6 +2644,7 @@ "level": 5, "modes": [ { + "display_name": "Hold an individual", "effect": { "condition": "paralysed", "cures_conditions": [], @@ -2615,6 +2675,7 @@ } }, { + "display_name": "Hold a group", "effect": { "condition": "paralysed", "cures_conditions": [], @@ -2674,6 +2735,7 @@ "level": 2, "modes": [ { + "display_name": "Hold an individual", "effect": { "condition": "paralysed", "cures_conditions": [], @@ -2705,6 +2767,7 @@ } }, { + "display_name": "Hold a group", "effect": { "condition": "paralysed", "cures_conditions": [], @@ -2765,6 +2828,7 @@ "level": 3, "modes": [ { + "display_name": "Hold an individual", "effect": { "condition": "paralysed", "cures_conditions": [], @@ -2796,6 +2860,7 @@ } }, { + "display_name": "Hold a group", "effect": { "condition": "paralysed", "cures_conditions": [], @@ -2856,6 +2921,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2893,6 +2959,7 @@ "level": 3, "modes": [ { + "display_name": "Grant", "effect": { "condition": null, "cures_conditions": [], @@ -2949,6 +3016,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -2986,6 +3054,7 @@ "level": 2, "modes": [ { + "display_name": "Invisibility", "effect": { "condition": "invisible", "cures_conditions": [], @@ -3042,6 +3111,7 @@ "level": 3, "modes": [ { + "display_name": "Invisibility", "effect": { "condition": "invisible", "cures_conditions": [], @@ -3100,6 +3170,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3137,6 +3208,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3174,6 +3246,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3211,6 +3284,7 @@ "level": 2, "modes": [ { + "display_name": "Grant", "effect": { "condition": null, "cures_conditions": [], @@ -3267,6 +3341,7 @@ "level": 1, "modes": [ { + "display_name": "Conjure light", "effect": { "condition": null, "cures_conditions": [], @@ -3295,6 +3370,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -3323,6 +3399,7 @@ } }, { + "display_name": "Cancel darkness", "effect": { "condition": null, "cures_conditions": [], @@ -3362,6 +3439,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Conjure darkness", "effect": { "condition": null, "cures_conditions": [], @@ -3376,7 +3454,7 @@ }, "key": "darken", "manual": false, - "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision).", "save": null, "targeting": { "count": null, @@ -3390,6 +3468,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -3400,7 +3479,7 @@ }, "key": "blind", "manual": false, - "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "prose": "Like light, it may alternatively be used to blind creatures.", "save": { "category": "spells", "modifier": 0, @@ -3418,6 +3497,7 @@ } }, { + "display_name": "Cancel light", "effect": { "condition": null, "cures_conditions": [], @@ -3430,7 +3510,7 @@ }, "key": "cancel", "manual": false, - "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "prose": "Like light, it may alternatively be used to dispel a light spell.", "save": null, "targeting": { "count": null, @@ -3467,6 +3547,7 @@ "level": 1, "modes": [ { + "display_name": "Conjure light", "effect": { "condition": null, "cures_conditions": [], @@ -3495,6 +3576,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -3523,6 +3605,7 @@ } }, { + "display_name": "Cancel darkness", "effect": { "condition": null, "cures_conditions": [], @@ -3562,6 +3645,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Conjure darkness", "effect": { "condition": null, "cures_conditions": [], @@ -3576,7 +3660,7 @@ }, "key": "darken", "manual": false, - "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision).", "save": null, "targeting": { "count": null, @@ -3590,6 +3674,7 @@ } }, { + "display_name": "Blind a creature", "effect": { "condition": "blind", "cures_conditions": [], @@ -3600,7 +3685,7 @@ }, "key": "blind", "manual": false, - "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "prose": "Like light, it may alternatively be used to blind creatures.", "save": { "category": "spells", "modifier": 0, @@ -3618,6 +3703,7 @@ } }, { + "display_name": "Cancel light", "effect": { "condition": null, "cures_conditions": [], @@ -3630,7 +3716,7 @@ }, "key": "cancel", "manual": false, - "prose": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "prose": "Like light, it may alternatively be used to dispel a light spell.", "save": null, "targeting": { "count": null, @@ -3667,6 +3753,7 @@ "level": 3, "modes": [ { + "display_name": "Damage", "effect": { "condition": null, "cures_conditions": [], @@ -3731,6 +3818,7 @@ "level": 3, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3768,6 +3856,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3805,6 +3894,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3842,6 +3932,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3879,6 +3970,7 @@ "level": 1, "modes": [ { + "display_name": "Missiles", "effect": { "condition": null, "cures_conditions": [], @@ -3938,6 +4030,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -3975,6 +4068,7 @@ "level": 2, "modes": [ { + "display_name": "Images", "effect": { "condition": null, "cures_conditions": [], @@ -4031,6 +4125,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4068,6 +4163,7 @@ "level": 4, "modes": [ { + "display_name": "Neutralize poison on a character", "effect": { "condition": null, "cures_conditions": [ @@ -4097,6 +4193,7 @@ } }, { + "display_name": "Remove poison from an item", "effect": null, "key": "items", "manual": true, @@ -4134,6 +4231,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4171,6 +4269,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4208,6 +4307,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4245,6 +4345,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4282,6 +4383,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4319,6 +4421,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4356,6 +4459,7 @@ "level": 4, "modes": [ { + "display_name": "Ward", "effect": { "condition": null, "cures_conditions": [], @@ -4439,6 +4543,7 @@ "level": 3, "modes": [ { + "display_name": "Ward", "effect": { "condition": null, "cures_conditions": [], @@ -4522,6 +4627,7 @@ "level": 1, "modes": [ { + "display_name": "Ward", "effect": { "condition": null, "cures_conditions": [], @@ -4602,6 +4708,7 @@ "level": 1, "modes": [ { + "display_name": "Ward", "effect": { "condition": null, "cures_conditions": [], @@ -4682,6 +4789,7 @@ "level": 3, "modes": [ { + "display_name": "Ward", "effect": { "condition": null, "cures_conditions": [], @@ -4746,6 +4854,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4783,6 +4892,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4812,6 +4922,7 @@ }, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -4843,6 +4954,7 @@ "level": 5, "modes": [ { + "display_name": "Restore life", "effect": { "condition": null, "cures_conditions": [], @@ -4870,6 +4982,7 @@ } }, { + "display_name": "Destroy undead", "effect": { "condition": null, "cures_conditions": [], @@ -4914,6 +5027,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Kill", "effect": { "condition": null, "cures_conditions": [], @@ -4965,6 +5079,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5002,6 +5117,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5039,6 +5155,7 @@ "level": 6, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5076,6 +5193,7 @@ "level": 3, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5105,6 +5223,7 @@ }, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5136,6 +5255,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5165,6 +5285,7 @@ }, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5196,6 +5317,7 @@ "level": 1, "modes": [ { + "display_name": "Remove", "effect": { "condition": null, "cures_conditions": [ @@ -5238,6 +5360,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Frighten", "effect": { "condition": "afraid", "cures_conditions": [], @@ -5289,6 +5412,7 @@ "level": 1, "modes": [ { + "display_name": "Resist", "effect": { "condition": null, "cures_conditions": [], @@ -5367,6 +5491,7 @@ "level": 2, "modes": [ { + "display_name": "Resist", "effect": { "condition": null, "cures_conditions": [], @@ -5443,6 +5568,7 @@ "level": 1, "modes": [ { + "display_name": "Shield", "effect": { "condition": null, "cures_conditions": [], @@ -5517,6 +5643,7 @@ "level": 2, "modes": [ { + "display_name": "Silence a creature", "effect": { "condition": "silenced", "cures_conditions": [], @@ -5548,10 +5675,11 @@ } }, { + "display_name": "Silence an area", "effect": null, "key": "area", "manual": true, - "prose": "A 15’ radius area is rendered utterly silent.\nWithin the area: All sound is prevented. Conversation and spell casting are impossible.\nNoise from outside the area: Can be heard by those within it.\nCasting upon a creature: Silence may be cast upon a creature, which must save versus spells. If the save fails, the 15’ radius area of silence moves with the creature. If the save succeeds, the spell’s effect remains stationary—the targeted creature may move out of it.", + "prose": "A 15’ radius area is rendered utterly silent.\nWithin the area: All sound is prevented. Conversation and spell casting are impossible.\nNoise from outside the area: Can be heard by those within it.", "save": null, "targeting": null } @@ -5585,6 +5713,7 @@ "level": 1, "modes": [ { + "display_name": "Put a creature with 4+1 Hit Dice to sleep", "effect": { "condition": "asleep", "cures_conditions": [], @@ -5613,6 +5742,7 @@ } }, { + "display_name": "Put creatures of 4 Hit Dice or lower to sleep", "effect": { "condition": "asleep", "cures_conditions": [], @@ -5669,6 +5799,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5706,6 +5837,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5743,6 +5875,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5877,6 +6010,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -5914,6 +6048,7 @@ "level": 6, "modes": [ { + "display_name": "Restore", "effect": { "condition": null, "cures_conditions": [ @@ -5953,6 +6088,7 @@ "duration_spec": null, "modes": [ { + "display_name": "Petrify", "effect": { "condition": "petrified", "cures_conditions": [], @@ -6006,6 +6142,7 @@ "level": 3, "modes": [ { + "display_name": "Enchant", "effect": { "condition": null, "cures_conditions": [], @@ -6080,6 +6217,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6117,6 +6255,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6154,6 +6293,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6183,6 +6323,7 @@ }, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6214,6 +6355,7 @@ "level": 1, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6251,6 +6393,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6288,6 +6431,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6325,6 +6469,7 @@ "level": 5, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6362,6 +6507,7 @@ "level": 3, "modes": [ { + "display_name": "Grant", "effect": { "condition": null, "cures_conditions": [], @@ -6417,6 +6563,7 @@ "level": 2, "modes": [ { + "display_name": "Entangle", "effect": { "condition": "entangled", "cures_conditions": [], @@ -6478,6 +6625,7 @@ "level": 4, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, @@ -6515,6 +6663,7 @@ "level": 2, "modes": [ { + "display_name": "Cast", "effect": null, "key": "cast", "manual": true, diff --git a/tests/saves/spell_mode_names_2.8.0.json b/tests/saves/spell_mode_names_2.8.0.json new file mode 100644 index 0000000..26feb29 --- /dev/null +++ b/tests/saves/spell_mode_names_2.8.0.json @@ -0,0 +1,493 @@ +{ + "engine_version": "2.8.0", + "kind": "save", + "payload": { + "adventure": { + "description": "", + "dungeons": [ + { + "id": "crypt", + "levels": [ + { + "areas": [], + "edges": { + "1,0:west": { + "door": null, + "kind": "open" + } + }, + "entrance": [ + 0, + 0 + ], + "features": [], + "guidance": "", + "height": 1, + "number": 1, + "transitions": [], + "wandering": { + "chance_in_six": 1, + "interval_turns": 2, + "table": null + }, + "width": 2 + } + ], + "name": "Crypt" + } + ], + "hooks": [], + "items": [], + "monsters": [], + "name": "A", + "party": null, + "quests": [], + "spells": [ + { + "conjured_monster_ids": [], + "conjured_monsters": [], + "duration": "6 turns +1 per level", + "duration_spec": { + "amount": 6, + "concentration_cap_amount": null, + "concentration_cap_unit": null, + "dice": null, + "kind": "fixed", + "per_level": 1, + "unit": "turn" + }, + "id": "gloaming", + "intro": "This spell has three usages:", + "level": 1, + "modes": [ + { + "effect": { + "condition": null, + "cures_conditions": [], + "cures_effect_kinds": [], + "kind": "attach_only", + "modifiers": [], + "params": { + "brightness": "reading", + "effect_kind": "light", + "radius_feet": 15 + } + }, + "key": "illuminate", + "manual": false, + "prose": "Conjuring light: In a 15\u2019 radius. The magical light is sufficient for reading, but is not as bright as daylight. The spell may be cast upon an object, in which case the light moves with the object.", + "save": null, + "targeting": { + "count": null, + "count_dice": null, + "dimensions": {}, + "hd_budget_dice": null, + "hd_cap": null, + "hd_min": null, + "mode": "single", + "shape": null + } + }, + { + "effect": { + "condition": "blind", + "cures_conditions": [], + "cures_effect_kinds": [], + "kind": "condition", + "modifiers": [], + "params": {} + }, + "key": "blind", + "manual": false, + "prose": "Blinding a creature: By casting the spell upon its eyes. If the target fails a saving throw versus spells, it is blinded for the duration. A blind creature cannot attack.", + "save": { + "category": "spells", + "modifier": 0, + "on_save": "negates" + }, + "targeting": { + "count": null, + "count_dice": null, + "dimensions": {}, + "hd_budget_dice": null, + "hd_cap": null, + "hd_min": null, + "mode": "single", + "shape": null + } + }, + { + "effect": { + "condition": null, + "cures_conditions": [], + "cures_effect_kinds": [ + "darkness" + ], + "kind": "cure", + "modifiers": [], + "params": {} + }, + "key": "cancel", + "manual": false, + "prose": "Cancelling darkness: Light may cancel a darkness spell (see below).", + "save": null, + "targeting": { + "count": null, + "count_dice": null, + "dimensions": {}, + "hd_budget_dice": null, + "hd_cap": null, + "hd_min": null, + "mode": "single", + "shape": null + } + } + ], + "name": "Gloaming", + "overrides_applied": [], + "range": "120\u2019", + "range_spec": { + "feet": 120, + "kind": "feet", + "per_level_feet": null + }, + "reversed_form": { + "duration": null, + "duration_spec": null, + "modes": [ + { + "effect": { + "condition": null, + "cures_conditions": [], + "cures_effect_kinds": [], + "kind": "attach_only", + "modifiers": [], + "params": { + "blocks_infravision": false, + "effect_kind": "darkness", + "radius_feet": 15 + } + }, + "key": "darken", + "manual": false, + "prose": "Creates a 15\u2019 radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "save": null, + "targeting": { + "count": null, + "count_dice": null, + "dimensions": {}, + "hd_budget_dice": null, + "hd_cap": null, + "hd_min": null, + "mode": "single", + "shape": null + } + }, + { + "effect": { + "condition": "blind", + "cures_conditions": [], + "cures_effect_kinds": [], + "kind": "condition", + "modifiers": [], + "params": {} + }, + "key": "blind", + "manual": false, + "prose": "Creates a 15\u2019 radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "save": { + "category": "spells", + "modifier": 0, + "on_save": "negates" + }, + "targeting": { + "count": null, + "count_dice": null, + "dimensions": {}, + "hd_budget_dice": null, + "hd_cap": null, + "hd_min": null, + "mode": "single", + "shape": null + } + }, + { + "effect": { + "condition": null, + "cures_conditions": [], + "cures_effect_kinds": [ + "light" + ], + "kind": "cure", + "modifiers": [], + "params": {} + }, + "key": "cancel", + "manual": false, + "prose": "Creates a 15\u2019 radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell.", + "save": null, + "targeting": { + "count": null, + "count_dice": null, + "dimensions": {}, + "hd_budget_dice": null, + "hd_cap": null, + "hd_min": null, + "mode": "single", + "shape": null + } + } + ], + "name": "Darkness", + "prose": "Creates a 15\u2019 radius area of magical blackness, preventing normal sight (but not infravision). Like light, it may alternatively be used to blind creatures or to dispel a light spell." + }, + "spell_list": "magic_user" + } + ], + "town": { + "description": "", + "healing_prices": {}, + "name": "Threshold", + "services": [], + "travel_turns": { + "crypt": 1 + } + }, + "triggers": [] + }, + "allocator": { + "counters": { + "character": 2 + } + }, + "battle": null, + "clock_rounds": 3240, + "command_log": [ + { + "command_type": "rest", + "hidden": false, + "kind": "night", + "source": null + }, + { + "character_id": "character-0002", + "command_type": "prepare_spells", + "selections": [ + { + "reversed": true, + "spell_id": "gloaming" + }, + { + "reversed": false, + "spell_id": "light_mu" + } + ], + "source": null + } + ], + "death_records": {}, + "defeated_monsters": [], + "deprivation": {}, + "dungeon_state": { + "doors": {}, + "emptied_caches": [], + "explored": {}, + "found_traps": [], + "found_tricks": [], + "generated_caches": {}, + "generated_lair_hoards": [], + "generated_treasure_areas": [], + "inspect_attempts": {}, + "listen_attempts": {}, + "location": { + "dungeon_id": null, + "facing": null, + "kind": "town", + "level_number": null, + "position": null + }, + "lock_failures": {}, + "piles": {}, + "removal_attempts": {}, + "removed_traps": [], + "resolved_encounters": [], + "search_attempts": {}, + "seen": {}, + "sprung_traps": [] + }, + "encounter": null, + "event_log": [ + { + "code": "exploration.rest.rested", + "event_type": "rested", + "kind": "night", + "visibility": "player" + }, + { + "caster_id": "character-0002", + "code": "magic.memorize.prepared", + "event_type": "spells_memorized", + "prepared": [ + { + "reversed": true, + "spell_id": "gloaming" + }, + { + "reversed": false, + "spell_id": "light_mu" + } + ], + "visibility": "player" + } + ], + "exploration": { + "alerted_areas": [], + "heard_areas": [], + "last_prepared_sleep": { + "character-0002": 1 + }, + "noise_since_check": false, + "odometer_thirds": 0, + "provisions_day": 0, + "sleep_count": 1, + "turns_since_rest": 0, + "wandering_counter": 0 + }, + "fired_triggers": [], + "flags": {}, + "journal": [], + "ledger": { + "effects": [] + }, + "listener_state": {}, + "master_seed": 7, + "mode": "town", + "monsters": [], + "npcs": [], + "party": { + "members": [ + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "fighter", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0001", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 3, + "max_hp": 400, + "memorized_spells": [], + "name": "Hild", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 10, + "con": 10, + "dex": 10, + "int": 10, + "str": 10, + "wis": 10 + }, + "spell_book": [], + "stat_modifiers": [], + "xp": 4000 + }, + { + "alignment": "lawful", + "carrying_treasure": false, + "class_id": "magic_user", + "conditions": [], + "current_hp": 400, + "custom_class": null, + "extra_languages": [], + "id": "character-0002", + "inventory": { + "items": [], + "purse": { + "cp": 0, + "ep": 0, + "gp": 0, + "pp": 0, + "sp": 0 + }, + "rings": [], + "shield": null, + "valuables": [], + "wielded": [], + "worn_armour": null + }, + "level": 3, + "max_hp": 400, + "memorized_spells": [ + { + "reversed": true, + "spell_id": "gloaming" + }, + { + "reversed": false, + "spell_id": "light_mu" + } + ], + "name": "Wren", + "nonregen_damage": 0, + "race": "human", + "scores": { + "cha": 12, + "con": 12, + "dex": 12, + "int": 12, + "str": 12, + "wis": 12 + }, + "spell_book": [ + "gloaming", + "light_mu" + ], + "stat_modifiers": [], + "xp": 5000 + } + ] + }, + "quests": {}, + "rng_streams": { + "effects": { + "inc": 110921974297112361420962594425958014099, + "state": 323578275112908533770403587567316273018 + } + }, + "ruleset": { + "aoe_friendly_fire": true, + "back_stab_needs_both_skills": true, + "deprivation_penalties": false, + "encumbrance": "basic", + "failed_trap_removal_springs": true, + "formation_width_limit": true, + "hd5_counts_as_magical": false, + "hp_reroll_at_first_level": false, + "individual_initiative": false, + "magic_item_death_save": true, + "thac0_arithmetic": false, + "variable_weapon_damage": true, + "weapon_reload": false, + "xp_award_timing": "on_return" + }, + "treasure_snapshot_cp": null + }, + "schema_version": 4 +} diff --git a/tests/test_spell_mode_names.py b/tests/test_spell_mode_names.py new file mode 100644 index 0000000..a1d3811 --- /dev/null +++ b/tests/test_spell_mode_names.py @@ -0,0 +1,378 @@ +"""Every mode of a spell with more than one has a label and prose of its own (issue #340). + +A client's cast dialog lists a form's modes for the player to choose from. In 2.8.0 the three modes of +*darkness*, the reverse of *light*, had the same prose and the same targeting, so a client could tell them +apart only by their keys. `SpellMode.display_name` is a short label for each mode, and each mode of the +reverses of *light* and *continual light* has the part of the reverse's text that covers it. + +The labels are instructions in sentence case, with no closing punctuation. A built-in label comes from the +lead-in the OSE SRD prints before a usage, turned into an instruction where the lead-in is a gerund +("Blinding a creature:" is "Blind a creature"), and is written for osrlib where the page prints no lead-in or +one that isn't an instruction ("Against a group:" is "Hold a group"). A mode that has no label, such as the +one mode of a single-mode spell or a mode of a spell written for 2.8.0, gets one from its key. + +The compiled data in `src/osrlib/data/spells.json` is what these tests read, so they pass once the SRD +compiler fills the labels and divides the prose. +""" + +import json +from pathlib import Path + +import pytest + +import positions_fixtures as pf +from osrlib.core.spells import SpellMode, SpellTemplate +from osrlib.crawl.adventure import Adventure +from osrlib.crawl.party import Party +from osrlib.crawl.session import GameSession +from osrlib.data import load_spells +from osrlib.persistence import load_game +from test_custom_spells import wizard + +REPO = Path(__file__).resolve().parent.parent +SAVE_2_8_0 = Path(__file__).parent / "saves" / "spell_mode_names_2.8.0.json" +"""A save written by osrlib 2.8.0, before modes had labels. + +Wren, a 3rd-level magic-user, has the adventure's own spell `gloaming` (the built-in `light_mu` under a new id +and name, as 2.8.0 dumped it) and the built-in `light_mu` in her book. After a night's rest she prepared +`gloaming` reversed and `light_mu`. +""" + +# Each form of a built-in spell that has more than one mode: its modes' keys and labels, in the form's order. +# The OSE SRD lead-ins the labels come from are in the comments. Where a comment gives none, the page prints +# no lead-in for the usage, or a lead-in that is a noun or a phrase rather than something the caster does. +MULTI_MODE_LABELS: dict[tuple[str, bool], tuple[tuple[str, str], ...]] = { + # "Battle:" and "Ritual:" name the situations, not what the caster does. + ("bless", False): (("battle", "Bless allies in battle"), ("ritual", "Bless a ritual")), + # One paragraph: "a charm upon either 3d6 creatures of 3 HD or less or a single creature of more than 3 HD". + ("charm_monster", False): (("individual", "Charm an individual"), ("group", "Charm a group")), + # "Conjuring light:", "Blinding a creature:", "Cancelling darkness:". + ("continual_light_c", False): ( + ("illuminate", "Conjure light"), + ("blind", "Blind a creature"), + ("cancel", "Cancel darkness"), + ), + # The reverse prints one paragraph and no lead-ins. Its labels mirror the normal form's. + ("continual_light_c", True): ( + ("darken", "Conjure darkness"), + ("blind", "Blind a creature"), + ("cancel", "Cancel light"), + ), + ("continual_light_mu", False): ( + ("illuminate", "Conjure light"), + ("blind", "Blind a creature"), + ("cancel", "Cancel darkness"), + ), + ("continual_light_mu", True): ( + ("darken", "Conjure darkness"), + ("blind", "Blind a creature"), + ("cancel", "Cancel light"), + ), + # "Cure a subject of any disease:" and "Kill green slime:" are instructions already. + ("cure_disease", False): (("cure", "Cure a subject of any disease"), ("kill_green_slime", "Kill green slime")), + # "Healing a living subject:" and "Curing paralysis:". + ("cure_light_wounds", False): (("heal", "Heal a living subject"), ("cure_paralysis", "Cure paralysis")), + # "Against an individual:" and "Against a group:". + ("hold_monster", False): (("individual", "Hold an individual"), ("group", "Hold a group")), + ("hold_person_c", False): (("individual", "Hold an individual"), ("group", "Hold a group")), + ("hold_person_mu", False): (("individual", "Hold an individual"), ("group", "Hold a group")), + ("light_c", False): (("illuminate", "Conjure light"), ("blind", "Blind a creature"), ("cancel", "Cancel darkness")), + ("light_c", True): (("darken", "Conjure darkness"), ("blind", "Blind a creature"), ("cancel", "Cancel light")), + ("light_mu", False): ( + ("illuminate", "Conjure light"), + ("blind", "Blind a creature"), + ("cancel", "Cancel darkness"), + ), + ("light_mu", True): (("darken", "Conjure darkness"), ("blind", "Blind a creature"), ("cancel", "Cancel light")), + # "Characters:" and "Items:" name the subjects. The words are the usages' own: "Neutralize the effects of + # poison on a character" and "Remove poison from an item". + ("neutralize_poison", False): ( + ("neutralize", "Neutralize poison on a character"), + ("items", "Remove poison from an item"), + ), + # "Restore life:" and "Destroy undead:" are instructions already. + ("raise_dead", False): (("restore_life", "Restore life"), ("destroy_undead", "Destroy undead")), + # No numbered usages: the area, and "Casting upon a creature:" among the bullets. + ("silence_15_radius", False): (("creature", "Silence a creature"), ("area", "Silence an area")), + # "The spell may target either: 1. A single creature with 4+1 Hit Dice ... 2. A total of 2d8 Hit Dice". + # The page's two usages are "A single creature with 4+1 Hit Dice" and "A total of 2d8 Hit Dice of + # creatures of 4 HD or lower each", so each label says which creatures its mode works on. + ("sleep", False): ( + ("single_4_plus", "Put a creature with 4+1 Hit Dice to sleep"), + ("hd_budget", "Put creatures of 4 Hit Dice or lower to sleep"), + ), +} + +# The reverse of light, as the SRD prints it: "Creates a 15’ radius area of magical blackness, preventing normal +# sight (but not infravision). Like *light*, it may alternatively be used to blind creatures or to dispel a +# *light* spell." Each mode takes the words that cover it, and the shared "Like light, it may alternatively be +# used to" goes with both of the modes the second sentence names. +DARKNESS = ( + "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision). " + "Like light, it may alternatively be used to blind creatures or to dispel a light spell." +) +DARKNESS_MODE_PROSE = { + "darken": "Creates a 15’ radius area of magical blackness, preventing normal sight (but not infravision).", + "blind": "Like light, it may alternatively be used to blind creatures.", + "cancel": "Like light, it may alternatively be used to dispel a light spell.", +} +CONTINUAL_DARKNESS = ( + "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. " + "Light sources brought within the area of darkness do not illuminate it. " + "Like continual light, it may alternatively be used to blind creatures or to dispel a continual light spell." +) +CONTINUAL_DARKNESS_MODE_PROSE = { + "darken": ( + "Creates a 30’ radius area of magical blackness, preventing both normal sight and infravision. " + "Light sources brought within the area of darkness do not illuminate it." + ), + "blind": "Like continual light, it may alternatively be used to blind creatures.", + "cancel": "Like continual light, it may alternatively be used to dispel a continual light spell.", +} + +# Charm monster's page is one passage for both modes. Its first sentence offers the two: "This spell places a +# charm upon either 3d6 creatures of 3 HD or less or a single creature of more than 3 HD." Each mode keeps the +# alternative it is, and the rest of the passage, which covers both. +CHARM_MONSTER_REST = ( + " Each subject must make a save versus spells or be charmed as follows:\n" + "Friendship: Charmed creatures regard the caster as a close friend and will come to the caster’s defence.\n" + "Commands: If they share a language, the caster may give charmed creatures commands, which they will obey.\n" + "Subject’s nature: Charmed creatures may resist commands that contradict their habits or alignment.\n" + "Suicidal commands: Are always refused.\n" + "Restrictions: Undead are not affected.\n" + "Duration: The charm lasts indefinitely, but the subject is allowed to make further saves versus spells at " + "intervals, depending on its INT score. If one of these saves succeeds, the spell ends.\n" + "INT 3–8: New save once every month.\n" + "INT 9–12: New save each week.\n" + "INT 13–18: New save once every day." +) +CHARM_MONSTER_PROSE = { + "individual": "This spell places a charm upon a single creature of more than 3 HD." + CHARM_MONSTER_REST, + "group": "This spell places a charm upon 3d6 creatures of 3 HD or less." + CHARM_MONSTER_REST, +} + +# Silence 15' radius: the page describes the area, then "Casting upon a creature:" as a bullet. The area mode has +# the text without that bullet. The creature mode has all of it, because the area that moves with the creature +# is the same silent area. +SILENCE_AREA = ( + "A 15’ radius area is rendered utterly silent.\n" + "Within the area: All sound is prevented. Conversation and spell casting are impossible.\n" + "Noise from outside the area: Can be heard by those within it." +) +SILENCE_UPON_A_CREATURE = ( + "Casting upon a creature: Silence may be cast upon a creature, which must save versus spells. If the save " + "fails, the 15’ radius area of silence moves with the creature. If the save succeeds, the spell’s effect " + "remains stationary—the targeted creature may move out of it." +) + + +def _forms() -> list[tuple[SpellTemplate, bool, tuple[SpellMode, ...]]]: + """Every form of every built-in spell: the template, whether it's the reverse, and the form's modes.""" + forms = [] + for spell in load_spells().spells: + forms.append((spell, False, spell.modes)) + if spell.reversed_form is not None: + forms.append((spell, True, spell.reversed_form.modes)) + return forms + + +def _label_from_key(key: str) -> str: + """The label a mode without one gets: underscores become spaces, and the first letter becomes a capital.""" + words = key.replace("_", " ") + return words[:1].upper() + words[1:] + + +# ---------------------------------------------------------------------- the built-in labels + + +def test_every_multi_mode_form_has_the_labels_the_srd_supports(): + """Each form with more than one mode has the labels in `MULTI_MODE_LABELS`, and there are no other such forms.""" + multi_mode = {(spell.id, reversed): modes for spell, reversed, modes in _forms() if len(modes) > 1} + assert set(multi_mode) == set(MULTI_MODE_LABELS) + for form, modes in multi_mode.items(): + assert tuple((mode.key, mode.display_name) for mode in modes) == MULTI_MODE_LABELS[form], form + + +def test_sibling_modes_never_share_a_label(): + """No two modes of one form, normal or reversed, have the same label, so a dialog can list them by label.""" + for spell, reversed, modes in _forms(): + labels = [mode.display_name for mode in modes] + assert all(labels), (spell.id, reversed) + assert len(set(labels)) == len(labels), (spell.id, reversed, labels) + + +def test_every_built_in_label_is_an_instruction_in_sentence_case(): + """A label starts with a capital, has no space at either end, and ends without punctuation.""" + for spell, reversed, modes in _forms(): + for mode in modes: + label = mode.display_name + assert label, (spell.id, reversed, mode.key) + assert label == label.strip(), (spell.id, mode.key, label) + assert label[0].isupper(), (spell.id, mode.key, label) + assert label[-1] not in ".,:;!?", (spell.id, mode.key, label) + + +def test_the_mode_of_a_single_mode_form_is_labelled_from_its_key(): + """A form with one mode has no choice to label, so its mode gets the label a mode without one gets.""" + spells = load_spells() + assert spells.get("fire_ball").mode("damage").display_name == "Damage" + assert spells.get("magic_missile").mode("missiles").display_name == "Missiles" + assert spells.get("cure_light_wounds").mode("harm", reversed=True).display_name == "Harm" + assert spells.get("bless").mode("battle", reversed=True).display_name == "Battle" # blight's one mode + assert spells.get("speak_with_plants").mode("cast").display_name == "Cast" # a manual spell's one mode + for spell, reversed, modes in _forms(): + if len(modes) == 1: + assert modes[0].display_name == _label_from_key(modes[0].key), (spell.id, reversed) + + +# ---------------------------------------------------------------------- the prose of each mode + + +def test_sibling_modes_never_share_prose(): + """No two modes of one form have the same prose, so the prose shown for a mode describes that mode.""" + for spell, reversed, modes in _forms(): + prose = [mode.prose for mode in modes] + assert all(prose), (spell.id, reversed) + assert len(set(prose)) == len(prose), (spell.id, reversed, [mode.key for mode in modes]) + + +@pytest.mark.parametrize("spell_id", ["light_c", "light_mu"]) +def test_each_mode_of_darkness_has_the_text_that_covers_it(spell_id): + modes = load_spells().get(spell_id).reversed_form.modes + assert {mode.key: mode.prose for mode in modes} == DARKNESS_MODE_PROSE + + +@pytest.mark.parametrize("spell_id", ["continual_light_c", "continual_light_mu"]) +def test_each_mode_of_continual_darkness_has_the_text_that_covers_it(spell_id): + modes = load_spells().get(spell_id).reversed_form.modes + assert {mode.key: mode.prose for mode in modes} == CONTINUAL_DARKNESS_MODE_PROSE + + +def test_each_mode_of_charm_monster_has_its_own_alternative(): + modes = load_spells().get("charm_monster").modes + assert {mode.key: mode.prose for mode in modes} == CHARM_MONSTER_PROSE + + +def test_the_area_mode_of_silence_leaves_out_casting_upon_a_creature(): + silence = load_spells().get("silence_15_radius") + assert silence.mode("area").prose == SILENCE_AREA + assert silence.mode("creature").prose == SILENCE_AREA + "\n" + SILENCE_UPON_A_CREATURE + + +def test_the_reverse_keeps_its_whole_text(): + """`ReversedForm.prose` is the whole of the reverse's text, which its modes now divide between them.""" + spells = load_spells() + for spell_id in ("light_c", "light_mu"): + assert spells.get(spell_id).reversed_form.prose == DARKNESS + for spell_id in ("continual_light_c", "continual_light_mu"): + assert spells.get(spell_id).reversed_form.prose == CONTINUAL_DARKNESS + + +def test_the_normal_light_modes_keep_the_prose_of_their_usages(): + """The normal forms' modes already had a usage each, and their prose doesn't change.""" + spells = load_spells() + for spell_id in ("light_c", "light_mu", "continual_light_c", "continual_light_mu"): + modes = spells.get(spell_id).modes + assert [mode.prose.split(":", 1)[0] for mode in modes] == [ + "Conjuring light", + "Blinding a creature", + "Cancelling darkness", + ] + + +# ---------------------------------------------------------------------- a mode you write + + +def test_a_mode_you_write_without_a_label_gets_one_from_its_key(): + assert SpellMode(key="darken", manual=True).display_name == "Darken" + assert SpellMode.model_validate({"key": "kill_green_slime", "manual": True}).display_name == "Kill green slime" + assert SpellMode(key="snuff", manual=True, display_name="").display_name == "Snuff" + + +def test_a_label_of_only_spaces_counts_as_missing(): + # A label a cast dialog would show as a blank line is no label. + assert SpellMode(key="blind", manual=True, display_name=" ").display_name == "Blind" + assert SpellMode.model_validate({"key": "blind", "manual": True, "display_name": "\t"}).display_name == "Blind" + + +@pytest.mark.parametrize( + ("key", "label"), + [ + # Underscores at either end leave no space at either end, and the first letter is still a capital. + ("_lead", "Lead"), + ("trailing_", "Trailing"), + # A run of underscores is one space. + ("a__b", "A b"), + # A first character whose capital is more than one character stays as it is. + ("ß_key", "ß key"), + # A key with no letter to show is its own label, so the label is never empty. + ("__", "__"), + ], +) +def test_a_label_made_from_an_odd_key_is_trimmed_and_never_empty(key, label): + assert SpellMode(key=key, manual=True).display_name == label + + +@pytest.mark.parametrize(("key", "label"), [("x", "X"), ("2nd_try", "2nd try"), ("élan", "Élan")]) +def test_a_label_made_from_a_short_or_accented_key(key, label): + assert SpellMode(key=key, manual=True).display_name == label + + +def test_a_mode_you_write_keeps_the_label_you_give_it(): + mode = SpellMode(key="snuff", manual=True, display_name="Snuff the candles") + assert mode.display_name == "Snuff the candles" + assert SpellMode.model_validate(mode.model_dump()) == mode + + +def test_a_spell_document_from_2_8_0_loads_with_a_label_on_every_mode(): + """A spell dumped before modes had labels validates, and each of its modes is labelled from its key.""" + document = load_spells().get("light_mu").model_dump(mode="json") + for mode in (*document["modes"], *document["reversed_form"]["modes"]): + del mode["display_name"] + + spell = SpellTemplate.model_validate(document) + + assert [mode.display_name for mode in spell.modes] == ["Illuminate", "Blind", "Cancel"] + assert [mode.display_name for mode in spell.reversed_form.modes] == ["Darken", "Blind", "Cancel"] + + +def test_a_save_from_osrlib_2_8_0_labels_the_adventure_spells_from_their_keys(): + """A bundled spell is its author's text, so loading labels it from its keys and keeps its prose. + + The built-in spells come from the catalog, so the same session has the compiled labels for them. A fresh + session from the same adventure document has the same catalog as the restored one. + """ + document = json.loads(SAVE_2_8_0.read_text(encoding="utf-8")) + assert document["engine_version"] == "2.8.0" + + game = load_game(document) + + gloaming = game.effective_spells.get("gloaming") + assert [mode.display_name for mode in gloaming.modes] == ["Illuminate", "Blind", "Cancel"] + assert [mode.display_name for mode in gloaming.reversed_form.modes] == ["Darken", "Blind", "Cancel"] + assert [mode.prose for mode in gloaming.reversed_form.modes] == [DARKNESS, DARKNESS, DARKNESS] + light = game.effective_spells.get("light_mu") + assert [mode.display_name for mode in light.reversed_form.modes] == [ + "Conjure darkness", + "Blind a creature", + "Cancel light", + ] + + adventure = Adventure.model_validate(document["payload"]["adventure"]) + party = Party(members=[pf.character("Hild", "fighter"), wizard("gloaming", "light_mu")]) + fresh = GameSession.new(party, adventure, seed=7) + assert fresh.effective_spells == game.effective_spells + + +# ---------------------------------------------------------------------- the changelog + + +def test_the_changelog_names_the_labels_and_shows_a_changed_mode_prose(): + """The (#340) bullet names `display_name` and gives the old and the new prose of one mode of darkness.""" + bullets = [line for line in (REPO / "CHANGELOG.md").read_text(encoding="utf-8").splitlines() if "(#340)" in line] + assert bullets, "no CHANGELOG.md bullet for #340" + text = " ".join(bullets) + assert "display_name" in text + assert DARKNESS in text, "the old prose of a mode of darkness, the whole reverse's text" + # The new prose of `darken` is the start of the old text, so only `blind` and `cancel` show a change. + assert any(DARKNESS_MODE_PROSE[key] in text for key in ("blind", "cancel")), "the new prose of that mode" diff --git a/tools/srd_compile/spells.py b/tools/srd_compile/spells.py index bc89582..7bccfea 100644 --- a/tools/srd_compile/spells.py +++ b/tools/srd_compile/spells.py @@ -29,6 +29,12 @@ mechanically); the *invisible stalker* spell page's `(MU)` marker distinguishes it from the monster page, not a dual-class pair — its id stays plain `invisible_stalker`. + +Each mode of a multi-mode form takes its `display_name` from the lead-in of the numbered +usage it binds, through `_LEAD_IN_VERBS`, and `_SPELL_MECHANICS` contains a written label +for every other mode of such a form. The forms in `_PROSE_DIVISIONS` describe several usages in +one passage, so the compiler divides the passage among their modes in the page's own words +and fails if the page no longer reads the way the division expects. """ import re @@ -75,9 +81,22 @@ def _mode( effect: dict[str, object] | None = None, manual: bool = False, usage: int | None = None, + display_name: str = "", ) -> dict[str, object]: - """Build one `_SPELL_MECHANICS` mode entry; `usage` binds a numbered item's prose.""" - return {"key": key, "targeting": targeting, "save": save, "effect": effect, "manual": manual, "usage": usage} + """Build one `_SPELL_MECHANICS` mode entry. + + `usage` binds a numbered item's prose. `display_name` is the label written for a mode of a + multi-mode form whose page prints no lead-in for it, or a lead-in that isn't an instruction. + """ + return { + "key": key, + "targeting": targeting, + "save": save, + "effect": effect, + "manual": manual, + "usage": usage, + "display_name": display_name, + } def _cond( @@ -106,6 +125,7 @@ def _charm_effect(person_gate: bool) -> dict[str, object]: save={"category": "spells", "modifier": -2}, effect=_HOLD_EFFECT_PERSON, usage=1, + display_name="Hold an individual", ), _mode( "group", @@ -113,6 +133,7 @@ def _charm_effect(person_gate: bool) -> dict[str, object]: save={"category": "spells"}, effect=_HOLD_EFFECT_PERSON, usage=2, + display_name="Hold a group", ), ] @@ -146,9 +167,21 @@ def _charm_effect(person_gate: bool) -> dict[str, object]: "kind": "attach_only", "params": {"effect_kind": "darkness", "radius_feet": 15, "blocks_infravision": False}, }, + display_name="Conjure darkness", + ), + _mode( + "blind", + targeting={"mode": "single"}, + save={"category": "spells"}, + effect=_cond("blind"), + display_name="Blind a creature", + ), + _mode( + "cancel", + targeting={"mode": "single"}, + effect={"kind": "cure", "cures_effect_kinds": ["light"]}, + display_name="Cancel light", ), - _mode("blind", targeting={"mode": "single"}, save={"category": "spells"}, effect=_cond("blind")), - _mode("cancel", targeting={"mode": "single"}, effect={"kind": "cure", "cures_effect_kinds": ["light"]}), ] _CONTINUAL_LIGHT_MODES = [ @@ -178,9 +211,21 @@ def _charm_effect(person_gate: bool) -> dict[str, object]: "kind": "attach_only", "params": {"effect_kind": "continual_darkness", "radius_feet": 30, "blocks_infravision": True}, }, + display_name="Conjure darkness", + ), + _mode( + "blind", + targeting={"mode": "single"}, + save={"category": "spells"}, + effect=_cond("blind"), + display_name="Blind a creature", + ), + _mode( + "cancel", + targeting={"mode": "single"}, + effect={"kind": "cure", "cures_effect_kinds": ["continual_light"]}, + display_name="Cancel light", ), - _mode("blind", targeting={"mode": "single"}, save={"category": "spells"}, effect=_cond("blind")), - _mode("cancel", targeting={"mode": "single"}, effect={"kind": "cure", "cures_effect_kinds": ["continual_light"]}), ] _PROTECTION_FROM_EVIL_MODES = [ @@ -314,12 +359,14 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, targeting={"mode": "single"}, effect=_cond("asleep", params={"excludes_undead": True, "hd_count": 4, "hd_bonus_required": True}), usage=1, + display_name="Put a creature with 4+1 Hit Dice to sleep", ), _mode( "hd_budget", targeting={"mode": "hd_budget", "hd_budget_dice": "2d8", "hd_cap": 4}, effect=_cond("asleep", params={"excludes_undead": True, "excludes_hd_4_plus": True}), usage=2, + display_name="Put creatures of 4 Hit Dice or lower to sleep", ), ], }, @@ -334,6 +381,7 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, save={"category": "spells", "modifier": -2}, effect=_HOLD_EFFECT_ANY, usage=1, + display_name="Hold an individual", ), _mode( "group", @@ -341,6 +389,7 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, save={"category": "spells"}, effect=_HOLD_EFFECT_ANY, usage=2, + display_name="Hold a group", ), ], }, @@ -361,12 +410,14 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, targeting={"mode": "single", "hd_min": 4}, save={"category": "spells"}, effect=_charm_effect(person_gate=False), + display_name="Charm an individual", ), _mode( "group", targeting={"mode": "up_to_n", "count_dice": "3d6", "hd_cap": 3}, save={"category": "spells"}, effect=_charm_effect(person_gate=False), + display_name="Charm a group", ), ], }, @@ -446,8 +497,9 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, "params": {"revives_poison_dead": True, "revive_window_rounds": 10}, }, usage=1, + display_name="Neutralize poison on a character", ), - _mode("items", manual=True, usage=2), + _mode("items", manual=True, usage=2, display_name="Remove poison from an item"), ], }, "raise_dead": { @@ -531,8 +583,9 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, ], }, usage=1, + display_name="Bless allies in battle", ), - _mode("ritual", manual=True, usage=2), + _mode("ritual", manual=True, usage=2, display_name="Bless a ritual"), ], "reversed_modes": [ _mode( @@ -610,8 +663,9 @@ def _resist_modes(element: str, targeting: dict[str, object]) -> list[dict[str, targeting={"mode": "single"}, save={"category": "spells"}, effect=_cond("silenced", params={"effect_kind": "silence", "radius_feet": 15}), + display_name="Silence a creature", ), - _mode("area", manual=True), + _mode("area", manual=True, display_name="Silence an area"), ], }, "web": { @@ -1006,26 +1060,160 @@ def _parse_body(lines: list[str]) -> tuple[dict[int, str], str, str, list[tuple[ return usages, body, intro, stat_lines -def _build_mode(raw: dict[str, object], usages: dict[int, str], body: str) -> dict[str, object]: - usage = raw.get("usage") - prose = usages.get(usage, body) if isinstance(usage, int) else body - mode: dict[str, object] = { - "key": raw["key"], - "targeting": raw["targeting"], - "save": raw["save"], - "effect": raw["effect"], - "manual": raw["manual"], - "prose": prose, - } - if isinstance(usage, int) and usage not in usages: - raise ValueError(f"mode {raw['key']!r} binds usage {usage}, but the page has usages {sorted(usages)}") - return mode +_LEAD_IN = re.compile(r"^(?P[A-Z][a-z]+)(?P[^:.\n]*): ") + +# The first word of a usage's lead-in → the instruction verb its label starts with. The SRD prints most +# lead-ins as gerunds ("Blinding a creature:") and a few as instructions already ("Kill green slime:"). +# A lead-in whose first word is missing here names a situation or a subject ("Battle:", "Against a +# group:", "Characters:"), so that mode's label is written in `_SPELL_MECHANICS` from the page's words. +_LEAD_IN_VERBS = { + "Blinding": "Blind", + "Cancelling": "Cancel", + "Conjuring": "Conjure", + "Cure": "Cure", + "Curing": "Cure", + "Destroy": "Destroy", + "Healing": "Heal", + "Kill": "Kill", + "Restore": "Restore", +} + + +def _lead_in_label(prose: str) -> str: + """Return the instruction a usage's lead-in gives, like "Blind a creature", or "" when it gives none.""" + match = _LEAD_IN.match(prose) + if match is None or match["verb"] not in _LEAD_IN_VERBS: + return "" + return _LEAD_IN_VERBS[match["verb"]] + match["rest"] + + +def _build_modes( + spell_id: str, raw_modes: list[dict[str, object]], usages: dict[int, str], body: str +) -> list[dict[str, object]]: + """Build one form's modes, labelling each mode of a multi-mode form. + + A mode bound to a usage whose lead-in gives an instruction takes its label from the lead-in, and + every other mode of a multi-mode form takes the label written in `_SPELL_MECHANICS`. The mode of a + single-mode form compiles with an empty label, which `SpellMode` fills from the key. + + Raises: + ValueError: If a mode binds a usage the page lacks, a written label stands in for a lead-in's, + or a mode of a multi-mode form ends with no label or with a sibling's label. + """ + multi_mode = len(raw_modes) > 1 + modes = [] + for raw in raw_modes: + usage = raw.get("usage") + if isinstance(usage, int) and usage not in usages: + raise ValueError(f"mode {raw['key']!r} binds usage {usage}, but the page has usages {sorted(usages)}") + prose = usages[usage] if isinstance(usage, int) else body + lead_in = _lead_in_label(prose) if isinstance(usage, int) else "" + written = raw["display_name"] + if lead_in and written: + raise ValueError(f"{spell_id} mode {raw['key']!r} has a written label, but its lead-in gives {lead_in!r}") + if written and not multi_mode: + raise ValueError(f"{spell_id} mode {raw['key']!r} is its form's only mode, so its label comes from its key") + display_name = (lead_in or written) if multi_mode else "" + if multi_mode and not display_name: + raise ValueError(f"{spell_id} mode {raw['key']!r} has no lead-in and no written label") + modes.append( + { + "key": raw["key"], + "display_name": display_name, + "targeting": raw["targeting"], + "save": raw["save"], + "effect": raw["effect"], + "manual": raw["manual"], + "prose": prose, + } + ) + labels = [mode["display_name"] for mode in modes] + if len(set(labels)) != len(labels): + raise ValueError(f"{spell_id}: two modes of one form have the same label: {labels}") + return modes def _default_mode(body: str) -> dict[str, object]: return {"key": "cast", "targeting": None, "save": None, "effect": None, "manual": True, "prose": body} +_DARKNESS_PASSAGE = re.compile( + r"(?P.+?) (?PLike [^,]+, it may alternatively be used to) (?Pblind creatures) " + r"or to (?Pdispel an? [^.]+ spell)\.", + re.DOTALL, +) +_CHARM_MONSTER_PASSAGE = re.compile( + r"(?PThis spell places a charm upon) either (?P3d6 creatures of 3 HD or less) " + r"or (?Pa single creature of more than 3 HD)\.(?P.*)", + re.DOTALL, +) +_SILENCE_UPON_A_CREATURE = "Casting upon a creature:" + + +def _divide_darkness(passage: str) -> dict[str, str]: + """Divide the reverse of *light* or *continual light* among its three modes. + + The passage describes the darkness, then offers both other usages in one sentence: "Like light, it may + alternatively be used to blind creatures or to dispel a light spell." The `darken` mode takes the + description, and `blind` and `cancel` each take the sentence's shared opening with their own alternative. + """ + match = _DARKNESS_PASSAGE.fullmatch(passage) + if match is None: + raise ValueError(f"the reverse no longer offers its two alternative usages in one sentence: {passage!r}") + return { + "darken": match["darken"], + "blind": f"{match['like']} {match['blind']}.", + "cancel": f"{match['like']} {match['cancel']}.", + } + + +def _divide_charm_monster(passage: str) -> dict[str, str]: + """Give each mode of *charm monster* its alternative from the first sentence, then the rest of the page.""" + match = _CHARM_MONSTER_PASSAGE.fullmatch(passage) + if match is None: + raise ValueError(f"charm monster no longer opens with its two alternatives: {passage!r}") + return { + "individual": f"{match['lead']} {match['individual']}.{match['rest']}", + "group": f"{match['lead']} {match['group']}.{match['rest']}", + } + + +def _divide_silence(passage: str) -> dict[str, str]: + """Give the `area` mode of *silence 15' radius* the page without its last bullet, which covers `creature`. + + The `creature` mode keeps the whole page, because the area that moves with the creature is the same + silent area the earlier lines describe. + """ + *area, upon = passage.split("\n") + if not upon.startswith(_SILENCE_UPON_A_CREATURE) or any(_SILENCE_UPON_A_CREATURE in line for line in area): + raise ValueError(f"silence no longer ends with its {_SILENCE_UPON_A_CREATURE!r} bullet: {passage!r}") + return {"creature": passage, "area": "\n".join(area)} + + +# (spell id, reversed) → the function that divides the form's one passage among its modes. A form here +# describes several usages in one passage, so without a division every mode would have the same prose. +_PROSE_DIVISIONS = { + ("light_c", True): _divide_darkness, + ("light_mu", True): _divide_darkness, + ("continual_light_c", True): _divide_darkness, + ("continual_light_mu", True): _divide_darkness, + ("charm_monster", False): _divide_charm_monster, + ("silence_15_radius", False): _divide_silence, +} + + +def _divide_prose(spell_id: str, reversed_form: bool, modes: list[dict[str, object]], passage: str) -> None: + """Replace each mode's prose with its part of the form's passage, for the forms in `_PROSE_DIVISIONS`.""" + divide = _PROSE_DIVISIONS.get((spell_id, reversed_form)) + if divide is None: + return + parts = divide(passage) + if set(parts) != {mode["key"] for mode in modes}: + raise ValueError(f"{spell_id}: the prose divides into {sorted(parts)}, not the form's modes") + for mode in modes: + mode["prose"] = parts[mode["key"]] + + def compile_spells(srd_dir: Path, monster_entries: list[dict[str, object]]) -> dict[str, object]: """Compile the spell pages into the `spells.json` structure (sans `_meta`). @@ -1091,9 +1279,8 @@ def compile_spells(srd_dir: Path, monster_entries: list[dict[str, object]]) -> d duration_spec, reversed_duration_spec, reversed_duration_raw = _parse_duration(page.duration_raw) mechanics = _SPELL_MECHANICS.get(spell_id, {}) raw_modes = mechanics.get("modes") - modes = ( - [_build_mode(raw, page.usages, page.body) for raw in raw_modes] if raw_modes else [_default_mode(page.body)] - ) + modes = _build_modes(spell_id, raw_modes, page.usages, page.body) if raw_modes else [_default_mode(page.body)] + _divide_prose(spell_id, False, modes, page.body) entry: dict[str, object] = { "id": spell_id, "name": page.name, @@ -1111,10 +1298,11 @@ def compile_spells(srd_dir: Path, monster_entries: list[dict[str, object]]) -> d if page.reversed_name is not None: raw_reversed = mechanics.get("reversed_modes") reversed_modes = ( - [_build_mode(raw, page.reversed_usages, page.reversed_body) for raw in raw_reversed] + _build_modes(spell_id, raw_reversed, page.reversed_usages, page.reversed_body) if raw_reversed else [_default_mode(page.reversed_body)] ) + _divide_prose(spell_id, True, reversed_modes, page.reversed_body) entry["reversed_form"] = { "name": page.reversed_name, "prose": page.reversed_body,