{
  "id": "058_jianye_command",
  "name": "Jianye Command",
  "objectives": {
    "victory": "Reach the Jianye command line with Cao Cao, then defeat the Wu command guard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "jianye_command_line_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Jianye Command",
    "location": "Command District Road, Jianye, Eastern Front, 220 CE",
    "lines": [
      "Inner Jianye has opened under Wei pressure, and Wu's command district now gathers the city's remaining officers, boats, and reserve spears.",
      "Cao Cao advances to break the command road and decide whether Jianye is secured by order or forced toward surrender."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_inner_jianye": true },
        "lines": [
          "Securing inner Jianye gives Wei mapped streets, guarded crossings, and a clear approach to the command district."
        ]
      },
      {
        "campaign_flags": { "forced_wu_last_stand": true },
        "lines": [
          "Forcing Wu's last stand brings the command guard forward, but every remaining defender now knows there is little city left behind them."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_inner_jianye": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "forced_wu_last_stand": 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_ch58",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch58",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch58",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch58",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch58",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch58",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch58",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "jianye_command_guard",
      "name": "Jianye Command Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 55,
      "pos": [14, 4],
      "base": { "hp": 186, "mp": 90, "atk": 58, "def": 49, "int": 47, "agi": 34 }
    },
    {
      "unit_id": "command_district_captain",
      "name": "Command District Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 55,
      "pos": [12, 4],
      "base": { "hp": 144, "atk": 57, "def": 50 }
    },
    {
      "unit_id": "wu_command_canal_boat",
      "name": "Wu Command Canal Boat",
      "class_id": "champion",
      "team": "enemy",
      "move_type": "water",
      "level": 55,
      "pos": [4, 3],
      "base": { "hp": 172, "mp": 12, "atk": 59, "def": 45, "int": 16, "agi": 41 }
    },
    {
      "unit_id": "jianye_command_advisor",
      "name": "Jianye Command Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 55,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 130, "mp": 114, "atk": 8, "def": 36, "int": 58, "agi": 31 }
    },
    {
      "unit_id": "command_district_spear_north",
      "name": "Command District Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 55,
      "pos": [12, 3],
      "base": { "hp": 132, "atk": 56, "def": 46 }
    },
    {
      "unit_id": "command_district_spear_south",
      "name": "Command District Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 55,
      "pos": [12, 5],
      "base": { "hp": 132, "atk": 56, "def": 46 }
    },
    {
      "unit_id": "command_district_arrow_boat",
      "name": "Command District Arrow Boat",
      "class_id": "marksman",
      "team": "enemy",
      "move_type": "water",
      "level": 55,
      "pos": [5, 5],
      "base": { "hp": 124, "atk": 57, "def": 32, "agi": 44 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Wei advances toward Jianye's command district after opening the inner city road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The command district is ahead. Wu has gathered what remains of its officers on one road." },
            { "speaker": "Guo Jia", "text": "When a city gathers its orders in one place, breaking that place breaks more than soldiers." },
            { "speaker": "Cao Cao", "text": "Then take the road and let Jianye learn where command now stands." }
          ]
        }
      ]
    },
    {
      "id": "secured_inner_city_guides_advance",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_inner_jianye": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The inner city roads are secured behind us. Our guides can point every cart and banner forward." },
            { "speaker": "Cao Cao", "text": "A city that cannot confuse our road has already surrendered half its defense." }
          ]
        }
      ]
    },
    {
      "id": "last_stand_commits_canal_boat",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "forced_wu_last_stand": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Jianye Command Guard", "text": "Wei has forced the last stand. Send the canal boat and make the command road bleed." },
            { "speaker": "Zhang He", "text": "That is the sound of a guard with no rear left to trust." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "wu_last_stand_canal_boat",
            "name": "Wu Last-Stand Canal Boat",
            "class_id": "champion",
            "team": "enemy",
            "move_type": "water",
            "level": 55,
            "pos": [5, 3],
            "base": { "hp": 122, "atk": 52, "def": 36, "agi": 42 }
          }
        }
      ]
    },
    {
      "id": "turn_4_command_guard_tightens",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Jianye Command Advisor", "text": "Guard the command road. If this line falls, orders become pleas." },
            { "speaker": "Guo Jia", "text": "They have named the truth themselves. Press it." }
          ]
        }
      ]
    },
    {
      "id": "jianye_command_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 command line is reached. Defeat the Wu command guard.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This is Jianye's command road. Break its guard and the city will speak with Wei's voice." },
            { "speaker": "Jianye Command Guard", "text": "A city can still refuse after its road is taken." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "jianye_command_last_guard",
              "name": "Jianye Command Last Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 55,
              "pos": [16, 4],
              "base": { "hp": 140, "atk": 56, "def": 49 }
            },
            {
              "unit_id": "jianye_command_crossbow_boat",
              "name": "Jianye Command Crossbow Boat",
              "class_id": "marksman",
              "team": "enemy",
              "move_type": "water",
              "level": 55,
              "pos": [10, 1],
              "base": { "hp": 116, "atk": 55, "def": 29, "agi": 43 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_command_line_cracks",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The command road is cracking. Their banners still stand, but fewer men look to them." },
            { "speaker": "Cao Cao", "text": "Then give the rest a reason to look elsewhere." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 11400,
    "items": ["bean", "wine", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Jianye's command road is broken. Wei can secure the district with order, or press Wu's remaining officers toward surrender before they find another banner." },
    { "speaker": "Cao Ren", "text": "Secure the command district and the city settles under our eye. Force surrender and the last guard must answer before it can hide." },
    { "speaker": "Cao Cao", "text": "A command road taken is not only ground. It is the place where tomorrow's orders begin." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_jianye_command",
      "label": "Secure Command",
      "description": "Cao Cao secures Jianye's command district and prepares an orderly settlement.",
      "set_flags": { "secured_jianye_command": true, "forced_wu_surrender": false },
      "gold": 2150,
      "items": ["imperial_seal"]
    },
    {
      "id": "force_wu_surrender",
      "label": "Force Surrender",
      "description": "Cao Cao presses Wu's remaining officers toward surrender before they can regroup.",
      "set_flags": { "secured_jianye_command": false, "forced_wu_surrender": true },
      "gold": 1950,
      "items": ["war_drum"]
    }
  ]
}
