1use crate::{
4 event::{impl_common, CommonEvent},
5 extract::Extract,
6 Event, EventCategory, TryExtract,
7};
8use num_enum::{FromPrimitive, IntoPrimitive};
9
10#[cfg(feature = "serde")]
11use serde::{Deserialize, Serialize};
12
13#[cfg(feature = "strum")]
14use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
15
16#[derive(Debug, Clone)]
18#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
19pub struct StrikeEvent {
20 #[cfg_attr(feature = "serde", serde(flatten))]
22 pub common: CommonEvent,
23
24 pub strike: Strike,
26
27 pub total_damage: i32,
29
30 pub shield_damage: u32,
32
33 pub target_downed: bool,
35}
36
37impl_common!(StrikeEvent);
38
39impl Extract for StrikeEvent {
40 #[inline]
41 unsafe fn extract(event: &Event) -> Self {
42 Self {
43 common: event.into(),
44 strike: event.result.into(),
45 total_damage: event.value,
46 shield_damage: event.overstack_value,
47 target_downed: event.is_offcycle == 1,
48 }
49 }
50}
51
52impl TryExtract for StrikeEvent {
53 #[inline]
54 fn can_extract(event: &Event) -> bool {
55 event.categorize() == EventCategory::Strike
56 }
57}
58
59#[derive(
63 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, FromPrimitive,
64)]
65#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
66#[cfg_attr(
67 feature = "strum",
68 derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
69)]
70#[repr(u8)]
71pub enum Strike {
72 Normal = 0,
76
77 Crit = 1,
79
80 Glance = 2,
82
83 Block = 3,
87
88 Evade = 4,
92
93 Interrupt = 5,
95
96 Absorb = 6,
100
101 Blind = 7,
105
106 KillingBlow = 8,
110
111 Downed = 9,
115
116 Breakbar = 10,
120
121 Activation = 11,
125
126 CrowdControl = 12,
130
131 #[num_enum(catch_all)]
133 Unknown(u8),
134}
135
136impl Strike {
137 #[inline]
139 pub const fn dealt_damage(&self) -> bool {
140 matches!(self, Self::Normal | Self::Crit | Self::Glance)
141 }
142}