use super::EffectLocation;
use crate::{
extract::{transmute_field, Extract},
Event, Position, StateChange, TryExtract,
};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EffectOld {
pub time: u64,
pub effect_id: u32,
pub owner: u64,
pub location: EffectLocation,
pub orientation: Position,
pub duration: EffectDuration,
}
impl EffectOld {
#[inline]
pub fn is_end(&self) -> bool {
self.effect_id == 0
}
}
impl Extract for EffectOld {
#[inline]
unsafe fn extract(event: &Event) -> Self {
let effect_id = event.skill_id;
let [x, y] = transmute_field!(event.affinity as [f32; 2]);
let z = transmute_field!(event.pad61 as f32);
let duration = transmute_field!(event.is_shields as u16);
Self {
time: event.time,
effect_id,
owner: event.src_agent,
location: EffectLocation::extract(event),
orientation: [x, y, z].into(),
duration: if event.is_flanking != 0 || effect_id == 0 {
EffectDuration::TrackingId(duration)
} else {
EffectDuration::Time(duration)
},
}
}
}
impl TryExtract for EffectOld {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::Effect
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum EffectDuration {
Time(u16),
TrackingId(u16),
}