use crate::{
event::{impl_common, CommonEvent},
extract::Extract,
Event, EventCategory, TryExtract,
};
use num_enum::{FromPrimitive, IntoPrimitive};
#[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 BuffRemoveEvent {
#[cfg_attr(feature = "serde", serde(flatten))]
pub common: CommonEvent,
pub remove: BuffRemoveKind,
pub removed_duration: i32,
pub removed_intensity: i32,
}
impl_common!(BuffRemoveEvent);
impl Extract for BuffRemoveEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
common: event.into(),
remove: event.extract(),
removed_duration: event.value,
removed_intensity: event.buff_dmg,
}
}
}
impl TryExtract for BuffRemoveEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.categorize() == EventCategory::BuffRemove
}
}
#[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 BuffRemove {
None = 0,
All = 1,
Single = 2,
Manual = 3,
#[num_enum(catch_all)]
Unknown(u8),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "kind"))]
#[cfg_attr(
feature = "strum",
derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
)]
pub enum BuffRemoveKind {
All {
stacks_removed: u8,
},
Single {
stack_id: u32,
},
Manual {
stack_id: u32,
},
Unknown(u8),
}
impl Extract for BuffRemoveKind {
#[inline]
unsafe fn extract(event: &Event) -> Self {
match event.get_buffremove() {
BuffRemove::None => unreachable!("extract buffremove on non-buffremove event"),
BuffRemove::All => Self::All {
stacks_removed: event.result,
},
BuffRemove::Single => Self::Single {
stack_id: event.get_pad_id(),
},
BuffRemove::Manual => Self::Manual {
stack_id: event.get_pad_id(),
},
BuffRemove::Unknown(value) => Self::Unknown(value),
}
}
}