From 99ce836acae5d57cfa7ec90af1206dc390e8fbd3 Mon Sep 17 00:00:00 2001 From: wormtql <584130248@qq.com> Date: Fri, 30 Aug 2024 00:28:45 +0800 Subject: [PATCH] feat: Add some artifact --- mona_core/Cargo.lock | 3 + mona_core/Cargo.toml | 2 +- mona_core/src/artifacts/artifact.rs | 1 + mona_core/src/artifacts/effect_config.rs | 14 +- mona_core/src/artifacts/effects/mod.rs | 2 + .../scroll_of_the_hero_of_cinder_city.rs | 119 ++++++++++++++ mona_core/src/common/element.rs | 12 +- mona_core/src/common/item_config_type.rs | 145 +++++++++++++++++- mona_generate/Cargo.lock | 31 +++- mona_generate/Cargo.toml | 2 +- mona_generate/src/utils/mod.rs | 8 + mona_wasm/Cargo.lock | 3 + src/components.d.ts | 1 + src/components/config/ConfigItem.vue | 8 +- src/components/select/SelectElementMulti.vue | 47 ++++-- src/store/modules/artifact.js | 3 +- src/store/pinia/artifact.ts | 6 +- src/utils/artifacts.ts | 4 +- 18 files changed, 377 insertions(+), 34 deletions(-) create mode 100644 mona_core/src/artifacts/effects/scroll_of_the_hero_of_cinder_city.rs diff --git a/mona_core/Cargo.lock b/mona_core/Cargo.lock index 1f1aac2f..0eb4855a 100644 --- a/mona_core/Cargo.lock +++ b/mona_core/Cargo.lock @@ -562,6 +562,9 @@ name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +dependencies = [ + "serde", +] [[package]] name = "strum" diff --git a/mona_core/Cargo.toml b/mona_core/Cargo.toml index 445d9c82..dc193520 100644 --- a/mona_core/Cargo.toml +++ b/mona_core/Cargo.toml @@ -29,7 +29,7 @@ getrandom = { version = "0.2", features = ["js"] } num = "0.4" num-derive = "0.4.2" num-traits = "0.2" -smallvec = "1.8.0" +smallvec = { version = "1.8.0", features = ["serde"] } askama = "0.12" askama_escape = "0.10.2" strum = { version = "0.26" } diff --git a/mona_core/src/artifacts/artifact.rs b/mona_core/src/artifacts/artifact.rs index 1320781d..6a788cc3 100644 --- a/mona_core/src/artifacts/artifact.rs +++ b/mona_core/src/artifacts/artifact.rs @@ -74,6 +74,7 @@ pub enum ArtifactSetName { NighttimeWhispersInTheEchoingWoods, FragmentOfHarmonicWhimsy, UnfinishedReverie, + ScrollOfTheHeroOfCinderCity, } impl ArtifactSetName { diff --git a/mona_core/src/artifacts/effect_config.rs b/mona_core/src/artifacts/effect_config.rs index 1e123732..be34898d 100644 --- a/mona_core/src/artifacts/effect_config.rs +++ b/mona_core/src/artifacts/effect_config.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; - +use smallvec::SmallVec; use crate::common::Element; +use crate::common::item_config_type::ConfigElements8Multi; use crate::common::max_trait::MaxValue; #[derive(Serialize, Deserialize)] @@ -178,6 +179,14 @@ pub struct ConfigNighttimeWhispersInTheEchoingWoods { pub rate2: f64, } +#[derive(Serialize, Deserialize)] +#[derive(Debug, Clone, Default)] +pub struct ConfigScrollOfTheHeroOfCinder { + pub elements: ConfigElements8Multi, + pub rate1: f64, + pub rate2: f64, +} + #[derive(Default, Debug, Clone)] #[derive(Serialize, Deserialize)] pub struct ArtifactEffectConfig { @@ -212,6 +221,7 @@ pub struct ArtifactEffectConfig { pub config_nighttime_whispers_in_the_echoing_woods: ConfigNighttimeWhispersInTheEchoingWoods, pub config_fragment_of_harmonic_whimsy: ConfigLevel, pub config_unfinished_reverie: ConfigRate, + pub config_scroll_of_the_hero_of_cinder_city: ConfigScrollOfTheHeroOfCinder, } #[derive(Serialize, Deserialize)] @@ -248,6 +258,7 @@ pub struct ArtifactConfigInterface { pub config_nighttime_whispers_in_the_echoing_woods: Option, pub config_fragment_of_harmonic_whimsy: Option, pub config_unfinished_reverie: Option, + pub config_scroll_of_the_hero_of_cinder_city: Option, } impl ArtifactConfigInterface { @@ -284,6 +295,7 @@ impl ArtifactConfigInterface { config_nighttime_whispers_in_the_echoing_woods: self.config_nighttime_whispers_in_the_echoing_woods.unwrap_or(Default::default()), config_fragment_of_harmonic_whimsy: self.config_fragment_of_harmonic_whimsy.unwrap_or_default(), config_unfinished_reverie: self.config_unfinished_reverie.unwrap_or_default(), + config_scroll_of_the_hero_of_cinder_city: self.config_scroll_of_the_hero_of_cinder_city.unwrap_or_default(), } } } diff --git a/mona_core/src/artifacts/effects/mod.rs b/mona_core/src/artifacts/effects/mod.rs index 34a35846..129ac829 100644 --- a/mona_core/src/artifacts/effects/mod.rs +++ b/mona_core/src/artifacts/effects/mod.rs @@ -56,6 +56,7 @@ pub use song_of_days_past::SongOfDaysPast; pub use nighttime_whispers_in_the_echoing_woods::NighttimeWhispersInTheEchoingWoods; pub use fragment_of_harmonic_whimsy::FragmentOfHarmonicWhimsy; pub use unfinished_reverie::UnfinishedReverie; +pub use scroll_of_the_hero_of_cinder_city::ScrollOfTheHeroOfCinderCity; pub mod empty; pub mod adventurer; @@ -109,6 +110,7 @@ pub mod song_of_days_past; pub mod nighttime_whispers_in_the_echoing_woods; pub mod fragment_of_harmonic_whimsy; pub mod unfinished_reverie; +pub mod scroll_of_the_hero_of_cinder_city; pub fn get_effect(name: ArtifactSetName, config: &ArtifactEffectConfig, character: &Character) -> Box> { name.create_effect(config, &character.common_data) diff --git a/mona_core/src/artifacts/effects/scroll_of_the_hero_of_cinder_city.rs b/mona_core/src/artifacts/effects/scroll_of_the_hero_of_cinder_city.rs new file mode 100644 index 00000000..4e8557a9 --- /dev/null +++ b/mona_core/src/artifacts/effects/scroll_of_the_hero_of_cinder_city.rs @@ -0,0 +1,119 @@ +use smallvec::{SmallVec, smallvec}; +use crate::artifacts::artifact_trait::{ArtifactMetaData, ArtifactTrait}; +use crate::artifacts::ArtifactSetName; +use crate::artifacts::effect::ArtifactEffect; +use crate::artifacts::effect_config::ArtifactEffectConfig; +use crate::attribute::{Attribute, AttributeName}; +use crate::character::character_common_data::CharacterCommonData; +use crate::common::Element; +use crate::common::i18n::locale; +use crate::common::item_config_type::{ConfigElements8Multi, ItemConfig, ItemConfigType}; + +pub struct ScrollOfTheHeroOfCinderCityEffect { + pub elements: ConfigElements8Multi, + pub rate1: f64, + pub rate2: f64, +} + +impl ArtifactEffect for ScrollOfTheHeroOfCinderCityEffect { + fn effect4(&self, attribute: &mut A) { + for &element in self.elements.collect_elements().iter() { + let bonus_attribute_name = AttributeName::bonus_name_by_element(element); + attribute.set_value_by(bonus_attribute_name, "烬城勇者绘卷4", self.rate1 * 0.12 + self.rate2 * 0.28); + } + } +} + +pub struct ScrollOfTheHeroOfCinderCity; + +impl ArtifactTrait for ScrollOfTheHeroOfCinderCity { + fn create_effect(config: &ArtifactEffectConfig, character_common_data: &CharacterCommonData) -> Box> { + Box::new(ScrollOfTheHeroOfCinderCityEffect { + elements: config.config_scroll_of_the_hero_of_cinder_city.elements.clone(), + rate1: config.config_scroll_of_the_hero_of_cinder_city.rate1, + rate2: config.config_scroll_of_the_hero_of_cinder_city.rate2 + }) + } + + #[cfg(not(target_family = "wasm"))] + const META_DATA: ArtifactMetaData = ArtifactMetaData { + name: ArtifactSetName::ScrollOfTheHeroOfCinderCity, + name_mona: "ScrollOfTheHeroOfCinderCity", + name_locale: locale!( + zh_cn: "烬城勇者绘卷", + en: "Scroll of the Hero of Cinder City" + ), + flower: Some(locale!( + zh_cn: "驯兽师的护符", + en: "Beast Tamer's Talisman" + )), + feather: Some(locale!( + zh_cn: "巡山客的信标", + en: "Mountain Ranger's Marker" + )), + sand: Some(locale!( + zh_cn: "秘术家的金盘", + en: "Mystic's Gold Dial" + )), + goblet: Some(locale!( + zh_cn: "游学者的爪杯", + en: "Wandering Scholar's Claw Cup" + )), + head: Some(locale!( + zh_cn: "魔战士的羽面", + en: "Demon-Warrior's Feather Mask" + )), + star: (4, 5), + effect1: None, + effect2: Some(locale!( + zh_cn: "队伍中附近的角色触发「夜魂迸发」时,装备者恢复6点元素能量。", + en: "When a nearby party member triggers a Nightsoul Burst, the equipping character regenerates 6 Elemental Energy." + )), + effect3: None, + effect4: Some(locale!( + zh_cn: "装备者触发其对应元素类型的相关反应后,队伍中附近的所有角色的该元素反应相关的元素伤害加成提升12%,持续15秒。若触发该效果时,装备者处于夜魂加持状态下,还将使队伍中附近的所有角色的与该元素反应相关的元素伤害加成提升28%,持续20秒。装备者处于后台时也能触发上述效果。同名圣遗物套装产生的伤害加成效果无法叠加。", + en: "After the equipping character triggers a reaction related to their Elemental Type, all nearby party members gain a 12% Elemental DMG Bonus for the Elemental Types involved in the elemental reaction for 15s. If the equipping character is in the Nightsoul's Blessing state when triggering this effect, all nearby party members gain an additional 28% Elemental DMG Bonus for the Elemental Types involved in the elemental reaction for 20s. The equipping character can trigger this effect while off-field, and the DMG bonus from Artifact Sets with the same name do not stack." + )), + effect5: None, + internal_id: 15037, + }; + + #[cfg(not(target_family = "wasm"))] + const CONFIG4: Option<&'static [ItemConfig]> = Some(&[ + ItemConfig { + name: "elements", + title: locale!( + zh_cn: "元素", + en: "Elements" + ), + config: ItemConfigType::Element8Multi { + default: ConfigElements8Multi { + pyro: false, + electro: false, + dendro: false, + cryo: false, + anemo: false, + geo: false, + hydro: false, + physical: false, + } + } + }, + ItemConfig { + name: "rate1", + title: locale!( + zh_cn: "效果1比例", + en: "Ratio 1" + ), + config: ItemConfigType::Float { min: 0.0, max: 1.0, default: 0.0 } + }, + ItemConfig { + name: "rate2", + title: locale!( + zh_cn: "效果2比例", + en: "Ratio 2" + ), + config: ItemConfigType::Float { min: 0.0, max: 1.0, default: 0.0 } + } + ]); +} \ No newline at end of file diff --git a/mona_core/src/common/element.rs b/mona_core/src/common/element.rs index 79e4344d..0c436c5f 100644 --- a/mona_core/src/common/element.rs +++ b/mona_core/src/common/element.rs @@ -1,7 +1,9 @@ use serde::{Serialize, Deserialize}; use strum_macros::Display; +use num_derive::FromPrimitive; +use num_traits::FromPrimitive; -#[derive(Serialize, Deserialize, Display)] +#[derive(Serialize, Deserialize, Display, FromPrimitive)] #[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)] pub enum Element { Electro, @@ -12,4 +14,10 @@ pub enum Element { Anemo, Hydro, Physical, -} \ No newline at end of file +} + +impl Element { + pub fn from_number(i: usize) -> Element { + FromPrimitive::from_usize(i).unwrap_or(Element::Physical) + } +} diff --git a/mona_core/src/common/item_config_type.rs b/mona_core/src/common/item_config_type.rs index 2b95b40f..529311a6 100644 --- a/mona_core/src/common/item_config_type.rs +++ b/mona_core/src/common/item_config_type.rs @@ -1,7 +1,139 @@ +use std::fmt::Formatter; +use std::marker::PhantomData; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::de::{SeqAccess, Visitor}; +use serde::ser::SerializeSeq; use serde_json::json; +use smallvec::{SmallVec}; use crate::common::{Element, SkillType}; use crate::common::i18n::{I18nLocale, locale}; +#[derive(Default, Debug, Clone, Copy)] +pub struct ConfigElements8Multi { + pub pyro: bool, + pub electro: bool, + pub dendro: bool, + pub cryo: bool, + pub anemo: bool, + pub geo: bool, + pub hydro: bool, + pub physical: bool, +} + +impl ConfigElements8Multi { + pub fn collect_elements(&self) -> Vec { + let mut ret = Vec::new(); + if self.pyro { + ret.push(Element::Pyro); + } + if self.electro { + ret.push(Element::Electro); + } + if self.dendro { + ret.push(Element::Dendro); + } + if self.cryo { + ret.push(Element::Cryo); + } + if self.anemo { + ret.push(Element::Anemo); + } + if self.geo { + ret.push(Element::Geo); + } + if self.hydro { + ret.push(Element::Hydro); + } + if self.physical { + ret.push(Element::Physical); + } + ret + } +} + +impl Serialize for ConfigElements8Multi { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut root = serializer.serialize_seq(None)?; + if self.pyro { + root.serialize_element(&Element::Pyro)?; + } + if self.electro { + root.serialize_element(&Element::Electro)?; + } + if self.dendro { + root.serialize_element(&Element::Dendro)?; + } + if self.cryo { + root.serialize_element(&Element::Cryo)?; + } + if self.anemo { + root.serialize_element(&Element::Anemo)?; + } + if self.geo { + root.serialize_element(&Element::Geo)?; + } + if self.hydro { + root.serialize_element(&Element::Hydro)?; + } + if self.physical { + root.serialize_element(&Element::Physical)?; + } + + root.end() + } +} + +struct ConfigElements8MultiVisitor; + +impl<'de> Visitor<'de> for ConfigElements8MultiVisitor { + type Value = ConfigElements8Multi; + + fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result { + formatter.write_str("expecting an array of elements") + } + + fn visit_seq(self, mut seq: A) -> Result + where + A: SeqAccess<'de>, + { + let mut ret = ConfigElements8Multi::default(); + while let Some(item) = seq.next_element::()? { + if item == Element::Pyro { + ret.pyro = true; + } else if item == Element::Electro { + ret.electro = true; + } else if item == Element::Anemo { + ret.anemo = true; + } else if item == Element::Cryo { + ret.cryo = true; + } else if item == Element::Geo { + ret.geo = true; + } else if item == Element::Hydro { + ret.hydro = true; + } else if item == Element::Dendro { + ret.dendro = true; + } else if item == Element::Physical { + ret.physical = true; + } + } + Ok(ret) + } +} + + + +impl<'de> Deserialize<'de> for ConfigElements8Multi { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_seq(ConfigElements8MultiVisitor) + } +} + pub enum ItemConfigType { Float { min: f64, @@ -42,6 +174,9 @@ pub enum ItemConfigType { Element8 { default: Element }, + Element8Multi { + default: ConfigElements8Multi + }, Skill4 { default: SkillType } @@ -55,7 +190,7 @@ pub struct ItemConfig { impl ItemConfigType { pub fn to_json(&self, title: &str, name: &str) -> String { - let j = match *self { + let j = match self { ItemConfigType::Skill4 { default } => { json!({ "type": "skill4", @@ -143,6 +278,14 @@ impl ItemConfigType { "default": default, "options": temp }) + }, + ItemConfigType::Element8Multi { default } => { + json!({ + "type": "element8multi", + "title": title, + "name": name, + "default": default + }) } }; diff --git a/mona_generate/Cargo.lock b/mona_generate/Cargo.lock index ae519493..a0877821 100644 --- a/mona_generate/Cargo.lock +++ b/mona_generate/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -366,9 +366,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -700,9 +700,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.6" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -711,9 +723,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustc-hash" @@ -793,6 +805,9 @@ name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +dependencies = [ + "serde", +] [[package]] name = "strsim" diff --git a/mona_generate/Cargo.toml b/mona_generate/Cargo.toml index 200174b0..ebc2f705 100644 --- a/mona_generate/Cargo.toml +++ b/mona_generate/Cargo.toml @@ -30,4 +30,4 @@ rustc-hash = "1.1.0" clap = { version = "3.1.18", features = ["derive"] } edit-distance = "2.1.0" serde_yaml = "0.8" -regex = { version = "1.5.6", features = ["pattern"] } +regex = { version = "1.10.6", features = ["pattern"] } diff --git a/mona_generate/src/utils/mod.rs b/mona_generate/src/utils/mod.rs index 8a76bc42..b97c28ae 100644 --- a/mona_generate/src/utils/mod.rs +++ b/mona_generate/src/utils/mod.rs @@ -99,6 +99,14 @@ pub fn config_to_json(config: &ItemConfig) -> String { "default": default, "options": temp }) + }, + ItemConfigType::Element8Multi { default } => { + json!({ + "type": "element8multi", + "title": title_index, + "name": name, + "default": default, + }) } }; diff --git a/mona_wasm/Cargo.lock b/mona_wasm/Cargo.lock index f34b3ef0..adabe43d 100644 --- a/mona_wasm/Cargo.lock +++ b/mona_wasm/Cargo.lock @@ -666,6 +666,9 @@ name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +dependencies = [ + "serde", +] [[package]] name = "strum" diff --git a/src/components.d.ts b/src/components.d.ts index 47043d15..96a79620 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -29,6 +29,7 @@ declare module '@vue/runtime-core' { ElCard: typeof import('element-plus/es')['ElCard'] ElCascader: typeof import('element-plus/es')['ElCascader'] ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] + ElCheckboxButton: typeof import('element-plus/es')['ElCheckboxButton'] ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup'] ElCol: typeof import('element-plus/es')['ElCol'] ElCollapse: typeof import('element-plus/es')['ElCollapse'] diff --git a/src/components/config/ConfigItem.vue b/src/components/config/ConfigItem.vue index d7fd9fee..8d52d84f 100644 --- a/src/components/config/ConfigItem.vue +++ b/src/components/config/ConfigItem.vue @@ -66,6 +66,12 @@ :elements="['Pyro', 'Cryo', 'Electro', 'Hydro', 'Anemo', 'Geo', 'Dendro', 'Physical']" > +