Skip to content

示例:心情条 ​

用到所有常见部件的最小资源包。它会加上:

  • 变量 mood(0 到 100,初始 50),AI 会加减它;
  • 一条词条,告诉 AI 这个数字是什么意思;
  • 一个行为,玩家按逗一逗时加 10;
  • 一个界面:屏幕右上角的心情条,带这个按钮。

下载 mood-meter-zh.bundle.json

文件 ​

json
{
  "bundleVersion": "3.0.0",
  "name": "心情条",
  "description": "角落里的一个小条,显示主角现在对玩家的心情。AI 随剧情加减,玩家也可以按「逗一逗」。",
  "tags": ["界面", "关系"],
  "createdAt": "2026-11-30T00:00:00.000Z",
  "entries": [
    {
      "id": "mood-guide",
      "name": "心情条说明",
      "content": "主角此刻对 {{user}} 的心情是 {{mood}}(满分 100)。0 到 29:冷淡、话少。30 到 69:平常。70 到 100:热情、愿意多说。让它影响主角说话的样子。",
      "role": "system",
      "section": "system-presets",
      "position": 0,
      "enabled": true,
      "alwaysSend": true,
      "keywords": [],
      "conditions": [],
      "conditionLogic": "all"
    }
  ],
  "variables": [
    {
      "id": "mood",
      "name": "心情",
      "type": "number",
      "defaultValue": 50,
      "min": 0,
      "max": 100,
      "description": "主角对玩家的心情",
      "behaviorRules": "玩家友善、有趣或帮了忙时加 3 到 10。玩家无礼或冷淡时减 3 到 10。每回合最多变 10。"
    }
  ],
  "rules": [],
  "reactions": [
    {
      "id": "cheer-up",
      "name": "逗一逗按钮",
      "when": { "eventType": "action:fired", "match": { "actionId": { "operator": "eq", "value": "cheer_up" } } },
      "conditions": [],
      "conditionLogic": "all",
      "then": [{ "type": "set", "path": "mood", "operation": "add", "value": 10 }],
      "priority": 0,
      "enabled": true
    }
  ],
  "audioTracks": [],
  "rootComponent": {
    "id": "mood-meter-ui",
    "name": "心情条",
    "entryFile": "index.tsx",
    "files": {
      "index.tsx": "export default function MoodMeter() {\n  const api = useYumina();\n  const mood = Number(api.variables.mood ?? 50);\n  const color = mood < 30 ? \"#6b8cff\" : mood < 70 ? \"#e0b44c\" : \"#ff6b8a\";\n  return (\n    <div style={{ position: \"fixed\", top: 64, right: 12, zIndex: 50, width: 168, padding: \"10px 12px\", borderRadius: 14, background: \"rgba(20,22,32,0.82)\", color: \"#fff\", fontSize: 13, fontFamily: \"system-ui, sans-serif\", boxShadow: \"0 6px 18px rgba(0,0,0,0.3)\" }}>\n      <div style={{ display: \"flex\", justifyContent: \"space-between\" }}>\n        <span>心情</span>\n        <b>{mood}</b>\n      </div>\n      <div style={{ height: 6, borderRadius: 3, background: \"rgba(255,255,255,0.15)\", margin: \"8px 0\" }}>\n        <div style={{ width: mood + \"%\", height: \"100%\", borderRadius: 3, background: color, transition: \"width .4s\" }} />\n      </div>\n      <button type=\"button\" disabled={api.readOnly} onClick={() => api.executeAction(\"cheer_up\")}\n        style={{ width: \"100%\", border: \"none\", borderRadius: 8, padding: \"6px 0\", cursor: \"pointer\", background: color, color: \"#1b1e2b\", fontWeight: 700 }}>\n        逗一逗\n      </button>\n    </div>\n  );\n}\n"
    },
    "updatedAt": "2026-11-30T00:00:00.000Z"
  }
}

界面代码去掉转义后是这样:

tsx
export default function MoodMeter() {
  const api = useYumina();
  const mood = Number(api.variables.mood ?? 50);
  const color = mood < 30 ? "#6b8cff" : mood < 70 ? "#e0b44c" : "#ff6b8a";
  return (
    <div style={{ position: "fixed", top: 64, right: 12, zIndex: 50, width: 168, padding: "10px 12px", borderRadius: 14, background: "rgba(20,22,32,0.82)", color: "#fff", fontSize: 13, fontFamily: "system-ui, sans-serif", boxShadow: "0 6px 18px rgba(0,0,0,0.3)" }}>
      <div style={{ display: "flex", justifyContent: "space-between" }}>
        <span>心情</span>
        <b>{mood}</b>
      </div>
      <div style={{ height: 6, borderRadius: 3, background: "rgba(255,255,255,0.15)", margin: "8px 0" }}>
        <div style={{ width: mood + "%", height: "100%", borderRadius: 3, background: color, transition: "width .4s" }} />
      </div>
      <button type="button" disabled={api.readOnly} onClick={() => api.executeAction("cheer_up")}
        style={{ width: "100%", border: "none", borderRadius: 8, padding: "6px 0", cursor: "pointer", background: color, color: "#1b1e2b", fontWeight: 700 }}>
        逗一逗
      </button>
    </div>
  );
}

各部分怎么连起来 ​

  • 界面读 api.variables.mood,它一变就重画。
  • 按钮调用 api.executeAction("cheer_up"),发出一个 actionId 为 "cheer_up" 的 action:fired 事件,正好对上行为的 when。行为给 mood 加 10;max: 100 保证它不超过上限。
  • AI 看得到这个变量和它的 behaviorRules,会在回复里用 [mood: +5] 这样的指令改它。见变量与指令。
  • 词条用 {{mood}} 宏读当前值,AI 每回合都知道这个数字代表什么。

试一试 ​

  1. 下载文件,在 我的库 → 资源包 → 导入资源包 导入。
  2. 在 Studio 打开任意一张卡,按添加旁边的资源市场,打开我的库,在「心情条」上按安装。
  3. 对话框里保持两个界面都留,取消勾选让助手适配到这张卡,按导入。
  4. 按试玩。右上角显示心情 50。按逗一逗变成 60;试玩面板会把这次变化记成「玩家点了按钮」。

改成你自己的 ​

把单文件规格放进 AI 的上下文,让它改。可以往这些方向改:

  • 每个角色一个心情:把 mood 改成按角色 id 存的 json 变量,每人画一条。
  • 改成 App:加上 export const app = { id: "mood", icon: "💗", name: "心情", variable: "mood", accent: "#ff6b8a" },把默认导出排成侧边面板的样子,而不是角落里的小条。
  • 限制按钮:给行为加 "cooldownTurns": 3。