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.program, self.instance, amount, self.now)
72    }
73
74    fn spend_all_secondary_resource(&mut self, cost: f64) -> f64 {
75        systems::spend_all_secondary_resource(self.program, self.instance, cost, self.now)
76    }
77
78    fn secondary_resource(&self) -> f64 {
79        self.program
80            .config
81            .base_stats
82            .secondary_resource_type
83            .and_then(|rt| {
84                self.program
85                    .buffer_resource(self.instance, rt)
86                    .map(|res| res.current)
87            })
88            .unwrap_or(0.0)
89    }
90
91    fn primary_resource(&self) -> f64 {
92        self.program
93            .config
94            .base_stats
95            .resource_type
96            .and_then(|resource_type| {
97                self.program
98                    .buffer_resource(self.instance, resource_type)
99                    .map(|pool| pool.current)
100            })
101            .unwrap_or(0.0)
102    }
103
104    fn primary_resource_max(&self) -> f64 {
105        self.program
106            .config
107            .base_stats
108            .resource_type
109            .and_then(|resource_type| {
110                self.program
111                    .buffer_resource(self.instance, resource_type)
112                    .map(|pool| pool.max)
113            })
114            .unwrap_or(0.0)
115    }
116
117    fn primary_resource_fraction(&self) -> f64 {
118        crate::CombatView::new(self.program, self.instance).primary_resource_fraction()
119    }
120
121    fn spell_resource_cost(&self, spell: crate::state::LocalSpellIdx) -> f64 {
122        let spell = self.spell_identity(spell);
123
124        self.program
125            .spells
126            .get(spell.as_usize())
127            .map_or(0.0, |definition| definition.cost.resource_cost)
128    }
129
130    fn primary_pet_resource(&self) -> Option<crate::PetResourceBinding> {
131        self.program.primary_pet_action_auto.map(|auto_attack| {
132            crate::PetResourceBinding::new(
133                self.program.spec_identity_brand.unwrap_or(0),
134                auto_attack,
135            )
136        })
137    }
138
139    fn gain_pet_resource(&mut self, binding: crate::PetResourceBinding, amount: f64) -> f64 {
140        systems::gain_pet_resource(self.program, self.instance, binding, amount, self.now)
141    }
142
143    fn last_primary_spent(&self) -> f64 {
144        self.instance.runtime.resources.last_primary_spent
145    }
146
147    fn last_optional_primary_spent(&self) -> f64 {
148        self.instance.runtime.resources.last_optional_primary_spent
149    }
150
151    fn last_secondary_spent(&self) -> f64 {
152        self.instance.runtime.resources.last_secondary_spent
153    }
154}