battler_data/mons/
nature.rs1use serde_string_enum::{
2 DeserializeLabeledStringEnum,
3 SerializeLabeledStringEnum,
4};
5
6use crate::Stat;
7
8#[derive(
10 Debug,
11 Default,
12 Clone,
13 Copy,
14 PartialEq,
15 Eq,
16 Hash,
17 SerializeLabeledStringEnum,
18 DeserializeLabeledStringEnum,
19)]
20pub enum Nature {
21 #[string = "Hardy"]
22 #[default]
23 Hardy,
24 #[string = "Lonely"]
25 Lonely,
26 #[string = "Adamant"]
27 Adamant,
28 #[string = "Naughty"]
29 Naughty,
30 #[string = "Brave"]
31 Brave,
32 #[string = "Bold"]
33 Bold,
34 #[string = "Docile"]
35 Docile,
36 #[string = "Impish"]
37 Impish,
38 #[string = "Lax"]
39 Lax,
40 #[string = "Relaxed"]
41 Relaxed,
42 #[string = "Modest"]
43 Modest,
44 #[string = "Mild"]
45 Mild,
46 #[string = "Bashful"]
47 Bashful,
48 #[string = "Rash"]
49 Rash,
50 #[string = "Quiet"]
51 Quiet,
52 #[string = "Calm"]
53 Calm,
54 #[string = "Gentle"]
55 Gentle,
56 #[string = "Careful"]
57 Careful,
58 #[string = "Quirky"]
59 Quirky,
60 #[string = "Sassy"]
61 Sassy,
62 #[string = "Timid"]
63 Timid,
64 #[string = "Hasty"]
65 Hasty,
66 #[string = "Jolly"]
67 Jolly,
68 #[string = "Naive"]
69 Naive,
70 #[string = "Serious"]
71 Serious,
72}
73
74impl Nature {
75 pub fn boosts(&self) -> Stat {
77 match self {
78 Self::Hardy | Self::Lonely | Self::Adamant | Self::Naughty | Self::Brave => Stat::Atk,
79 Self::Bold | Self::Docile | Self::Impish | Self::Lax | Self::Relaxed => Stat::Def,
80 Self::Modest | Self::Mild | Self::Bashful | Self::Rash | Self::Quiet => Stat::SpAtk,
81 Self::Calm | Self::Gentle | Self::Careful | Self::Quirky | Self::Sassy => Stat::SpDef,
82 Self::Timid | Self::Hasty | Self::Jolly | Self::Naive | Self::Serious => Stat::Spe,
83 }
84 }
85
86 pub fn drops(&self) -> Stat {
88 match self {
89 Self::Hardy | Self::Bold | Self::Modest | Self::Calm | Self::Timid => Stat::Atk,
90 Self::Lonely | Self::Docile | Self::Mild | Self::Gentle | Self::Hasty => Stat::Def,
91 Self::Adamant | Self::Impish | Self::Bashful | Self::Careful | Self::Jolly => {
92 Stat::SpAtk
93 }
94 Self::Naughty | Self::Lax | Self::Rash | Self::Quirky | Self::Naive => Stat::SpDef,
95 Self::Brave | Self::Relaxed | Self::Quiet | Self::Sassy | Self::Serious => Stat::Spe,
96 }
97 }
98}
99
100#[cfg(test)]
101mod nature_test {
102 use crate::{
103 mons::Nature,
104 test_util::{
105 test_string_deserialization,
106 test_string_serialization,
107 },
108 };
109
110 #[test]
111 fn serializes_to_string() {
112 test_string_serialization(Nature::Hardy, "Hardy");
113 test_string_serialization(Nature::Lonely, "Lonely");
114 test_string_serialization(Nature::Adamant, "Adamant");
115 }
116
117 #[test]
118 fn deserializes_lowercase() {
119 test_string_deserialization("naughty", Nature::Naughty);
120 test_string_deserialization("brave", Nature::Brave);
121 test_string_deserialization("bold", Nature::Bold);
122 }
123}