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 EnterCombatEvent {
pub time: u64,
pub agent: AgentId,
pub subgroup: u64,
}
impl Extract for EnterCombatEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
subgroup: event.dst_agent,
}
}
}
impl TryExtract for EnterCombatEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::EnterCombat
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MaxHealthEvent {
pub time: u64,
pub agent: AgentId,
pub max_health: u64,
}
impl Extract for MaxHealthEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
max_health: event.dst_agent,
}
}
}
impl TryExtract for MaxHealthEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::MaxHealthUpdate
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct HealthUpdateEvent {
pub time: u64,
pub agent: AgentId,
pub health: f32,
}
impl HealthUpdateEvent {
pub const CONVERT: f32 = 10_000.0;
}
impl Extract for HealthUpdateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
health: event.dst_agent as f32 / Self::CONVERT,
}
}
}
impl TryExtract for HealthUpdateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::HealthUpdate
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BarrierUpdateEvent {
pub time: u64,
pub agent: AgentId,
pub barrier: f32,
}
impl BarrierUpdateEvent {
pub const CONVERT: f32 = 10_000.0;
}
impl Extract for BarrierUpdateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
barrier: event.dst_agent as f32 / Self::CONVERT,
}
}
}
impl TryExtract for BarrierUpdateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::BarrierUpdate
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TeamChangeEvent {
pub time: u64,
pub agent: AgentId,
pub team: u64,
}
impl Extract for TeamChangeEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
team: event.dst_agent,
}
}
}
impl TryExtract for TeamChangeEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::TeamChange
}
}
#[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
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AttackTargetEvent {
pub time: u64,
pub agent: AgentId,
pub parent: AgentId,
pub targetable: i32,
}
impl Extract for AttackTargetEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
parent: AgentId::from_dst(event),
targetable: event.value,
}
}
}
impl TryExtract for AttackTargetEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::AttackTarget
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TargetableEvent {
pub time: u64,
pub agent: AgentId,
pub targetable: i32,
}
impl Extract for TargetableEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
targetable: event.value,
}
}
}
impl TryExtract for TargetableEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::Targetable
}
}