{
  "schemaVersion": 1,
  "type": "exclusive",
  "questName": "deserters_price",
  "initialState": {
    "helper_id": { "type": "player_uuid", "default": null },
    "route": { "type": "string", "default": "unclaimed" },
    "captain_battle_position": { "type": "position", "default": [0, 0, 0] }
  },
  "positions": {
    "captain_start": {
      "type": "random_room",
      "not_in_secret": true,
      "not_in_vault": true
    },
    "garin_start": {
      "type": "random_in_other_room",
      "positionRef": "quest.captain_start",
      "not_in_secret": true,
      "not_in_vault": true
    }
  },
  "items": {
    "captain_vane_sigil": {
      "display_name": "Captain Vane's Sigil",
      "sprite": "captain_vane/sigil"
    },
    "garins_lucky_charm": {
      "catalogId": "rabbits-foot",
      "level": 1
    }
  },
  "npcs": {
    "garin_holt": {
      "display_name": "Garin Holt, Deserter",
      "initialState": {},
      "solid": true,
      "opaque": false,
      "sprites": {
        "spawn": "garin_holt/spawn",
        "idle": "garin_holt/idle",
        "walk": "garin_holt/walk",
        "interact": "garin_holt/interact",
        "despawn": "garin_holt/despawn"
      },
      "functions": {
        "on_interact": [
          {
            "action": "check_condition",
            "conditionName": "quest.route_is_unclaimed",
            "onTrue": "quest.show_garin_plea",
            "onFalse": "quest.check_garin_helper"
          }
        ],
        "on_busy": [
          {
            "action": "call_function",
            "functionName": "noop"
          }
        ]
      }
    },
    "captain_vane": {
      "display_name": "Captain Aldric Vane",
      "initialState": {},
      "solid": true,
      "opaque": false,
      "sprites": {
        "spawn": "captain_vane/spawn",
        "idle": "captain_vane/idle",
        "walk": "captain_vane/walk",
        "interact": "captain_vane/interact",
        "despawn": "captain_vane/despawn"
      },
      "functions": {
        "on_interact": [
          {
            "action": "check_condition",
            "conditionName": "quest.route_is_unclaimed",
            "onTrue": "quest.show_captain_searching",
            "onFalse": "quest.check_captain_helper"
          }
        ],
        "on_busy": [
          {
            "action": "call_function",
            "functionName": "noop"
          }
        ]
      }
    },
    "wounded_captain_vane": {
      "display_name": "Wounded Captain Vane",
      "initialState": {},
      "solid": true,
      "opaque": false,
      "sprites": {
        "spawn": "wounded_captain_vane/spawn",
        "idle": "wounded_captain_vane/idle",
        "walk": "wounded_captain_vane/walk",
        "interact": "wounded_captain_vane/interact",
        "despawn": "wounded_captain_vane/despawn"
      },
      "functions": {
        "on_interact": [
          {
            "action": "check_condition",
            "conditionName": "quest.helper_is_interactor",
            "onTrue": "quest.check_surrender_still_active",
            "onFalse": "noop"
          }
        ],
        "on_busy": [
          {
            "action": "call_function",
            "functionName": "noop"
          }
        ]
      }
    }
  },
  "hostiles": {
    "hostile_captain_vane": {
      "catalogId": "bandit",
      "display_name": "Captain Aldric Vane",
      "level": 1,
      "hp": 100,
      "sprites": {
        "spawn": "captain_vane/spawn",
        "idle": "captain_vane/idle",
        "walk": "captain_vane/walk",
        "attack": "captain_vane/attack",
        "death": "captain_vane/death"
      },
      "functions": {
        "on_health_change": [
          {
            "action": "check_condition",
            "conditionName": "quest.captain_should_surrender",
            "onTrue": "quest.surrender_captain",
            "onFalse": "noop"
          }
        ]
      }
    }
  },
  "dialogs": {
    "garin_plea": {
      "text": "Please, keep your voice down. I'm Garin Holt. I deserted Captain Vane's company, and he has followed me here to finish what he started. If he finds me, he'll kill me. Will you help me?",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "I'll speak to Captain Vane.",
          "action": {
            "action": "call_function",
            "functionName": "accept_garin_quest"
          }
        },
        {
          "text": "This is not my concern.",
          "action": {
            "action": "call_function",
            "functionName": "noop"
          }
        }
      ]
    },
    "garin_accepts_help": {
      "text": "Thank you. Vane won't listen to me, but he might listen to someone with a sword and no uniform. Please—don't tell him where I am.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "garin_waiting": {
      "text": "Captain Vane is still out there. Whatever you decide to do, please finish it before he finds me.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "garin_reserved": {
      "text": "Garin studies you, then shakes his head. Whatever confidence he placed in another traveler, he does not extend it to you.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "garin_curse": {
      "text": "You let him walk away? He knows I'm alive. I'll always be looking over my shoulder because of you. May every road you take lead you straight back to the people hunting you.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "garin_after_reward": {
      "text": "Garin gives you a tired nod. There is nothing more to say between you.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "captain_searching": {
      "text": "Captain Aldric Vane looks you over with open suspicion. 'I'm hunting a deserter named Garin Holt. If you've seen him, report it. Otherwise, stay out of my way.'",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "captain_confrontation": {
      "text": "Vane rests one hand on his sword. 'You have the look of someone carrying information. Speak.'",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "For the right price, I might know where Garin is.",
          "action": {
            "action": "call_function",
            "functionName": "choose_betrayal"
          }
        },
        {
          "text": "Garin is under my protection. Draw your sword.",
          "action": {
            "action": "call_function",
            "functionName": "choose_fight"
          }
        }
      ]
    },
    "captain_reserved": {
      "text": "Vane dismisses you with a glance. 'I have business with someone else. Move along.'",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "captain_after_betrayal": {
      "text": "Vane smiles without warmth. 'Your information was useful. Garin's fate is no longer your concern.'",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "betrayal_paid": {
      "text": "Vane counts seventy-five gold into your hand. Somewhere beyond the torchlight, armored footsteps close on Garin's hiding place.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "captain_surrender": {
      "text": "Vane drops his weapon and presses one hand to his wounds. 'Enough! I yield. I was wrong. Let me leave, and you will never see me again.'",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "No. This ends here. Take his sigil.",
          "action": {
            "action": "call_function",
            "functionName": "choose_kill_captain"
          }
        },
        {
          "text": "Go. Do not come back.",
          "action": {
            "action": "call_function",
            "functionName": "choose_mercy"
          }
        }
      ]
    },
    "sigil_delivery_blocked": {
      "text": "You have no room to take Captain Vane's sigil. He remains on his knees, watching you carefully.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "captain_killed": {
      "text": "Vane reaches for his sword. You end the fight before he can grasp it, then tear the captain's iron sigil from his coat.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "captain_spared": {
      "text": "Vane staggers away without his weapon. He does not look back.",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "sigil_handoff": {
      "text": "You give Captain Vane's sigil to Garin. The deserter turns the iron badge over in his hands and falls silent.",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "You ran because you were afraid, didn't you?",
          "action": {
            "action": "display_dialog",
            "dialogId": "story_fear"
          }
        },
        {
          "text": "What order did you refuse?",
          "action": {
            "action": "display_dialog",
            "dialogId": "story_order"
          }
        },
        {
          "text": "Tell me what Vane did to you.",
          "action": {
            "action": "display_dialog",
            "dialogId": "story_vane"
          }
        }
      ]
    },
    "story_fear": {
      "text": "'Of course I was afraid,' Garin says. 'We were ordered into a village at dawn. Vane said anyone who ran was a traitor. I saw what obedience was about to make me, and I ran anyway.'",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "What happened after you fled?",
          "action": {
            "action": "display_dialog",
            "dialogId": "story_ending"
          }
        }
      ]
    },
    "story_order": {
      "text": "Garin closes his fist around the sigil. 'Vane ordered us to burn every house that sheltered rebels. There were families inside. I threw down my torch. He called that desertion. I called it the last decent choice I had left.'",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "And then you disappeared?",
          "action": {
            "action": "display_dialog",
            "dialogId": "story_ending"
          }
        }
      ]
    },
    "story_vane": {
      "text": "'Vane needed someone to blame,' Garin says. 'His command was falling apart, and I knew he had been selling army supplies to raiders. He named me a coward before I could expose him. Running was the only way to stay alive long enough to tell anyone.'",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "So this was never only about desertion.",
          "action": {
            "action": "display_dialog",
            "dialogId": "story_ending"
          }
        }
      ]
    },
    "story_ending": {
      "text": "Garin slips Vane's sigil into his coat. 'Whichever part of my story you believe, you gave me another morning. My mother swore this charm carried luck. I think I've borrowed enough of it.' He offers you a battered rabbit's foot.",
      "portrait": "placeholder",
      "onAbort": "noop",
      "choices": [
        {
          "text": "Take Garin's lucky charm.",
          "action": {
            "action": "call_function",
            "functionName": "finish_garins_story"
          }
        }
      ]
    },
    "reward_blocked": {
      "text": "Garin tries to hand you the charm, but your pack is full. 'Make room. I owe you this much.'",
      "portrait": "placeholder",
      "onAbort": "noop"
    },
    "reward_given": {
      "text": "You take Garin's lucky rabbit's foot. He exhales as though a weight has finally left him.",
      "portrait": "placeholder",
      "onAbort": "noop"
    }
  },
  "conditions": {
    "route_is_unclaimed": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "unclaimed",
      "operation": "eq"
    },
    "route_is_active": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "active",
      "operation": "eq"
    },
    "route_is_surrendered": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "surrendered",
      "operation": "eq"
    },
    "route_is_captain_killed": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "captain_killed",
      "operation": "eq"
    },
    "route_is_mercy": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "mercy",
      "operation": "eq"
    },
    "route_is_rewarded": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "rewarded",
      "operation": "eq"
    },
    "route_is_sigil_returned": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "sigil_returned",
      "operation": "eq"
    },
    "route_is_reward_pending": {
      "type": "compare",
      "opA": "quest.route",
      "opB": "reward_pending",
      "operation": "eq"
    },
    "helper_is_interactor": {
      "type": "compare",
      "opA": "quest.helper_id",
      "opB": "interactor.id",
      "operation": "eq"
    },
    "captain_should_surrender": {
      "type": "compare",
      "opA": "quest.hostile_captain_vane.hp",
      "opB": 20,
      "operation": "lte"
    }
  },
  "functions": {
    "on_start": [
      {
        "action": "spawn",
        "targetName": "quest.garin_holt",
        "position": "quest.garin_start"
      },
      {
        "action": "spawn",
        "targetName": "quest.captain_vane",
        "position": "quest.captain_start"
      }
    ],
    "on_complete": [
      {
        "action": "call_function",
        "functionName": "noop"
      }
    ],
    "show_garin_plea": [
      {
        "action": "dialog",
        "dialogId": "garin_plea"
      }
    ],
    "accept_garin_quest": [
      {
        "action": "check_condition",
        "conditionName": "route_is_unclaimed",
        "onTrue": "claim_garin_helper",
        "onFalse": "noop"
      }
    ],
    "claim_garin_helper": [
      {
        "action": "claim_quest_for_interactor"
      },
      {
        "action": "set_state",
        "stateRef": "quest.helper_id",
        "sourceRef": "interactor.id"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "active"
      },
      {
        "action": "dialog",
        "dialogId": "garin_accepts_help"
      }
    ],
    "check_garin_helper": [
      {
        "action": "check_condition",
        "conditionName": "helper_is_interactor",
        "onTrue": "route_owned_garin_interaction",
        "onFalse": "show_garin_reserved"
      }
    ],
    "show_garin_reserved": [
      {
        "action": "dialog",
        "dialogId": "garin_reserved"
      }
    ],
    "route_owned_garin_interaction": [
      {
        "action": "check_condition",
        "conditionName": "route_is_reward_pending",
        "onTrue": "deliver_garin_reward",
        "onFalse": "check_garin_captain_killed_route"
      }
    ],
    "check_garin_captain_killed_route": [
      {
        "action": "check_condition",
        "conditionName": "route_is_captain_killed",
        "onTrue": "attempt_sigil_turnin",
        "onFalse": "check_garin_sigil_returned_route"
      }
    ],
    "check_garin_sigil_returned_route": [
      {
        "action": "check_condition",
        "conditionName": "route_is_sigil_returned",
        "onTrue": "show_sigil_story",
        "onFalse": "check_garin_mercy_route"
      }
    ],
    "attempt_sigil_turnin": [
      {
        "action": "take_item",
        "sourceRef": "interactor",
        "itemName": "quest.captain_vane_sigil",
        "onFailure": "noop"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "sigil_returned"
      },
      {
        "action": "dialog",
        "dialogId": "sigil_handoff"
      }
    ],
    "show_sigil_story": [
      {
        "action": "dialog",
        "dialogId": "sigil_handoff"
      }
    ],
    "check_garin_mercy_route": [
      {
        "action": "check_condition",
        "conditionName": "route_is_mercy",
        "onTrue": "show_garin_curse",
        "onFalse": "check_garin_rewarded_route"
      }
    ],
    "check_garin_rewarded_route": [
      {
        "action": "check_condition",
        "conditionName": "route_is_rewarded",
        "onTrue": "show_garin_after_reward",
        "onFalse": "show_garin_waiting"
      }
    ],
    "show_garin_waiting": [
      {
        "action": "dialog",
        "dialogId": "garin_waiting"
      }
    ],
    "show_garin_curse": [
      {
        "action": "dialog",
        "dialogId": "garin_curse"
      }
    ],
    "show_garin_after_reward": [
      {
        "action": "dialog",
        "dialogId": "garin_after_reward"
      }
    ],
    "show_captain_searching": [
      {
        "action": "dialog",
        "dialogId": "captain_searching"
      }
    ],
    "check_captain_helper": [
      {
        "action": "check_condition",
        "conditionName": "helper_is_interactor",
        "onTrue": "route_owned_captain_interaction",
        "onFalse": "show_captain_reserved"
      }
    ],
    "route_owned_captain_interaction": [
      {
        "action": "check_condition",
        "conditionName": "route_is_active",
        "onTrue": "show_captain_confrontation",
        "onFalse": "show_captain_after_betrayal"
      }
    ],
    "show_captain_confrontation": [
      {
        "action": "dialog",
        "dialogId": "captain_confrontation"
      }
    ],
    "show_captain_reserved": [
      {
        "action": "dialog",
        "dialogId": "captain_reserved"
      }
    ],
    "show_captain_after_betrayal": [
      {
        "action": "dialog",
        "dialogId": "captain_after_betrayal"
      }
    ],
    "choose_betrayal": [
      {
        "action": "check_condition",
        "conditionName": "route_is_active",
        "onTrue": "resolve_betrayal",
        "onFalse": "noop"
      }
    ],
    "resolve_betrayal": [
      {
        "action": "claim_quest_for_interactor"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "betrayed"
      },
      {
        "action": "give_gold",
        "targetRef": "interactor",
        "amount": 75
      },
      {
        "action": "despawn",
        "targetName": "quest.garin_holt"
      },
      {
        "action": "complete_quest"
      },
      {
        "action": "dialog",
        "dialogId": "betrayal_paid"
      }
    ],
    "choose_fight": [
      {
        "action": "check_condition",
        "conditionName": "route_is_active",
        "onTrue": "begin_captain_fight",
        "onFalse": "noop"
      }
    ],
    "begin_captain_fight": [
      {
        "action": "set_state",
        "stateRef": "quest.captain_battle_position",
        "sourceRef": "quest.captain_vane.position"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "fighting"
      },
      {
        "action": "despawn",
        "targetName": "quest.captain_vane"
      },
      {
        "action": "spawn",
        "targetName": "quest.hostile_captain_vane",
        "position": "quest.captain_battle_position"
      }
    ],
    "surrender_captain": [
      {
        "action": "set_state",
        "stateRef": "quest.captain_battle_position",
        "sourceRef": "quest.hostile_captain_vane.position"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "surrendered"
      },
      {
        "action": "despawn",
        "targetName": "quest.hostile_captain_vane"
      },
      {
        "action": "spawn",
        "targetName": "quest.wounded_captain_vane",
        "position": "quest.captain_battle_position"
      },
      {
        "action": "dialog",
        "dialogId": "captain_surrender",
        "targetRef": "ddq.players.[[quest.helper_id]]"
      }
    ],
    "check_surrender_still_active": [
      {
        "action": "check_condition",
        "conditionName": "route_is_surrendered",
        "onTrue": "show_captain_surrender",
        "onFalse": "noop"
      }
    ],
    "show_captain_surrender": [
      {
        "action": "dialog",
        "dialogId": "captain_surrender"
      }
    ],
    "choose_kill_captain": [
      {
        "action": "check_condition",
        "conditionName": "route_is_surrendered",
        "onTrue": "resolve_kill_captain",
        "onFalse": "noop"
      }
    ],
    "resolve_kill_captain": [
      {
        "action": "give_item",
        "itemName": "quest.captain_vane_sigil",
        "targetRef": "interactor",
        "onFailure": "show_sigil_delivery_blocked"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "captain_killed"
      },
      {
        "action": "despawn",
        "targetName": "quest.wounded_captain_vane"
      },
      {
        "action": "dialog",
        "dialogId": "captain_killed"
      }
    ],
    "show_sigil_delivery_blocked": [
      {
        "action": "dialog",
        "dialogId": "sigil_delivery_blocked"
      }
    ],
    "choose_mercy": [
      {
        "action": "check_condition",
        "conditionName": "route_is_surrendered",
        "onTrue": "resolve_mercy",
        "onFalse": "noop"
      }
    ],
    "resolve_mercy": [
      {
        "action": "claim_quest_for_interactor"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "mercy"
      },
      {
        "action": "despawn",
        "targetName": "quest.wounded_captain_vane"
      },
      {
        "action": "complete_quest"
      },
      {
        "action": "dialog",
        "dialogId": "captain_spared"
      }
    ],
    "finish_garins_story": [
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "reward_pending"
      },
      {
        "action": "call_function",
        "functionName": "deliver_garin_reward"
      }
    ],
    "deliver_garin_reward": [
      {
        "action": "claim_quest_for_interactor"
      },
      {
        "action": "give_item",
        "itemName": "quest.garins_lucky_charm",
        "targetRef": "interactor",
        "onFailure": "show_reward_blocked"
      },
      {
        "action": "set_state",
        "stateRef": "quest.route",
        "value": "rewarded"
      },
      {
        "action": "complete_quest"
      },
      {
        "action": "dialog",
        "dialogId": "reward_given"
      }
    ],
    "show_reward_blocked": [
      {
        "action": "dialog",
        "dialogId": "reward_blocked"
      }
    ]
  }
}
