{
  "id": "064_final_harbor",
  "name": "Final Harbor",
  "objectives": {
    "victory": "Reach the final harbor marker with Cao Cao, then defeat the harbor captain.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "final_harbor_marker_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Final Harbor",
    "location": "Final Harbor Road, Southern Sea, Eastern Front, 220 CE",
    "lines": [
      "Hainan's coast road is broken, and Wu's last captains gather at the final harbor with their remaining boats and records.",
      "Cao Cao advances to end the southern coastal resistance before it can scatter beyond Wei's reach."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_hainan_coast": true },
        "lines": [
          "Securing the Hainan coast gives Wei shore guides, captured pilots, and a clean approach to the final harbor."
        ]
      },
      {
        "campaign_flags": { "pressed_final_harbor": true },
        "lines": [
          "Pressing the final harbor early has trapped the last captains near their boats, but every remaining guard now fights with no road left behind."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_hainan_coast": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pressed_final_harbor": 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_ch64",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch64",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch64",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch64",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch64",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch64",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch64",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "final_harbor_captain",
      "name": "Final Harbor Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 61,
      "pos": [14, 4],
      "base": { "hp": 210, "mp": 102, "atk": 64, "def": 55, "int": 53, "agi": 40 }
    },
    {
      "unit_id": "final_harbor_guard",
      "name": "Final Harbor Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 61,
      "pos": [12, 4],
      "base": { "hp": 156, "atk": 63, "def": 56 }
    },
    {
      "unit_id": "final_harbor_boat",
      "name": "Final Harbor Boat",
      "class_id": "champion",
      "team": "enemy",
      "move_type": "water",
      "level": 61,
      "pos": [4, 3],
      "base": { "hp": 184, "mp": 12, "atk": 65, "def": 51, "int": 16, "agi": 47 }
    },
    {
      "unit_id": "final_harbor_advisor",
      "name": "Final Harbor Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 61,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 142, "mp": 126, "atk": 8, "def": 42, "int": 64, "agi": 37 }
    },
    {
      "unit_id": "final_harbor_spear_north",
      "name": "Final Harbor Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 61,
      "pos": [12, 3],
      "base": { "hp": 144, "atk": 62, "def": 52 }
    },
    {
      "unit_id": "final_harbor_spear_south",
      "name": "Final Harbor Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 61,
      "pos": [12, 5],
      "base": { "hp": 144, "atk": 62, "def": 52 }
    },
    {
      "unit_id": "final_harbor_arrow_boat",
      "name": "Final Harbor Arrow Boat",
      "class_id": "marksman",
      "team": "enemy",
      "move_type": "water",
      "level": 61,
      "pos": [5, 5],
      "base": { "hp": 136, "atk": 63, "def": 38, "agi": 50 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Wei advances on the final harbor to end Wu's southern coastal resistance." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The final harbor is ahead. Their last captains have gathered around the road and the boats." },
            { "speaker": "Guo Jia", "text": "When the last harbor falls, refusal has no shore left to name." },
            { "speaker": "Cao Cao", "text": "Then take the shore, the boats, and the name." }
          ]
        }
      ]
    },
    {
      "id": "secured_coast_opens_harbor_road",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_hainan_coast": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The secured Hainan coast has opened the harbor road. Their guards can no longer hide behind false coves." },
            { "speaker": "Cao Cao", "text": "A clear road should carry a clear end. Advance." }
          ]
        }
      ]
    },
    {
      "id": "pressed_harbor_commits_last_boat",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_final_harbor": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Final Harbor Captain", "text": "Wei has reached the harbor too soon. Commit the last boat and hold the passage." },
            { "speaker": "Xiahou Yuan", "text": "If that is their last boat, then today can be their last tide." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "final_harbor_last_boat",
            "name": "Final Harbor Last Boat",
            "class_id": "champion",
            "team": "enemy",
            "move_type": "water",
            "level": 61,
            "pos": [5, 3],
            "base": { "hp": 134, "atk": 58, "def": 42, "agi": 48 }
          }
        }
      ]
    },
    {
      "id": "turn_4_harbor_guard_closes_gate",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Final Harbor Advisor", "text": "Hold the harbor marker. If Wei stands there, the last captains will have nowhere to swear loyalty." },
            { "speaker": "Zhang He", "text": "A loyalty that needs a marker is already losing its place." }
          ]
        }
      ]
    },
    {
      "id": "final_harbor_marker_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The final harbor marker is reached. Defeat the harbor captain.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This is the final harbor. There will be no farther shore for refusal." },
            { "speaker": "Final Harbor Captain", "text": "Then we make this shore remember every captain who stood here." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "final_harbor_last_guard",
              "name": "Final Harbor Last Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 61,
              "pos": [16, 4],
              "base": { "hp": 152, "atk": 62, "def": 55 }
            },
            {
              "unit_id": "final_harbor_crossbow_boat",
              "name": "Final Harbor Crossbow Boat",
              "class_id": "marksman",
              "team": "enemy",
              "move_type": "water",
              "level": 61,
              "pos": [10, 1],
              "base": { "hp": 128, "atk": 61, "def": 35, "agi": 49 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_final_harbor_wavers",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Dian Wei", "text": "Their harbor line is splintering. The boats still float, but the men have nowhere left to look." },
            { "speaker": "Cao Cao", "text": "Then let them look at Wei's banners and understand the end." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 12600,
    "items": ["bean", "wine", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The final harbor is broken. Wei can secure the harbor and end the coast in order, or pursue the last captains before they scatter into nameless coves." },
    { "speaker": "Cao Ren", "text": "Securing the harbor steadies every road behind us. Pursuit ensures no captain claims the sea still belongs to Wu." },
    { "speaker": "Cao Cao", "text": "A harbor taken is a campaign's last gate. Decide whether it closes with seals or hoofbeats." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_final_harbor",
      "label": "Secure Harbor",
      "description": "Cao Cao secures the final harbor and ends the southern coast under Wei order.",
      "set_flags": { "secured_final_harbor": true, "pursued_last_captains": false },
      "gold": 2450,
      "items": ["imperial_seal"]
    },
    {
      "id": "pursue_last_captains",
      "label": "Pursue Captains",
      "description": "Cao Cao sends riders and boats after the last captains before they can scatter.",
      "set_flags": { "secured_final_harbor": false, "pursued_last_captains": true },
      "gold": 2250,
      "items": ["war_drum"]
    }
  ]
}
