overlord_event_system/
lib.rs

1pub use behaviors::BehaviorRegistry;
2pub use behaviors::quests::progress::ConditionalProgress;
3pub use event_system::event::LogicalTimestamp;
4pub use event_system::pure::{Pure, PureLogic};
5pub use event_system::random::Seed;
6/// Re-exported so callers of `cases::try_finalize_item` can supply its RNG
7/// without depending on `event_system` directly.
8pub use event_system::rng::GameRng;
9pub use event_system::system::{
10    EventHandleResult, EventHandler, EventHandlerContext, EventMeta, SystemConfig,
11};
12
13use rand::SeedableRng;
14
15pub mod attributes;
16pub mod behaviors;
17pub mod bundles;
18pub mod cases;
19pub mod entities;
20pub mod event;
21pub mod fight;
22pub mod gacha;
23pub mod game_config_helpers;
24pub mod logic;
25pub mod mechanics;
26pub mod party;
27pub mod quests;
28pub mod state;
29
30/// DB-free handler over the pure game logic: `Pure` is the `EventHandler`
31/// half, `OverlordLogic` the logic. Used by tests and simulations through the
32/// synchronous `System::run`. `logic_mut` reaches the logic, so a caller can
33/// arm the fight seed of a precalculated PvP fight before replaying it (see
34/// `OverlordLogic::arm_fight_seed`).
35pub type PureEventHandler = Pure<logic::handler::OverlordLogic>;
36
37impl PureLogic<event::OverlordEvent, state::OverlordState> for logic::handler::OverlordLogic {
38    fn handle(
39        &mut self,
40        event: &event::OverlordEvent,
41        meta: &EventMeta,
42        state: state::OverlordState,
43    ) -> EventHandleResult<event::OverlordEvent, state::OverlordState> {
44        // Historical async RNG stream: `with_ts` of the pre-increment
45        // timestamp. Former-sync bodies use `with_ts(logical_ts)`; the
46        // asymmetry is historical and may be unified later as an isolated
47        // change with deliberate test-expectation updates.
48        let rand_gen =
49            rand::rngs::StdRng::seed_from_u64(meta.session_seed.with_ts(meta.logical_ts - 1));
50        self.handle_event(event, state, rand_gen, meta.current_tick)
51    }
52
53    fn compute_fields(
54        &self,
55        state: &mut state::OverlordState,
56        prev_state: &state::OverlordState,
57    ) -> Vec<event::OverlordEvent> {
58        logic::handler::OverlordLogic::compute_fields(self, state, prev_state)
59    }
60
61    fn collect_due_scheduled(&mut self, current_tick: u64) -> Vec<event::OverlordEvent> {
62        logic::handler::OverlordLogic::collect_due_scheduled(self, current_tick)
63    }
64}
65
66pub type System<H> = event_system::system::System<
67    event::OverlordEvent,
68    state::OverlordState,
69    H,
70    event_system::plugin::delayed::RealDelayedPlugin<event::OverlordEvent>,
71    event_system::plugin::cron::RealCronPlugin<event::OverlordEvent, state::OverlordState>,
72>;
73
74pub const TICKER_UNIT_DURATION_MS: u128 = 1;
75
76pub fn new_system<H>(handler: H, session_seed: Seed, zero_tick: bool) -> System<H>
77where
78    H: EventHandler<event::OverlordEvent, state::OverlordState>,
79{
80    let mut system_config = SystemConfig::default();
81    system_config.ticker_unit_duration_ms = if zero_tick {
82        0
83    } else {
84        TICKER_UNIT_DURATION_MS
85    };
86    System::new(
87        system_config,
88        handler,
89        state::OverlordState::default(),
90        session_seed,
91    )
92}