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, CustomType)]
9pub struct Effect {
10 #[schemars(schema_with = "id_schema")]
11 pub id: EffectId,
12 #[schemars(title = "Имя эффекта")]
13 pub name: i18n::I18nString,
14 #[schemars(title = "Скрипт эффекта", schema_with = "script_schema")]
15 pub script: String,
16 #[schemars(title = "Ссылка на иконку эффекта", schema_with = "webp_url_schema")]
17 pub icon_url: String,
18 #[schemars(title = "Иконка (unity)", schema_with = "aa_image_schema")]
19 pub icon: String,
20 #[schemars(title = "Код эффекта")]
21 pub code: String,
22 #[schemars(
23 title = "Опциональный интервал в тиках",
24 description = "Если указан – эффект будет выполняться в кроне с заданным интервалом"
25 )]
26 pub interval_ticks: Option<u64>,
27 #[schemars(
28 title = "Необходимые для эффекта аттрибуты",
29 description = "Эффект остановится при отсутствии перечисленных аттрибутов на Entity"
30 )]
31 pub required_attributes: Option<Vec<String>>,
32 #[schemars(title = "Опциональная подписка на ивенты")]
33 pub events_subscribe: Option<Vec<String>>,
34 #[schemars(title = "Является ли эффект позитивным/негативным")]
35 pub positive: bool,
36}
37
38impl Effect {
39 pub fn has_at_least_one_required_attribute(&self, attributes: &EntityAttributes) -> bool {
40 if let Some(required_attributes) = &self.required_attributes {
41 let contains_at_least_one = required_attributes
42 .iter()
43 .any(|attr| attributes.0.contains_key(attr));
44 return contains_at_least_one;
45 }
46 true
47 }
48}