1use crate::prelude::*;
2use enum_iterator::Sequence;
3use strum_macros::{Display, EnumIter, EnumString};
4
5use crate::currency::CurrencyUnit;
6use crate::skins::SkinId;
7
8#[declare]
9pub type AttributeId = Uuid;
10
11#[derive(
12 PartialEq,
13 Eq,
14 Default,
15 Hash,
16 Debug,
17 Clone,
18 Deserialize,
19 Serialize,
20 Tsify,
21 JsonSchema,
22 CustomType,
23)]
24pub struct Attribute {
25 #[schemars(schema_with = "id_schema")]
26 pub id: AttributeId,
27
28 #[schemars(title = "Название атрибута")]
29 pub name: i18n::I18nString,
30
31 #[schemars(title = "Префикс аттрибута")]
32 pub prefix: Option<i18n::I18nString>,
33
34 #[schemars(title = "Суффикс атрибута")]
35 pub suffix: Option<i18n::I18nString>,
36
37 #[schemars(title = "Код атрибута")]
38 pub code: String,
39
40 #[schemars(title = "Иконка аттрибута", schema_with = "webp_url_schema")]
41 pub icon: String,
42
43 #[schemars(title = "Иконка", schema_with = "asset_attribute_icon_schema")]
44 pub icon_path: String,
45
46 #[schemars(title = "Технический идентификатор", range(min = 0, max = 63))]
47 pub db_code: u8,
48
49 #[schemars(title = "Делитель значения аттрибута")]
50 pub denominator: Option<i64>,
51
52 #[schemars(title = "Является ли значение процентом")]
53 pub is_percent: bool,
54
55 #[schemars(title = "Скрипт вычисления значения", schema_with = "script_schema")]
56 pub calculation_script: String,
57
58 #[schemars(
59 title = "Приоритет атрибута",
60 description = "Приоритет атрибута, чем меньше значение - тем выше приоритет"
61 )]
62 pub order: i64,
63
64 #[schemars(title = "Показывать ли атрибут в ui")]
65 pub is_ui_visible: bool,
66
67 #[schemars(title = "Описание аттрибута")]
68 pub description: i18n::I18nString,
69}
70
71#[derive(
72 Debug,
73 Clone,
74 Copy,
75 EnumString,
76 Sequence,
77 Display,
78 Deserialize,
79 Serialize,
80 Hash,
81 Eq,
82 PartialEq,
83 EnumIter,
84 Default,
85 JsonSchema,
86 Tsify,
87)]
88#[tsify(namespace)]
89pub enum ItemType {
90 #[default]
91 Weapon,
92 Torso,
93 Head,
94 Legs,
95 Shoulders,
96 Boots,
97 Gloves,
98 Waist,
99 Neck,
100 Ring,
101}
102
103impl CustomType for ItemType {
104 fn build(mut builder: TypeBuilder<Self>) {
105 builder
106 .with_name("ItemType")
107 .with_get("str", |it: &mut ItemType| ItemType::to_string(it));
108 }
109}
110
111#[declare]
112pub type ItemRarityId = Uuid;
113
114#[derive(
115 Default,
116 PartialEq,
117 Eq,
118 Hash,
119 Debug,
120 Clone,
121 Serialize,
122 Deserialize,
123 Tsify,
124 JsonSchema,
125 CustomType,
126)]
127pub struct ItemRarity {
128 #[schemars(schema_with = "id_schema")]
129 pub id: ItemRarityId,
130 #[schemars(title = "Название редкости")]
131 pub name: i18n::I18nString,
132 #[schemars(title = "Цвет редкости текста", schema_with = "color_schema")]
133 pub text_color: String,
134 #[schemars(title = "URL картинки редкости", schema_with = "webp_url_schema")]
135 pub rarity_icon: String,
136 #[schemars(title = "Картинка", schema_with = "asset_item_rarity_icon_schema")]
137 pub rarity_icon_path: String,
138 #[schemars(
139 title = "URL картинки ленточки под айтемом",
140 schema_with = "webp_url_schema"
141 )]
142 pub ribbon_icon: String,
143 #[schemars(
144 title = "Лента-подложка",
145 schema_with = "asset_item_ribbon_icon_schema"
146 )]
147 pub ribbon_icon_path: String,
148 #[schemars(
149 title = "Приоритет редкости",
150 description = "Приоритет редкости, чем меньше значение - тем выше приоритет"
151 )]
152 pub order: i64,
153}
154
155#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, Tsify)]
156pub struct ItemAttributeSettings {
157 #[schemars(title = "Количество опциональных атрибутов у элемента")]
158 pub optional_attributes_count: u64,
159
160 #[schemars(
161 title = "Идентификаторы опциональных атрибутов",
162 schema_with = "attribute_link_id_array_schema"
163 )]
164 pub optional_attributes_ids: Vec<AttributeId>,
165}
166
167#[declare]
168pub type ItemTemplateId = Uuid;
169
170#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, Tsify)]
171pub struct ItemTemplate {
172 #[schemars(schema_with = "id_schema")]
173 pub id: ItemTemplateId,
174
175 #[schemars(title = "Название предмета")]
176 pub name: i18n::I18nString,
177
178 #[schemars(title = "URL картинки", schema_with = "webp_url_schema")]
179 pub icon_url: String,
180
181 #[schemars(title = "Иконка", schema_with = "asset_item_icon_schema")]
182 pub icon_path: String,
183
184 #[schemars(title = "Тип предмета")]
185 pub item_type: ItemType,
186
187 #[schemars(title = "Id редкости", schema_with = "item_rarity_link_id_schema")]
188 pub rarity_id: ItemRarityId,
189
190 #[schemars(title = "Настройки атрибутов для предмета")]
191 pub attributes_settings: ItemAttributeSettings,
192
193 #[schemars(title = "Id скина", schema_with = "skin_link_id_schema")]
194 pub skin_id: Option<SkinId>,
195
196 #[schemars(title = "Исключить из выдачи мимика")]
197 pub exclude_from_mimic: bool,
198}
199
200#[derive(
201 Debug, Deserialize, Serialize, Clone, Eq, PartialEq, Hash, JsonSchema, Tsify, CustomType,
202)]
203pub struct ItemAttribute {
204 pub attr_id: AttributeId,
205 pub value: i32,
206}
207
208#[derive(
209 Debug,
210 PartialEq,
211 Eq,
212 Deserialize,
213 Serialize,
214 Clone,
215 Default,
216 Hash,
217 JsonSchema,
218 Tsify,
219 CustomType,
220)]
221#[tsify(from_wasm_abi)]
222pub struct Item {
223 pub id: Uuid,
224 pub item_template_id: ItemTemplateId,
225 pub item_type: ItemType,
226 pub rarity: ItemRarity,
227 pub level: i64,
228 pub name: i18n::I18nString,
229 pub icon_url: String,
230 pub icon_path: String,
231 pub is_equipped: bool,
232 pub price: Vec<CurrencyUnit>,
233 pub experience: i64,
234 pub attributes: Vec<ItemAttribute>,
235}