CastSpell
Cast a memorized spell outside battle (one round).
Full documentation: CastSpell. Wire type: cast_spell.
Legal session modes: exploring, town
JSON Schema
{
"description": "Cast a memorized spell outside battle (one round).\n\nThe caster needs a memorized copy of the spell, which\n`PrepareSpells` gives them, and casting uses the\ncopy up. Each target is an entity id, or a `cell:` reference for a spell that affects a\nplace. This command isn't legal during an encounter or a battle. To cast at monsters the\nparty has met, open battle with\n`EngageBattle` and declare a `cast`\n`BattleDeclaration` in the round.\n\nModes:\n `town`, `exploring`\n\nRejections:\n - `session.command.wrong_mode` - an encounter or battle is underway, or the\n session has ended.\n - `session.command.unknown_member` - `character_id` matches no party member.\n - `session.command.member_incapacitated` - the member can't act.\n - `magic.cast.unknown_spell` - `spell_id` matches no spell in the session's catalog.\n - `magic.cast.silenced_area` - a *silence* effect covers the party's cell.\n - `magic.cast.unknown_target` - a target id matches no entity in the session.\n - `magic.cast.not_memorized` - the caster has no memorized copy. A member who\n can't cast spells at all gets this code too.\n - `magic.cast.caster_incapacitated`, `magic.cast.caster_restrained`,\n `magic.cast.anti_magic_shell` - the caster can't cast right now.\n - `magic.cast.not_reversible` - `reversed` is set on a spell with no reversed\n form.\n - `magic.cast.unknown_mode` - `mode` matches no mode of the spell.\n - `magic.cast.target_count` - the number of targets is wrong for the mode.\n - `magic.cast.target_must_be_creature` - a target is a cell reference, and the\n mode works only on creatures, like *fire ball*'s or *sleep*'s.\n - `magic.cast.out_of_range` - a target is beyond the spell's range.\n\nEvents:\n `SpellCastEvent`, then the events of the\n spell's resolution: saving throws, damage, healing, and effects attached, each a\n separate event. One round passes.\n\nExamples:\n A magic-user rests in town, prepares *light*, and casts it on themselves in the\n dungeon so the party can see:\n\n ```python\n from osrlib.core.alignment import Alignment\n from osrlib.core.character import CHARACTER_CREATION_STREAM, create_character\n from osrlib.core.rng import RngStreams\n from osrlib.core.ruleset import Ruleset\n from osrlib.core.spells import MemorizedSpell\n from osrlib.crawl.adventure import Adventure, TownSpec\n from osrlib.crawl.commands import CastSpell, EnterDungeon, PrepareSpells, Rest\n from osrlib.crawl.dungeon import DungeonSpec, LevelSpec\n from osrlib.crawl.party import Party\n from osrlib.crawl.session import GameSession\n\n stream = RngStreams(master_seed=7).get(CHARACTER_CREATION_STREAM)\n mage = create_character(\n name=\"Wenna\",\n class_id=\"magic_user\",\n alignment=Alignment.NEUTRAL,\n ruleset=Ruleset(),\n stream=stream,\n starting_spell_ids=[\"light_mu\"],\n ).character\n level = LevelSpec(number=1, width=1, height=1, entrance=(0, 0))\n crypt = DungeonSpec(id=\"crypt\", name=\"The Old Crypt\", levels=(level,))\n adventure = Adventure(name=\"A First Delve\", town=TownSpec(name=\"Threshold\"), dungeons=(crypt,))\n session = GameSession.new(Party(members=[mage]), adventure, seed=7)\n\n prepare = PrepareSpells(character_id=mage.id, selections=(MemorizedSpell(spell_id=\"light_mu\"),))\n print(session.execute(prepare).rejections[0].code) # no sleep yet\n # magic.memorize.needs_sleep\n session.execute(Rest(kind=\"night\"))\n print(session.execute(prepare).accepted)\n # True\n\n session.execute(EnterDungeon(dungeon_id=\"crypt\"))\n light = CastSpell(character_id=mage.id, spell_id=\"light_mu\", mode=\"illuminate\", targets=(mage.id,))\n result = session.execute(light)\n print([event.code for event in result.events])\n # ['magic.cast.cast', 'effects.effect.attached']\n print(session.party_light())\n # (True, True)\n ```",
"properties": {
"command_type": {
"const": "cast_spell",
"default": "cast_spell",
"title": "Command Type",
"type": "string",
"description": "The name that identifies the command class in serialized data. Each command class fixes\nit to a distinct snake_case string, like `\"move_party\"` or `\"open_door\"`, and constructing\nthe class sets it, so you never pass it yourself.\n`parse_command` and the\n`AnyCommand` union use it to rebuild the right class\nfrom a serialized mapping. A class's value never changes between releases."
},
"source": {
"anyOf": [
{
"minLength": 1,
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Source",
"description": "Who or what issued the command on whose behalf: an authored trigger or quest id, or the\nname of one of your game's systems. The engine never reads it, so a command with a\n`source` does exactly what the same command without one does. The session logs and\nreplays it with the command, so the log alone shows why something happened. Leave it\n`None` when there's nothing to record. An empty string fails validation when the command\nis constructed."
},
"character_id": {
"title": "Character Id",
"type": "string",
"description": "The caster, by `MemberView.id`. The caster needs a\nmemorized copy of the spell, and casting uses it up."
},
"spell_id": {
"title": "Spell Id",
"type": "string",
"description": "The spell to cast, by its id in\n`GameSession.effective_spells`: a\nbuilt-in spell (see the\n[spell id index](https://mmacy.github.io/osrlib-python/reference/content-ids/spells/)) or one\nthe adventure bundles. The session refuses a caster with no memorized copy with\n`magic.cast.not_memorized`, and refuses a member who can't cast spells at all the same way."
},
"mode": {
"title": "Mode",
"type": "string",
"description": "Which of the spell's usages to cast, by that usage's\n`SpellMode.key` on the form you're casting. A spell with\nseveral usages, like *light*, has one mode for each. For a spell with one usage, you still name\nits one key. The session refuses a key the form doesn't have with `magic.cast.unknown_mode`."
},
"reversed": {
"default": false,
"title": "Reversed",
"type": "boolean",
"description": "Cast the reversed form, like *cause light wounds* for *cure light wounds*. An arcane\ncaster fixes the form when memorizing, so a reversed cast needs a reversed copy memorized.\nA divine caster memorizes the normal form and chooses the form here, when casting. The session\nrefuses `reversed` on a spell with no reversed form, with `magic.cast.not_reversible`."
},
"targets": {
"default": [],
"items": {
"type": "string"
},
"title": "Targets",
"type": "array",
"description": "Who or what the spell targets, as entity ids: a party member's\n`MemberView.id`, a monster's id, or, for a spell that\naffects a place rather than a creature, a cell reference in the\n`cell:{dungeon}:{level}:{x},{y}` form that `cell_ref`\nbuilds. The mode's targeting sets how many targets it takes, and the session refuses the\nwrong number with `magic.cast.target_count`. The session refuses a cell reference for a\nmode that works only on creatures with `magic.cast.target_must_be_creature`."
}
},
"required": [
"character_id",
"spell_id",
"mode"
],
"title": "CastSpell",
"type": "object"
}