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
179
180
181
182
183
184
use core::fmt;
use serde::{Deserialize, Serialize};
pub mod action;
pub mod creature;
pub mod item;
pub mod monster;
pub mod spell;
pub mod world;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub struct AttributeInfo {
pub name: String,
pub description: String,
}
impl fmt::Display for AttributeInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.name, self.description)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum DamageType {
Slashing,
Piercing,
Bludgeoning,
Poison,
Acid,
Fire,
Cold,
Radiant,
Necrotic,
Lightning,
Thunder,
Force,
Psychic,
}
impl fmt::Display for DamageType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub enum ConditionType {
Blinded,
Charmed,
Deafened,
Exhaustion,
Frightened,
Grappled,
Incapacitated,
Invisible,
Paralyzed,
Petrified,
Poisoned,
Prone,
Restrained,
Stunned,
Unconscious,
}
impl fmt::Display for ConditionType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Die {
D4,
D6,
D8,
D10,
D12,
D20,
D100,
}
impl fmt::Display for Die {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "d{}", self.to_i32())
}
}
impl Die {
pub fn to_i32(&self) -> i32 {
match &self {
Die::D4 => 4,
Die::D6 => 6,
Die::D8 => 8,
Die::D10 => 10,
Die::D12 => 12,
Die::D20 => 20,
Die::D100 => 100,
}
}
pub fn to_f64(&self) -> f64 {
self.to_i32() as f64
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub struct DieStat {
pub die_count: i32,
pub die_type: Die,
pub extra: i32,
}
impl DieStat {
pub fn value(&self) -> i32 {
(self.die_count as f64 * (self.die_type.to_f64() / 2_f64 + 0.5)).floor() as i32 + self.extra
}
}
impl fmt::Display for DieStat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}{} + {}",
self.die_count,
self.die_type.to_string(),
self.extra
)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub struct OtherAttribute {
pub title: String,
pub description: String,
pub value: String,
}
impl fmt::Display for OtherAttribute {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.title, self.value)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub enum Alignment {
ChaoticEvil,
ChaoticNeutral,
ChaoticGood,
LawfulEvil,
LawfulNeutral,
LawfulGood,
NeutralEvil,
TrueNeutral,
NeutralGood,
Unaligned,
}
impl fmt::Display for Alignment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
Alignment::ChaoticEvil => write!(f, "{}", String::from("chaotic evil")),
Alignment::ChaoticNeutral => write!(f, "{}", String::from("chaotic neutral")),
Alignment::ChaoticGood => write!(f, "{}", String::from("chaotic good")),
Alignment::LawfulEvil => write!(f, "{}", String::from("lawful evil")),
Alignment::LawfulNeutral => write!(f, "{}", String::from("lawful neutral")),
Alignment::LawfulGood => write!(f, "{}", String::from("lawful good")),
Alignment::NeutralEvil => write!(f, "{}", String::from("neutral evil")),
Alignment::TrueNeutral => write!(f, "{}", String::from("true neutral")),
Alignment::NeutralGood => write!(f, "{}", String::from("neutral good")),
Alignment::Unaligned => write!(f, "{}", String::from("unaligned")),
}
}
}