{
  "id": "005_puyang_raid",
  "name": "Puyang Raid",
  "objectives": {
    "victory": "Defeat Lu Bu's forward guard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 11."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "turn_3_lu_bu_arrives" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 11, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Puyang Raid",
    "location": "Puyang, 194 CE",
    "lines": [
      "Lu Bu has seized momentum in Yan Province.",
      "Cao Cao launches a night raid near Puyang to break the forward guard before the main cavalry can gather.",
      "Dian Wei joins the front line as Cao Cao's personal shield."
    ],
    "camp_conversations": [
      {
        "id": "puyang_night_raid_council",
        "group": "officer",
        "officer_id": "cao_cao",
        "label": "Cao Cao - Night Raid",
        "speaker": "Cao Cao",
        "summary": "Review the timing of the strike against Lu Bu's forward guard.",
        "lines": [
          { "speaker": "Cao Cao", "side": "left", "text": "Lu Bu wins when a field becomes a race. Tonight we deny him daylight, distance, and the first clean charge." },
          { "speaker": "Xiahou Dun", "side": "right", "text": "Then we hit the guard camp before the horses are bridled. I like battles that begin with the enemy half awake." }
        ]
      },
      {
        "id": "puyang_dian_wei_shield",
        "group": "officer",
        "officer_id": "dian_wei",
        "label": "Dian Wei - Iron Shield",
        "speaker": "Dian Wei",
        "summary": "Hear Dian Wei's first pledge as Cao Cao's personal shield.",
        "lines": [
          { "speaker": "Dian Wei", "side": "right", "text": "You gave me a place in the line. I will make that place difficult for any rider to cross." },
          { "speaker": "Cao Cao", "side": "left", "text": "Stand close when the alarm rises. Lu Bu's men will aim for the banner before they understand the field." }
        ]
      },
      {
        "id": "puyang_raider_stores",
        "group": "topic",
        "label": "Raider Stores",
        "summary": "Pack a small supply bundle for the night raid.",
        "lines": [
          { "speaker": "Puyang Night Trader", "side": "right", "text": "A night raid does not leave room for wagons. I tied the beans into dark cloth so the men can carry them under armor." },
          { "speaker": "Xiahou Yuan", "side": "left", "text": "Good. When Lu Bu's riders wake, no one will have time to search a cart." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "bean", "count": 1, "text": "The raider stores add a Bean to the field supplies." }
        ]
      },
      {
        "id": "puyang_hardened_vanguard",
        "campaign_flags": { "pursued_dong_zhuo": true },
        "group": "topic",
        "label": "Hardened Vanguard",
        "summary": "Issue wine to veterans used to forced marches and sudden strikes.",
        "lines": [
          { "speaker": "Xiahou Dun", "side": "right", "text": "The men who chased Dong Zhuo still move before the drum finishes. Puyang's night road will not frighten them." },
          { "speaker": "Cao Cao", "side": "left", "text": "Give those veterans wine before we step off. Men who endure hard roads should know their endurance is seen." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "wine", "count": 1, "text": "The hardened vanguard adds Wine to the field supplies." }
        ]
      },
      {
        "id": "puyang_qingzhou_reserve_wagon",
        "campaign_flags": { "regrouped_after_sishui": true },
        "group": "topic",
        "label": "Qingzhou Reserve Wagon",
        "summary": "Open a physician's bundle preserved during the steadier march.",
        "lines": [
          { "speaker": "Puyang Night Trader", "side": "right", "text": "The reserve wagon from Qingzhou still has a sealed physician's bundle. Quiet hands packed it better than hurried ones." },
          { "speaker": "Dian Wei", "side": "left", "text": "Keep it near the banner. If Lu Bu's riders break through, wounded men will need more than courage." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "panacea", "count": 1, "text": "The Qingzhou reserve wagon adds a Panacea to the field supplies." }
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "panacea",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "iron_armor"
    ],
    "merchant": {
      "name": "Puyang Night Trader",
      "lines": [
        "Keep the lamps hooded. Lu Bu's scouts buy anything that shines.",
        "His riders spend silver on speed. You will spend it on armor, beans, and living long enough to use both."
      ]
    }
  },
  "roster": {
    "max_units": 4,
    "required_officers": ["cao_cao", "dian_wei"]
  },
  "formation": {
    "cells": [[1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4]]
  },
  "map": {
    "width": 14,
    "height": 10,
    "terrain": [
      "GGGGGHHGGGGGGG",
      "GGGFFHHGGGFFGG",
      "GGGFFRRRRRFFGG",
      "GGGGGRGGGRGGGG",
      "RRRRRRRRRRRRRR",
      "GGGGGRGGGRGGGG",
      "GGFFFRRRRRFFGG",
      "GGFFFHHGGGFFGG",
      "GGGGGHHGGGWWGG",
      "GGGGGGGGGGWWGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch5",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "dian_wei_ch5",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "xiahou_dun_ch5",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch5",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "cao_ren_ch5",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "zhang_liao_vanguard",
      "name": "Zhang Liao Vanguard",
      "class_id": "cavalry",
      "team": "enemy",
      "level": 5,
      "pos": [10, 4],
      "base": { "hp": 48, "atk": 12, "def": 8, "agi": 10 },
      "equipment": { "weapon": "training_spear" }
    },
    {
      "unit_id": "gao_shun_guard",
      "name": "Gao Shun Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 5,
      "pos": [9, 3],
      "base": { "hp": 44, "atk": 10, "def": 9 },
      "equipment": { "weapon": "training_spear" }
    },
    {
      "unit_id": "puyang_cavalry_1",
      "name": "Puyang Rider",
      "class_id": "cavalry",
      "team": "enemy",
      "level": 5,
      "pos": [11, 3],
      "base": { "hp": 38, "atk": 9, "def": 7 },
      "equipment": { "weapon": "training_spear" }
    },
    {
      "unit_id": "puyang_cavalry_2",
      "name": "Puyang Rider",
      "class_id": "cavalry",
      "team": "enemy",
      "level": 5,
      "pos": [11, 5],
      "base": { "hp": 38, "atk": 9, "def": 7 },
      "equipment": { "weapon": "training_spear" }
    },
    {
      "unit_id": "puyang_archer",
      "name": "Puyang Archer",
      "class_id": "archer",
      "team": "enemy",
      "level": 5,
      "pos": [10, 2],
      "base": { "hp": 30, "atk": 9, "def": 5 },
      "equipment": { "weapon": "short_bow" }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao's raiding force slips toward Puyang under cover of darkness." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Lu Bu's cavalry is dangerous once it gathers speed. We strike before the whole camp wakes." },
            { "speaker": "Dian Wei", "text": "Stay behind me, my lord. Any rider who reaches you answers to my axe." },
            { "speaker": "Xiahou Dun", "text": "Good. We cut open their guard and withdraw before dawn." }
          ]
        }
      ]
    },
    {
      "id": "turn_2_alarm",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2 },
      "actions": [
        { "type": "log", "text": "Puyang's forward camp sounds the alarm." },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang Liao", "text": "Cao Cao comes in the night. Riders, close the road and pin him here." },
            { "speaker": "Cao Cao", "text": "The alarm is raised. Break their line before Lu Bu himself arrives." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_lu_bu_arrives",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        { "type": "log", "text": "Lu Bu's banner appears beyond the eastern road." },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Lu Bu", "text": "Cao Cao dares raid Puyang? Then let him see how fast my riders wake." },
            { "speaker": "Dian Wei", "text": "That one has a loud voice. I will hold the road while you finish the guard." }
          ]
        },
        {
          "type": "set_objective",
          "victory": "Defeat Zhang Liao's guard and the arriving riders.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 11."
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "lu_bu_banner",
              "name": "Lu Bu Banner Guard",
              "class_id": "elite_cavalry",
              "team": "enemy",
              "level": 6,
              "pos": [13, 4],
              "base": { "hp": 54, "atk": 14, "def": 9, "agi": 12 },
              "equipment": { "weapon": "training_spear" }
            },
            {
              "unit_id": "lu_bu_rider_north",
              "name": "Lu Bu Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 5,
              "pos": [12, 2],
              "base": { "hp": 38, "atk": 10, "def": 7 },
              "equipment": { "weapon": "training_spear" }
            },
            {
              "unit_id": "lu_bu_rider_south",
              "name": "Lu Bu Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 5,
              "pos": [12, 6],
              "base": { "hp": 38, "atk": 10, "def": 7 },
              "equipment": { "weapon": "training_spear" }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_5_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 5 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Dian Wei", "text": "Their riders hit hard, but their line bends. Give the word and I will split it." },
            { "speaker": "Cao Cao", "text": "Press them. We leave Puyang with their vanguard broken." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 900,
    "items": ["bean", "wine", "iron_sword"]
  },
  "post_battle_dialogue": [
    { "speaker": "Xiahou Dun", "text": "Lu Bu's men still hold Puyang, but their forward guard will remember tonight." },
    { "speaker": "Dian Wei", "text": "They came fast. Next time, let them come closer." },
    { "speaker": "Cao Cao", "text": "We have measured their strength. Now we choose whether to fortify Yan Province or strike again." }
  ],
  "post_battle_choices": [
    {
      "id": "fortify_yan_province",
      "label": "Fortify Yan Province",
      "description": "Secure supply roads before another clash with Lu Bu.",
      "set_flags": { "fortified_yan_province": true, "pressed_lu_bu": false }
    },
    {
      "id": "press_lu_bu",
      "label": "Press Lu Bu",
      "description": "Keep pressure on Puyang while Lu Bu's guard is shaken.",
      "set_flags": { "fortified_yan_province": false, "pressed_lu_bu": true }
    }
  ]
}
