{
  "id": "056_jianye_sortie",
  "name": "Jianye Sortie",
  "objectives": {
    "victory": "Reach the capital sortie line with Cao Cao, then defeat the Jianye sortie commander.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "capital_sortie_line_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Jianye Sortie",
    "location": "Capital Sortie Road, Jianye, Eastern Front, 220 CE",
    "lines": [
      "Jianye's outer gate line has broken, and the capital guard now tests whether Wei's army can hold the road under a sudden sortie.",
      "Cao Cao advances to contain the sortie, force the defenders back, and choose whether to consolidate outside the walls or press deeper into Jianye."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_jianye_gate": true },
        "lines": [
          "Securing the Jianye gate gives Wei a firmer siege road, so the capital sortie must cross prepared shields before reaching the carts."
        ]
      },
      {
        "campaign_flags": { "forced_capital_sortie": true },
        "lines": [
          "Forcing the capital sortie draws Wu's guard outside the walls early, but the defenders now strike with urgency instead of waiting behind stone."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_jianye_gate": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "forced_capital_sortie": true },
        "items": ["war_drum"]
      }
    ]
  },
  "roster": {
    "max_units": 7,
    "required_officers": ["cao_cao", "guo_jia"]
  },
  "formation": {
    "cells": [[1, 3], [1, 4], [1, 5], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6]]
  },
  "map": {
    "width": 18,
    "height": 11,
    "terrain": [
      "WWWWWWWWWWWWWWWWWW",
      "WGGGFFWWRRWWFFGGGW",
      "GGGGWWGGGGRRGGGGGG",
      "GGFFWWGGRRRRGFFGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGFFWWGGRRRRGFFGGG",
      "GGGGWWGGGGRRGGGGGG",
      "GHHHWWGFFFGGFFFGGG",
      "GHHHWWGGGGHHHGGGGG",
      "GGGGWWGGGGHHHFFGGG",
      "WWWWWWWWWWWWWWWWWW"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch56",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch56",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch56",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch56",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch56",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch56",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch56",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "jianye_sortie_commander",
      "name": "Jianye Sortie Commander",
      "class_id": "commander",
      "team": "enemy",
      "level": 53,
      "pos": [14, 4],
      "base": { "hp": 178, "mp": 86, "atk": 56, "def": 47, "int": 45, "agi": 32 }
    },
    {
      "unit_id": "capital_sortie_captain",
      "name": "Capital Sortie Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 53,
      "pos": [12, 4],
      "base": { "hp": 140, "atk": 55, "def": 48 }
    },
    {
      "unit_id": "quan_cong_sortie_boat",
      "name": "Quan Cong Sortie Boat",
      "class_id": "champion",
      "team": "enemy",
      "move_type": "water",
      "level": 53,
      "pos": [4, 3],
      "base": { "hp": 168, "mp": 12, "atk": 57, "def": 43, "int": 15, "agi": 39 }
    },
    {
      "unit_id": "capital_sortie_advisor",
      "name": "Capital Sortie Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 53,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 126, "mp": 110, "atk": 8, "def": 34, "int": 56, "agi": 29 }
    },
    {
      "unit_id": "capital_sortie_spear_north",
      "name": "Capital Sortie Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 53,
      "pos": [12, 3],
      "base": { "hp": 128, "atk": 54, "def": 44 }
    },
    {
      "unit_id": "capital_sortie_spear_south",
      "name": "Capital Sortie Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 53,
      "pos": [12, 5],
      "base": { "hp": 128, "atk": 54, "def": 44 }
    },
    {
      "unit_id": "capital_sortie_arrow_boat",
      "name": "Capital Sortie Arrow Boat",
      "class_id": "marksman",
      "team": "enemy",
      "move_type": "water",
      "level": 53,
      "pos": [5, 5],
      "base": { "hp": 120, "atk": 55, "def": 30, "agi": 42 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Jianye's capital guard sorties outside the gate to test Wei's siege road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The capital guard is outside the walls. Jianye has chosen to spend men before stone." },
            { "speaker": "Guo Jia", "text": "A sortie is courage with a door left open behind it. Close the road and it becomes a retreat." },
            { "speaker": "Cao Cao", "text": "Then hold the road. Let Jianye learn that leaving the wall does not make the field theirs." }
          ]
        }
      ]
    },
    {
      "id": "secured_gate_absorbs_sortie",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_jianye_gate": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Dun", "text": "The secured gate road is holding. Their sortie must cross ground we already measured." },
            { "speaker": "Cao Cao", "text": "Measured ground makes rash courage expensive." }
          ]
        }
      ]
    },
    {
      "id": "forced_sortie_commits_boats",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "forced_capital_sortie": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Jianye Sortie Commander", "text": "Wei forced us from the gate. Push the boats hard before their road line closes." },
            { "speaker": "Zhang He", "text": "The sortie has committed to the water as well as the road. Break either and the other panics." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "wu_committed_sortie_boat",
            "name": "Wu Committed Sortie Boat",
            "class_id": "champion",
            "team": "enemy",
            "move_type": "water",
            "level": 53,
            "pos": [5, 3],
            "base": { "hp": 118, "atk": 50, "def": 34, "agi": 40 }
          }
        }
      ]
    },
    {
      "id": "turn_4_sortie_surges",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Capital Sortie Advisor", "text": "Surge now. If Wei settles here, the inner city hears their drums all night." },
            { "speaker": "Guo Jia", "text": "They know time is turning against them. Let their haste expose the seam." }
          ]
        }
      ]
    },
    {
      "id": "capital_sortie_line_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The capital sortie line is reached. Defeat the Jianye sortie commander.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This sortie line is spent ground. Break its commander and drive the capital guard back under its own gate." },
            { "speaker": "Jianye Sortie Commander", "text": "The capital has more doors than this road can threaten." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "capital_sortie_inner_guard",
              "name": "Capital Sortie Inner Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 53,
              "pos": [16, 4],
              "base": { "hp": 136, "atk": 54, "def": 47 }
            },
            {
              "unit_id": "capital_sortie_crossbow_boat",
              "name": "Capital Sortie Crossbow Boat",
              "class_id": "marksman",
              "team": "enemy",
              "move_type": "water",
              "level": 53,
              "pos": [10, 1],
              "base": { "hp": 112, "atk": 53, "def": 27, "agi": 41 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_sortie_falters",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The sortie is faltering. Their gate is close, but their road back is thinner than before." },
            { "speaker": "Cao Cao", "text": "Then make retreat feel like pursuit and pursuit feel like judgment." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 11000,
    "items": ["bean", "wine", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The capital sortie is contained. Wei can lock down the road outside Jianye, or press toward the inner city while the guard retreats in disorder." },
    { "speaker": "Cao Ren", "text": "Contain the sortie and our siege line becomes hard to break. Press inward and the defenders have no time to breathe." },
    { "speaker": "Cao Cao", "text": "A sortie defeated outside its gate leaves two victories to choose from: ground held, or fear carried inward." }
  ],
  "post_battle_choices": [
    {
      "id": "contain_capital_sortie",
      "label": "Contain Sortie",
      "description": "Cao Cao contains the capital sortie and locks down the siege road outside Jianye.",
      "set_flags": { "contained_capital_sortie": true, "pressed_inner_jianye": false },
      "gold": 2050,
      "items": ["imperial_seal"]
    },
    {
      "id": "press_inner_jianye",
      "label": "Press Inner City",
      "description": "Cao Cao presses inward before Jianye's capital guard can reorganize.",
      "set_flags": { "contained_capital_sortie": false, "pressed_inner_jianye": true },
      "gold": 1850,
      "items": ["war_drum"]
    }
  ]
}
