evtc\buff/
info.rs

1use crate::{extract::Extract, Event, StateChange, TryExtract};
2use num_enum::{IntoPrimitive, TryFromPrimitive};
3
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7#[cfg(feature = "strum")]
8use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
9
10/// Buff information from an [`Event`] with [`StateChange::BuffInfo`].
11#[derive(Debug, Clone)]
12#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13pub struct BuffInfo {
14    /// Buff skill id.
15    pub skill_id: u32,
16
17    /// The category of buff.
18    ///
19    /// See [`BuffCategory`] and [`BuffCategoryOld`].
20    pub category: u8,
21
22    /// Buff stacking behavior.
23    ///
24    /// See [`BuffStackType`].
25    pub stacking_type: u8,
26
27    /// Maximum amount of stacks.
28    pub max_stacks: u16,
29
30    /// Maximum buff duration.
31    pub duration_cap: u32,
32
33    /// Probably invulnerable.
34    pub invulnerable: bool,
35
36    /// Probably invert.
37    pub invert: bool,
38
39    /// Probably resistance.
40    pub resistance: bool,
41}
42
43impl Extract for BuffInfo {
44    #[inline]
45    unsafe fn extract(event: &Event) -> Self {
46        Self {
47            skill_id: event.skill_id,
48            category: event.is_offcycle,
49            stacking_type: event.pad61,
50            max_stacks: event.src_master_instance_id,
51            duration_cap: event.overstack_value,
52            invulnerable: event.is_flanking != 0,
53            invert: event.is_shields != 0,
54            resistance: event.pad62 != 0,
55        }
56    }
57}
58
59impl TryExtract for BuffInfo {
60    #[inline]
61    fn can_extract(event: &Event) -> bool {
62        event.get_statechange() == StateChange::BuffInfo
63    }
64}
65
66/// Buff info category **after** 13 December 2022.
67///
68/// Used in [`StateChange::BuffInfo`](crate::StateChange::BuffInfo) events.
69#[derive(
70    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
71)]
72#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
73#[repr(u8)]
74pub enum BuffCategory {
75    /// Buff is a Boon.
76    Boon = 0,
77
78    /// Buff is generic category.
79    Any = 1,
80
81    /// Buff is a Condition.
82    Condition = 2,
83
84    /// Buff is granted by Food consumable.
85    Food = 5,
86
87    /// Buff is a gear item or upgrade.
88    Upgrade = 7,
89
90    /// Buff is granted by a Boost consumable.
91    Boost = 9,
92
93    /// Buff is granted by a Trait.
94    Trait = 12,
95
96    /// Buff is a Transform.
97    Transform = 13,
98
99    /// Buff is Enhancement granted by a Utility consumable.
100    Enhancement = 14,
101
102    /// Buff is a Stance.
103    Stance = 17,
104}
105
106/// Buff info category **before** 13 December 2022.
107///
108/// Used in [`StateChange::BuffInfo`](crate::StateChange::BuffInfo) events.
109#[derive(
110    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
111)]
112#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
113#[repr(u8)]
114pub enum BuffCategoryOld {
115    /// Buff is a Boon.
116    Boon = 0,
117
118    /// Buff is generic category.
119    Any = 1,
120
121    /// Buff is a Condition.
122    Condition = 2,
123
124    /// Buff is granted by Food consumable.
125    Food = 4,
126
127    /// Buff is granted by gear item or upgrade.
128    Upgrade = 6,
129
130    /// Buff is granted by a Boost consumable.
131    Boost = 8,
132
133    /// Buff is granted by a Trait.
134    Trait = 11,
135
136    /// Buff is a Transform.
137    Transform = 12,
138
139    /// Buff is Enhancement granted by a Utility consumable.
140    Enhancement = 13,
141
142    /// Buff is a Stance.
143    Stance = 16,
144}
145
146/// Buff stacking behavior.
147///
148/// Occurs in [`BuffInfo`].
149#[derive(
150    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
151)]
152#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
153#[cfg_attr(
154    feature = "strum",
155    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
156)]
157#[repr(u8)]
158pub enum BuffStackType {
159    /// Stacking in intensity with conditional loss.
160    ///
161    /// Similar to [`BuffStackType::Stacking`].
162    StackingConditionalLoss = 0,
163
164    /// Stacking in duration with queue.
165    Queue = 1,
166
167    /// Stacking in duration with cap.
168    CappedDuration = 2,
169
170    /// Regeneration-like stacking in duration.
171    Regeneration = 3,
172
173    /// Stacking in intensity.
174    Stacking = 4,
175
176    /// No stacking. Force override.
177    Force = 5,
178}