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
use crate::{
    event::{impl_common, CommonEvent},
    extract::Extract,
    Event, TryExtract,
};

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

/// Buff initial event.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BuffInitialEvent {
    /// Common combat event information.
    #[cfg_attr(feature = "serde", serde(flatten))]
    pub common: CommonEvent,

    /// Current remaining duration.
    pub duration: i32,

    /// Original full duration.
    pub original_duration: i32,

    /// Whether stack is active.
    pub stack_active: u8,

    /// Buff stack (instance) id.
    pub stack_id: u32,
}

impl_common!(BuffInitialEvent);

impl Extract for BuffInitialEvent {
    #[inline]
    unsafe fn extract(event: &Event) -> Self {
        Self {
            common: event.into(),
            duration: event.value,
            original_duration: event.buff_dmg,
            stack_active: event.is_shields,
            stack_id: event.get_pad_id(),
        }
    }
}

impl TryExtract for BuffInitialEvent {
    #[inline]
    fn can_extract(event: &Event) -> bool {
        event.is_buffinitial()
    }
}