Skip to content

Commit

Permalink
feat: Add artifacts, supports config2
Browse files Browse the repository at this point in the history
  • Loading branch information
wormtql committed Aug 30, 2024
1 parent 99ce836 commit d5e3c04
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 26 deletions.
1 change: 1 addition & 0 deletions mona_core/src/artifacts/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum ArtifactSetName {
FragmentOfHarmonicWhimsy,
UnfinishedReverie,
ScrollOfTheHeroOfCinderCity,
ObsidianCodex,
}

impl ArtifactSetName {
Expand Down
3 changes: 3 additions & 0 deletions mona_core/src/artifacts/artifact_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ pub trait ArtifactTrait {

#[cfg(not(target_family = "wasm"))]
const CONFIG4: Option<&'static [ItemConfig]> = None;

#[cfg(not(target_family = "wasm"))]
const CONFIG2: Option<&'static [ItemConfig]> = None;
}
10 changes: 10 additions & 0 deletions mona_core/src/artifacts/effect_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ pub struct ConfigScrollOfTheHeroOfCinder {
pub rate2: f64,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Clone, Default)]
pub struct ConfigObsidianCodex {
pub set2_rate: f64,
pub set4_rate: f64,
}

#[derive(Default, Debug, Clone)]
#[derive(Serialize, Deserialize)]
pub struct ArtifactEffectConfig {
Expand Down Expand Up @@ -222,6 +229,7 @@ pub struct ArtifactEffectConfig {
pub config_fragment_of_harmonic_whimsy: ConfigLevel,
pub config_unfinished_reverie: ConfigRate,
pub config_scroll_of_the_hero_of_cinder_city: ConfigScrollOfTheHeroOfCinder,
pub config_obsidian_codex: ConfigObsidianCodex,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -259,6 +267,7 @@ pub struct ArtifactConfigInterface {
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>,
pub config_obsidian_codex: Option<ConfigObsidianCodex>,
}

impl ArtifactConfigInterface {
Expand Down Expand Up @@ -296,6 +305,7 @@ impl ArtifactConfigInterface {
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(),
config_obsidian_codex: self.config_obsidian_codex.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 @@ -57,6 +57,7 @@ pub use nighttime_whispers_in_the_echoing_woods::NighttimeWhispersInTheEchoingWo
pub use fragment_of_harmonic_whimsy::FragmentOfHarmonicWhimsy;
pub use unfinished_reverie::UnfinishedReverie;
pub use scroll_of_the_hero_of_cinder_city::ScrollOfTheHeroOfCinderCity;
pub use obsidian_codex::ObsidianCodex;

pub mod empty;
pub mod adventurer;
Expand Down Expand Up @@ -111,6 +112,7 @@ 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 mod obsidian_codex;

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
101 changes: 101 additions & 0 deletions mona_core/src/artifacts/effects/obsidian_codex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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::i18n::locale;
use crate::common::item_config_type::{ItemConfig, ItemConfigType};

pub struct ObsidianCodexEffect {
pub set2_rate: f64,
pub set4_rate: f64,
}

impl<A: Attribute> ArtifactEffect<A> for ObsidianCodexEffect {
fn effect2(&self, attribute: &mut A) {
attribute.set_value_by(AttributeName::BonusBase, "黑曜秘典2", self.set2_rate * 0.15);
}

fn effect4(&self, attribute: &mut A) {
attribute.set_value_by(AttributeName::CriticalBase, "黑曜秘典4", self.set4_rate * 0.4);
}
}

pub struct ObsidianCodex;

impl ArtifactTrait for ObsidianCodex {
fn create_effect<A: Attribute>(config: &ArtifactEffectConfig, character_common_data: &CharacterCommonData) -> Box<dyn ArtifactEffect<A>> {
Box::new(ObsidianCodexEffect {
set2_rate: config.config_obsidian_codex.set2_rate,
set4_rate: config.config_obsidian_codex.set4_rate
})
}

#[cfg(not(target_family = "wasm"))]
const META_DATA: ArtifactMetaData = ArtifactMetaData {
name: ArtifactSetName::ObsidianCodex,
name_mona: "ObsidianCodex",
name_locale: locale!(
zh_cn: "黑曜秘典",
en: "Obsidian Codex"
),
flower: Some(locale!(
zh_cn: "异种的期许",
en: "Reckoning of the Xenogenic"
)),
feather: Some(locale!(
zh_cn: "灵髓的根脉",
en: "Root of the Spirit-Marrow"
)),
sand: Some(locale!(
zh_cn: "夜域的迷思",
en: "Myths of the Night Realm"
)),
goblet: Some(locale!(
zh_cn: "纷争的前宴",
en: "Pre-Banquet of the Contenders"
)),
head: Some(locale!(
zh_cn: "诸圣的礼冠",
en: "Crown of the Saints"
)),
star: (4, 5),
effect1: None,
effect2: Some(locale!(
zh_cn: "装备者处于夜魂加持状态,并且在场上时,造成的伤害提高15%。",
en: "While the equipping character is in Nightsoul's Blessing and is on the field, their DMG dealt is increased by 15%."
)),
effect3: None,
effect4: Some(locale!(
zh_cn: "装备者在场上消耗1点夜魂值后,暴击率提高40%,持续6秒。该效果每1秒至多触发一次。",
en: "After the equipping character consumes 1 Nightsoul point while on the field, CRIT Rate increases by 40% for 6s. This effect can trigger once every second."
)),
effect5: None,
internal_id: 15038,
};

#[cfg(not(target_family = "wasm"))]
const CONFIG4: Option<&'static [ItemConfig]> = Some(&[
ItemConfig {
name: "set4_rate",
title: locale!(
zh_cn: "四件套被动比例",
en: "4-Set Ratio"
),
config: ItemConfigType::Float { min: 0.0, max: 1.0, default: 0.0 }
}
]);

#[cfg(not(target_family = "wasm"))]
const CONFIG2: Option<&'static [ItemConfig]> = Some(&[
ItemConfig {
name: "set2_rate",
title: locale!(
zh_cn: "二件套被动比例",
en: "2-Set Ratio"
),
config: ItemConfigType::Float { min: 0.0, max: 1.0, default: 0.0 }
}
]);
}
12 changes: 11 additions & 1 deletion mona_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ pub fn derive_artifact_data(input: TokenStream) -> TokenStream {
let mut rows_effect = String::new();
let mut rows_meta = String::new();
let mut rows_config4 = String::new();
let mut rows_config2 = String::new();
for v in vars.iter() {
rows_effect.push_str(&format!("ArtifactSetName::{n} => crate::artifacts::effects::{n}::create_effect(config, common),\n", n=v));
rows_meta.push_str(&format!("ArtifactSetName::{n} => crate::artifacts::effects::{n}::META_DATA,\n", n=v));
rows_config4.push_str(&format!("ArtifactSetName::{n} => crate::artifacts::effects::{n}::CONFIG4,\n", n=v));
rows_config2.push_str(&format!("ArtifactSetName::{n} => crate::artifacts::effects::{n}::CONFIG2,\n", n=v))
}

let output = format!(
Expand Down Expand Up @@ -172,11 +174,19 @@ pub fn derive_artifact_data(input: TokenStream) -> TokenStream {
{rows_config4}
}}
}}
#[cfg(not(target_family = "wasm"))]
pub fn get_config2(&self) -> Option<&'static [ItemConfig]> {{
match *self {{
{rows_config2}
}}
}}
}}
"#,
rows_effect=rows_effect,
rows_meta=rows_meta,
rows_config4=rows_config4
rows_config4=rows_config4,
rows_config2=rows_config2
);

