{
  "id": "012_guandu_showdown",
  "name": "Guandu Showdown",
  "objectives": {
    "victory": "Defeat Yuan Shao's main assault after the full line commits.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 13."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "turn_4_yuan_main_assault" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 13, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Guandu Showdown",
    "location": "Guandu, 200 CE",
    "lines": [
      "Yuan Shao's vast army presses into Guandu, confident that numbers will crush Cao Cao's thin line.",
      "Guo Jia urges patience: hold the camps, expose the rhythm of Yuan Shao's command, and look for the supply wound."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_guandu_line": true },
        "lines": [
          "The defensive camps prepared after Yan Ford give the front line room to bend without breaking."
        ]
      },
      {
        "campaign_flags": { "scouted_wuchao_depots": true },
        "lines": [
          "Scouts from Yan Ford report unusually heavy traffic toward Wuchao. Yuan Shao's grain may be less protected than his banners."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_guandu_line": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "scouted_wuchao_depots": true },
        "items": ["war_drum"]
      }
    ]
  },
  "roster": {
    "max_units": 6,
    "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, 3], [3, 4]]
  },
  "map": {
    "width": 17,
    "height": 11,
    "terrain": [
      "GGGGGHHGGGGHHGGGG",
      "GGFFGHHGGFFHHGFFG",
      "GGFFRRRRRRRRRFFGG",
      "GGGGGRGGGGRGGGGGG",
      "RRRRRRRRRRRRRRRRR",
      "GGGGGRGGGGRGGGGGG",
      "GGHHGFFFGGWWWGGGG",
      "GGHHGFFFGGWWWGGGG",
      "GGGGGGFFGGWWWGGGG",
      "GGFFGGGGGGGGGFFGG",
      "GGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch12",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch12",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "xiahou_dun_ch12",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch12",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch12",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "cao_ren_ch12",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "yuan_shao_main_body",
      "name": "Yuan Shao Main Body",
      "class_id": "commander",
      "team": "enemy",
      "level": 12,
      "pos": [14, 4],
      "base": { "hp": 70, "mp": 16, "atk": 19, "def": 13, "int": 13, "agi": 10 }
    },
    {
      "unit_id": "ju_shou_advisor",
      "name": "Ju Shou Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 12,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 46, "mp": 32, "atk": 7, "def": 8, "int": 17, "agi": 10 }
    },
    {
      "unit_id": "zhang_he_vanguard",
      "name": "Zhang He Vanguard",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 12,
      "pos": [11, 4],
      "base": { "hp": 60, "atk": 20, "def": 12, "agi": 15 }
    },
    {
      "unit_id": "yuan_center_guard",
      "name": "Yuan Center Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 11,
      "pos": [10, 4],
      "base": { "hp": 56, "atk": 17, "def": 14 }
    },
    {
      "unit_id": "yuan_north_guard",
      "name": "Yuan North Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 11,
      "pos": [11, 3],
      "base": { "hp": 50, "atk": 16, "def": 11 }
    },
    {
      "unit_id": "yuan_south_guard",
      "name": "Yuan South Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 11,
      "pos": [11, 5],
      "base": { "hp": 50, "atk": 16, "def": 11 }
    },
    {
      "unit_id": "guandu_archer_north",
      "name": "Guandu Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 11,
      "pos": [12, 2],
      "base": { "hp": 40, "atk": 16, "def": 7, "agi": 14 }
    },
    {
      "unit_id": "guandu_archer_south",
      "name": "Guandu Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 11,
      "pos": [13, 6],
      "base": { "hp": 40, "atk": 16, "def": 7, "agi": 14 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Yuan Shao's main army bears down on Guandu." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Yuan Shao brings more banners than the field can hold." },
            { "speaker": "Guo Jia", "text": "Then each banner must be fed, signaled, and protected. A large army has larger seams." },
            { "speaker": "Xiahou Dun", "text": "Hold the front until those seams show. I understand." }
          ]
        }
      ]
    },
    {
      "id": "turn_2_siege_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Shao", "text": "Press the camps from both wings. Cao Cao cannot answer everywhere." },
            { "speaker": "Ju Shou", "text": "Steady pressure, my lord. Do not let their small line choose the tempo." }
          ]
        }
      ]
    },
    {
      "id": "secured_line_holds",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 3, "campaign_flags": { "secured_guandu_line": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The camps we reinforced are holding. Their first push has spent itself on timber and earth." },
            { "speaker": "Cao Cao", "text": "Good. Let Yuan Shao pay for every step." }
          ]
        }
      ]
    },
    {
      "id": "wuchao_traces_found",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 3, "campaign_flags": { "scouted_wuchao_depots": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The supply marks match the Yan Ford reports. Wuchao is feeding this entire assault." },
            { "speaker": "Cao Cao", "text": "Then this battle is not only a wall. It is a lantern pointing toward their granary." }
          ]
        }
      ]
    },
    {
      "id": "turn_4_yuan_main_assault",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "set_objective",
          "victory": "Defeat Yuan Shao's main body and every committed assault unit.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 13."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The center still stands. Send the rear cavalry in; break them before they settle." },
            { "speaker": "Guo Jia", "text": "Now the main weight is committed. If we endure this, Yuan Shao must expose his stores." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "yuan_rear_cavalry",
              "name": "Yuan Rear Cavalry",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 11,
              "pos": [15, 4],
              "base": { "hp": 46, "atk": 17, "def": 9, "agi": 12 }
            },
            {
              "unit_id": "yuan_north_crossbow",
              "name": "Yuan Crossbow",
              "class_id": "archer",
              "team": "enemy",
              "level": 11,
              "pos": [16, 3],
              "base": { "hp": 36, "atk": 15, "def": 6, "agi": 12 }
            },
            {
              "unit_id": "yuan_south_crossbow",
              "name": "Yuan Crossbow",
              "class_id": "archer",
              "team": "enemy",
              "level": 11,
              "pos": [16, 5],
              "base": { "hp": 36, "atk": 15, "def": 6, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "center_countertrap",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [9, 4] },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Guard", "text": "Cao Cao steps into the center! Close ranks around him." },
            { "speaker": "Dian Wei", "text": "Around him? Then you are around me too." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "yuan_center_spearman",
              "name": "Yuan Center Spearman",
              "class_id": "infantry",
              "team": "enemy",
              "level": 11,
              "pos": [8, 3],
              "base": { "hp": 48, "atk": 16, "def": 10 }
            },
            {
              "unit_id": "yuan_center_archer",
              "name": "Yuan Center Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 11,
              "pos": [8, 5],
              "base": { "hp": 36, "atk": 15, "def": 6, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_7_guandu_holds",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 7 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "Their assault no longer moves as one army. It moves as arguments." },
            { "speaker": "Cao Cao", "text": "Then answer each argument with steel. Guandu will hold." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 1900,
    "items": ["bean", "wine", "imperial_seal", "yitian_sword"]
  },
  "post_battle_dialogue": [
    { "speaker": "Xiahou Dun", "text": "Yuan Shao's first great push is broken, but his camps still fill the horizon." },
    { "speaker": "Guo Jia", "text": "The horizon eats grain. Wuchao is now more important than the banners before us." },
    { "speaker": "Cao Cao", "text": "Then we decide whether to strike the grain or strengthen the wall before the next tide." }
  ],
  "post_battle_choices": [
    {
      "id": "prepare_wuchao_raid",
      "label": "Prepare Wuchao Raid",
      "description": "Cao Cao commits scouts and fast troops toward Yuan Shao's exposed granaries.",
      "set_flags": { "prepared_wuchao_raid": true, "strengthened_guandu_defense": false },
      "gold": 100,
      "items": ["wine", "war_drum"]
    },
    {
      "id": "strengthen_guandu_defense",
      "label": "Strengthen Guandu",
      "description": "The army reinforces the camps before planning a deeper strike.",
      "set_flags": { "prepared_wuchao_raid": false, "strengthened_guandu_defense": true },
      "gold": 250,
      "items": ["iron_armor"]
    }
  ]
}
