{
  "id": "006_dingtao_counterattack",
  "name": "Dingtao Counterattack",
  "objectives": {
    "victory": "Defeat Lu Bu's counterattack force.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 12."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "turn_3_counterattack" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 12, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Dingtao Counterattack",
    "location": "Dingtao, 194 CE",
    "lines": [
      "After the raid at Puyang, Lu Bu moves to punish Cao Cao's army near Dingtao.",
      "The field is broken by ridges and roads. Keep the line tight and blunt the cavalry charge."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "fortified_yan_province": true },
        "lines": [
          "Fortified supply roads give Cao Cao time to choose the battlefield and prepare reserves."
        ]
      },
      {
        "campaign_flags": { "pressed_lu_bu": true },
        "lines": [
          "Cao Cao's pressure has kept Lu Bu off balance, but the army enters Dingtao with little rest."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "antidote",
      "panacea",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "leather_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "fortified_yan_province": true },
        "items": ["iron_armor"]
      },
      {
        "campaign_flags": { "pressed_lu_bu": true },
        "items": ["war_axe"]
      }
    ]
  },
  "roster": {
    "max_units": 4,
    "required_officers": ["cao_cao", "dian_wei"]
  },
  "formation": {
    "cells": [[1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5]]
  },
  "map": {
    "width": 14,
    "height": 10,
    "terrain": [
      "GGGGGGGGGGGGGG",
      "GGGFFGGGHHGGGG",
      "GGGFFRRRHHGGGG",
      "GGGGGRRRGGGGGG",
      "RRRRRRRRRRRRRR",
      "GGGGGRRRGGGGGG",
      "GGHHGFFFGRRGGG",
      "GGHHGFFFGGGWWG",
      "GGGGGGFFGGGWWG",
      "GGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch6",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "dian_wei_ch6",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "xiahou_dun_ch6",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch6",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "cao_ren_ch6",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "lu_bu_counterattack",
      "name": "Lu Bu Counterattack",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 7,
      "pos": [10, 4],
      "base": { "hp": 58, "atk": 19, "def": 10, "agi": 12 }
    },
    {
      "unit_id": "zhang_liao_pursuer",
      "name": "Zhang Liao Pursuer",
      "class_id": "cavalry",
      "team": "enemy",
      "level": 6,
      "pos": [9, 3],
      "base": { "hp": 46, "atk": 16, "def": 8, "agi": 11 }
    },
    {
      "unit_id": "gao_shun_line",
      "name": "Gao Shun Line",
      "class_id": "infantry",
      "team": "enemy",
      "level": 6,
      "pos": [9, 5],
      "base": { "hp": 46, "atk": 15, "def": 10 }
    },
    {
      "unit_id": "dingtao_archer",
      "name": "Dingtao Archer",
      "class_id": "archer",
      "team": "enemy",
      "level": 6,
      "pos": [11, 2],
      "base": { "hp": 32, "atk": 12, "def": 5 }
    },
    {
      "unit_id": "dingtao_strategist",
      "name": "Dingtao Strategist",
      "class_id": "strategist",
      "team": "enemy",
      "level": 6,
      "pos": [11, 6],
      "base": { "hp": 34, "mp": 18, "atk": 7, "def": 5, "int": 12 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Lu Bu's counterattack sweeps toward Dingtao." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Lu Bu wants a swift decision. We deny him speed and break his vanguard." },
            { "speaker": "Dian Wei", "text": "Let the riders come. A road is narrow when I stand in it." },
            { "speaker": "Xiahou Dun", "text": "The center road is their best charge lane. We hold there, then counter." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_fortified_reserve",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3, "campaign_flags": { "fortified_yan_province": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Scout", "text": "The eastern riders are moving exactly where the reserve scouts predicted." },
            { "speaker": "Cao Cao", "text": "Good. Let them spend their charge against prepared ground." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "screened_lu_bu_rider",
              "name": "Screened Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 6,
              "pos": [12, 3],
              "base": { "hp": 38, "atk": 14, "def": 7 }
            },
            {
              "unit_id": "screened_lu_bu_archer",
              "name": "Screened Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 6,
              "pos": [12, 6],
              "base": { "hp": 30, "atk": 12, "def": 5 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_3_pressed_lu_bu_charge",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3, "campaign_flags": { "pressed_lu_bu": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Lu Bu", "text": "Cao Cao chased too far. Trample his tired line!" },
            { "speaker": "Dian Wei", "text": "Tired men still swing hard when cornered." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "fierce_lu_bu_rider",
              "name": "Fierce Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 6,
              "pos": [12, 2],
              "base": { "hp": 40, "atk": 15, "def": 7 }
            },
            {
              "unit_id": "fierce_lu_bu_guard",
              "name": "Fierce Guard",
              "class_id": "infantry",
              "team": "enemy",
              "level": 6,
              "pos": [13, 4],
              "base": { "hp": 42, "atk": 14, "def": 9 }
            },
            {
              "unit_id": "fierce_lu_bu_rider_south",
              "name": "Fierce Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 6,
              "pos": [12, 6],
              "base": { "hp": 40, "atk": 15, "def": 7 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_3_counterattack",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        { "type": "log", "text": "Lu Bu commits his second wave." },
        {
          "type": "set_objective",
          "victory": "Defeat Lu Bu's counterattack and every second-wave unit.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 12."
        }
      ]
    },
    {
      "id": "turn_5_hold_center",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 5 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Their charge is spent. Now strike at the officers holding the line together." },
            { "speaker": "Xiahou Yuan", "text": "I have their archers marked. One clear shot can open the road." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 1000,
    "items": ["bean", "wine", "war_axe"]
  },
  "post_battle_dialogue": [
    { "speaker": "Cao Cao", "text": "Lu Bu's charge is powerful, but not invincible." },
    { "speaker": "Dian Wei", "text": "His riders bleed like anyone else." },
    { "speaker": "Xiahou Dun", "text": "Then Yan Province is not lost. We keep fighting." }
  ]
}
