overlord_event_system/behaviors/quests/
triggers.rs

1//! Native functions for the `trigger` category — the offer `trigger_script`
2//! slot (`OfferTemplate::trigger_script`). A trigger script decides whether a
3//! wrapper runs it as `run_expression::<bool>` with `Event` / `CharacterState`
4//! / `Offer` in scope (see `should_give_new_offer` in
5//! `logic/handler.rs`).
6//!
7//! offer is skipped — the effective outcome is "do not auto-give this offer".
8//! The single trivial native fn below mirrors that default by returning
9//! `false`.
10//!
11//! Follows the reference shape in [`super::power`]: a typed `*Ctx`, a `*Fn`
12//! alias, a native impl, and a `register`.
13
14use configs::game_config::GameConfig;
15use essences::character_state::CharacterState;
16use essences::offers::OfferTemplate;
17
18use crate::event::OverlordEvent;
19
20/// `trigger_script` sees: the firing event (`Event`), the player
21/// (`CharacterState`), and the candidate offer (`Offer`). `config` is carried
22/// for parity with the other categories' contexts even though the trivial
23/// default does not read it.
24pub struct TriggerCtx<'a> {
25    pub trigger_event: &'a OverlordEvent,
26    /// `CharacterState`).
27    pub character: &'a CharacterState,
28    pub offer: &'a OfferTemplate,
29    pub config: &'a GameConfig,
30}
31
32/// Signature of a `trigger` native fn. Free `fn` (no captured state) so it is
33/// `Copy` and trivially stored in the registry; runtime context arrives via
34pub type TriggerFn = fn(&TriggerCtx) -> anyhow::Result<bool>;
35
36/// Native port of the `trigger_script: "true"` content used by every offer that
37/// is meant to be auto-given the moment one of its `events_subscribe` events
38/// fires. By the time `should_give_new_offer` runs, the candidate offer is
39/// already known to be `enabled` and to have the firing event in its
40/// `events_subscribe` list (see `try_give_new_offers`), so the faithful
41/// decision for a subscribing offer is simply "give it" → `true`.
42pub fn always_trigger(_ctx: &TriggerCtx) -> anyhow::Result<bool> {
43    Ok(true)
44}