output.parse().unwrap()
Expand Down
3 changes: 3 additions & 0 deletions mona_generate/src/gen_meta/gen_artifact_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct ArtifactMeta {
effect4: Option<usize>,
effect5: Option<usize>,
config4: Vec<String>,
config2: Vec<String>,

flower: Option<usize>,
feather: Option<usize>,
Expand Down Expand Up @@ -58,6 +59,7 @@ pub fn gen_artifact_meta_as_js_file() -> String {
let e: ArtifactSetName = num::FromPrimitive::from_usize(i).unwrap();
let meta: ArtifactMetaData = e.get_meta();
let config4: Option<&'static [ItemConfig]> = e.get_config4();
let config2: Option<&'static [ItemConfig]> = e.get_config2();

let flower_icon: String = if let Some(_) = meta.flower { format!("UI_RelicIcon_{}_4", meta.internal_id) } else { String::new() };
let feather_icon: String = if let Some(_) = meta.feather { format!("UI_RelicIcon_{}_2", meta.internal_id) } else { String::new() };
Expand All @@ -77,6 +79,7 @@ pub fn gen_artifact_meta_as_js_file() -> String {
effect4: if let Some(ref x) = meta.effect4 { Some(*index_map.get(x).unwrap()) } else { None },
effect5: if let Some(ref x) = meta.effect5 { Some(*index_map.get(x).unwrap()) } else { None },
config4: config4.unwrap_or(&[]).iter().map(|x| config_to_json(x)).collect(),
config2: config2.unwrap_or(&[]).iter().map(|x| config_to_json(x)).collect(),
flower: if let Some(ref x) = meta.flower { Some(*index_map.get(x).unwrap()) } else { None },
feather: if let Some(ref x) = meta.feather { Some(*index_map.get(x).unwrap()) } else { None },
sand: if let Some(ref x) = meta.sand { Some(*index_map.get(x).unwrap()) } else { None },
Expand Down
5 changes: 5 additions & 0 deletions mona_generate/src/gen_meta/gen_locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ pub fn collect_config_locale() -> Vec<I18nLocale> {
set.insert(item.title.clone());
}
}
if let Some(x) = a.get_config2() {
for item in x.iter() {
set.insert(item.title.clone());
}
}
}

for pf in PotentialFunctionName::iter() {
Expand Down
5 changes: 5 additions & 0 deletions mona_generate/templates/artifact_meta_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export default {
{{ config|e("none") }},
{% endfor %}
],
config2: [
{% for config in a.config2 %}
{{ config|e("none") }},
{% endfor %}
],
},
{% endfor %}
}
79 changes: 69 additions & 10 deletions src/composables/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type {ArtifactSetName, IArtifact, IArtifactWasm} from "@/types/artifact"
import {artifactsData} from "@artifact"
import {convertArtifact, convertArtifactName} from "@/utils/converter"
import {toSnakeCase} from "@/utils/common"
import {newDefaultArtifactConfigForWasm} from "@/utils/artifacts"
import {getArtifactAllConfigsByName, newDefaultArtifactConfigForWasm} from "@/utils/artifacts"
import {useI18n} from "@/i18n/i18n"

