use crate::{extract::Extract, AgentId, Event, EventCategory, Position, TryExtract};
use num_enum::{FromPrimitive, IntoPrimitive};
use std::mem::transmute;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "strum")]
use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ActivationEvent {
pub time: u64,
pub agent: AgentId,
pub skill_id: u32,
pub activation: Activation,
pub duration: i32,
pub scaled_duration: i32,
pub target: Position,
}
impl Extract for ActivationEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
let [x, y]: [f32; 2] = transmute(event.dst_agent);
let z = f32::from_bits(event.overstack_value);
Self {
time: event.time,
agent: AgentId::from_src(event),
skill_id: event.skill_id,
activation: event.get_activation(),
duration: event.value,
scaled_duration: event.buff_dmg,
target: Position::new(x, y, z),
}
}
}
impl TryExtract for ActivationEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.categorize() == EventCategory::Activation
}
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, FromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "strum",
derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
)]
#[repr(u8)]
pub enum Activation {
None = 0,
Start = 1,
QuicknessUnused = 2,
CancelFire = 3,
CancelCancel = 4,
Reset = 5,
#[num_enum(catch_all)]
Unknown(u8),
}