evtc\agent/
status.rs

1use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// Simple event regarding an agent.
7///
8/// The meaning depends on the context.
9#[derive(Debug, Clone)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11pub struct AgentStatusEvent {
12    /// Time of registering the status change.
13    pub time: u64,
14
15    /// Agent that the status change happened to.
16    pub agent: AgentId,
17}
18
19impl Extract for AgentStatusEvent {
20    #[inline]
21    unsafe fn extract(event: &Event) -> Self {
22        Self {
23            time: event.time,
24            agent: AgentId::from_src(event),
25        }
26    }
27}
28
29impl TryExtract for AgentStatusEvent {
30    #[inline]
31    fn can_extract(event: &Event) -> bool {
32        matches!(
33            event.get_statechange(),
34            StateChange::ExitCombat
35                | StateChange::ChangeUp
36                | StateChange::ChangeDead
37                | StateChange::ChangeDown
38                | StateChange::Spawn
39                | StateChange::Despawn
40                | StateChange::PointOfView
41        )
42    }
43}
44
45/// Agent down contribution event (retired).
46#[derive(Debug, Clone)]
47#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
48pub struct DownContributionEvent {
49    /// Time of registering the downed state.
50    pub time: u64,
51
52    /// Agent that entered downed state.
53    pub agent: AgentId,
54
55    /// Time since last 90% HP in milliseconds.
56    pub time_frame: u64,
57}
58
59impl Extract for DownContributionEvent {
60    #[inline]
61    unsafe fn extract(event: &Event) -> Self {
62        Self {
63            time: event.time,
64            agent: AgentId::from_src(event),
65            time_frame: event.dst_agent,
66        }
67    }
68}
69
70impl TryExtract for DownContributionEvent {
71    #[inline]
72    fn can_extract(event: &Event) -> bool {
73        event.get_statechange() == StateChange::Last90BeforeDown
74    }
75}