1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
use crate::{extract::Extract, Event, StateChange, TryExtract};
use num_enum::{IntoPrimitive, TryFromPrimitive};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "strum")]
use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};

/// Buff information from an [`Event`] with [`StateChange::BuffInfo`].
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BuffInfo {
    /// Buff skill id.
    pub skill_id: u32,

    /// The category of buff.
    ///
    /// See [`BuffCategory`] and [`BuffCategoryOld`].
    pub category: u8,

    /// Buff stacking behavior.
    ///
    /// See [`BuffStackType`].
    pub stacking_type: u8,

    /// Maximum amount of stacks.
    pub max_stacks: u16,

    /// Maximum buff duration.
    pub duration_cap: u32,

    /// Probably invulnerable.
    pub invulnerable: bool,

    /// Probably invert.
    pub invert: bool,

    /// Probably resistance.
    pub resistance: bool,
}

impl Extract for BuffInfo {
    #[inline]
    unsafe fn extract(event: &Event) -> Self {
        Self {
            skill_id: event.skill_id,
            category: event.is_offcycle,
            stacking_type: event.pad61,
            max_stacks: event.src_master_instance_id,
            duration_cap: event.overstack_value,
            invulnerable: event.is_flanking != 0,
            invert: event.is_shields != 0,
            resistance: event.pad62 != 0,
        }
    }
}

impl TryExtract for BuffInfo {
    #[inline]
    fn can_extract(event: &Event) -> bool {
        event.get_statechange() == StateChange::BuffInfo
    }
}

/// Buff info category **after** 13 December 2022.
///
/// Used in [`StateChange::BuffInfo`](crate::StateChange::BuffInfo) events.
#[derive(
    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum BuffCategory {
    /// Buff is a Boon.
    Boon = 0,

    /// Buff is generic category.
    Any = 1,

    /// Buff is a Condition.
    Condition = 2,

    /// Buff is granted by Food consumable.
    Food = 5,

    /// Buff is a gear item or upgrade.
    Upgrade = 7,

    /// Buff is granted by a Boost consumable.
    Boost = 9,

    /// Buff is granted by a Trait.
    Trait = 12,

    /// Buff is a Transform.
    Transform = 13,

    /// Buff is Enhancement granted by a Utility consumable.
    Enhancement = 14,

    /// Buff is a Stance.
    Stance = 17,
}

/// Buff info category **before** 13 December 2022.
///
/// Used in [`StateChange::BuffInfo`](crate::StateChange::BuffInfo) events.
#[derive(
    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum BuffCategoryOld {
    /// Buff is a Boon.
    Boon = 0,

    /// Buff is generic category.
    Any = 1,

    /// Buff is a Condition.
    Condition = 2,

    /// Buff is granted by Food consumable.
    Food = 4,

    /// Buff is granted by gear item or upgrade.
    Upgrade = 6,

    /// Buff is granted by a Boost consumable.
    Boost = 8,

    /// Buff is granted by a Trait.
    Trait = 11,

    /// Buff is a Transform.
    Transform = 12,

    /// Buff is Enhancement granted by a Utility consumable.
    Enhancement = 13,

    /// Buff is a Stance.
    Stance = 16,
}

/// Buff stacking behavior.
///
/// Occurs in [`BuffInfo`].
#[derive(
    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
    feature = "strum",
    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
)]
#[repr(u8)]
pub enum BuffStackType {
    /// Stacking in intensity with conditional loss.
    ///
    /// Similar to [`BuffStackType::Stacking`].
    StackingConditionalLoss = 0,

    /// Stacking in duration with queue.
    Queue = 1,

    /// Stacking in duration with cap.
    CappedDuration = 2,

    /// Regeneration-like stacking in duration.
    Regeneration = 3,

    /// Stacking in intensity.
    Stacking = 4,

    /// No stacking. Force override.
    Force = 5,
}