{
  "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."
    ]
  },
  "shop": {
    "items": [
      "bean",
      "panacea",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "iron_armor"
    ]
  },
  "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 }
    }
  ]
}
