zz_data/core/
wizform.rs

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
use serde::{Deserialize, Serialize};
use sqlx::types::Json;
use strum::{Display, EnumIter, FromRepr};
use uuid::Uuid;

use super::magic::Magic;

#[derive(Debug, Serialize, Default, Deserialize, FromRepr, Display, EnumIter, Clone, sqlx::Type)]
#[repr(i16)]
pub enum WizformElementType {
    #[strum(to_string = "Нейтральная стихия 1")]
    NeutralOne = 0,
    #[default]
    #[strum(to_string = "Природа")]
    Nature = 1,
    #[strum(to_string = "Воздух")]
    Air = 2,
    #[strum(to_string = "Вода")]
    Water = 3,
    #[strum(to_string = "Свет")]
    Light = 4,
    #[strum(to_string = "Энергия")]
    Energy = 5,
    #[strum(to_string = "Пси")]
    Psi = 6,
    #[strum(to_string = "Камень")]
    Stone = 7,
    #[strum(to_string = "Лёд")]
    Ice = 8,
    #[strum(to_string = "Огонь")]
    Fire = 9,
    #[strum(to_string = "Тьма")]
    Dark = 10,
    #[strum(to_string = "Хаос")]
    Chaos = 11,
    #[strum(to_string = "Металл")]
    Metall = 12,
    #[strum(to_string = "Нейтральная стихия 2")]
    NeutralTwo = 13,
    #[strum(to_string = "Пользовательская стихия 1")]
    Custom1 = 14,
    #[strum(to_string = "Пользовательская стихия 2")]
    Custom2 = 15,
    #[strum(to_string = "Пользовательская стихия 3")]
    Custom3 = 16,
    #[strum(to_string = "Пользовательская стихия 4")]
    Custom4 = 17,
    #[strum(to_string = "Пользовательская стихия 5")]
    Custom5 = 18
}

/// Represents a wizform parsed from the game files
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Wizform {
    pub id: String,
    pub game_id: String,
    pub model: String,
    /// Id of name text in game texts
    pub name: String,
    /// Id of desc text in game texts
    pub desc: String,
    pub element: WizformElementType,
    pub magics: Vec<Magic>,
    pub number: u16,
    pub hitpoints: i32,
    pub agility: i32,
    pub jump_ability: i32,
    pub precision: i32,
    /// Number of wizform this one evolutes into (-501 if no evolution)
    pub evolution_form: i32,
    /// Level this wizform evolutes(-1 if no evolution)
    pub evolution_level: i32,
    pub voice_type: i32,
    pub exp_modifier: i32
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Magics {
    pub types: Vec<Magic>
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Filters {
    pub ids: Vec<Uuid>
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SpawnPoints {
    pub ids: Vec<Uuid>
}

#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
pub struct WizformDBModel {
    pub id: Uuid,
    pub book_id: Uuid,
    pub game_id: String,
    pub element: WizformElementType,
    pub magics: Json<Magics>,
    pub number: i16,
    pub hitpoints: i16,
    pub agility: i16,
    pub jump_ability: i16,
    pub precision: i16,
    pub evolution_form: i16,
    pub evolution_level: i16,
    pub exp_modifier: i16,
    pub enabled: bool,
    pub filters: Json<Filters>,
    pub description: String,
    pub icon64: String,
    pub spawn_points: Json<SpawnPoints>,
    pub name: Vec<u8>,
    pub cleared_name: String
}

#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)]
pub struct SpawnPointDBModel {
    pub id: Uuid,
    pub book_id: Uuid,
    pub name: String
}

#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
pub struct ElementDBModel {
    pub id: Uuid,
    pub element: WizformElementType,
    pub name: String,
    pub book_id: Uuid,
    pub enabled: bool
}

impl Wizform {
    pub fn new() -> Self {
        Wizform::default()
    }

    pub fn id(mut self, id: String) -> Self {
        self.id = id;
        self
    }

    pub fn model(mut self, model_id: String) -> Self {
        self.model = model_id;
        self
    }

    pub fn name(mut self, name_id: String) -> Self {
        self.name = name_id;
        self
    }

    pub fn desc(mut self, desc_id: String) -> Self {
        self.desc = desc_id;
        self
    }

    pub fn element(mut self, element: u8) -> Self {
        self.element = WizformElementType::from_repr(element as i16).unwrap_or_default();
        self
    }

    pub fn magics(mut self, magics: Vec<Magic>) -> Self {
        self.magics = magics;
        self
    }

    pub fn number(mut self, number: u16) -> Self {
        self.number = number;
        self
    }

    pub fn hitpoints(mut self, hp: i32) -> Self {
        self.hitpoints = hp;
        self
    }

    pub fn agility(mut self, agility: i32) -> Self {
        self.agility = agility;
        self
    }

    pub fn jump_ability(mut self, jump: i32) -> Self {
        self.jump_ability = jump;
        self
    }

    pub fn precision(mut self, precision: i32) -> Self {
        self.precision = precision;
        self
    }

    pub fn evolution_form(mut self, evo_form_number: i32) -> Self {
        self.evolution_form = evo_form_number;
        self
    }

    pub fn evolution_level(mut self, evo_level: i32) -> Self {
        self.evolution_level = evo_level;
        self
    }

    pub fn voice(mut self, voice: i32) -> Self {
        self.voice_type = voice;
        self
    }

    pub fn exp_modifier(mut self, modifier: i32) -> Self {
        self.exp_modifier = modifier;
        self
    }
}