1use crate::prelude::*;
2
3use crate::entity::EntityAttributes;
4
5#[declare]
6pub type EffectId = Uuid;
7
8#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Tsify, JsonSchema)]
9pub struct Effect {
10 #[schemars(schema_with = "id_schema")]
11 pub id: EffectId,
12 #[schemars(title = "Имя эффекта")]
13 pub name: i18n::I18nString,
14 #[schemars(
15 title = "Нативная функция эффекта",
16 description = "Имя нативной функции категории event, выполняющей эффект.",
17 schema_with = "event_ref_schema"
18 )]
19 #[serde(default)]
20 pub behavior: Option<String>,
21 #[schemars(title = "Ссылка на иконку эффекта", schema_with = "webp_url_schema")]
22 pub icon_url: String,
23 #[schemars(title = "Иконка", schema_with = "asset_ui_status_icon_schema")]
24 pub icon_path: String,
25 #[schemars(title = "Код эффекта")]
26 pub code: String,
27 #[schemars(
28 title = "Опциональный интервал в тиках",
29 description = "Если указан – эффект будет выполняться в кроне с заданным интервалом"
30 )]
31 pub interval_ticks: Option<u64>,
32 #[schemars(
33 title = "Необходимые для эффекта аттрибуты",
34 description = "Эффект остановится при отсутствии перечисленных аттрибутов на Entity"
35 )]
36 pub required_attributes: Option<Vec<String>>,
37 #[schemars(title = "Опциональная подписка на ивенты")]
38 pub events_subscribe: Option<Vec<String>>,
39 #[schemars(title = "Является ли эффект позитивным/негативным")]
40 pub positive: bool,
41 #[schemars(
42 title = "Боевой VFX эффекта",
43 description = "Путь к VFX, проигрывающемуся однократно при наложении эффекта"
44 )]
45 pub vfx_path: String,
46
47 #[schemars(
48 title = "Максимальная длительность (сек)",
49 description = "Потолок длительности эффекта в секундах. Конвертируется в max_duration_ticks (мс) = duration * 1000. null = дефолт 5 сек."
50 )]
51 #[serde(default)]
52 pub duration: Option<i64>,
53}
54
55impl Effect {
56 pub fn has_at_least_one_required_attribute(&self, attributes: &EntityAttributes) -> bool {
57 if let Some(required_attributes) = &self.required_attributes {
58 let contains_at_least_one = required_attributes
59 .iter()
60 .any(|attr| attributes.0.contains_key(attr));
61 return contains_at_least_one;
62 }
63 true
64 }
65}