evtc\buff/
damage.rs

1use crate::{
2    event::{impl_common, CommonEvent},
3    extract::Extract,
4    Event, EventCategory, TryExtract,
5};
6use num_enum::{FromPrimitive, IntoPrimitive};
7
8#[cfg(feature = "serde")]
9use serde::{Deserialize, Serialize};
10
11#[cfg(feature = "strum")]
12use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
13
14/// Buff damage event.
15///
16/// For example from a Condition.
17#[derive(Debug, Clone)]
18#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
19pub struct BuffDamageEvent {
20    /// Common combat event information.
21    #[cfg_attr(feature = "serde", serde(flatten))]
22    pub common: CommonEvent,
23
24    /// Buff.
25    // TODO: meaning?
26    pub buff: u8,
27
28    /// Buff damage amount.
29    pub damage: i32,
30
31    /// Whether damage happened on tick (cycle) or reactively (off-cycle).
32    pub cycle: BuffCycle,
33
34    /// Result of buff damage.
35    pub result: BuffDamageResult,
36}
37
38impl_common!(BuffDamageEvent);
39
40impl Extract for BuffDamageEvent {
41    #[inline]
42    unsafe fn extract(event: &Event) -> Self {
43        Self {
44            common: event.into(),
45            buff: event.buff,
46            damage: event.buff_dmg,
47            cycle: event.is_offcycle.into(),
48            result: event.result.into(),
49        }
50    }
51}
52
53impl TryExtract for BuffDamageEvent {
54    #[inline]
55    fn can_extract(event: &Event) -> bool {
56        event.categorize() == EventCategory::BuffDamage
57    }
58}
59
60/// Buff damage tick results.
61#[derive(
62    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, FromPrimitive,
63)]
64#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
65#[cfg_attr(
66    feature = "strum",
67    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
68)]
69#[repr(u8)]
70pub enum BuffDamageResult {
71    /// Expected to hit.
72    Hit = 0,
73
74    /// Target invulnerable by buff.
75    InvulnByBuff = 1,
76
77    /// Target invulnerable by player skill.
78    InvulnBySkill1 = 2,
79
80    /// Target invulnerable by player skill.
81    InvulnBySkill2 = 3,
82
83    /// Target invulnerable by player skill.
84    InvulnBySkill3 = 4,
85
86    /// Unknown or invalid.
87    #[num_enum(catch_all)]
88    Unknown(u8),
89}
90
91/// Combat buff cycle.
92#[derive(
93    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, FromPrimitive,
94)]
95#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
96#[cfg_attr(
97    feature = "strum",
98    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
99)]
100#[repr(u8)]
101pub enum BuffCycle {
102    /// Damage happened on tick timer.
103    Cycle = 0,
104
105    /// Damage happened outside tick timer (resistable).
106    NotCycle = 1,
107
108    /// Retired since May 2021.
109    NotCycleOrResist = 2,
110
111    /// Damage happened to target on hitting target.
112    NotCycleDmgToTargetOnHit = 3,
113
114    /// Damage happened to source on hitting target.
115    NotCycleDmgToSourceOnHit = 4,
116
117    /// Damage happened to target on source losing a stack.
118    NotCycleDmgToTargetOnStackRemove = 5,
119
120    /// Unknown or invalid.
121    #[num_enum(catch_all)]
122    Unknown(u8),
123}