Skip to content

Migration guide: v0.7 → v0.8

v0.8.0 is a minor release of dnd5e-engine, dnd5e-srd-data and nat20-bridge, in lockstep. Every new name and field is additive and defaulted, and a payload a host stored under 0.7.0 (specs, intents, an outcome, an event log) still validates on the 0.8.0 models. What a host can notice is a handful of behaviour changes: a move takes a detour, the monster AI's closing walk no longer shares cells, an item that casts a spell targets as that spell, kills are credited to the creature that dealt them, and the new KnockedOut event. The dataset does not change.

Upgrade checklist

Upgrade the three packages together: dnd5e-engine requires dnd5e-srd-data>=0.8.0, and nat20-bridge requires both at >=0.8.0. Then:

  1. Handle KnockedOut if you match CombatEvent exhaustively: it is a new member of the closed union. It is emitted only when a host asks for a knock-out.
  2. Handle knock_out_not_melee if you match IntentRejectedError.RejectionReason exhaustively.
  3. Stop mirroring the old blocked_path refusal. A move to an adjacent cell behind a wall now walks around it when it can; a host that rejects such a move up front (a move preview, a destination filter) needs the same change.
  4. List an item that casts a spell with the spell's own targeting. A Wand of Fireballs now places Fireball's Sphere and a Wand of Magic Missiles splits its darts; a host that catalogued such items as single-target should stop.
  5. Read DeathRecord.killer_id as the creature that dealt the blow, not the creature whose turn it was.
  6. Optionally adopt the new features: party-side allies (EncounterMemberSpec.side), a host-chosen monster target (advance_monster_turn(target_id=...)) and knock-outs (PlayerIntent.knock_out).

Grid movement

What a host has to do

Nothing, unless it mirrors the engine's movement rules: see the checklist.

Behaviour changes

  • A move takes a detour. When the direct step to an adjacent destination crosses a wall or cuts a blocked corner, the move takes the shortest legal route around, priced and walked like any other route: it pays the longer route's movement and can provoke opportunity attacks on the way. The refusals are now:
    • blocked_path: the destination is adjacent, the direct step is illegal, and no route goes around;
    • insufficient_movement: the detour costs more than the movement left; nothing moves;
    • unreachable: no legal route, as before.
  • The monster AI's closing walk honours occupancy. It passes through allies, never ends on another creature and never enters an enemy's cell. It stops on the first cell of its route that is in range with line of sight when that cell is free, else on the cheapest free cell in range; with no creature in the way the walk is the same cell for cell as before. It walks before it Dashes: it takes the Dash only when no free cell in range is within its remaining movement, and the Dash is priced to the cell it stops on, not to the target's own cell. When no free cell in range is reachable even with a Dash, it walks as far as its movement goes and stops on the last free cell; with no route to the target at all it stays where it is. An opportunity attack that stops it part-way can still leave it on an ally's cell it was passing through (BACKLOG.md).
  • Walled maps are faster. Wall segments are indexed by the cells they touch, so a step or sight test reads only nearby walls. Every answer is unchanged; the cost per step no longer grows with the number of walls.

Item casts

What a host has to do

List an item whose use casts a spell with that spell's targeting (checklist item 4).

Behaviour changes

  • A use_item whose one resolved activity is a cast targets the way the spell it casts does. The spell's area is placed, with AreaTargeted, and catches whoever the spell would, allies and the caster included. A count that scales (Magic Missile's darts, extra targets) is read at the item's cast level: the level its extra charges buy, else the item's printed level, else the spell's own. More target_ids than the count allows is refused with CastFailed(reason="target_invalid") before any charge is spent.
  • A spell with an attack roll still places no area, a feature's cast is unchanged, and an item with several activities and no activity_id still places nothing.
  • Item text that changes the spell's area or targets (the Wand of Fear's 60-foot Cone) is not honoured yet, and an item's cast is not range-gated (BACKLOG.md).

Sides

What a host has to do

Nothing, unless it seats allies. With no side on any spec a combat runs exactly as on 0.7.

New behaviour

  • EncounterMemberSpec.side is "encounter" (the default) or "party". A party-side member joins party_ids: foes target it, it fights foes, and every ally rule reads it as the party's. On its own turn advance_monster_turn runs the AI for it, or the host commands it through submit_player_intent as it would a summon.
  • It is not a character: at 0 Hit Points it dies as a monster does, and its DeathRecord.target_kind is "npc" or "monster". A host that assumed a party-side death is always a character's must accept those kinds.
  • XP is divided among the surviving characters only; an ally takes no share. residual_hp reports an ally's Hit Points with the party's.
  • start_combat raises ValueError unless at least one encounter member fights on the encounter side.
  • A standing ally keeps the party in the fight: a combat closed after every character has died while an ally still stands reads ended_reason "forced" (or "flee" when every foe still in the fight has fled), not "defeat_tpk".

A host-chosen monster target

What a host has to do

Nothing: target_id=None keeps the engine's lowest-HP pick.

