evtc\content/
mod.rs
1mod guid;
4
5#[cfg(feature = "serde")]
6pub mod serde_guid;
7
8use crate::{
9 extract::{transmute_field, Extract},
10 Event, StateChange, TryExtract,
11};
12use num_enum::{IntoPrimitive, TryFromPrimitive};
13
14#[cfg(feature = "serde")]
15use serde::{Deserialize, Serialize};
16
17#[cfg(feature = "strum")]
18use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
19
20pub use self::guid::*;
21
22#[derive(Debug, Clone)]
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31pub struct ContentInfo {
32 pub content_id: u32,
34
35 #[cfg_attr(feature = "serde", serde(with = "serde_guid"))]
37 pub guid: GUID,
38
39 pub content_type: ContentType,
41}
42
43impl ContentInfo {
44 #[inline]
46 pub fn guid_string(&self) -> String {
47 self.guid.format_simple()
48 }
49
50 #[inline]
52 pub fn is_effect(&self) -> bool {
53 matches!(self.content_type, ContentType::Effect { .. })
54 }
55
56 #[inline]
58 pub fn is_marker(&self) -> bool {
59 matches!(self.content_type, ContentType::Marker)
60 }
61
62 #[inline]
64 pub fn is_skill(&self) -> bool {
65 matches!(self.content_type, ContentType::Skill)
66 }
67
68 #[inline]
70 pub fn is_species(&self) -> bool {
71 matches!(self.content_type, ContentType::Species)
72 }
73}
74
75impl Extract for ContentInfo {
76 #[inline]
77 unsafe fn extract(event: &Event) -> Self {
78 Self {
79 content_id: event.skill_id,
80 guid: transmute_field!(event.src_agent as GUID),
81 content_type: event.extract(),
82 }
83 }
84}
85
86impl TryExtract for ContentInfo {
87 #[inline]
88 fn can_extract(event: &Event) -> bool {
89 event.get_statechange() == StateChange::IdToGUID
90 }
91}
92
93#[derive(Debug, Clone)]
95#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
96pub enum ContentType {
97 Effect {
99 effect_type: u16,
101
102 default_duration: f32,
104 },
105
106 Marker,
108
109 Skill,
113
114 Species,
116
117 Unknown(u32),
119}
120
121impl Extract for ContentType {
122 #[inline]
123 unsafe fn extract(event: &Event) -> Self {
124 match event.overstack_value.try_into() {
125 Ok(ContentLocal::Effect) => Self::Effect {
126 effect_type: event.src_instance_id,
127 default_duration: transmute_field!(event.buff_dmg as f32),
128 },
129 Ok(ContentLocal::Marker) => Self::Marker,
130 Ok(ContentLocal::Skill) => Self::Skill,
131 Ok(ContentLocal::Species) => Self::Species,
132 Err(err) => Self::Unknown(err.number),
133 }
134 }
135}
136
137impl TryExtract for ContentType {
138 #[inline]
139 fn can_extract(event: &Event) -> bool {
140 event.get_statechange() == StateChange::IdToGUID
141 }
142}
143
144#[derive(
146 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive,
147)]
148#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
149#[cfg_attr(
150 feature = "strum",
151 derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
152)]
153#[repr(u32)]
154pub enum ContentLocal {
155 Effect = 0,
160
161 Marker = 1,
163
164 Skill = 2,
168
169 Species = 3,
171}