Skip to main content

wowlab_engine_combat/state/combat_state/
lookups.rs

1//! Read-only access to static definitions and their local indices.
2
3use super::CombatState;
4use crate::state::{AuraData, LocalAuraIdx, LocalRppmIdx, LocalSpellIdx, RppmTracker, SpellData};
5
6impl CombatState {
7    #[inline]
8    #[must_use]
9    pub fn spell_local(&self, spell_id: u32) -> Option<LocalSpellIdx> {
10        self.index.spell_by_id.get(&spell_id).copied()
11    }
12
13    #[inline]
14    #[must_use]
15    pub fn aura_local(&self, aura_id: u32) -> Option<LocalAuraIdx> {
16        self.index.aura_by_id.get(&aura_id).copied()
17    }
18
19    #[inline]
20    #[must_use]
21    pub fn item_rppm_local(&self, item_id: u32) -> Option<LocalRppmIdx> {
22        self.index.item_rppm_indices.get(&item_id).copied()
23    }
24
25    #[inline]
26    #[must_use]
27    pub fn system_rppm_local(&self, driver_spell_id: u32) -> Option<LocalRppmIdx> {
28        self.index
29            .system_rppm_indices
30            .get(&driver_spell_id)
31            .copied()
32    }
33
34    #[inline]
35    #[must_use]
36    pub fn enchant_rppm_local(&self, enchantment_id: u32) -> Option<LocalRppmIdx> {
37        self.index
38            .enchant_rppm_indices
39            .get(&enchantment_id)
40            .copied()
41    }
42
43    #[inline]
44    #[must_use]
45    pub fn enchant_buff_spell_id(&self, enchantment_id: u32) -> Option<u32> {
46        self.index
47            .enchant_buff_spell_ids
48            .get(&enchantment_id)
49            .copied()
50    }
51
52    #[inline]
53    #[must_use]
54    pub fn spell_data(&self, spell_id: u32) -> Option<(LocalSpellIdx, &SpellData)> {
55        let &local = self.index.spell_by_id.get(&spell_id)?;
56
57        // #t(rust_unchecked_indexing) local from spell_by_id, always valid
58        Some((local, &self.defs.spells[local.as_usize()]))
59    }
60
61    #[inline]
62    pub fn spell(&self, local: LocalSpellIdx) -> &SpellData {
63        // #t(rust_unchecked_indexing) local indices are produced inside the crate and bounded
64        &self.defs.spells[local.as_usize()]
65    }
66
67    #[inline]
68    pub fn spells(&self) -> &[SpellData] {
69        &self.defs.spells
70    }
71
72    #[inline]
73    pub fn aura(&self, local: LocalAuraIdx) -> &AuraData {
74        // #t(rust_unchecked_indexing) local indices are produced inside the crate and bounded
75        &self.defs.auras[local.as_usize()]
76    }
77
78    #[inline]
79    pub fn auras(&self) -> &[AuraData] {
80        &self.defs.auras
81    }
82
83    #[inline]
84    pub fn precombat_auras(&self) -> &[LocalAuraIdx] {
85        &self.defs.precombat_auras
86    }
87
88    #[inline]
89    pub fn talent_aura_stacks(&self) -> &[(LocalAuraIdx, u8)] {
90        &self.defs.talent_aura_stacks
91    }
92
93    #[inline]
94    #[must_use]
95    pub fn rppm_tracker(&self, tracker: LocalRppmIdx) -> Option<&RppmTracker> {
96        self.defs.rppm_trackers.get(tracker.as_usize())
97    }
98}