Skip to content

ルールとリアクション

ルールはイベントに基づいてターン間に自動的に発火します。AIの関与なしに精密なメカニクスを処理します。

ルールスキーマ

json
{
  "id": "low-health-warning",
  "name": "Low Health Warning",
  "description": "Warn the player when health is critical",
  "trigger": {
    "type": "variable-crossed",
    "variableId": "health",
    "direction": "drops-below",
    "threshold": 20
  },
  "conditions": [],
  "conditionLogic": "all",
  "actions": [
    {
      "type": "notify-player",
      "style": "warning",
      "message": "Your vision blurs. You're barely standing."
    },
    {
      "type": "inject-directive",
      "directiveId": "critical-health",
      "content": "The player is near death. Describe their physical deterioration — stumbling, blurred vision, trembling hands.",
      "position": "after_char",
      "persistent": true
    }
  ],
  "priority": 50,
  "enabled": true,
  "cooldownTurns": null,
  "maxFireCount": null
}

トリガータイプ

タイプフィールド発火するとき
variable-crossedvariableIddirection(rises-above | drops-below)、threshold変数がしきい値を越える
state-changevariableId(任意)任意の変数が変化(または特定の変数)
turn-countatTurn(number)、everyNTurns(number)特定のターン番号、またはNターンごと
session-start新しいセッションの最初のメッセージ
keywordkeywords[]プレイヤーメッセージに任意のキーワードが含まれる
ai-keywordkeywords[]AI応答に任意のキーワードが含まれる
every-turn毎ターンの後
actionactionId(string)特定のアクションが実行される(例: カスタムUIボタンから)
manual他のルールによってトリガーされたときだけ発火

条件

ルールが発火するためにパスしなければならない、任意の状態チェック:

json
"conditions": [
  {
    "variableId": "story-phase",
    "operator": "eq",
    "value": "act2"
  },
  {
    "variableId": "health",
    "operator": "gt",
    "value": 0
  }
]

演算子: eqneqgtltgteltecontains

conditionLogic: "all"(AND)または "any"(OR)

アクションタイプ

modify-variable

変数値を変更。

json
{
  "type": "modify-variable",
  "variableId": "hunger",
  "operation": "subtract",
  "value": 5
}

操作: setaddsubtractmultiplytoggleappendmergepushdelete

inject-directive

将来のターンに向けてAIのプロンプトに指示を追加。

json
{
  "type": "inject-directive",
  "directiveId": "romance-mode",
  "content": "The character has developed feelings. Write romantic tension naturally.",
  "position": "after_char",
  "persistent": true
}

位置: topbefore_charafter_charautodepthbottom

persistent: true は明示的に削除されるまでディレクティブをアクティブに保ちます。persistent: false(デフォルト)= 1回限り、1ターン後に削除。

duration: 任意の数値。設定された場合、ディレクティブはNターン後に自動削除されます。

remove-directive

以前に注入したディレクティブを削除。

json
{
  "type": "remove-directive",
  "directiveId": "romance-mode"
}

notify-player

トースト通知を表示。

json
{
  "type": "notify-player",
  "style": "warning",
  "message": "You're running low on supplies."
}

スタイル: infoachievementwarningdanger

play-audio

オーディオトラックをトリガー。

json
{
  "type": "play-audio",
  "trackId": "bgm-battle",
  "action": "play"
}

toggle-entry

ロアブックエントリを有効化または無効化。

json
{
  "type": "toggle-entry",
  "entryId": "secret-lore",
  "enabled": true
}

toggle-rule

別のルールを有効化または無効化(連鎖反応)。

json
{
  "type": "toggle-rule",
  "ruleId": "phase-2-triggers",
  "enabled": true
}

send-context

次のターンでAIに1回限りのコンテキストメッセージを送信。

json
{
  "type": "send-context",
  "message": "The player just triggered a hidden event. React accordingly.",
  "role": "system"
}

role: "system"(デフォルト)または "user"。コンテキストがどう会話に注入されるかを決定。

ルールのオプション

フィールドタイプ説明
prioritynumber高い方が先に発火(複数ルールがトリガーされたとき)(デフォルト: 0)
cooldownTurnsnumber | null発火間の最小ターン数
maxFireCountnumber | nullこのルールが発火できる総回数(null = 無制限)
enabledboolean他のルールから切り替え可能

リアクション(イベントパターンシステム)

リアクションは、汎用イベントパターンに基づくより新しく柔軟なルールシステムです。

json
{
  "id": "zone-enter-forest",
  "name": "Enter Forest",
  "when": {
    "eventType": "spatial:zone-enter",
    "zone": "forest"
  },
  "conditions": [],
  "conditionLogic": "all",
  "then": [
    {
      "type": "set",
      "path": "weather",
      "value": "foggy"
    },
    {
      "type": "set",
      "path": "@audio.ambient",
      "value": "forest-ambient",
      "operation": "set"
    },
    {
      "type": "emit",
      "event": { "type": "spatial:ambience-changed" }
    }
  ]
}

システムエフェクトパス

リアクションは @ パスでシステム機能をターゲットにできます。

パスエフェクト
@audio.bgmBGMトラックを再生
@audio.sfxSFXを再生
@audio.ambientアンビエントトラックを再生
@audio.stopトラックを停止
@prompt.directive.<id>ディレクティブを注入/削除
@prompt.entry.<id>エントリの表示を切り替え
@prompt.context1回限りのコンテキストメッセージ
@rules.disabled.<id>ルール有効/無効を切り替え
@ui.notificationトースト通知を表示
@ai.requestAI生成をトリガー
@ai.context次のAIメッセージにコンテキストを追加

毎ターン生成されるイベント

AIが応答した後、これらのイベントが発火され、すべてのルール/リアクションに対してチェックされます。

  1. message:user — プレイヤーのメッセージ(キーワードマッチング用のコンテンツ付き)
  2. message:ai — AIの応答(キーワードマッチング用のコンテンツ付き)
  3. turn:complete — ターン終了(ターン数付き)
  4. state:changed — 変更された変数ごとに1つ(variableId、oldValue、newValue付き)