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
use strum_macros::{Display, EnumString, EnumIter};
use num_enum::{TryFromPrimitive, IntoPrimitive};
use serde_repr::{Serialize_repr, Deserialize_repr};
use std::fmt;
use crate::{Attribute, Attributes};
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
pub enum Spell {
Footprints(FootprintsSpell),
Paint(PaintSpell),
VoicesFromBelow,
PumpkinBombs,
HalloweenFire,
Exorcism,
}
impl Spell {
pub const DEFINDEX_PAINT: u32 = 1004;
pub const DEFINDEX_FOOTPRINTS: u32 = 1005;
pub const DEFINDEX_VOICES_FROM_BELOW: u32 = 1006;
pub const DEFINDEX_PUMPKIN_BOMBS: u32 = 1007;
pub const DEFINDEX_HALLOWEEN_FIRE: u32 = 1008;
pub const DEFINDEX_EXORCISM: u32 = 1009;
pub fn attribute_defindex(&self) -> u32 {
match self {
Spell::Paint(_) => Self::DEFINDEX_PAINT,
Spell::Footprints(_) => Self::DEFINDEX_FOOTPRINTS,
Spell::VoicesFromBelow => Self::DEFINDEX_VOICES_FROM_BELOW,
Spell::PumpkinBombs => Self::DEFINDEX_PUMPKIN_BOMBS,
Spell::HalloweenFire => Self::DEFINDEX_HALLOWEEN_FIRE,
Spell::Exorcism => Self::DEFINDEX_EXORCISM,
}
}
}
impl Attributes for Spell {
const DEFINDEX: &'static [u32] = &[1004, 1005, 1006, 1007, 1008, 1009];
}
impl fmt::Display for Spell {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Spell::Paint(spell) => write!(f, "{}", spell),
Spell::Footprints(spell) => write!(f, "{}", spell),
Spell::VoicesFromBelow => write!(f, "Voices From Below"),
Spell::PumpkinBombs => write!(f, "Pumpkin Bombs"),
Spell::HalloweenFire => write!(f, "Halloween Fire"),
Spell::Exorcism => write!(f, "Exorcism"),
}
}
}
impl std::str::FromStr for Spell {
type Err = ::strum::ParseError;
fn from_str(s: &str) -> Result<Spell, Self::Err> {
match s {
"Die Job" => Result::Ok(Spell::Paint(PaintSpell::DieJob)),
"Chromatic Corruption" => Result::Ok(Spell::Paint(PaintSpell::ChromaticCorruption)),
"Putrescent Pigmentation" => Result::Ok(Spell::Paint(PaintSpell::PutrescentPigmentation)),
"Spectral Spectrum" => Result::Ok(Spell::Paint(PaintSpell::SpectralSpectrum)),
"Sinister Staining" => Result::Ok(Spell::Paint(PaintSpell::SinisterStaining)),
"Team Spirit Footprints" => Result::Ok(Spell::Footprints(FootprintsSpell::TeamSpiritFootprints)),
"Gangreen Footprints" => Result::Ok(Spell::Footprints(FootprintsSpell::GangreenFootprints)),
"Corpse Gray Footprints" => Result::Ok(Spell::Footprints(FootprintsSpell::CorpseGrayFootprints)),
"Violent Violet Footprints" => Result::Ok(Spell::Footprints(FootprintsSpell::ViolentVioletFootprints)),
"Rotten Orange Footprints" => Result::Ok(Spell::Footprints(FootprintsSpell::RottenOrangeFootprints)),
"Bruised Purple Footprints" => Result::Ok(Spell::Footprints(FootprintsSpell::BruisedPurpleFootprints)),
"Headless Horseshoes" => Result::Ok(Spell::Footprints(FootprintsSpell::HeadlessHorseshoes)),
"Voices From Below" => Result::Ok(Spell::VoicesFromBelow),
"Pumpkin Bombs" => Result::Ok(Spell::PumpkinBombs),
"Halloween Fire" => Result::Ok(Spell::HalloweenFire),
"Exorcism" => Result::Ok(Spell::Exorcism),
_ => Result::Err(strum::ParseError::VariantNotFound),
}
}
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Hash, Eq, PartialEq, Display, EnumString, EnumIter, TryFromPrimitive, IntoPrimitive, Clone, Copy)]
#[repr(u32)]
pub enum PaintSpell {
#[strum(serialize = "Die Job")]
DieJob = 0,
#[strum(serialize = "Chromatic Corruption")]
ChromaticCorruption = 1,
#[strum(serialize = "Putrescent Pigmentation")]
PutrescentPigmentation = 2,
#[strum(serialize = "Spectral Spectrum")]
SpectralSpectrum = 3,
#[strum(serialize = "Sinister Staining")]
SinisterStaining = 4,
}
impl Attribute for PaintSpell {
const DEFINDEX: u32 = 1004;
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Hash, Eq, PartialEq, Display, EnumString, EnumIter, TryFromPrimitive, IntoPrimitive, Clone, Copy)]
#[repr(u32)]
pub enum FootprintsSpell {
#[strum(serialize = "Team Spirit Footprints")]
TeamSpiritFootprints = 1,
#[strum(serialize = "Gangreen Footprints")]
GangreenFootprints = 8421376,
#[strum(serialize = "Corpse Gray Footprints")]
CorpseGrayFootprints = 3100495,
#[strum(serialize = "Violent Violet Footprints")]
ViolentVioletFootprints = 5322826,
#[strum(serialize = "Rotten Orange Footprints")]
RottenOrangeFootprints = 13595446,
#[strum(serialize = "Bruised Purple Footprints")]
BruisedPurpleFootprints = 8208497,
#[strum(serialize = "Headless Horseshoes")]
HeadlessHorseshoes = 2,
}
impl Attribute for FootprintsSpell {
const DEFINDEX: u32 = 1005;
}
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
#[test]
fn from_str() {
assert_eq!(Spell::from_str("Headless Horseshoes").unwrap(), Spell::Footprints(FootprintsSpell::HeadlessHorseshoes));
}
#[test]
fn to_string() {
assert_eq!(Spell::Footprints(FootprintsSpell::HeadlessHorseshoes).to_string(), "Headless Horseshoes");
}
#[test]
fn from_repr() {
assert_eq!(FootprintsSpell::try_from(2).unwrap(), FootprintsSpell::HeadlessHorseshoes);
}
}