Skip to main content

wowlab_engine_combat/state/combat_state/
runtime_events.rs

1use super::{AuraKey, CombatState, Event, LocalAuraIdx, SpecRuntimeError};
2
3impl CombatState {
4    #[inline]
5    pub fn schedule(&mut self, event: Event) {
6        self.runtime.pending_events.push(event);
7    }
8
9    #[inline]
10    pub fn drain_events(&mut self) -> std::vec::Drain<'_, Event> {
11        self.runtime.pending_events.drain(..)
12    }
13
14    pub(crate) fn record_runtime_error(&mut self, error: SpecRuntimeError) {
15        if self.runtime.runtime_error.is_none() {
16            self.runtime.runtime_error = Some(error);
17        }
18    }
19
20    #[must_use]
21    pub(crate) const fn has_runtime_error(&self) -> bool {
22        self.runtime.runtime_error.is_some()
23    }
24
25    pub(crate) fn take_runtime_error(&mut self) -> Option<SpecRuntimeError> {
26        self.runtime.runtime_error.take()
27    }
28
29    #[inline]
30    #[must_use]
31    pub(crate) fn aura_local_for_key(&self, key: AuraKey) -> Option<LocalAuraIdx> {
32        self.index
33            .aura_by_identity
34            .get(&(key.aura().as_u32(), key.on()))
35            .copied()
36            .or_else(|| {
37                (key.on() == wowlab_types::sim::AuraOn::Player)
38                    .then(|| {
39                        self.index
40                            .aura_by_identity
41                            .get(&(key.aura().as_u32(), wowlab_types::sim::AuraOn::Target))
42                    })
43                    .flatten()
44                    .copied()
45            })
46    }
47}