{
  "id": "065_last_captains",
  "name": "Last Captains",
  "objectives": {
    "victory": "Reach the last captains' line with Cao Cao, then defeat the captain leader.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "last_captains_line_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Last Captains",
    "location": "Last Captains' Road, Southern Sea, Eastern Front, 220 CE",
    "lines": [
      "The final harbor has fallen, but the last Wu captains gather with their ship ledgers and loyal guards on the road beyond the docks.",
      "Cao Cao advances to decide whether those captains are settled under Wei order or driven out as sea exiles."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_final_harbor": true },
        "lines": [
          "Securing the final harbor gives Wei its ledgers, dock seals, and surrendered pilots, leaving the last captains few names to hide behind."
        ]
      },
      {
        "campaign_flags": { "pursued_last_captains": true },
        "lines": [
          "Pursuing the last captains keeps them from scattering, but the men who remain now fight because every other harbor has closed."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_final_harbor": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pursued_last_captains": 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_ch65",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch65",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch65",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch65",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch65",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch65",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch65",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "last_captain_leader",
      "name": "Last Captain Leader",
      "class_id": "commander",
      "team": "enemy",
      "level": 62,
      "pos": [14, 4],
      "base": { "hp": 214, "mp": 104, "atk": 65, "def": 56, "int": 54, "agi": 41 }
    },
    {
      "unit_id": "captain_ledger_guard",
      "name": "Captain Ledger Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 62,
      "pos": [12, 4],
      "base": { "hp": 158, "atk": 64, "def": 57 }
    },
    {
      "unit_id": "last_captain_boat",
      "name": "Last Captain Boat",
      "class_id": "champion",
      "team": "enemy",
      "move_type": "water",
      "level": 62,
      "pos": [4, 3],
      "base": { "hp": 186, "mp": 12, "atk": 66, "def": 52, "int": 16, "agi": 48 }
    },
    {
      "unit_id": "last_captain_advisor",
      "name": "Last Captain Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 62,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 144, "mp": 128, "atk": 8, "def": 43, "int": 65, "agi": 38 }
    },
    {
      "unit_id": "last_captain_spear_north",
      "name": "Last Captain Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 62,
      "pos": [12, 3],
      "base": { "hp": 146, "atk": 63, "def": 53 }
    },
    {
      "unit_id": "last_captain_spear_south",
      "name": "Last Captain Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 62,
      "pos": [12, 5],
      "base": { "hp": 146, "atk": 63, "def": 53 }
    },
    {
      "unit_id": "last_captain_arrow_boat",
      "name": "Last Captain Arrow Boat",
      "class_id": "marksman",
      "team": "enemy",
      "move_type": "water",
      "level": 62,
      "pos": [5, 5],
      "base": { "hp": 138, "atk": 64, "def": 39, "agi": 51 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Wei advances beyond the final harbor to bring the last Wu captains to terms." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The last captains are ahead. They still guard the ledgers as if paper can float them away." },
            { "speaker": "Guo Jia", "text": "Names matter at the end. A captain without a ledger becomes a bandit with a boat." },
            { "speaker": "Cao Cao", "text": "Then take the names and leave no boat outside Wei's count." }
          ]
        }
      ]
    },
    {
      "id": "secured_harbor_lists_captains",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_final_harbor": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The final harbor ledgers list their captains and stores. Their hiding places are already ink." },
            { "speaker": "Cao Cao", "text": "Ink can bind a campaign as surely as iron. Advance." }
          ]
        }
      ]
    },
    {
      "id": "pursued_captains_commit_escape_boat",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pursued_last_captains": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Last Captain Leader", "text": "Wei gives chase even past the harbor. Send the escape boat and keep our names from their ledgers." },
            { "speaker": "Cao Ren", "text": "They fear being counted more than being struck. That fear has weight." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "last_captain_escape_boat",
            "name": "Last Captain Escape Boat",
            "class_id": "champion",
            "team": "enemy",
            "move_type": "water",
            "level": 62,
            "pos": [5, 3],
            "base": { "hp": 136, "atk": 59, "def": 43, "agi": 49 }
          }
        }
      ]
    },
    {
      "id": "turn_4_captains_burn_ledgers",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Last Captain Advisor", "text": "Burn the spare ledgers. If Wei wins, let them count ashes." },
            { "speaker": "Guo Jia", "text": "They still mistake records for loyalty. Take the men before the ash cools." }
          ]
        }
      ]
    },
    {
      "id": "last_captains_line_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The last captains' line is reached. Defeat the captain leader.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This line ends the captains' names as Wu's servants. Submit them to Wei, or lose them here." },
            { "speaker": "Last Captain Leader", "text": "A name can still outlive a banner if men carry it to sea." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "last_captain_final_guard",
              "name": "Last Captain Final Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 62,
              "pos": [16, 4],
              "base": { "hp": 154, "atk": 63, "def": 56 }
            },
            {
              "unit_id": "last_captain_crossbow_boat",
              "name": "Last Captain Crossbow Boat",
              "class_id": "marksman",
              "team": "enemy",
              "move_type": "water",
              "level": 62,
              "pos": [10, 1],
              "base": { "hp": 130, "atk": 62, "def": 36, "agi": 50 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_captain_line_breaks",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Dian Wei", "text": "The last captains are losing their line. They still clutch the ledgers, but their guards keep looking back." },
            { "speaker": "Cao Cao", "text": "Then take both the line and the ledgers." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 12800,
    "items": ["bean", "wine", "war_axe"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The last captains are broken. Wei can settle their names into the coastal register, or pursue the sea exiles before any claim survives beyond the shore." },
    { "speaker": "Cao Ren", "text": "Settlement ends the ledgers. Pursuit ends the whispers that a fleet still waits." },
    { "speaker": "Cao Cao", "text": "A name kept in order is harmless. A name carried by fugitives becomes tomorrow's spark." }
  ],
  "post_battle_choices": [
    {
      "id": "settle_last_captains",
      "label": "Settle Captains",
      "description": "Cao Cao settles the last captains into Wei's coastal register.",
      "set_flags": { "settled_last_captains": true, "pursued_sea_exiles": false },
      "gold": 2500,
      "items": ["imperial_seal"]
    },
    {
      "id": "pursue_sea_exiles",
      "label": "Pursue Exiles",
      "description": "Cao Cao pursues the remaining sea exiles before their names become a new banner.",
      "set_flags": { "settled_last_captains": false, "pursued_sea_exiles": true },
      "gold": 2300,
      "items": ["war_drum"]
    }
  ]
}
