1use core::fmt;
11
12use serde::{Deserialize, Serialize};
13
14pub mod action;
15pub mod creature;
16pub mod item;
17pub mod monster;
18pub mod spell;
19pub mod world;
20
21#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
22pub struct AttributeInfo {
23 pub name: String,
24 pub description: String,
25 }
27
28impl fmt::Display for AttributeInfo {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 write!(f, "{}: {}", self.name, self.description)
31 }
32}
33
34#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
35pub enum DamageType {
36 Slashing,
37 Piercing,
38 Bludgeoning,
39 Poison,
40 Acid,
41 Fire,
42 Cold,
43 Radiant,
44 Necrotic,
45 Lightning,
46 Thunder,
47 Force,
48 Psychic,
49}
50
51impl fmt::Display for DamageType {
52 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53 write!(f, "{:?}", self)
54 }
55}
56
57#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
58pub enum ConditionType {
59 Blinded,
60 Charmed,
61 Deafened,
62 Exhaustion,
63 Frightened,
64 Grappled,
65 Incapacitated,
66 Invisible,
67 Paralyzed,
68 Petrified,
69 Poisoned,
70 Prone,
71 Restrained,
72 Stunned,
73 Unconscious,
74}
75
76impl fmt::Display for ConditionType {
77 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78 write!(f, "{:?}", self)
79 }
80}
81
82#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
83pub enum Die {
84 D4,
85 D6,
86 D8,
87 D10,
88 D12,
89 D20,
90 D100,
91}
92
93impl fmt::Display for Die {
94 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95 write!(f, "d{}", self.to_i32())
96 }
97}
98
99impl Die {
100 pub fn to_i32(&self) -> i32 {
101 match &self {
102 Die::D4 => 4,
103 Die::D6 => 6,
104 Die::D8 => 8,
105 Die::D10 => 10,
106 Die::D12 => 12,
107 Die::D20 => 20,
108 Die::D100 => 100,
109 }
110 }
111
112 pub fn to_f64(&self) -> f64 {
113 self.to_i32() as f64
114 }
115}
116
117#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
118pub struct DieStat {
119 pub die_count: i32,
120 pub die_type: Die,
121 pub extra: i32,
122}
123
124impl DieStat {
125 pub fn value(&self) -> i32 {
126 (self.die_count as f64 * (self.die_type.to_f64() / 2_f64 + 0.5)).floor() as i32 + self.extra
127 }
128}
129
130impl fmt::Display for DieStat {
131 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
132 write!(
133 f,
134 "{}{} + {}",
135 self.die_count,
136 self.die_type.to_string(),
137 self.extra
138 )
139 }
140}
141
142#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
143pub struct OtherAttribute {
144 pub title: String,
145 pub description: String,
146 pub value: String,
147}
148
149impl fmt::Display for OtherAttribute {
150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151 write!(f, "{}: {}", self.title, self.value)
152 }
153}
154
155#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
156pub enum Alignment {
157 ChaoticEvil,
158 ChaoticNeutral,
159 ChaoticGood,
160 LawfulEvil,
161 LawfulNeutral,
162 LawfulGood,
163 NeutralEvil,
164 TrueNeutral,
165 NeutralGood,
166 Unaligned,
167}
168
169impl fmt::Display for Alignment {
170 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
171 match &self {
172 Alignment::ChaoticEvil => write!(f, "{}", String::from("chaotic evil")),
173 Alignment::ChaoticNeutral => write!(f, "{}", String::from("chaotic neutral")),
174 Alignment::ChaoticGood => write!(f, "{}", String::from("chaotic good")),
175 Alignment::LawfulEvil => write!(f, "{}", String::from("lawful evil")),
176 Alignment::LawfulNeutral => write!(f, "{}", String::from("lawful neutral")),
177 Alignment::LawfulGood => write!(f, "{}", String::from("lawful good")),
178 Alignment::NeutralEvil => write!(f, "{}", String::from("neutral evil")),
179 Alignment::TrueNeutral => write!(f, "{}", String::from("true neutral")),
180 Alignment::NeutralGood => write!(f, "{}", String::from("neutral good")),
181 Alignment::Unaligned => write!(f, "{}", String::from("unaligned")),
182 }
183 }
184}