use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AgentStatusEvent {
pub time: u64,
pub agent: AgentId,
}
impl Extract for AgentStatusEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
}
}
}
impl TryExtract for AgentStatusEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
matches!(
event.get_statechange(),
StateChange::ExitCombat
| StateChange::ChangeUp
| StateChange::ChangeDead
| StateChange::ChangeDown
| StateChange::Spawn
| StateChange::Despawn
| StateChange::PointOfView
)
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DownContributionEvent {
pub time: u64,
pub agent: AgentId,
pub time_frame: u64,
}
impl Extract for DownContributionEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
time_frame: event.dst_agent,
}
}
}
impl TryExtract for DownContributionEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::Last90BeforeDown
}
}