{
  "id": "034_ma_chao_counterstroke",
  "name": "Ma Chao Counterstroke",
  "objectives": {
    "victory": "Reach the counterstroke line with Cao Cao, then defeat Ma Chao's charge.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "counterstroke_line_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Ma Chao Counterstroke",
    "location": "Tong Pass, Guanzhong, 211 CE",
    "lines": [
      "Tong Pass has opened, but Ma Chao answers lost ground with a countercharge meant to shatter Cao Cao's western column.",
      "The pass road is narrow, the dust is thick, and Han Sui's banners watch for any sign that Cao Cao's army can be split."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "fortified_tong_pass": true },
        "lines": [
          "Tong Pass fortifications give Cao Cao a hard anchor before Ma Chao's riders crash against the line."
        ]
      },
      {
        "campaign_flags": { "pressed_ma_chao_vanguard": true },
        "lines": [
          "Pressing Ma Chao's vanguard kept the initiative, but it also pulled Cao Cao's front into the path of a sharper counterstroke."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "fortified_tong_pass": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pressed_ma_chao_vanguard": 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": [
      "GGGGHHGGGGGGHHGGGG",
      "GGFFHHGGRRGGHHFFGG",
      "GGRRRRRRRRRRRRFFGG",
      "GGGFGHGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGHHGGGRRGFFGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch34",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch34",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch34",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch34",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch34",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch34",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch34",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "ma_chao_counterstroke",
      "name": "Ma Chao Counterstroke",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 32,
      "pos": [14, 4],
      "base": { "hp": 128, "mp": 14, "atk": 37, "def": 25, "int": 13, "agi": 26 }
    },
    {
      "unit_id": "pang_de_assault",
      "name": "Pang De Assault",
      "class_id": "champion",
      "team": "enemy",
      "level": 31,
      "pos": [15, 3],
      "base": { "hp": 122, "mp": 10, "atk": 36, "def": 24, "int": 12, "agi": 23 }
    },
    {
      "unit_id": "han_sui_wing_captain",
      "name": "Han Sui Wing Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 31,
      "pos": [15, 5],
      "base": { "hp": 116, "mp": 42, "atk": 33, "def": 26, "int": 25, "agi": 18 }
    },
    {
      "unit_id": "counterstroke_gate_captain",
      "name": "Counterstroke Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 31,
      "pos": [12, 4],
      "base": { "hp": 94, "atk": 32, "def": 26 }
    },
    {
      "unit_id": "western_division_advisor",
      "name": "Western Division Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 31,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 82, "mp": 66, "atk": 8, "def": 15, "int": 34, "agi": 16 }
    },
    {
      "unit_id": "counterstroke_spear_north",
      "name": "Counterstroke Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 31,
      "pos": [12, 3],
      "base": { "hp": 84, "atk": 32, "def": 23 }
    },
    {
      "unit_id": "counterstroke_spear_south",
      "name": "Counterstroke Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 31,
      "pos": [12, 5],
      "base": { "hp": 84, "atk": 32, "def": 23 }
    },
    {
      "unit_id": "western_ridge_marksman",
      "name": "Western Ridge Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 31,
      "pos": [13, 2],
      "base": { "hp": 76, "atk": 33, "def": 12, "agi": 24 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Ma Chao's riders surge back toward Tong Pass, turning Cao Cao's outpost victory into a test of nerve." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "Ma Chao is coming back harder than before. He wants the pass to remember his name." },
            { "speaker": "Guo Jia", "text": "A proud countercharge can break an army, or reveal where its pride is fastened." },
            { "speaker": "Cao Cao", "text": "Then hold until the fastening shows." }
          ]
        }
      ]
    },
    {
      "id": "fortified_pass_absorbs_charge",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "fortified_tong_pass": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The pass works are holding. Their first riders are forced into the teeth of the line." },
            { "speaker": "Cao Cao", "text": "Let the fortifications take the breath from their charge." }
          ]
        }
      ]
    },
    {
      "id": "pressed_vanguard_draws_countercharge",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_ma_chao_vanguard": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Ma Chao Counterstroke", "text": "Cao Cao pressed us too far. Ride through his front before it can root." },
            { "speaker": "Zhang He", "text": "The pursuit has become the bait. Brace." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "ma_clan_counter_riders",
            "name": "Ma Clan Counter Riders",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 31,
            "pos": [16, 3],
            "base": { "hp": 80, "atk": 31, "def": 16, "agi": 22 }
          }
        }
      ]
    },
    {
      "id": "turn_4_han_sui_watches",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Han Sui Wing Captain", "text": "If Ma Chao breaks Cao Cao here, Guanzhong follows his dust." },
            { "speaker": "Guo Jia", "text": "Han Sui watches Ma Chao as carefully as he watches us. Remember that." }
          ]
        }
      ]
    },
    {
      "id": "counterstroke_line_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The counterstroke line is reached. Defeat Ma Chao's charge.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This is the line. Break the charge and the western alliance begins to doubt itself." },
            { "speaker": "Pang De Assault", "text": "Doubt can wait. Steel first!" }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "counterstroke_halberd_guard",
              "name": "Counterstroke Halberd Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 31,
              "pos": [16, 4],
              "base": { "hp": 92, "atk": 32, "def": 26 }
            },
            {
              "unit_id": "counterstroke_arrow_screen",
              "name": "Counterstroke Arrow Screen",
              "class_id": "archer",
              "team": "enemy",
              "level": 31,
              "pos": [16, 5],
              "base": { "hp": 70, "atk": 31, "def": 10, "agi": 22 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_charge_slows",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "Their charge is losing shape. Even Ma Chao's riders need ground beneath pride." },
            { "speaker": "Cao Cao", "text": "Then take the ground." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 6600,
    "items": ["bean", "wine", "imperial_seal"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Ma Chao's counterstroke is broken, but Han Sui has seen enough to know pride can be steered." },
    { "speaker": "Xiahou Yuan", "text": "We can anchor camps along the Wei River, or work the space between Ma Chao and Han Sui before they settle." },
    { "speaker": "Cao Cao", "text": "The west will be won by ground or by doubt. Choose which blade cuts first." }
  ],
  "post_battle_choices": [
    {
      "id": "anchor_weishui_camps",
      "label": "Anchor Camps",
      "description": "Cao Cao anchors camps along the Wei River, preparing a stable line against Ma Chao.",
      "set_flags": { "anchored_weishui_camps": true, "sowed_han_sui_doubt": false },
      "gold": 950,
      "items": ["imperial_seal"]
    },
    {
      "id": "sow_han_sui_doubt",
      "label": "Sow Doubt",
      "description": "Cao Cao works to divide Han Sui from Ma Chao before the western alliance can harden.",
      "set_flags": { "anchored_weishui_camps": false, "sowed_han_sui_doubt": true },
      "gold": 750,
      "items": ["war_drum"]
    }
  ]
}
