{
  "id": "022_liaoxi_pursuit",
  "name": "Liaoxi Pursuit",
  "objectives": {
    "victory": "Reach the White Wolf road with Cao Cao, then defeat the Yuan envoys and Wuhuan outriders.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 17."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "white_wolf_road_found" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 17, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Liaoxi Pursuit",
    "location": "Liaoxi Frontier, 204 CE",
    "lines": [
      "Yuan Shang and Yuan Xi flee beyond Bohai, sending envoys toward the Wuhuan riders who rule the northern approaches.",
      "Cao Cao pushes into Liaoxi to find the White Wolf road before the Yuan brothers can turn exile into a frontier alliance."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pressed_liaoxi_pursuit": true },
        "lines": [
          "The fast pursuit has reached Liaoxi before the Yuan envoys can settle their route, forcing their escorts to fight while still scattered."
        ]
      },
      {
        "campaign_flags": { "secured_liaoxi_approaches": true },
        "lines": [
          "Secured depots and guides now anchor the advance, letting Cao Cao's army cross the frontier roads with fewer blind corners."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pressed_liaoxi_pursuit": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "secured_liaoxi_approaches": true },
        "items": ["imperial_seal"]
      }
    ]
  },
  "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": [
      "GGGHHHGGGGGHHHGGGG",
      "GGFFHHGGRRGGHHFFGG",
      "GGRRRRRRRRRRRRFFGG",
      "GGGFGHGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGHHGGGRRGFFGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch22",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch22",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch22",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch22",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch22",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch22",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch22",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "yuan_envoy_commander",
      "name": "Yuan Envoy Commander",
      "class_id": "commander",
      "team": "enemy",
      "level": 21,
      "pos": [14, 4],
      "base": { "hp": 100, "mp": 28, "atk": 27, "def": 21, "int": 16, "agi": 14 }
    },
    {
      "unit_id": "liaoxi_rear_captain",
      "name": "Liaoxi Rear Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 20,
      "pos": [12, 4],
      "base": { "hp": 72, "atk": 24, "def": 19 }
    },
    {
      "unit_id": "yuan_frontier_advisor",
      "name": "Frontier Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 20,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 60, "mp": 44, "atk": 7, "def": 11, "int": 23, "agi": 12 }
    },
    {
      "unit_id": "liaoxi_spear_north",
      "name": "Liaoxi Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 20,
      "pos": [12, 3],
      "base": { "hp": 64, "atk": 23, "def": 16 }
    },
    {
      "unit_id": "liaoxi_spear_south",
      "name": "Liaoxi Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 20,
      "pos": [12, 5],
      "base": { "hp": 64, "atk": 23, "def": 16 }
    },
    {
      "unit_id": "wuhuan_scout_north",
      "name": "Wuhuan Scout",
      "class_id": "marksman",
      "team": "enemy",
      "level": 20,
      "pos": [13, 2],
      "base": { "hp": 54, "atk": 23, "def": 9, "agi": 17 }
    },
    {
      "unit_id": "wuhuan_scout_south",
      "name": "Wuhuan Scout",
      "class_id": "marksman",
      "team": "enemy",
      "level": 20,
      "pos": [14, 6],
      "base": { "hp": 54, "atk": 23, "def": 9, "agi": 17 }
    },
    {
      "unit_id": "wuhuan_forward_rider",
      "name": "Wuhuan Forward Rider",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 20,
      "pos": [15, 3],
      "base": { "hp": 68, "atk": 24, "def": 14, "agi": 18 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "The Yuan envoys flee into Liaoxi seeking Wuhuan shelter." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The Yuan brothers no longer need a city. They need a road and another man's cavalry." },
            { "speaker": "Cao Cao", "text": "Then we take the road first." },
            { "speaker": "Zhang He", "text": "Their escorts are watching the hills. They know the frontier answers quickly." }
          ]
        }
      ]
    },
    {
      "id": "pursuit_overtakes_envoys",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_liaoxi_pursuit": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Envoy Commander", "text": "Cao Cao's vanguard has crossed already? We were promised the road was empty." },
            { "speaker": "Xiahou Yuan", "text": "It was empty until we filled it." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "rushed_liaoxi_rider",
            "name": "Rushed Liaoxi Rider",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 20,
            "pos": [16, 3],
            "base": { "hp": 58, "atk": 22, "def": 12, "agi": 15 }
          }
        }
      ]
    },
    {
      "id": "secured_road_guides",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_liaoxi_approaches": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The Liaoxi guides marked the dry road. The supply carts can follow without breaking formation." },
            { "speaker": "Cao Cao", "text": "Good. A frontier campaign is won first by arriving whole." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_frontier_riders",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Wuhuan Forward Rider", "text": "The Yuan envoys carry gifts. Cao Cao carries a claim. Which one reaches our chiefs?" },
            { "speaker": "Guo Jia", "text": "The rider asks the correct question. Make our answer faster." }
          ]
        }
      ]
    },
    {
      "id": "white_wolf_road_found",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The White Wolf road is found. Defeat the Yuan envoys and Wuhuan outriders.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 17."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This is the road. Cut the envoys from the riders before promises become banners." },
            { "speaker": "Yuan Envoy Commander", "text": "If we fall here, the brothers lose the north. Hold the pass!" }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "white_wolf_outrider",
              "name": "White Wolf Outrider",
              "class_id": "elite_cavalry",
              "team": "enemy",
              "level": 20,
              "pos": [16, 4],
              "base": { "hp": 66, "atk": 23, "def": 14, "agi": 18 }
            },
            {
              "unit_id": "yuan_envoy_archer",
              "name": "Yuan Envoy Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 20,
              "pos": [16, 5],
              "base": { "hp": 48, "atk": 21, "def": 8, "agi": 15 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_8_frontier_wind",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 8 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The wind is behind us now. Their riders keep looking north instead of forward." },
            { "speaker": "Cao Cao", "text": "Then push them toward the answer they fear." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 4200,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The envoys are broken, but Wuhuan scouts have seen enough to know Cao Cao is coming." },
    { "speaker": "Zhang He", "text": "The Yuan brothers will trade urgency for allies. Their next shield will be faster than city walls." },
    { "speaker": "Cao Cao", "text": "Then choose whether we strike the riders first or fortify the White Wolf road before the chiefs gather." }
  ],
  "post_battle_choices": [
    {
      "id": "strike_wuhuan_vanguard",
      "label": "Strike Vanguard",
      "description": "Cao Cao attacks the Wuhuan forward riders before the Yuan brothers can gather a full host.",
      "set_flags": { "struck_wuhuan_vanguard": true, "fortified_white_wolf_route": false },
      "gold": 300,
      "items": ["war_drum"]
    },
    {
      "id": "fortify_white_wolf_route",
      "label": "Fortify Route",
      "description": "The army secures the White Wolf road, building a steadier approach into Wuhuan territory.",
      "set_flags": { "struck_wuhuan_vanguard": false, "fortified_white_wolf_route": true },
      "gold": 600,
      "items": ["imperial_seal"]
    }
  ]
}
