{
  "schemaVersion": 1,
  "type": "exclusive",
  "questName": "embers_remembered",
  "initialState": {
    "story_phase": {
      "type": "enum",
      "values": [
        "opening",
        "culvert_revealed",
        "signal_revealed",
        "reward_ready",
        "ration_selected",
        "ring_selected",
        "charm_selected",
        "completed"
      ],
      "default": "opening"
    }
  },
  "positions": {
    "storyteller_start": {
      "type": "random_room",
      "not_in_secret": true,
      "not_in_vault": true
    }
  },
  "items": {
    "road_rations": {
      "catalogId": "travelers-ration",
      "level": 1,
      "quantity": 2
    },
    "copper_ring": {
      "catalogId": "copper-ring",
      "level": 1
    },
    "lucky_charm": {
      "catalogId": "rabbits-foot",
      "level": 1
    }
  },
  "npcs": {
    "sable_marr": {
      "display_name": "Sable Marr, Storykeeper",
      "initialState": {},
      "solid": true,
      "opaque": false,
      "sprites": {
        "spawn": "sable_marr/spawn",
        "idle": "sable_marr/idle",
        "walk": "sable_marr/walk",
        "interact": "sable_marr/interact",
        "despawn": "sable_marr/despawn"
      },
      "dialogs": {
        "opening": {
          "text": "Sable turns three blackened coins across her knuckles. 'Greymark burned on a night of hard rain. Before the first flame, its bell rang once. A courier crossed the flooded ford without wetting his boots, the magistrate vanished with the tax silver, and a widow scattered hearth ash into the river. Ask the question that matters, and I will tell you what happened next.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "What color was the courier's coat?",
              "action": {
                "action": "display_dialog",
                "dialogId": "opening_misdirection"
              }
            },
            {
              "text": "How did the courier keep his boots dry?",
              "action": {
                "action": "call_function",
                "functionName": "reveal_culvert"
              }
            },
            {
              "text": "How much silver was stolen?",
              "action": {
                "action": "display_dialog",
                "dialogId": "opening_misdirection"
              }
            },
            {
              "text": "Was the magistrate well liked?",
              "action": {
                "action": "display_dialog",
                "dialogId": "opening_misdirection"
              }
            }
          ]
        },
        "opening_misdirection": {
          "text": "Sable shakes her head. 'Decoration. Ask for the fact the story cannot survive without.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "Ask another question.",
              "action": {
                "action": "display_dialog",
                "dialogId": "opening"
              }
            }
          ]
        },
        "culvert_revealed": {
          "text": "'There was no miracle,' Sable says. 'The courier used an old ash culvert beneath the bell tower. Inside, the watch found fresh boot marks, candle wax, and fibers from a new rope. The tower itself had been empty all night.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "Who made the candle wax?",
              "action": {
                "action": "display_dialog",
                "dialogId": "culvert_misdirection"
              }
            },
            {
              "text": "Why was the tower empty?",
              "action": {
                "action": "display_dialog",
                "dialogId": "culvert_misdirection"
              }
            },
            {
              "text": "What rang the bell if nobody was in the tower?",
              "action": {
                "action": "call_function",
                "functionName": "reveal_signal"
              }
            },
            {
              "text": "Were the boot marks the courier's size?",
              "action": {
                "action": "display_dialog",
                "dialogId": "culvert_misdirection"
              }
            }
          ]
        },
        "culvert_misdirection": {
          "text": "'Possible, but not useful,' Sable says. 'Listen for cause, not color.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "Ask another question.",
              "action": {
                "action": "display_dialog",
                "dialogId": "culvert_revealed"
              }
            }
          ]
        },
        "signal_revealed": {
          "text": "Sable smiles. 'A rope ran from the bell through the culvert to the ferry winch. The courier pulled it once. At that signal the ferryman cut a barge loose, and the magistrate stepped aboard with the silver. The widow watched from the bank, casting ash onto the current.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "Where was the real bell-ringer?",
              "action": {
                "action": "display_dialog",
                "dialogId": "signal_misdirection"
              }
            },
            {
              "text": "How old was the barge?",
              "action": {
                "action": "display_dialog",
                "dialogId": "signal_misdirection"
              }
            },
            {
              "text": "Did the courier know the magistrate?",
              "action": {
                "action": "display_dialog",
                "dialogId": "signal_misdirection"
              }
            },
            {
              "text": "Why did the widow mark the current with ash?",
              "action": {
                "action": "call_function",
                "functionName": "reveal_solution"
              }
            }
          ]
        },
        "signal_misdirection": {
          "text": "Sable closes one fist around the coins. 'That answer might decorate a trial. It would not solve the crime.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "Ask another question.",
              "action": {
                "action": "display_dialog",
                "dialogId": "signal_revealed"
              }
            }
          ]
        },
        "solution": {
          "text": "'Because the widow was Greymark's constable,' Sable says. 'Her people waited downstream in the rain. The drifting ash showed them which reed channel hid the barge. They recovered the silver before dawn; the magistrate burned the town records to hide his theft. You followed the hinges of the tale instead of its ornaments. Let the story choose your reward.'",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "Let the story choose.",
              "action": {
                "action": "call_function",
                "functionName": "choose_reward"
              }
            }
          ]
        },
        "reward_blocked": {
          "text": "Sable glances at your burdened pack. 'Chance has spoken, but you have nowhere to put its answer. Make room and return. I will not ask chance twice.'",
          "portrait": "placeholder",
          "onAbort": "noop"
        },
        "rations_given": {
          "text": "Sable gives you two carefully wrapped traveler's rations. 'Most true stories end with someone needing breakfast.'",
          "portrait": "placeholder",
          "onAbort": "noop"
        },
        "ring_given": {
          "text": "Sable presses a plain copper ring into your hand. 'It belonged to a magistrate who learned too late that circles also close traps.'",
          "portrait": "placeholder",
          "onAbort": "noop"
        },
        "charm_given": {
          "text": "Sable loops a battered rabbit's foot around your wrist. 'Luck is only a pattern we have not understood yet. Wear this until you do.'",
          "portrait": "placeholder",
          "onAbort": "noop"
        },
        "epilogue": {
          "text": "Sable's blackened coins pass silently from hand to hand. 'You already know how this story ends. Carry it carefully.'",
          "portrait": "placeholder",
          "onAbort": "noop"
        }
      },
      "functions": {
        "on_interact": [
          {
            "action": "switch_function",
            "stateRef": "quest.story_phase",
            "cases": {
              "opening": "show_opening",
              "culvert_revealed": "show_culvert",
              "signal_revealed": "show_signal",
              "reward_ready": "show_reward_ready",
              "ration_selected": "deliver_rations",
              "ring_selected": "deliver_ring",
              "charm_selected": "deliver_charm",
              "completed": "show_epilogue"
            }
          }
        ],
        "on_busy": [
          {
            "action": "call_function",
            "functionName": "noop"
          }
        ],
        "show_opening": [
          {
            "action": "dialog",
            "dialogId": "opening"
          }
        ],
        "show_culvert": [
          {
            "action": "dialog",
            "dialogId": "culvert_revealed"
          }
        ],
        "show_signal": [
          {
            "action": "dialog",
            "dialogId": "signal_revealed"
          }
        ],
        "show_reward_ready": [
          {
            "action": "dialog",
            "dialogId": "solution"
          }
        ],
        "show_epilogue": [
          {
            "action": "dialog",
            "dialogId": "epilogue"
          }
        ],
        "reveal_culvert": [
          {
            "action": "claim_quest_for_interactor"
          },
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "culvert_revealed"
          },
          {
            "action": "dialog",
            "dialogId": "culvert_revealed"
          }
        ],
        "reveal_signal": [
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "signal_revealed"
          },
          {
            "action": "dialog",
            "dialogId": "signal_revealed"
          }
        ],
        "reveal_solution": [
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "reward_ready"
          },
          {
            "action": "dialog",
            "dialogId": "solution"
          }
        ],
        "choose_reward": [
          {
            "action": "random_function",
            "outcomes": [
              {
                "weight": 55,
                "functionName": "select_rations"
              },
              {
                "weight": 30,
                "functionName": "select_ring"
              },
              {
                "weight": 15,
                "functionName": "select_charm"
              }
            ]
          }
        ],
        "select_rations": [
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "ration_selected"
          },
          {
            "action": "call_function",
            "functionName": "deliver_rations"
          }
        ],
        "select_ring": [
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "ring_selected"
          },
          {
            "action": "call_function",
            "functionName": "deliver_ring"
          }
        ],
        "select_charm": [
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "charm_selected"
          },
          {
            "action": "call_function",
            "functionName": "deliver_charm"
          }
        ],
        "deliver_rations": [
          {
            "action": "claim_quest_for_interactor"
          },
          {
            "action": "give_item",
            "itemName": "quest.road_rations",
            "targetRef": "interactor",
            "onFailure": "show_reward_blocked"
          },
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "completed"
          },
          {
            "action": "complete_quest"
          },
          {
            "action": "dialog",
            "dialogId": "rations_given"
          }
        ],
        "deliver_ring": [
          {
            "action": "claim_quest_for_interactor"
          },
          {
            "action": "give_item",
            "itemName": "quest.copper_ring",
            "targetRef": "interactor",
            "onFailure": "show_reward_blocked"
          },
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "completed"
          },
          {
            "action": "complete_quest"
          },
          {
            "action": "dialog",
            "dialogId": "ring_given"
          }
        ],
        "deliver_charm": [
          {
            "action": "claim_quest_for_interactor"
          },
          {
            "action": "give_item",
            "itemName": "quest.lucky_charm",
            "targetRef": "interactor",
            "onFailure": "show_reward_blocked"
          },
          {
            "action": "set_state",
            "stateRef": "quest.story_phase",
            "value": "completed"
          },
          {
            "action": "complete_quest"
          },
          {
            "action": "dialog",
            "dialogId": "charm_given"
          }
        ],
        "show_reward_blocked": [
          {
            "action": "dialog",
            "dialogId": "reward_blocked"
          }
        ]
      }
    }
  },
  "functions": {
    "on_start": [
      {
        "action": "spawn",
        "targetName": "quest.sable_marr",
        "position": "quest.storyteller_start"
      }
    ],
    "on_complete": [
      {
        "action": "call_function",
        "functionName": "noop"
      }
    ]
  }
}
