Skip to content

Commit

Permalink
feat: Add some artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
wormtql committed Aug 29, 2024
1 parent 817d0a1 commit 99ce836
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 34 deletions.
3 changes: 3 additions & 0 deletions mona_core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mona_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions mona_core/src/artifacts/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum ArtifactSetName {
NighttimeWhispersInTheEchoingWoods,
FragmentOfHarmonicWhimsy,
UnfinishedReverie,
ScrollOfTheHeroOfCinderCity,
}

impl ArtifactSetName {
Expand Down
14 changes: 13 additions & 1 deletion mona_core/src/artifacts/effect_config.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -248,6 +258,7 @@ pub struct ArtifactConfigInterface {
pub config_nighttime_whispers_in_the_echoing_woods: Option<ConfigNighttimeWhispersInTheEchoingWoods>,
pub config_fragment_of_harmonic_whimsy: Option<ConfigLevel>,
pub config_unfinished_reverie: Option<ConfigRate>,
pub config_scroll_of_the_hero_of_cinder_city: Option<ConfigScrollOfTheHeroOfCinder>,
}

impl ArtifactConfigInterface {
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions mona_core/src/artifacts/effects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T: Attribute>(name: ArtifactSetName, config: &ArtifactEffectConfig, character: &Character<T>) -> Box<dyn ArtifactEffect<T>> {
name.create_effect(config, &character.common_data)
Expand Down
119 changes: 119 additions & 0 deletions mona_core/src/artifacts/effects/scroll_of_the_hero_of_cinder_city.rs
Original file line number Diff line number Diff line change
@@ -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<A: Attribute> ArtifactEffect<A> 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<A: Attribute>(config: &ArtifactEffectConfig, character_common_data: &CharacterCommonData) -> Box<dyn ArtifactEffect<A>> {
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 }
}
]);
}
12 changes: 10 additions & 2 deletions mona_core/src/common/element.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,4 +14,10 @@ pub enum Element {
Anemo,
Hydro,
Physical,
}
}

impl Element {
pub fn from_number(i: usize) -> Element {
FromPrimitive::from_usize(i).unwrap_or(Element::Physical)
}
}
Loading

0 comments on commit 99ce836

Please sign in to comment.