{
  "id": "055_jianye_gate",
  "name": "Jianye Gate",
  "objectives": {
    "victory": "Reach the Jianye gate line with Cao Cao, then defeat the Wu gate commander.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "jianye_gate_line_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Jianye Gate",
    "location": "Outer Gate Road, Jianye, Eastern Front, 220 CE",
    "lines": [
      "Wu's counterstroke has failed, and the road now runs close enough for Jianye's outer gate drums to answer Wei's march.",
      "Cao Cao advances to test the gate line, break the outer guard, and decide whether to secure the approach or force the capital to sortie."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "held_lower_yangtze_route": true },
        "lines": [
          "Holding the lower Yangtze route gives Wei a steadier siege road, guarded carts, and room to measure the gate before committing."
        ]
      },
      {
        "campaign_flags": { "pressed_jianye_gate": true },
        "lines": [
          "Pressing the Jianye gate keeps Wu's guard unsettled, but the capital's defenders are already hurrying boats and spears into the outer road."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "held_lower_yangtze_route": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pressed_jianye_gate": 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": [
      "WWWWWWWWWWWWWWWWWW",
      "WGGGFFWWRRWWFFGGGW",
      "GGGGWWGGGGRRGGGGGG",
      "GGFFWWGGRRRRGFFGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGFFWWGGRRRRGFFGGG",
      "GGGGWWGGGGRRGGGGGG",
      "GHHHWWGFFFGGFFFGGG",
      "GHHHWWGGGGHHHGGGGG",
      "GGGGWWGGGGHHHFFGGG",
      "WWWWWWWWWWWWWWWWWW"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch55",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch55",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch55",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch55",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch55",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch55",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch55",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "jianye_gate_commander",
      "name": "Jianye Gate Commander",
      "class_id": "commander",
      "team": "enemy",
      "level": 52,
      "pos": [14, 4],
      "base": { "hp": 174, "mp": 84, "atk": 55, "def": 46, "int": 44, "agi": 31 }
    },
    {
      "unit_id": "outer_gate_captain",
      "name": "Outer Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 52,
      "pos": [12, 4],
      "base": { "hp": 138, "atk": 54, "def": 47 }
    },
    {
      "unit_id": "zhu_ran_gate_boat",
      "name": "Zhu Ran Gate Boat",
      "class_id": "champion",
      "team": "enemy",
      "move_type": "water",
      "level": 52,
      "pos": [4, 3],
      "base": { "hp": 166, "mp": 12, "atk": 56, "def": 42, "int": 15, "agi": 38 }
    },
    {
      "unit_id": "jianye_gate_advisor",
      "name": "Jianye Gate Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 52,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 124, "mp": 108, "atk": 8, "def": 33, "int": 55, "agi": 28 }
    },
    {
      "unit_id": "jianye_gate_spear_north",
      "name": "Jianye Gate Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 52,
      "pos": [12, 3],
      "base": { "hp": 126, "atk": 53, "def": 43 }
    },
    {
      "unit_id": "jianye_gate_spear_south",
      "name": "Jianye Gate Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 52,
      "pos": [12, 5],
      "base": { "hp": 126, "atk": 53, "def": 43 }
    },
    {
      "unit_id": "jianye_gate_arrow_boat",
      "name": "Jianye Gate Arrow Boat",
      "class_id": "marksman",
      "team": "enemy",
      "move_type": "water",
      "level": 52,
      "pos": [5, 5],
      "base": { "hp": 118, "atk": 54, "def": 29, "agi": 41 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Wei reaches the outer gate road before Jianye's capital guard can settle." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The outer gate drums are close enough to answer our march." },
            { "speaker": "Guo Jia", "text": "A gate hears more than footsteps. It hears whether the army outside has time." },
            { "speaker": "Cao Cao", "text": "Then give it no comfort. Take the gate line and make Jianye choose." }
          ]
        }
      ]
    },
    {
      "id": "held_route_sets_siege_line",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "held_lower_yangtze_route": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The lower Yangtze route is held. Our carts are close enough to feed a siege line." },
            { "speaker": "Cao Cao", "text": "Then the gate faces an army with time, not merely a vanguard with dust." }
          ]
        }
      ]
    },
    {
      "id": "pressed_gate_draws_sortie_boat",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_jianye_gate": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Jianye Gate Commander", "text": "Wei presses the gate before the watch changes. Launch the sortie boat through the side water." },
            { "speaker": "Zhang He", "text": "The gate is reacting before it is ready. That is pressure worth keeping." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "wu_gate_sortie_boat",
            "name": "Wu Gate Sortie Boat",
            "class_id": "champion",
            "team": "enemy",
            "move_type": "water",
            "level": 52,
            "pos": [5, 3],
            "base": { "hp": 116, "atk": 49, "def": 33, "agi": 39 }
          }
        }
      ]
    },
    {
      "id": "turn_4_gate_line_closes",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Jianye Gate Advisor", "text": "Close the outer line. Let Wei spend strength before the gate can even be named theirs." },
            { "speaker": "Guo Jia", "text": "They want the word gate to slow us. Names have less weight than opened ground." }
          ]
        }
      ]
    },
    {
      "id": "jianye_gate_line_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Jianye gate line is reached. Defeat the Wu gate commander.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This is Jianye's outer gate line. Break its commander and the capital must answer from inside." },
            { "speaker": "Jianye Gate Commander", "text": "A capital does not fear the first army to see its gate." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "jianye_gate_inner_guard",
              "name": "Jianye Gate Inner Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 52,
              "pos": [16, 4],
              "base": { "hp": 134, "atk": 53, "def": 46 }
            },
            {
              "unit_id": "jianye_gate_crossbow_boat",
              "name": "Jianye Gate Crossbow Boat",
              "class_id": "marksman",
              "team": "enemy",
              "move_type": "water",
              "level": 52,
              "pos": [10, 1],
              "base": { "hp": 110, "atk": 52, "def": 26, "agi": 40 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_gate_line_bends",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The outer gate line is bending. Their commander is spending reserves to keep the road narrow." },
            { "speaker": "Cao Cao", "text": "Then widen it until Jianye has to answer with more than a gate." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 10800,
    "items": ["bean", "wine", "imperial_seal"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Jianye's outer gate line is broken. Wei can secure the gate road for a deliberate siege, or force the capital to sortie before its inner guard is ready." },
    { "speaker": "Cao Ren", "text": "Secure the gate and the army breathes. Force the sortie and the capital spends its own shield outside the walls." },
    { "speaker": "Cao Cao", "text": "The gate has heard us. Now decide whether it hears patience or command." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_jianye_gate",
      "label": "Secure Gate",
      "description": "Cao Cao secures Jianye's outer gate road before committing to the capital battle.",
      "set_flags": { "secured_jianye_gate": true, "forced_capital_sortie": false },
      "gold": 2000,
      "items": ["imperial_seal"]
    },
    {
      "id": "force_capital_sortie",
      "label": "Force Sortie",
      "description": "Cao Cao pressures Jianye until the capital guard sorties outside the walls.",
      "set_flags": { "secured_jianye_gate": false, "forced_capital_sortie": true },
      "gold": 1800,
      "items": ["war_drum"]
    }
  ]
}
