Skip to main content

wowlab_engine_combat/context/hook/
resources.rs

1use super::ResourceOps;
2use crate::{context::HookCtx, systems};
3
4impl ResourceOps for HookCtx<'_> {
5    /// Gain primary resource, attributed to the hook's driver spell. Returns wasted amount.
6    fn gain_resource(&mut self, amount: f64) -> f64 {
7        let source = self.driver_resource_gain_source();
8        let (_, wasted) = systems::gain_hook_resource_with_procs(
9            self,
10            crate::state::ResourceGain::modified(amount, source),
11            false,
12        );
13
14        wasted
15    }
16
17    /// Gain primary resource with explicit provenance.
18    fn gain_resource_from(&mut self, amount: f64, source: crate::state::ResourceGainSource) -> f64 {
19        let (_, wasted) = systems::gain_hook_resource_with_procs(
20            self,
21            crate::state::ResourceGain::modified(amount, source),
22            false,
23        );
24
25        wasted
26    }
27
28    /// Gain primary resource without applying active gain multipliers.
29    fn gain_unmodified_resource_from(
30        &mut self,
31        amount: f64,
32        source: crate::state::ResourceGainSource,
33    ) -> f64 {
34        let (_, wasted) = systems::gain_hook_resource_with_procs(
35            self,
36            crate::state::ResourceGain::unmodified(amount, source),
37            false,
38        );
39
40        wasted
41    }
42
43    /// Gain secondary resource, attributed to the hook's driver spell. Returns wasted amount.
44    fn gain_secondary_resource(&mut self, amount: f64) -> f64 {
45        let source = self.driver_resource_gain_source();
46        let (_, wasted) = systems::gain_hook_resource_with_procs(
47            self,
48            crate::state::ResourceGain::modified(amount, source),
49            true,
50        );
51
52        wasted
53    }
54
55    /// Gain secondary resource with explicit provenance.
56    fn gain_secondary_resource_from(
57        &mut self,
58        amount: f64,
59        source: crate::state::ResourceGainSource,
60    ) -> f64 {
61        let (_, wasted) = systems::gain_hook_resource_with_procs(
62            self,
63            crate::state::ResourceGain::modified(amount, source),
64            true,
65        );
66
67        wasted
68    }
69
70    fn spend_secondary_resource(&mut self, amount: f64) -> bool {
71        systems::spend_secondary_resource(self.state, self.buf, amount)
72    }
73
74    fn spend_all_secondary_resource(&mut self, cost: f64) -> f64 {
75        systems::spend_all_secondary_resource(self.state, self.buf, cost)
76    }
77
78    fn secondary_resource(&self) -> f64 {
79        self.state
80            .config
81            .base_stats
82            .secondary_resource_type
83            .and_then(|rt| self.buf.resource(rt).map(|res| res.current))
84            .unwrap_or(0.0)
85    }
86
87    fn primary_resource(&self) -> f64 {
88        self.state
89            .config
90            .base_stats
91            .resource_type
92            .and_then(|resource_type| self.buf.resource(resource_type).map(|pool| pool.current))
93            .unwrap_or(0.0)
94    }
95
96    fn spell_resource_cost(&self, spell: u8) -> f64 {
97        self.state
98            .defs
99            .spells
100            .get(usize::from(spell))
101            .map_or(0.0, |definition| definition.cost.resource_cost)
102    }
103
104    fn gain_pet_resource(&mut self, npc_id: u32, amount: f64) -> f64 {
105        systems::gain_pet_resource(self.state, self.buf, npc_id, amount, self.now)
106    }
107
108    fn last_primary_spent(&self) -> f64 {
109        self.state.runtime.resources.last_primary_spent
110    }
111
112    fn last_optional_primary_spent(&self) -> f64 {
113        self.state.runtime.resources.last_optional_primary_spent
114    }
115
116    fn last_secondary_spent(&self) -> f64 {
117        self.state.runtime.resources.last_secondary_spent
118    }
119}