1use crate::items::AttributeId;
2use crate::prelude::*;
3use std::collections::BTreeMap;
4
5#[declare]
6pub type StatueBonusGradeId = Uuid;
7
8#[derive(Default, PartialEq, Eq, Hash, Debug, Clone, Serialize, Deserialize, Tsify, JsonSchema)]
10pub struct StatueBonusGrade {
11 #[schemars(schema_with = "id_schema")]
12 pub id: StatueBonusGradeId,
13
14 #[schemars(title = "Название грейда")]
15 pub name: i18n::I18nString,
16
17 #[schemars(title = "Цвет грейда", schema_with = "color_schema")]
18 pub color: String,
19
20 #[schemars(
21 title = "Порядок",
22 description = "Порядок грейда, чем меньше значение - тем ниже грейд"
23 )]
24 pub order: i64,
25}
26
27#[derive(Default, PartialEq, Eq, Hash, Debug, Clone, Serialize, Deserialize, Tsify, JsonSchema)]
29pub struct StatueBonusSlot {
30 #[schemars(schema_with = "attribute_link_id_schema")]
31 pub attribute_id: AttributeId,
32
33 pub grade_id: StatueBonusGradeId,
34
35 pub is_locked: bool,
36}
37
38#[derive(Default, PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Tsify, JsonSchema)]
41pub struct StatueSlotsMap(pub BTreeMap<u8, StatueBonusSlot>);
42
43impl rhai::CustomType for StatueSlotsMap {
44 fn build(mut builder: rhai::TypeBuilder<Self>) {
45 builder
46 .with_name("StatueSlotsMap")
47 .with_indexer_get(|map: &mut StatueSlotsMap, idx: i64| -> rhai::Dynamic {
48 match map.0.get(&(idx as u8)) {
49 Some(slot) => rhai::Dynamic::from(slot.clone()),
50 None => rhai::Dynamic::UNIT,
51 }
52 })
53 .with_fn("values", |map: &mut StatueSlotsMap| -> rhai::Array {
54 map.0.values().cloned().map(rhai::Dynamic::from).collect()
55 })
56 .with_fn("len", |map: &mut StatueSlotsMap| -> i64 {
57 map.0.len() as i64
58 });
59 }
60}
61
62#[derive(Default, PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Tsify, JsonSchema)]
64pub struct StatueSet {
65 pub name: String,
66 pub slots: StatueSlotsMap,
67}
68
69#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Tsify, JsonSchema)]
71pub struct StatueState {
72 pub level: i64,
73 pub experience: i64,
74
75 pub active_set_index: u8,
77
78 pub sets: Vec<StatueSet>,
80}
81
82impl Default for StatueState {
83 fn default() -> Self {
84 Self {
85 level: 1,
86 experience: 0,
87 active_set_index: 0,
88 sets: vec![],
89 }
90 }
91}