export function use5Artifacts() {
const { t, ta } = useI18n()
const artifactStore = useArtifactStore()

const artifactIds = ref([-1, -1, -1, -1, -1])
// artifact set 4 config
// artifact set 2/4 config
const artifactSingleConfig = ref<any>(null)

const artifactItems = computed(() => {
Expand Down Expand Up @@ -61,9 +61,28 @@ export function use5Artifacts() {
return null
})

const artifactConfig4ItemName = computed((): string | null => {
if (artifactNeedConfig4.value) {
const setNameWasm = convertArtifactName(artifactNeedConfig4.value)
const artifactNeedConfig2 = computed((): ArtifactSetName | null => {
for (let setName in artifactSetCount.value) {
const count = artifactSetCount.value[setName]
if (count >= 2) {
const data = artifactsData[setName]
if (data.config2 && data.config2.length > 0) {
return setName
}
}
}

return null
})

const artifactConfigItemName = computed((): string | null => {
if (artifactNeedConfig4.value || artifactNeedConfig2.value) {
let setNameWasm;
if (artifactNeedConfig2.value) {
setNameWasm = convertArtifactName(artifactNeedConfig2.value);
} else if (artifactNeedConfig4.value) {
setNameWasm = convertArtifactName(artifactNeedConfig4.value)
}
return `config_${toSnakeCase(setNameWasm)}`
}
return null
Expand All @@ -77,6 +96,14 @@ export function use5Artifacts() {
return ta(data.effect4)
})

const artifactEffect2Text = computed((): string => {
if (!artifactNeedConfig2.value) {
return ""
}
const data = artifactsData[artifactNeedConfig2.value]
return ta(data.effect2)
})

const artifactConfig4Configs = computed(() => {
if (artifactNeedConfig4.value) {
const data = artifactsData[artifactNeedConfig4.value]
Expand All @@ -85,6 +112,14 @@ export function use5Artifacts() {
return []
})

const artifactConfig2Configs = computed(() => {
if (artifactNeedConfig2.value) {
const data = artifactsData[artifactNeedConfig2.value]
return data.config2
}
return []
})

const artifactWasmFormat = computed((): IArtifactWasm[] => {
let temp: IArtifactWasm[] = []
for (let id of artifactIds.value) {
Expand All @@ -103,7 +138,7 @@ export function use5Artifacts() {
let base = newDefaultArtifactConfigForWasm()

if (artifactNeedConfig4.value) {
let name = artifactConfig4ItemName.value as string
let name = artifactConfigItemName.value as string
base[name] = artifactSingleConfig.value[name]
}

Expand Down Expand Up @@ -140,10 +175,31 @@ export function use5Artifacts() {
if (!newName) {
artifactSingleConfig.value = null
} else {
const data = artifactsData[newName]
const configAll = getArtifactAllConfigsByName(newName)

let defaultConfig: any = {}
for (let c of configAll) {
defaultConfig[c.name] = c.default
}

const nameWasm = convertArtifactName(newName)
const configItemName = `config_${toSnakeCase(nameWasm)}`
artifactSingleConfig.value = {
[configItemName]: defaultConfig
}
}
}, {
flush: "sync"
})

watch(() => artifactNeedConfig2.value, newName => {
if (!newName) {
artifactSingleConfig.value = null
} else {
const configAll = getArtifactAllConfigsByName(newName)

let defaultConfig: any = {}
for (let c of data.config4) {
for (let c of configAll) {
defaultConfig[c.name] = c.default
}

Expand All @@ -166,13 +222,16 @@ export function use5Artifacts() {
artifactItems,
artifactSetCount,
artifactNeedConfig4,
artifactConfig4ItemName,
artifactNeedConfig2,
artifactConfigItemName,
artifactEffect4Text,
artifactEffect2Text,
artifactConfig4Configs,
artifactConfig2Configs,
artifactConfigForCalculator,

setArtifact,
removeArtifact,
toggleArtifact,
}
}
}
Loading

0 comments on commit d5e3c04

Please sign in to comment.