Skip to main content

wowlab_engine_combat/context/hook/
mod.rs

1//! Public capabilities available to combat hooks.
2
3use wowlab_engine_domain::pool::SpellGate;
4use wowlab_engine_ports::Event;
5use wowlab_types::sim::{ActorId, EnemyIdx, SimTime};
6
7use super::{DamageOutcome, FreeActionSource};
8use crate::{
9    DamageFlags,
10    state::{
11        CastHookFn, GroundEffectSpec, GuardianHandle, GuardianSpec, LocalRppmIdx,
12        LocalThresholdIdx, ResourceGainSource, SwingHand,
13    },
14};
15
16mod ground_effects;
17mod guardians;
18mod proc_counters;
19mod resources;
20mod rppm;
21mod spells;
22
23/// Aura lifecycle and aura-owned accumulator operations.
24pub trait AuraOps {
25    fn with_resolved_target(&mut self, target: EnemyIdx, apply: impl FnOnce(&mut Self));
26    fn now(&self) -> SimTime;
27    fn apply_aura(&mut self, local: u8);
28    fn apply_owner_aura(&mut self, local: u8);
29    fn apply_aura_with_duration(&mut self, local: u8, duration_ms: u32);
30    fn apply_aura_with_rolling_multiplier(&mut self, local: u8, multiplier: f64);
31    fn apply_pet_aura_with_duration(&mut self, local: u8, duration_ms: u32);
32    fn apply_aura_n(&mut self, local: u8, n: i32);
33    fn add_aura_stack(&mut self, local: u8);
34    fn add_owner_aura_stack(&mut self, local: u8);
35    fn add_residual_damage(&mut self, local: u8, amount: f64);
36    fn residual_damage_remaining(&self, local: u8) -> f64;
37    fn accumulate_damage(&mut self, local: u8, amount: f64);
38    fn accumulate_owner_damage(&mut self, local: u8, amount: f64);
39    fn take_accumulated_damage(&mut self, local: u8) -> f64;
40    fn expire_aura(&mut self, local: u8);
41    fn expire_owner_aura(&mut self, local: u8);
42    fn consume_aura(&mut self, local: u8) -> bool;
43    fn consume_aura_stack(&mut self, local: u8) -> bool;
44    fn consume_owner_aura_stack(&mut self, local: u8) -> bool;
45    fn consume_aura_stacks(&mut self, local: u8, count: i32) -> i32;
46    fn refresh_aura_snapshot_multiplier(&mut self, local: u8, multiplier: f64) -> bool;
47    fn extend_aura(&mut self, local: u8, ms: u32);
48    fn reduce_aura(&mut self, local: u8, ms: u32);
49    fn is_aura_active(&self, local: u8) -> bool;
50    fn is_owner_aura_active(&self, local: u8) -> bool;
51    fn aura_stacks(&self, local: u8) -> i32;
52    fn aura_remaining_ms(&self, local: u8) -> Option<u32>;
53    fn flat_periodic_damage_remaining(&self, local: u8) -> Option<f64>;
54    fn aura_local_index(&self, aura_id: u32) -> Option<u8>;
55    fn apply_aura_id(&mut self, aura_id: u32);
56    fn apply_aura_id_n(&mut self, aura_id: u32, n: i32);
57    fn add_aura_stack_id(&mut self, aura_id: u32);
58    fn expire_aura_id(&mut self, aura_id: u32);
59    fn is_aura_active_id(&self, aura_id: u32) -> bool;
60    fn aura_stacks_id(&self, aura_id: u32) -> i32;
61    fn flat_periodic_damage_remaining_id(&self, aura_id: u32) -> Option<f64>;
62    fn take_aura_stacks_id(&mut self, aura_id: u32) -> i32;
63}
64
65/// Damage calculation and impact operations.
66pub trait DamageOps {
67    fn deal_damage_ap(&mut self, spell_id: u32, coef: f64, flags: DamageFlags);
68    fn deal_damage_ap_result(
69        &mut self,
70        spell_id: u32,
71        coef: f64,
72        flags: DamageFlags,
73    ) -> DamageOutcome;
74    fn deal_damage_from_result(
75        &mut self,
76        spell_id: u32,
77        parent: DamageOutcome,
78        multiplier: f64,
79        flags: DamageFlags,
80    ) -> DamageOutcome;
81    fn deal_profiled_damage_ap(
82        &mut self,
83        spell_id: u32,
84        profile_spell_id: u32,
85        coef: f64,
86        flags: DamageFlags,
87    );
88    fn haste_multiplier(&self) -> f64;
89    fn deal_damage_ap_to_target(
90        &mut self,
91        target: EnemyIdx,
92        spell_id: u32,
93        coef: f64,
94        flags: DamageFlags,
95    );
96    fn deal_damage_ap_if_positive(&mut self, spell_id: u32, coefficient: f64, flags: DamageFlags);
97    fn deal_effect_damage_ap(&mut self, effect: (u32, u8), multiplier: f64, flags: DamageFlags);
98    fn deal_effect_damage_ap_with_geometry(
99        &mut self,
100        effect: (u32, u8),
101        geometry_effect: (u32, u8),
102        multiplier: f64,
103        flags: DamageFlags,
104    );
105    fn deal_effect_damage_sp_with_geometry(
106        &mut self,
107        effect: (u32, u8),
108        geometry_effect: (u32, u8),
109        multiplier: f64,
110        flags: DamageFlags,
111    );
112    fn deal_physical_damage_ap_if_positive(&mut self, spell_id: u32, coefficient: f64);
113    fn deal_pet_damage_ap(&mut self, spell_id: u32, coefficient: f64);
114    fn deal_pet_damage_ap_for_npc(&mut self, npc_id: u32, spell_id: u32, coefficient: f64);
115    fn deal_physical_pet_damage_ap(&mut self, spell_id: u32, coefficient: f64);
116    fn deal_damage_sp(&mut self, spell_id: u32, coef: f64, flags: DamageFlags);
117    fn deal_damage_sp_to_target(
118        &mut self,
119        target: EnemyIdx,
120        spell_id: u32,
121        coef: f64,
122        flags: DamageFlags,
123    );
124    fn deal_profiled_damage_sp(
125        &mut self,
126        spell_id: u32,
127        profile_spell_id: u32,
128        coef: f64,
129        flags: DamageFlags,
130    );
131    fn deal_damage_flat(&mut self, spell_id: u32, amount: f64);
132    fn deal_resolved_damage(&mut self, spell_id: u32, amount: f64);
133    fn deal_triggered_damage(
134        &mut self,
135        source_spell_id: u32,
136        effect_index: u8,
137        multiplier: f64,
138        flags: DamageFlags,
139    ) -> bool;
140    fn deal_item_damage_sp(&mut self, spell_id: u32);
141    fn effect_base_points(&self, effect: (u32, u8)) -> f64;
142    fn effect_points(&self, effect: (u32, u8)) -> f64;
143    fn effect_percent(&self, effect: (u32, u8)) -> f64;
144    fn effect_ap_coefficient(&self, effect: (u32, u8)) -> f64;
145    fn effect_sp_coefficient(&self, effect: (u32, u8)) -> f64;
146    fn target_health_fraction(&self) -> f64;
147    fn player_swing_period_ms(&self, hand: SwingHand) -> Option<u32>;
148}
149
150/// Spell cooldown, charge, and cast-gate operations.
151pub trait CooldownOps {
152    fn spend_spell_charge(&mut self, spell: u8) -> bool;
153    fn reduce_cooldown(&mut self, spell: u8, amount_ms: u32);
154    fn reset_cooldown(&mut self, spell: u8);
155    fn start_cooldown(&mut self, spell: u8);
156    fn set_spell_gate(&mut self, spell: u8, gate: SpellGate, available: bool);
157    fn grant_charges(&mut self, spell: u8, amount: u8);
158    fn spell_cooldown_ms(&self, spell: u8) -> u32;
159    fn spell_cooldown_remaining_ms(&self, spell: u8) -> u32;
160    fn spell_ready(&self, spell: u8) -> bool;
161    fn spell_current_charges(&self, spell: u8) -> i32;
162}
163
164/// Player and persistent-pet resource operations.
165pub trait ResourceOps {
166    fn gain_resource(&mut self, amount: f64) -> f64;
167    fn gain_resource_from(&mut self, amount: f64, source: ResourceGainSource) -> f64;
168    fn gain_unmodified_resource_from(&mut self, amount: f64, source: ResourceGainSource) -> f64;
169    fn gain_secondary_resource(&mut self, amount: f64) -> f64;
170    fn gain_secondary_resource_from(&mut self, amount: f64, source: ResourceGainSource) -> f64;
171    fn gain_pet_resource(&mut self, npc_id: u32, amount: f64) -> f64;
172    fn spend_secondary_resource(&mut self, amount: f64) -> bool;
173    fn spend_all_secondary_resource(&mut self, cost: f64) -> f64;
174    fn secondary_resource(&self) -> f64;
175    fn primary_resource(&self) -> f64;
176    fn spell_resource_cost(&self, spell: u8) -> f64;
177    fn last_primary_spent(&self) -> f64;
178    fn last_optional_primary_spent(&self) -> f64;
179    fn last_secondary_spent(&self) -> f64;
180}
181
182/// Deterministic proc rolls, attempt tracking, and driver counters.
183pub trait ProcOps {
184    fn roll_rppm(&mut self, idx: LocalRppmIdx) -> bool;
185    fn roll_threshold(&mut self, idx: LocalThresholdIdx, increment_scale: f64) -> bool;
186    fn roll_item_rppm(&mut self, item_id: u32) -> bool;
187    fn roll_system_rppm(&mut self, driver_spell_id: u32) -> bool;
188    fn proc_category_ready(&self, driver_spell_id: u32) -> bool;
189    fn start_proc_category_cooldown(&mut self, driver_spell_id: u32);
190    fn roll_enchant_rppm(&mut self, enchantment_id: u32) -> bool;
191    fn roll_accumulating_proc(&mut self, driver_spell_id: u32, chance_per_attempt: f64) -> bool;
192    fn roll_attempt_proc(
193        &mut self,
194        driver_spell_id: u32,
195        chance_for_attempt: impl FnOnce(u32) -> f64,
196    ) -> bool;
197    fn add_proc_counter(&mut self, driver_spell_id: u32, amount: u32) -> u32;
198    fn reset_proc_counter(&mut self, driver_spell_id: u32);
199    fn proc_counter(&self, driver_spell_id: u32) -> u32;
200    fn mark_proc_flags_once(&mut self, driver_spell_id: u32, flags: u32) -> bool;
201    fn consume_proc_counter(&mut self, driver_spell_id: u32, amount: u32) -> u32;
202    fn advance_proc_counter_by(
203        &mut self,
204        driver_spell_id: u32,
205        amount: u32,
206        threshold: u32,
207    ) -> bool;
208    fn advance_proc_counter(&mut self, driver_spell_id: u32, threshold: u32) -> bool;
209}
210
211/// Delayed hook, periodic-driver, and ground-effect scheduling.
212pub trait SchedulingOps {
213    fn dispatch_free_action(&mut self, spell_id: u32, source: FreeActionSource) -> bool;
214    fn dispatch_proc_spell(
215        &mut self,
216        spell_id: u32,
217        proc_driver_spell_id: u32,
218        affected: ActorId,
219    ) -> bool;
220    fn schedule_event(&mut self, event: Event);
221    fn schedule_hook(&mut self, delay_ms: u32, hook: CastHookFn);
222    fn trigger_periodic_driver(&mut self, driver_spell_id: u32) -> bool;
223    fn trigger_periodic_driver_for(&mut self, driver_spell_id: u32, duration_ms: u32) -> bool;
224    fn schedule_ground_effect(&mut self, spec: GroundEffectSpec);
225    fn schedule_ground_effect_from_data(
226        &mut self,
227        driver_spell_id: u32,
228        timing_effect_index: u8,
229        geometry_effect: (u32, u8),
230        damage_effect: (u32, u8),
231        flags: DamageFlags,
232    ) -> bool;
233}
234
235/// Temporary guardian lifecycle and command operations.
236pub trait GuardianOps {
237    fn summon_guardian(&mut self, spec: GuardianSpec) -> GuardianHandle;
238    fn active_guardian_count(&self, tag: u32) -> usize;
239    fn extend_guardians(&mut self, tag: u32, amount_ms: u32);
240    fn command_guardians(&mut self, tag: u32, ability_index: usize) -> usize;
241    fn dismiss_guardians(&mut self, tag: u32, count: usize) -> usize;
242}