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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
use core::fmt;
use std::{collections::BTreeMap, hash::Hash};
use serde::{Deserialize, Serialize};
use crate::{DamageType, DieStat};
#[cfg_attr(feature = "diesel", derive(Queryable, Insertable))]
#[cfg_attr(feature = "diesel", diesel(table_name = "spells"))]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub struct Spell {
pub id: i32,
pub name: String,
pub description: String,
pub attributes: BTreeMap<AttributeType, Attribute>,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum AttributeType {
SpellLevel,
CastingTime,
Duration,
Damage,
Range,
Area,
DamageType,
Components,
AttackBonus,
Save,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Attribute {
SpellLevel(SpellLevel),
CastingTime(CastingTime),
Duration(Duration),
Damage(DieStat),
Range(SpellRange),
Area(Area),
DamageType(DamageType),
Components(Components),
AttackBonus(i32),
Save(Save),
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum SpellLevel {
Cantrip,
Level1,
Level2,
Level3,
Level4,
Level5,
Level6,
Level7,
Level8,
Level9,
}
impl fmt::Display for SpellLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
SpellLevel::Cantrip => write!(f, "Cantrip"),
SpellLevel::Level1 => write!(f, "1st Level"),
SpellLevel::Level2 => write!(f, "2nd Level"),
SpellLevel::Level3 => write!(f, "3rd Level"),
SpellLevel::Level4 => write!(f, "4th Level"),
SpellLevel::Level5 => write!(f, "5th Level"),
SpellLevel::Level6 => write!(f, "6th Level"),
SpellLevel::Level7 => write!(f, "7th Level"),
SpellLevel::Level8 => write!(f, "8th Level"),
SpellLevel::Level9 => write!(f, "9th Level"),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum CastingTime {
Action,
BonusAction,
Reaction,
Minute,
Hour,
}
impl fmt::Display for CastingTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
CastingTime::Action => write!(f, "Action"),
CastingTime::BonusAction => write!(f, "Bonus Action"),
CastingTime::Reaction => write!(f, "Reaction"),
CastingTime::Minute => write!(f, "Minute"),
CastingTime::Hour => write!(f, "Hour"),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Duration {
Instantaneous,
Concentration,
Minute,
Hour,
Day,
UntilDispelled,
UntilDispelledOrTriggered,
UntilTriggered,
}
impl fmt::Display for Duration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Duration::Instantaneous => write!(f, "Instantaneous"),
Duration::Concentration => write!(f, "Concentration"),
Duration::Minute => write!(f, "Minute"),
Duration::Hour => write!(f, "Hour"),
Duration::Day => write!(f, "Day"),
Duration::UntilDispelled => write!(f, "Until Dispelled"),
Duration::UntilDispelledOrTriggered => write!(f, "Until Dispelled or Triggered"),
Duration::UntilTriggered => write!(f, "Until Triggered"),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum SpellRange {
S,
Touch,
Range(i32),
}
impl fmt::Display for SpellRange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
SpellRange::S => write!(f, "Self"),
SpellRange::Touch => write!(f, "Touch"),
SpellRange::Range(range) => write!(f, "{}", range),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Area {
Cube(i32),
Sphere(i32),
Cone(i32),
Line(i32),
Cylinder(i32),
Wall(i32),
}
impl fmt::Display for Area {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Area::Cube(size) => write!(f, "{} ft. Cube", size),
Area::Sphere(size) => write!(f, "{} ft. Sphere", size),
Area::Cone(size) => write!(f, "{} ft. Cone", size),
Area::Line(size) => write!(f, "{} ft. Line", size),
Area::Cylinder(size) => write!(f, "{} ft. Cylinder", size),
Area::Wall(size) => write!(f, "{} ft. Wall", size),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Components {
V,
S,
M,
VS,
VM,
SM,
VSM,
}
impl fmt::Display for Components {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Components::V => write!(f, "V"),
Components::S => write!(f, "S"),
Components::M => write!(f, "M"),
Components::VS => write!(f, "V, S"),
Components::VM => write!(f, "V, M"),
Components::SM => write!(f, "S, M"),
Components::VSM => write!(f, "V, S, M"),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Save {
Strength(Option<i32>),
Dexterity(Option<i32>),
Constitution(Option<i32>),
Intelligence(Option<i32>),
Wisdom(Option<i32>),
Charisma(Option<i32>),
}
impl fmt::Display for Save {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Save::Strength(Some(dc)) => write!(f, "Strength DC {}", dc),
Save::Dexterity(Some(dc)) => write!(f, "Dexterity DC {}", dc),
Save::Constitution(Some(dc)) => write!(f, "Constitution DC {}", dc),
Save::Intelligence(Some(dc)) => write!(f, "Intelligence DC {}", dc),
Save::Wisdom(Some(dc)) => write!(f, "Wisdom DC {}", dc),
Save::Charisma(Some(dc)) => write!(f, "Charisma DC {}", dc),
Save::Strength(None) => write!(f, "Strength"),
Save::Dexterity(None) => write!(f, "Dexterity"),
Save::Constitution(None) => write!(f, "Constitution"),
Save::Intelligence(None) => write!(f, "Intelligence"),
Save::Wisdom(None) => write!(f, "Wisdom"),
Save::Charisma(None) => write!(f, "Charisma"),
}
}
}