{
  "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."
        ]
      }
    ],
    "camp_conversations": [
      {
        "id": "dingtao_countercharge_council",
        "group": "officer",
        "officer_id": "cao_cao",
        "label": "Cao Cao - Countercharge",
        "speaker": "Cao Cao",
        "summary": "Set the line before Lu Bu's cavalry reaches Dingtao.",
        "lines": [
          { "speaker": "Cao Cao", "side": "left", "text": "Lu Bu answers the Puyang raid with speed. That is his habit, and habits can be prepared for." },
          { "speaker": "Cao Ren", "side": "right", "text": "The ridges will break his charge if our line does not break first. I will keep the reserves close." }
        ]
      },
      {
        "id": "dingtao_dian_wei_roadblock",
        "group": "officer",
        "officer_id": "dian_wei",
        "label": "Dian Wei - Roadblock",
        "speaker": "Dian Wei",
        "summary": "Let Dian Wei anchor the road against Lu Bu's riders.",
        "lines": [
          { "speaker": "Dian Wei", "side": "right", "text": "A horse needs road and courage. I cannot take the horse's road away, but I can test the rider's courage." },
          { "speaker": "Xiahou Dun", "side": "left", "text": "Stand where the road narrows. If Lu Bu wants the banner, he must spend men to reach it." }
        ]
      },
      {
        "id": "dingtao_fortified_reserves",
        "campaign_flags": { "fortified_yan_province": true },
        "group": "topic",
        "label": "Fortified Reserves",
        "summary": "Distribute medicine from the secured Yan Province supply road.",
        "lines": [
          { "speaker": "Dingtao Field Sutler", "side": "right", "text": "The fortified roads kept the physician's chest whole. I brought the clean bundle forward before the riders closed." },
          { "speaker": "Cao Cao", "side": "left", "text": "Then the choice to fortify already pays us back. Keep it near the center line." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "panacea", "count": 1, "text": "The fortified reserves add a Panacea to the field supplies." }
        ]
      },
      {
        "id": "dingtao_pressed_vanguard",
        "campaign_flags": { "pressed_lu_bu": true },
        "group": "topic",
        "label": "Pressed Vanguard",
        "summary": "Issue wine to the soldiers who kept pressure on Lu Bu after Puyang.",
        "lines": [
          { "speaker": "Xiahou Yuan", "side": "right", "text": "The vanguard has not slept enough to dream, but they still reached Dingtao before Lu Bu expected." },
          { "speaker": "Dian Wei", "side": "left", "text": "Give them wine, then give them a short order. Tired men do best when the road ahead is simple." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "wine", "count": 1, "text": "The pressed vanguard adds Wine to the field supplies." }
        ]
      }
    ]
  },
  "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_drum"]
      }
    ],
    "merchant": {
      "name": "Dingtao Field Sutler",
      "lines": [
        "Buy before the dust rises. Once Lu Bu's riders arrive, even a good price will not stand still.",
        "Fortified roads bring armor; forced marches bring drums. Either way, keep one hand free for medicine."
      ]
    }
  },
  "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." }
  ]
}
