Skip to main content

wowlab_engine_combat/context/hook/
guardians.rs

1use super::GuardianOps;
2use crate::{
3    context::{CombatCtx, HookCtx},
4    state::{GuardianHandle, GuardianSpec},
5    systems,
6};
7
8impl GuardianOps for HookCtx<'_> {
9    fn summon_guardian(&mut self, spec: GuardianSpec) -> GuardianHandle {
10        systems::summon_guardian(self.state, self.buf, spec, self.now)
11    }
12
13    fn active_guardian_count(&self, tag: u32) -> usize {
14        systems::active_guardian_count(self.state, tag)
15    }
16
17    fn extend_guardians(&mut self, tag: u32, amount_ms: u32) {
18        systems::extend_guardians(self.state, tag, amount_ms);
19    }
20
21    /// Drive an `on_demand` ability on every active guardian with `tag`, returning how many fired.
22    fn command_guardians(&mut self, tag: u32, ability_index: usize) -> usize {
23        let target = self
24            .target
25            .or_else(|| self.state.current_target())
26            .or_else(|| {
27                self.state
28                    .runtime
29                    .companions
30                    .guardians
31                    .iter()
32                    .flatten()
33                    .find(|guardian| guardian.spec.tag == tag)
34                    .map(|guardian| guardian.target)
35            });
36
37        CombatCtx::for_optional_target(self, target, |ctx| {
38            systems::command_guardians(ctx, tag, ability_index)
39        })
40        .unwrap_or(0)
41    }
42
43    fn dismiss_guardians(&mut self, tag: u32, count: usize) -> usize {
44        systems::dismiss_guardians(self.state, tag, count)
45    }
46}