Skip to content

AttackRolledEvent

One attack roll and everything that went into it.

Full documentation: AttackRolledEvent. Wire type: attack_rolled.

Default visibility: player

Message codes: combat.attack.auto_hit, combat.attack.hit, combat.attack.missed

JSON Schema

{
  "$defs": {
    "Visibility": {
      "description": "Who may see an event: the players, or only the referee.\n\nEvery event has one of these values, because in B/X the referee makes some rolls behind a screen. Filter\na log on it before you show anything to a player, or call\n`GameSession.view`, which builds the players' view and the referee's\nview for you. A narrator that plays the referee reads every event.\n\nA serialized event contains the lowercase value. The values stay fixed within a `schema_version`, the version\nstamp of the saved format.\n\nExamples:\n    ```python\n    from osrlib.core.events import DamageDealtEvent, HitPointsReportedEvent, Visibility\n\n    log = [\n        DamageDealtEvent(target_id=\"monster-0001\", amount=5),\n        HitPointsReportedEvent(target_id=\"monster-0001\", current_hp=2, max_hp=7),\n    ]\n    shown = [event.code for event in log if event.visibility is Visibility.PLAYER]\n    assert shown == [\"combat.damage.dealt\"]  # the goblin's remaining hit points stay hidden\n    ```",
      "enum": [
        "player",
        "referee"
      ],
      "title": "Visibility",
      "type": "string"
    }
  },
  "description": "One attack roll and everything that went into it.\n\n`attack_roll` reports one of these for every attack, and\n`resolve_attack` reports it before the damage that follows. Read `code`\nfor the outcome, and the number fields to show the arithmetic.\n\nAn automatic hit has no roll. A melee attack hits a paralysed, sleeping, or petrified defender automatically, and\nany attack hits a monster with no armour class, like green slime. On an automatic hit, `roll`, `total`,\n`required`, and `defender_ac` are `None`.",
  "properties": {
    "code": {
      "title": "Code",
      "type": "string",
      "description": "What happened, like `combat.attack.hit`: two or more lowercase parts separated by dots. The first part is\nthe area of the rules the event comes from, like `combat` or `magic`.\n\nBranch on it, and pass the event to `format_message` to turn it into English.\nBuilding an event with a code in any other format raises a pydantic `ValidationError`."
    },
    "visibility": {
      "$ref": "#/$defs/Visibility",
      "default": "player",
      "description": "Player visibility: attack rolls happen in the open."
    },
    "event_type": {
      "const": "attack_rolled",
      "default": "attack_rolled",
      "title": "Event Type",
      "type": "string",
      "description": "The fixed string that identifies this event class in a serialized event."
    },
    "attacker_id": {
      "title": "Attacker Id",
      "type": "string",
      "description": "The entity id of whoever attacked."
    },
    "defender_id": {
      "title": "Defender Id",
      "type": "string",
      "description": "The entity id of whoever was attacked."
    },
    "attack_name": {
      "title": "Attack Name",
      "type": "string",
      "description": "The name of what the attacker used: a weapon, a gear item, a magic item, or a monster's attack. It's\n`\"unarmed\"` for an unarmed attack, and `\"improvised\"` for an attack with a gear item's combat stats alone."
    },
    "roll": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Roll",
      "description": "The d20 as it landed, before modifiers. `None` on an automatic hit."
    },
    "modifier": {
      "default": 0,
      "title": "Modifier",
      "type": "integer",
      "description": "The sum of everything added to the roll, like STR, range, magic, spells, and your situational modifier. It\ncan be negative."
    },
    "total": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Total",
      "description": "The roll plus the modifier, which is the number compared with `required`. `None` on an automatic hit."
    },
    "required": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Required",
      "description": "The total the attacker needed to hit, from its THAC0 and the defender's armour class. `None` on an\nautomatic hit."
    },
    "defender_ac": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Defender Ac",
      "description": "The defender's armour class as the roll used it, after its shield, spells, and the situation. `None` on\nan automatic hit."
    },
    "natural": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Natural",
      "description": "1 or 20 when the d20 alone decided the outcome, and `None` otherwise.\n\nA natural 20 always hits and a natural 1 always misses. This field is set only when that rule changed the\noutcome: a 20 whose total was below `required`, or a 1 whose total reached it."
    },
    "back_stab": {
      "default": false,
      "title": "Back Stab",
      "type": "boolean",
      "description": "True when the attack was a thief's back-stab, so your game can say so.\n\n`attack_roll` sets it when the attack's\n`AttackContext` sets both `behind_target` and `target_unaware`, and the\nattacker's class has the `back_stab` ability. The back-stab's bonus to hit is part of `modifier`, and the damage\nthat follows is doubled. It's true on an automatic hit too, because the damage still doubles. A\n`GameSession` makes that attack for a member who declares\n`BattleDeclaration.back_stab`."
    }
  },
  "required": [
    "code",
    "attacker_id",
    "defender_id",
    "attack_name"
  ],
  "title": "AttackRolledEvent",
  "type": "object"
}