New behaviour

  • advance_monster_turn(handle, target_id=...) names the creature the acting monster attacks, or targets with a stat-block cast. The monster walks toward it, Dashing when it must, and never substitutes another creature.
  • The id must be in the monster's own target pool: an enemy in the initiative order, alive, not knocked out, not its charmer. Any other id, and any id on a summon's turn, raises IntentRejectedError("target_invalid") before the turn starts: no die is rolled, nothing is spent, no event is emitted, and the turn stays where it was. On a character's turn not_actor_turn is raised first.
  • An area action keeps the engine's own aim. With legendary=True the keyword names the legendary action's target, checked before LegendaryActionUsed.

Knocking out a creature

What a host has to do

Handle KnockedOut and knock_out_not_melee (checklist items 1 and 2). Every default leaves the 0.7 behaviour in place.

New behaviour

  • PlayerIntent.knock_out=True on an attack pulls every melee blow of the intent (SRD 5.2 Knocking Out a Creature). A blow that would drop a creature to 0 Hit Points leaves it at 1 instead: DamageApplied(knock_out=True), KnockedOut(target_id, attacker_id), ConditionApplied("unconscious"). It is not dying: no Unconscious marker and no death saves.
  • The intent is refused with knock_out_not_melee, before anything is spent, unless every attack it resolves is a melee attack. Only the attack's own damage is pulled: a rider resolved by a saving throw after the hit can still kill. Other intent types ignore the flag, so a melee spell attack kills.
  • A creature immune to Unconscious is left at 1 Hit Point and stays conscious; a summon still leaves at 0.
  • A knocked-out creature stays out until it regains Hit Points (any healing, Regeneration included, wakes it Prone) or drops to 0 Hit Points. While out it is in LiveCombatView.knocked_out_ids, no monster targets it, a host may not name it as target_id, and the end reason counts it with the dead on its side.
  • At end_combat, CombatOutcome.knock_outs lists the creatures still out, in the order they went down, as KnockOutRecords. A foe still knocked out is worth its XP, as a dead one is.
  • First aid as an action, a knock-out by a melee spell attack, and a monster-driven turn pulling its blow are not modelled (BACKLOG.md).

Kill attribution

Behaviour changes

  • DeathRecord.killer_id names the creature that dealt the killing damage, whoever's turn it was. On 0.7 it named the creature whose turn it was, so an opportunity attack that killed the mover recorded nobody and a legendary action recorded whoever's turn it interrupted. A spell construct's kill names its caster; a summon's kill names the summon. A death save the dying creature fails on its own turn, and a creature that killed itself, name nobody; damage that adds the third failure names the creature that dealt it. KnockedOut.attacker_id and KnockOutRecord.attacker_id follow the same rule.
  • Combatant.last_damaged_by follows the same source, so a reaction that answers damage (Hellish Rebuke) can target an opportunity attack's reactor.
  • LiveCombatView.deaths lists the deaths so far, in order, with that attribution: the records CombatOutcome.deaths will hold.

Smaller changes

  • A character already Unconscious from an effect (a sleep) that drops to 0 Hit Points now emits the Unconscious dying marker, as any character at 0 Hit Points does, and stays Unconscious when that effect ends; it used to wake at 0 Hit Points.
  • end_combat and LiveCombatView.final_outcome return a copy of the kept outcome each time, so mutating one no longer changes what a later call returns.

nat20-bridge

New behaviour

  • POST /v1/combat takes allies, a list of monster slugs seated on the party's side; they share the foes' numbering. Allies alone answer 422.
  • POST /v1/combat/{cid}/advance-monster takes an optional body {"target_id": "<entity id>"}. No body, {} or {"target_id": null} keeps the engine's pick; an illegal target answers 409 target_invalid; any other key answers 422.
  • An intent body accepts knock_out; a non-melee attack answers 409 knock_out_not_melee. A knock-out narrates as a line.
  • GET /v1/combat/{cid} adds party_ids, encounter_ids, knocked_out_ids and deaths.

New API

  • EncounterMemberSpec.side and Side (dnd5e_engine.specs).
  • advance_monster_turn(..., target_id=None).
  • PlayerIntent.knock_out and the knock_out_not_melee rejection reason.
  • KnockOutRecord (top level) and CombatOutcome.knock_outs.
  • LiveCombatView.knocked_out_ids and LiveCombatView.deaths.
  • KnockedOut and DamageApplied.knock_out (dnd5e_engine.events).
  • For hosts that resolve activities themselves: ActivityResolutionContext.knock_out and knock_out_exempt_ids, the same two keywords on build_activity_context, the knock_out keyword of apply_damage, and is_melee_attack (dnd5e_engine.activities.attack).
  • dnd5e_engine.testing.rng_factory: a test-support context manager that scripts or records a combat's dice, Initiative included. It is process-wide for the block and not for production code.

Moved seeded pins

With no side, no target_id and no knock_out, seeded fights produce the same event logs as on 0.7, except where a monster's closing walk used to end on or pass through another creature's cell, and where a move used to be refused with a detour available. Three engine pins moved, each to the detour:

  • tests/test_c16_orchestrator.py: the blocked_path pin is now a 10 ft detour; a walled-in destination still answers blocked_path, and a detour that costs too much answers insufficient_movement.
  • tests/test_orchestrator_grid_combat.py: the wall between two adjacent cells is now a 25 ft detour.
  • tests/e2e/test_c16_spatial_targeting.py, the cut-corner scene: one 10 ft move around the corner instead of a refusal.

DeathRecord.killer_id changes where a kill came from a creature other than the current actor.