Skip to content

PurchaseEquipment

Buy equipment in town for one member, one purchase lot for each item_ids entry (takes no game time).

Full documentation: PurchaseEquipment. Wire type: purchase_equipment.

Legal session modes: town

JSON Schema

{
  "description": "Buy equipment in town for one member, one purchase lot for each `item_ids` entry (takes no game time).\n\nThe party must be in town. The session adds up the price of every entry first, and if\nthe member can't afford the total, nothing is bought. The shop stocks only the built-in\nequipment from `load_equipment` (see the\n[equipment id index](https://mmacy.github.io/osrlib-python/reference/content-ids/equipment/)).\nAn item the adventure bundles isn't for sale, even when the party has seen its id, and\nthe session refuses it as not stocked rather than as unknown.\n\nModes:\n    `town`\n\nRejections:\n    - `session.command.wrong_mode` - the party is not in town.\n    - `session.command.unknown_member` - `character_id` matches no party member.\n    - `session.command.member_incapacitated` - the member can't act.\n    - `session.command.unknown_item` - an entry matches no equipment item.\n    - `items.purchase.not_stocked` - an entry is an item the adventure\n      bundles, which the shop doesn't sell.\n    - `items.purchase.insufficient_funds` - the member's purse can't cover the total.\n\nEvents:\n    `ItemAcquiredEvent` listing the\n    purchases, `origin` `\"purchase\"`.\n\nExamples:\n    ```python\n    from osrlib.core.alignment import Alignment\n    from osrlib.core.character import CHARACTER_CREATION_STREAM, create_character\n    from osrlib.core.events import Visibility\n    from osrlib.core.rng import RngStreams\n    from osrlib.core.ruleset import Ruleset\n    from osrlib.crawl.adventure import Adventure, TownSpec\n    from osrlib.crawl.commands import PurchaseEquipment\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    hero = create_character(\n        name=\"Hild\", class_id=\"fighter\", alignment=Alignment.LAWFUL, ruleset=Ruleset(), stream=stream\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=[hero]), adventure, seed=7)\n\n    # One lot of torches (1 gp) and a tinder box (3 gp).\n    result = session.execute(PurchaseEquipment(character_id=hero.id, item_ids=(\"torch\", \"tinder_box\")))\n    print(result.accepted)\n    # True\n\n    inventory = session.view(Visibility.PLAYER).party[0].inventory\n    print([(item\"template\", item[\"quantity\"]) for item in inventory[\"items\"]])\n    # [('torch', 6), ('tinder_box', 1)]\n    print(inventory\"purse\")\n    # 96\n    ```",
  "properties": {
    "command_type": {
      "const": "purchase_equipment",
      "default": "purchase_equipment",
      "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 buyer, by `MemberView.id`. This member's purse\npays for every entry, and the goods go into this member's pack."
    },
    "item_ids": {
      "items": {
        "type": "string"
      },
      "minItems": 1,
      "title": "Item Ids",
      "type": "array",
      "description": "What to buy, one purchase lot per entry, so repeat an id to buy more lots. A purchase lot\nis what one purchase at the item's listed price delivers: a lot of torches costs 1 gp and\narrives as six torches, while a weapon or a suit of armour is a single item. The ids come\nfrom `load_equipment` (see the\n[equipment id index](https://mmacy.github.io/osrlib-python/reference/content-ids/equipment/)).\nThe session refuses an id the adventure bundles with `items.purchase.not_stocked`, because\nit isn't for sale.\nAn empty tuple fails validation when the command is constructed."
    }
  },
  "required": [
    "character_id",
    "item_ids"
  ],
  "title": "PurchaseEquipment",
  "type": "object"
}