{
  "id": "015_ye_campaign",
  "name": "Ye Campaign",
  "objectives": {
    "victory": "Defeat the Yuan heirs' outer defense after their split command reveals itself.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 14."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "turn_3_yuan_heir_split" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 14, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Ye Campaign",
    "location": "Ye Outskirts, 202 CE",
    "lines": [
      "Yuan Shao's heirs inherit banners, grudges, and a northern capital that cannot obey two masters.",
      "Cao Cao advances toward Ye, while Zhang He explains where the Yuan defense is strong and where pride has hollowed it out."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "advanced_to_ye": true },
        "lines": [
          "The rapid march from Cangting catches Yuan Tan's scouts arguing over orders instead of watching the road."
        ]
      },
      {
        "campaign_flags": { "secured_hebei_crossings": true },
        "lines": [
          "Secured crossings behind the army keep Cao Cao's supply line steady as the campaign enters Yuan territory."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "advanced_to_ye": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "secured_hebei_crossings": true },
        "items": ["imperial_seal"]
      }
    ]
  },
  "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": [
      "GGGGGHHGGGGGGGGGGG",
      "GGFFGHHGGGFFGGGFFG",
      "GGRRRRRRRRRRRRGFFG",
      "GGGGGRGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGRGGGGRRGGGGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch15",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch15",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch15",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch15",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch15",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch15",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch15",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "yuan_tan_outer_guard",
      "name": "Yuan Tan Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 14,
      "pos": [14, 4],
      "base": { "hp": 72, "mp": 16, "atk": 20, "def": 14, "int": 12, "agi": 11 }
    },
    {
      "unit_id": "yuan_shang_inner_guard",
      "name": "Yuan Shang Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 14,
      "pos": [13, 5],
      "base": { "hp": 64, "atk": 19, "def": 15, "agi": 10 }
    },
    {
      "unit_id": "ye_council_advisor",
      "name": "Ye Council Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 14,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 48, "mp": 34, "atk": 7, "def": 8, "int": 18, "agi": 10 }
    },
    {
      "unit_id": "ye_center_guard",
      "name": "Ye Center Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 13,
      "pos": [11, 4],
      "base": { "hp": 58, "atk": 18, "def": 14 }
    },
    {
      "unit_id": "ye_north_guard",
      "name": "Ye Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 13,
      "pos": [12, 3],
      "base": { "hp": 52, "atk": 17, "def": 12 }
    },
    {
      "unit_id": "ye_south_guard",
      "name": "Ye Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 13,
      "pos": [12, 5],
      "base": { "hp": 52, "atk": 17, "def": 12 }
    },
    {
      "unit_id": "ye_archer_north",
      "name": "Ye Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 13,
      "pos": [13, 2],
      "base": { "hp": 42, "atk": 17, "def": 7, "agi": 14 }
    },
    {
      "unit_id": "ye_archer_south",
      "name": "Ye Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 13,
      "pos": [14, 6],
      "base": { "hp": 42, "atk": 17, "def": 7, "agi": 14 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "The Yuan heirs argue behind Ye's outer defense." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Ye's outer road looks strong, but Yuan Tan and Yuan Shang will not agree who commands it." },
            { "speaker": "Cao Cao", "text": "Then their wall already has two gates." },
            { "speaker": "Guo Jia", "text": "Let them quarrel loudly enough for our blades to hear." }
          ]
        }
      ]
    },
    {
      "id": "rapid_march_confusion",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "advanced_to_ye": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Tan Guard", "text": "Cao Cao is already here? Yuan Shang promised another day!" },
            { "speaker": "Zhang He", "text": "They are blaming one another before the first order is given." }
          ]
        }
      ]
    },
    {
      "id": "crossings_secure_supply",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_hebei_crossings": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The crossings behind us are secure. We can keep pressure on Ye without starving the rear." },
            { "speaker": "Cao Cao", "text": "A campaign is won by the road as much as the sword." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_yuan_heir_split",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "set_objective",
          "victory": "Exploit the Yuan heirs' split command and defeat every outer defender.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 14."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Shang Guard", "text": "Hold for Yuan Shang! Do not yield command to Yuan Tan's men." },
            { "speaker": "Guo Jia", "text": "There it is. Two drums, one army, no rhythm." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "yuan_tan_rider",
              "name": "Yuan Tan Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 13,
              "pos": [16, 3],
              "base": { "hp": 48, "atk": 17, "def": 9, "agi": 12 }
            },
            {
              "unit_id": "yuan_shang_rider",
              "name": "Yuan Shang Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 13,
              "pos": [16, 5],
              "base": { "hp": 48, "atk": 17, "def": 9, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "outer_wall_trap",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Ye Guard", "text": "Cao Cao has pushed to the outer wall. Seal the road!" },
            { "speaker": "Zhang He", "text": "They seal late and from bad ground. Press through the center." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "ye_road_blocker",
              "name": "Ye Road Blocker",
              "class_id": "infantry",
              "team": "enemy",
              "level": 13,
              "pos": [9, 3],
              "base": { "hp": 50, "atk": 17, "def": 11 }
            },
            {
              "unit_id": "ye_road_archer",
              "name": "Ye Road Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 13,
              "pos": [9, 5],
              "base": { "hp": 38, "atk": 16, "def": 6, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_7_ye_outer_breaks",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 7 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Their outer command breaks before the wall does." },
            { "speaker": "Guo Jia", "text": "A city divided is already partly open." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 2500,
    "items": ["bean", "wine", "war_axe", "wind_chaser_bow"]
  },
  "post_battle_dialogue": [
    { "speaker": "Zhang He", "text": "Ye's outer defense is broken. The heirs will blame each other before they blame us." },
    { "speaker": "Guo Jia", "text": "Good. Their family quarrel is now a campaign map." },
    { "speaker": "Cao Cao", "text": "Then we decide whether to strike the city or widen the fracture." }
  ],
  "post_battle_choices": [
    {
      "id": "press_ye_siege",
      "label": "Press Ye Siege",
      "description": "Cao Cao prepares a direct siege before the Yuan heirs can reorganize.",
      "set_flags": { "pressed_ye_siege": true, "split_yuan_heirs": false },
      "gold": 100,
      "items": ["war_drum"]
    },
    {
      "id": "split_yuan_heirs",
      "label": "Split Heirs",
      "description": "The army spreads rumors and pressure to deepen Yuan Tan and Yuan Shang's rivalry.",
      "set_flags": { "pressed_ye_siege": false, "split_yuan_heirs": true },
      "gold": 250,
      "items": ["imperial_seal"]
    }
  ]
}
