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(
10        &mut self,
11        spec: GuardianSpec,
12    ) -> Result<GuardianHandle, crate::GuardianSummonError> {
13        systems::summon_guardian(self.program, self.instance, &spec, self.now)
14    }
15
16    fn active_guardian_count(&self, tag: u32) -> usize {
17        systems::active_guardian_count(self.instance, tag)
18    }
19
20    fn extend_guardians(&mut self, tag: u32, amount_ms: u32) {
21        systems::extend_guardians(self.program, self.instance, tag, amount_ms);
22    }
23
24    /// Drive an `on_demand` ability on every active guardian with `tag`, returning how many fired.
25    fn command_guardians(&mut self, tag: u32, ability_index: usize) -> usize {
26        let target = self
27            .target
28            .or_else(|| self.instance.current_target())
29            .or_else(|| {
30                self.instance
31                    .runtime
32                    .companions
33                    .guardians
34                    .iter()
35                    .flatten()
36                    .find(|guardian| guardian.spec.tag == tag)
37                    .map(|guardian| guardian.target)
38            });
39
40        CombatCtx::for_optional_target(self, target, |ctx| {
41            systems::command_guardians(ctx, tag, ability_index)
42        })
43        .unwrap_or(0)
44    }
45
46    fn dismiss_guardians(&mut self, tag: u32, count: usize) -> usize {
47        systems::dismiss_guardians(self.program, self.instance, tag, count)
48    }
49}