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