1use serde::{Deserialize, Serialize};
2use sqlx::types::Json;
3use strum::{Display, EnumIter, FromRepr};
4use uuid::Uuid;
5
6use super::magic::Magic;
7
8#[derive(Debug, Serialize, Default, Deserialize, FromRepr, Display, EnumIter, Clone, sqlx::Type)]
9#[repr(i16)]
10pub enum WizformElementType {
11 #[strum(to_string = "Нейтральная стихия 1")]
12 NeutralOne = 0,
13 #[default]
14 #[strum(to_string = "Природа")]
15 Nature = 1,
16 #[strum(to_string = "Воздух")]
17 Air = 2,
18 #[strum(to_string = "Вода")]
19 Water = 3,
20 #[strum(to_string = "Свет")]
21 Light = 4,
22 #[strum(to_string = "Энергия")]
23 Energy = 5,
24 #[strum(to_string = "Пси")]
25 Psi = 6,
26 #[strum(to_string = "Камень")]
27 Stone = 7,
28 #[strum(to_string = "Лёд")]
29 Ice = 8,
30 #[strum(to_string = "Огонь")]
31 Fire = 9,
32 #[strum(to_string = "Тьма")]
33 Dark = 10,
34 #[strum(to_string = "Хаос")]
35 Chaos = 11,
36 #[strum(to_string = "Металл")]
37 Metall = 12,
38 #[strum(to_string = "Нейтральная стихия 2")]
39 NeutralTwo = 13,
40 #[strum(to_string = "Пользовательская стихия 1")]
41 Custom1 = 14,
42 #[strum(to_string = "Пользовательская стихия 2")]
43 Custom2 = 15,
44 #[strum(to_string = "Пользовательская стихия 3")]
45 Custom3 = 16,
46 #[strum(to_string = "Пользовательская стихия 4")]
47 Custom4 = 17,
48 #[strum(to_string = "Пользовательская стихия 5")]
49 Custom5 = 18
50}
51
52#[derive(Debug, Default, Serialize, Deserialize)]
54pub struct Wizform {
55 pub id: String,
56 pub game_id: String,
57 pub model: String,
58 pub name: String,
60 pub desc: String,
62 pub element: WizformElementType,
63 pub magics: Vec<Magic>,
64 pub number: u16,
65 pub hitpoints: i32,
66 pub agility: i32,
67 pub jump_ability: i32,
68 pub precision: i32,
69 pub evolution_form: i32,
71 pub evolution_level: i32,
73 pub voice_type: i32,
74 pub exp_modifier: i32
75}
76
77#[derive(Debug, Serialize, Deserialize, Clone)]
78pub struct Magics {
79 pub types: Vec<Magic>
80}
81
82#[derive(Debug, Serialize, Deserialize, Clone)]
83pub struct Filters {
84 pub ids: Vec<Uuid>
85}
86
87#[derive(Debug, Serialize, Deserialize, Clone)]
88pub struct SpawnPoints {
89 pub ids: Vec<Uuid>
90}
91
92#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
93pub struct WizformDBModel {
94 pub id: Uuid,
95 pub book_id: Uuid,
96 pub game_id: String,
97 pub element: WizformElementType,
98 pub magics: Json<Magics>,
99 pub number: i16,
100 pub hitpoints: i16,
101 pub agility: i16,
102 pub jump_ability: i16,
103 pub precision: i16,
104 pub evolution_form: i16,
105 pub evolution_level: i16,
106 pub exp_modifier: i16,
107 pub enabled: bool,
108 pub filters: Json<Filters>,
109 pub description: String,
110 pub icon64: String,
111 pub spawn_points: Json<SpawnPoints>,
112 pub name: Vec<u8>,
113 pub cleared_name: String
114}
115
116#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)]
117pub struct SpawnPointDBModel {
118 pub id: Uuid,
119 pub book_id: Uuid,
120 pub name: String
121}
122
123#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
124pub struct ElementDBModel {
125 pub id: Uuid,
126 pub element: WizformElementType,
127 pub name: String,
128 pub book_id: Uuid,
129 pub enabled: bool
130}
131
132impl Wizform {
133 pub fn new() -> Self {
134 Wizform::default()
135 }
136
137 pub fn id(mut self, id: String) -> Self {
138 self.id = id;
139 self
140 }
141
142 pub fn model(mut self, model_id: String) -> Self {
143 self.model = model_id;
144 self
145 }
146
147 pub fn name(mut self, name_id: String) -> Self {
148 self.name = name_id;
149 self
150 }
151
152 pub fn desc(mut self, desc_id: String) -> Self {
153 self.desc = desc_id;
154 self
155 }
156
157 pub fn element(mut self, element: u8) -> Self {
158 self.element = WizformElementType::from_repr(element as i16).unwrap_or_default();
159 self
160 }
161
162 pub fn magics(mut self, magics: Vec<Magic>) -> Self {
163 self.magics = magics;
164 self
165 }
166
167 pub fn number(mut self, number: u16) -> Self {
168 self.number = number;
169 self
170 }
171
172 pub fn hitpoints(mut self, hp: i32) -> Self {
173 self.hitpoints = hp;
174 self
175 }
176
177 pub fn agility(mut self, agility: i32) -> Self {
178 self.agility = agility;
179 self
180 }
181
182 pub fn jump_ability(mut self, jump: i32) -> Self {
183 self.jump_ability = jump;
184 self
185 }
186
187 pub fn precision(mut self, precision: i32) -> Self {
188 self.precision = precision;
189 self
190 }
191
192 pub fn evolution_form(mut self, evo_form_number: i32) -> Self {
193 self.evolution_form = evo_form_number;
194 self
195 }
196
197 pub fn evolution_level(mut self, evo_level: i32) -> Self {
198 self.evolution_level = evo_level;
199 self
200 }
201
202 pub fn voice(mut self, voice: i32) -> Self {
203 self.voice_type = voice;
204 self
205 }
206
207 pub fn exp_modifier(mut self, modifier: i32) -> Self {
208 self.exp_modifier = modifier;
209 self
210 }
211}