{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/AdventureFile",
  "definitions": {
    "AdventureFile": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "summary": {
          "type": "string"
        },
        "pitch": {
          "type": "string"
        },
        "setup": {
          "type": "string"
        },
        "storyHook": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "meta": {
          "$ref": "#/definitions/AdventureMeta"
        },
        "library": {
          "type": "object",
          "properties": {
            "characters": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AdventureCharacter"
              }
            },
            "places": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AdventurePlace"
              }
            },
            "factions": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AdventureFaction"
              }
            },
            "items": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AdventureItem"
              }
            },
            "units": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AdventureUnit"
              }
            }
          },
          "required": [
            "characters",
            "places",
            "factions",
            "items",
            "units"
          ]
        },
        "connections": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Connection"
          },
          "description": "How the places join up: the graph the sound travels along."
        },
        "facts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Fact"
          }
        },
        "acts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Act"
          }
        },
        "type": {
          "$ref": "#/definitions/DocType"
        },
        "str_version": {
          "type": "string"
        }
      },
      "required": [
        "acts",
        "library",
        "name",
        "str_version",
        "type"
      ]
    },
    "AdventureMeta": {
      "type": "object",
      "properties": {
        "author": {
          "type": "string"
        },
        "setting": {
          "$ref": "#/definitions/Setting",
          "description": "The setting the adventure is written for (taxonomy.ts); the tags carried it before."
        },
        "version": {
          "type": "string"
        },
        "players": {
          "type": "object",
          "properties": {
            "min": {
              "type": "number"
            },
            "max": {
              "type": "number"
            }
          },
          "required": [
            "min",
            "max"
          ]
        },
        "pointLimit": {
          "type": "number"
        },
        "difficulty": {
          "type": "string"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "estimatedSessions": {
          "type": "number"
        }
      }
    },
    "Setting": {
      "type": "string",
      "enum": [
        "fantasy",
        "sci-fi",
        "any"
      ]
    },
    "AdventureCharacter": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "role": {
          "type": "string"
        },
        "faction": {
          "type": "string"
        },
        "short": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "sheet": {
          "$ref": "#/definitions/Character",
          "description": "The full sheet — always: the cast are characters, not units, and the party may talk to, deceive or race any of them, which is a check against their stats. A boss who is also fought has a bestiary unit besides."
        }
      },
      "required": [
        "id",
        "name",
        "sheet"
      ],
      "description": "A reference-able thing in an adventure's library. Mentions use `@[label](kind:id)`."
    },
    "Character": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "player": {
          "type": "string",
          "description": "The player's name, printed on the sheet."
        },
        "classKey": {
          "type": "string",
          "description": "Key into rpg.json → classes; empty for a classless NPC."
        },
        "stats": {
          "$ref": "#/definitions/CharacterStats",
          "description": "The rolled (or typed) stats before class bonuses."
        },
        "background": {
          "$ref": "#/definitions/CharacterBackground"
        },
        "notes": {
          "type": "string"
        },
        "armor": {
          "type": "boolean"
        },
        "attributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          },
          "description": "The character's own attributes; class and base attributes are added by the engine."
        },
        "equipment": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Equipment"
          }
        },
        "startingPoints": {
          "type": "number",
          "description": "Starting equipment budget the builder enforced; defaults to rpg.json → starting_points."
        },
        "specialLists": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SpecialList"
          },
          "description": "Special-action lists embedded for Special(x), as on a unit file."
        },
        "loot": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LootRow"
          }
        }
      },
      "required": [
        "name",
        "classKey",
        "stats",
        "background",
        "notes",
        "attributes",
        "equipment"
      ],
      "description": "A player character or story NPC: a unit plus RPG stats and a background. Skill and Defence are derived (engine/rpg.ts), never stored."
    },
    "CharacterStats": {
      "type": "object",
      "properties": {
        "body": {
          "type": "number"
        },
        "agility": {
          "type": "number"
        },
        "mind": {
          "type": "number"
        },
        "spirit": {
          "type": "number"
        }
      },
      "required": [
        "body",
        "agility",
        "mind",
        "spirit"
      ]
    },
    "CharacterBackground": {
      "type": "object",
      "properties": {
        "origin": {
          "type": "string"
        },
        "calling": {
          "type": "string"
        },
        "drive": {
          "type": "string"
        },
        "bonds": {
          "type": "string"
        },
        "scar": {
          "type": "string"
        },
        "spark": {
          "type": "string"
        }
      },
      "required": [
        "origin",
        "calling",
        "drive",
        "bonds",
        "scar",
        "spark"
      ]
    },
    "AttrRef": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "value": {
          "type": [
            "number",
            "string"
          ]
        }
      },
      "required": [
        "id"
      ],
      "description": "A reference to a catalogue attribute (unit attribute, weapon attribute or weapon limitation) with its chosen parameter. `value` is a number for `param.kind === 'number'`, a weapon type for `'type'`, and a special-list name for `'list'`. Absent when the attribute has no parameter."
    },
    "Equipment": {
      "anyOf": [
        {
          "$ref": "#/definitions/Weapon"
        },
        {
          "$ref": "#/definitions/Item"
        }
      ]
    },
    "Weapon": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/definitions/WeaponKind"
        },
        "name": {
          "type": "string"
        },
        "attacks": {
          "type": "number"
        },
        "range": {
          "type": "number"
        },
        "attributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          }
        },
        "limitations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          },
          "description": "At most one. Absent on weapons created by an effect."
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "attacks",
        "range",
        "attributes"
      ],
      "description": "Attack gear: anything with attacks and a range. Range 0 = melee."
    },
    "WeaponKind": {
      "type": "string",
      "enum": [
        "melee",
        "ranged"
      ]
    },
    "Item": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "item"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "grants": {
          "type": "object",
          "properties": {
            "attributes": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/AttrRef"
              }
            },
            "body": {
              "type": "number",
              "description": "RPG-only stat modifiers; never affect points."
            },
            "agility": {
              "type": "number"
            },
            "mind": {
              "type": "number"
            },
            "spirit": {
              "type": "number"
            }
          },
          "required": [
            "attributes"
          ]
        }
      },
      "required": [
        "type",
        "name",
        "grants"
      ],
      "description": "Non-attack gear that grants a unit attribute. Never modifies Skill or Defence."
    },
    "SpecialList": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SpecialAction"
          }
        },
        "meta": {
          "$ref": "#/definitions/SpecialListMeta"
        }
      },
      "required": [
        "name",
        "actions"
      ]
    },
    "SpecialAction": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "effects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Effect"
          }
        },
        "aoe": {
          "anyOf": [
            {
              "$ref": "#/definitions/AreaOfEffect"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "name",
        "effects"
      ],
      "description": "A special action inside a special-action list: same blocks, no condition."
    },
    "Effect": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "x": {
          "type": "number",
          "description": "Numeric parameter, bounded by the catalogue entry's min/max."
        },
        "option": {
          "type": "string",
          "description": "Chosen option key for option-varying effects."
        },
        "attrId": {
          "type": "string",
          "description": "Gain / grant attribute: which attribute, its value, and (gain only) the target."
        },
        "attrValue": {
          "type": [
            "number",
            "string",
            "null"
          ]
        },
        "attrTarget": {
          "type": "string"
        },
        "width": {
          "type": "number",
          "description": "create_obstacle"
        },
        "height": {
          "type": "number"
        },
        "spawnedUnit": {
          "$ref": "#/definitions/Unit",
          "description": "create_new_unit"
        },
        "weapon": {
          "$ref": "#/definitions/Weapon",
          "description": "create_attack"
        },
        "noLos": {
          "type": "boolean"
        }
      },
      "required": [
        "id"
      ],
      "description": "One building block of an upgrade or special action. Which of the optional fields apply depends on the catalogue entry `id` points to."
    },
    "Unit": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "role": {
          "type": "string",
          "description": "Role label shown on the card, e.g. \"Leader\", \"Warrior\"."
        },
        "description": {
          "type": "string",
          "description": "Flavour text."
        },
        "lore": {
          "type": "string"
        },
        "skill": {
          "type": "number"
        },
        "defence": {
          "type": "number"
        },
        "armor": {
          "type": "boolean"
        },
        "unique": {
          "type": "boolean"
        },
        "outsider": {
          "type": "boolean"
        },
        "equipment": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Equipment"
          }
        },
        "attributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AttrRef"
          }
        },
        "upgrades": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Upgrade"
          },
          "description": "Absent on spawned units, which may not have upgrades."
        },
        "selectedUpgrade": {
          "anyOf": [
            {
              "$ref": "#/definitions/Upgrade"
            },
            {
              "type": "null"
            }
          ]
        },
        "count": {
          "type": "number",
          "description": "Number of units in a force entry."
        },
        "loot": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LootRow"
          },
          "description": "Optional D6 loot table (RPG bestiary use)."
        },
        "specialLists": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SpecialList"
          },
          "description": "Special-action lists embedded on a standalone unit file."
        },
        "meta": {
          "$ref": "#/definitions/UnitMeta",
          "description": "Library shelf data (taxonomy.ts); read by the catalogue, never by the rules."
        }
      },
      "required": [
        "name",
        "skill",
        "defence",
        "armor",
        "equipment",
        "attributes"
      ],
      "description": "A single unit (skirmish) or a template for one. In a force it also carries `count` and `selectedUpgrade`. In a faction it is a template and its equipment lists every option a fielded unit may choose from."
    },
    "Upgrade": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "effects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Effect"
          }
        },
        "condition": {
          "anyOf": [
            {
              "$ref": "#/definitions/ConditionRef"
            },
            {
              "type": "null"
            }
          ]
        },
        "aoe": {
          "anyOf": [
            {
              "$ref": "#/definitions/AreaOfEffect"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "name",
        "effects"
      ],
      "description": "A purchasable special action for a unit. Priced from its blocks; a stored `cost` is never trusted and is removed on import."
    },
    "ConditionRef": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "x": {
          "type": "number"
        }
      },
      "required": [
        "id"
      ]
    },
    "AreaOfEffect": {
      "type": "object",
      "properties": {
        "x": {
          "type": "number",
          "description": "Radius in inches, 1–12."
        },
        "allFactions": {
          "type": "boolean",
          "description": "Hits friend and foe alike (discounted)."
        }
      },
      "required": [
        "x"
      ]
    },
    "LootRow": {
      "type": "object",
      "properties": {
        "roll": {
          "type": "number",
          "description": "D6 result 1–6."
        },
        "text": {
          "type": "string"
        }
      },
      "required": [
        "roll",
        "text"
      ],
      "description": "One row of a unit's D6 loot table."
    },
    "UnitMeta": {
      "type": "object",
      "properties": {
        "setting": {
          "$ref": "#/definitions/Setting"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "creator": {
          "type": "string"
        },
        "date": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        },
        "category": {
          "$ref": "#/definitions/UnitCategory"
        },
        "threat": {
          "$ref": "#/definitions/Threat",
          "description": "The author's intent; the audit proves the fielded maximum lands in the band."
        },
        "family": {
          "type": "string",
          "description": "Variants of one creature (Wolf → Dire Wolf → Winter Wolf) share a family and climb the bands together."
        }
      },
      "description": "A unit's shelf: what kind of creature, which threat band its price must land in, and its variant family."
    },
    "UnitCategory": {
      "type": "string",
      "enum": [
        "beast",
        "humanoid",
        "giant",
        "undead",
        "construct",
        "spirit",
        "fiend",
        "dragon",
        "aberration",
        "plant",
        "alien",
        "swarm"
      ]
    },
    "Threat": {
      "type": "string",
      "enum": [
        "low",
        "moderate",
        "high",
        "severe",
        "extreme",
        "legendary"
      ]
    },
    "SpecialListMeta": {
      "type": "object",
      "properties": {
        "setting": {
          "$ref": "#/definitions/Setting"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "creator": {
          "type": "string"
        },
        "date": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        },
        "category": {
          "$ref": "#/definitions/SpecialCategory"
        }
      }
    },
    "SpecialCategory": {
      "type": "string",
      "enum": [
        "elemental",
        "divine",
        "nature",
        "dark",
        "arcane",
        "mind",
        "tech",
        "martial",
        "trickery",
        "command"
      ]
    },
    "AdventurePlace": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "parent": {
          "type": "string"
        },
        "short": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "map": {
          "type": "string",
          "description": "A .stmap reference."
        },
        "moods": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PlaceMood"
          },
          "description": "The ways this place can sound; a scene picks one."
        }
      },
      "required": [
        "id",
        "name"
      ]
    },
    "PlaceMood": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Made once from the label; it stays when the label is renamed."
        },
        "label": {
          "type": "string"
        },
        "sounds": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AmbienceSound"
          }
        }
      },
      "required": [
        "id",
        "label",
        "sounds"
      ],
      "description": "One way a place can sound — \"Busy evening\", \"Early morning\": a named mix of loops. One-shots belong to the connections, played on the way in."
    },
    "AmbienceSound": {
      "type": "object",
      "properties": {
        "sound": {
          "type": "string"
        },
        "volume": {
          "type": "number",
          "description": "0–1."
        }
      },
      "required": [
        "sound",
        "volume"
      ],
      "description": "One sound in a mix: a key from the sound library and its volume. A looping sound fades in and keeps going; a one-shot plays once as the mix starts."
    },
    "AdventureFaction": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "short": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "name"
      ]
    },
    "AdventureItem": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "name"
      ]
    },
    "AdventureUnit": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "unit": {
          "$ref": "#/definitions/Unit"
        }
      },
      "required": [
        "id",
        "unit"
      ]
    },
    "Connection": {
      "type": "object",
      "properties": {
        "a": {
          "type": "string"
        },
        "b": {
          "type": "string"
        },
        "sound": {
          "type": "string"
        }
      },
      "required": [
        "a",
        "b"
      ],
      "description": "A way between two places, both directions. `sound` is a one-shot played on the way through (a door, a bell); without it the sound simply crossfades."
    },
    "Fact": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "item",
            "information",
            "task"
          ]
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "kind",
        "label"
      ],
      "description": "A prerequisite the party can acquire: an item, a piece of information, or a task done."
    },
    "Act": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "summary": {
          "type": "string"
        },
        "objective": {
          "type": "string"
        },
        "obstacle": {
          "type": "string"
        },
        "stakes": {
          "type": "string"
        },
        "rewards": {
          "type": "string"
        },
        "resolution": {
          "type": "string"
        },
        "dmComments": {
          "type": "string"
        },
        "scenes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Scene"
          }
        }
      },
      "required": [
        "id",
        "title",
        "scenes"
      ]
    },
    "Scene": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "location": {
          "type": "string",
          "description": "The place the scene starts in."
        },
        "mood": {
          "type": "string",
          "description": "A mood id of `location`; without one the place's first mood plays."
        },
        "moveTo": {
          "type": "object",
          "properties": {
            "place": {
              "type": "string"
            },
            "mood": {
              "type": "string"
            }
          },
          "required": [
            "place"
          ],
          "description": "Where the scene leaves to, if it does: \"we step out into the rainy night\"."
        },
        "precondition": {
          "type": "string",
          "description": "Free-text precondition shown to the GM; `requires` is the checked one."
        },
        "requires": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Fact ids that must be acquired before this scene unlocks."
        },
        "outcomes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Fact ids the party acquires when the scene resolves."
        },
        "readAloud": {
          "type": "string"
        },
        "body": {
          "type": "string"
        },
        "hasEncounter": {
          "type": "boolean"
        },
        "encounter": {
          "$ref": "#/definitions/Encounter"
        },
        "rewards": {
          "type": "string"
        },
        "dmComments": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "title"
      ]
    },
    "Encounter": {
      "type": "object",
      "properties": {
        "combatants": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Combatant"
          }
        },
        "tactics": {
          "type": "string"
        },
        "scenario": {
          "type": "string",
          "description": "Scenario setup from Campaign & Scenarios, if any."
        },
        "loot": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LootRow"
          }
        }
      },
      "required": [
        "combatants"
      ]
    },
    "Combatant": {
      "type": "object",
      "properties": {
        "unitId": {
          "type": "string"
        },
        "count": {
          "type": "number"
        }
      },
      "required": [
        "unitId",
        "count"
      ]
    },
    "DocType": {
      "type": "string",
      "enum": [
        "unit",
        "faction",
        "force",
        "special_actions",
        "pgcharacter",
        "adventure",
        "world"
      ]
    }
  },
  "$id": "https://simple-tabletop.example/schema/adventure.schema.json",
  "title": "Simple Tabletop AdventureFile"
}
