From c3a120c551be74970d0b9e09205dfad63dc42f6b Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Mon, 7 Jun 2021 01:54:15 +0300 Subject: [PATCH] Post refactoring --- .../custom/mindflayer/summonminions.ron | 4 ++-- .../abilities/custom/tidalwarrior/totem.ron | 2 +- .../entity/dungeon/tier-5/beastmaster.ron | 12 +++++++++++ assets/common/entity/dungeon/tier-5/husk.ron | 8 ++++++++ common/src/comp/inventory/loadout_builder.rs | 10 +++++----- common/src/generation.rs | 17 ++++------------ common/src/states/basic_summon.rs | 12 +++++------ server/src/sys/terrain.rs | 20 ++++++------------- world/src/site/dungeon/mod.rs | 13 ++---------- 9 files changed, 46 insertions(+), 52 deletions(-) create mode 100644 assets/common/entity/dungeon/tier-5/beastmaster.ron create mode 100644 assets/common/entity/dungeon/tier-5/husk.ron diff --git a/assets/common/abilities/custom/mindflayer/summonminions.ron b/assets/common/abilities/custom/mindflayer/summonminions.ron index d26ecb51a4..99117ce2c0 100644 --- a/assets/common/abilities/custom/mindflayer/summonminions.ron +++ b/assets/common/abilities/custom/mindflayer/summonminions.ron @@ -10,7 +10,7 @@ BasicSummon( )), scale: None, health_scaling: 80, - loadout_config: Some(Husk), + loadout_config: Some(HuskSummon), skillset_config: None, ), -) \ No newline at end of file +) diff --git a/assets/common/abilities/custom/tidalwarrior/totem.ron b/assets/common/abilities/custom/tidalwarrior/totem.ron index 343f0e4c2d..31df64a7cd 100644 --- a/assets/common/abilities/custom/tidalwarrior/totem.ron +++ b/assets/common/abilities/custom/tidalwarrior/totem.ron @@ -10,4 +10,4 @@ BasicSummon( loadout_config: None, skillset_config: None, ), -) \ No newline at end of file +) diff --git a/assets/common/entity/dungeon/tier-5/beastmaster.ron b/assets/common/entity/dungeon/tier-5/beastmaster.ron new file mode 100644 index 0000000000..c34e9bc99e --- /dev/null +++ b/assets/common/entity/dungeon/tier-5/beastmaster.ron @@ -0,0 +1,12 @@ +EntityConfig ( + name: Some("Beastmaster"), + + main_tool: Some(Choice([ + (1.0, Some(Item("common.items.weapons.axe.malachite_axe-0"))), + (1.0, Some(Item("common.items.weapons.sword.bloodsteel-1"))), + (1.0, Some(Item("common.items.weapons.bow.velorite"))), + ])), + second_tool: None, + + loadout_config: Some("common.loadout.dungeon.tier-5.beastmaster"), +) diff --git a/assets/common/entity/dungeon/tier-5/husk.ron b/assets/common/entity/dungeon/tier-5/husk.ron new file mode 100644 index 0000000000..4e8bd6d35b --- /dev/null +++ b/assets/common/entity/dungeon/tier-5/husk.ron @@ -0,0 +1,8 @@ +EntityConfig ( + name: Some("Cultist Husk"), + + main_tool: None, + second_tool: None, + + loadout_config: Some("common.loadout.dungeon.tier-5.husk"), +) diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 4bf4cab6ff..0d8d6469a4 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -41,8 +41,8 @@ use tracing::warn; pub struct LoadoutBuilder(Loadout); #[derive(Copy, Clone, PartialEq, Deserialize, Serialize, Debug, EnumIter)] -pub enum LoadoutPreset { - Husk, +pub enum Preset { + HuskSummon, } #[derive(Debug, Deserialize, Clone)] @@ -426,10 +426,10 @@ impl LoadoutBuilder { } #[must_use] - pub fn with_preset(mut self, preset: LoadoutPreset) -> Self { + pub fn with_preset(mut self, preset: Preset) -> Self { let rng = &mut rand::thread_rng(); match preset { - LoadoutPreset::Husk => { + Preset::HuskSummon => { self = self.with_asset_expect("common.loadout.dungeon.tier-5.husk", rng) }, } @@ -671,7 +671,7 @@ mod tests { // Things that will be catched - invalid assets paths #[test] fn test_loadout_presets() { - for preset in LoadoutPreset::iter() { + for preset in Preset::iter() { std::mem::drop(LoadoutBuilder::default().with_preset(preset)); } } diff --git a/common/src/generation.rs b/common/src/generation.rs index 79959c5552..4cf13c361e 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -2,7 +2,7 @@ use crate::{ assets::{self, AssetExt}, comp::{ self, agent, humanoid, - inventory::loadout_builder::{ItemSpec, LoadoutBuilder, LoadoutPreset}, + inventory::loadout_builder::{ItemSpec, LoadoutBuilder}, Alignment, Body, Item, }, npc::{self, NPC_NAMES}, @@ -43,10 +43,7 @@ pub struct EntityInfo { // TODO: Properly give NPCs skills pub level: Option, pub loot_drop: Option, - // FIXME: using both preset and asset is silly, make it enum - // so it will be correct by construction pub loadout_config: Option, - pub loadout_preset: Option, pub make_loadout: Option) -> LoadoutBuilder>, pub skillset_config: Option, pub skillset_preset: Option, @@ -73,7 +70,6 @@ impl EntityInfo { level: None, loot_drop: None, loadout_config: None, - loadout_preset: None, make_loadout: None, skillset_config: None, skillset_preset: None, @@ -114,7 +110,7 @@ impl EntityInfo { } if let Some(loadout_config) = loadout_config { - self = self.with_loadout_config(&loadout_config); + self = self.with_loadout_config(loadout_config); } self @@ -187,13 +183,8 @@ impl EntityInfo { self } - pub fn with_loadout_preset(mut self, preset: LoadoutPreset) -> Self { - self.loadout_preset = Some(preset); - self - } - - pub fn with_loadout_config(mut self, config: &str) -> Self { - self.loadout_config = Some(config.to_owned()); + pub fn with_loadout_config(mut self, config: String) -> Self { + self.loadout_config = Some(config); self } diff --git a/common/src/states/basic_summon.rs b/common/src/states/basic_summon.rs index 5385dca55a..8b69c6a3ab 100644 --- a/common/src/states/basic_summon.rs +++ b/common/src/states/basic_summon.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ self, - inventory::loadout_builder::{LoadoutBuilder, LoadoutPreset}, + inventory::loadout_builder::{self, LoadoutBuilder}, Behavior, BehaviorCapability, CharacterState, StateUpdate, }, event::{LocalEvent, ServerEvent}, @@ -79,7 +79,7 @@ impl CharacterBehavior for Data { let mut loadout_builder = LoadoutBuilder::new().with_default_maintool(&body); - if let Some(preset) = self.static_data.summon_info.loadout_preset { + if let Some(preset) = self.static_data.summon_info.loadout_config { loadout_builder = loadout_builder.with_preset(preset); } @@ -88,7 +88,7 @@ impl CharacterBehavior for Data { let stats = comp::Stats::new("Summon".to_string()); let skill_set = SkillSetBuilder::build_skillset( &None, - self.static_data.summon_info.skillset_preset, + self.static_data.summon_info.skillset_config, ) .build(); @@ -177,7 +177,7 @@ pub struct SummonInfo { body: comp::Body, scale: Option, health_scaling: u16, - // TODO: use assets for specifying skills and loadouts? - loadout_preset: Option, - skillset_preset: Option, + // TODO: use assets for specifying skills and loadout? + loadout_config: Option, + skillset_config: Option, } diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 9925a5926a..b4decd5bad 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -197,7 +197,6 @@ impl<'a> System<'a> for Sys { let EntityInfo { skillset_preset, main_tool, - loadout_preset, loadout_config, make_loadout, trading_information: economy, @@ -217,20 +216,13 @@ impl<'a> System<'a> for Sys { loadout_builder = loadout_builder.with_default_maintool(&body); } - // If there are configs, apply them - match (loadout_preset, &loadout_config) { - (Some(preset), Some(config)) => { - loadout_builder = loadout_builder.with_preset(preset); - loadout_builder = loadout_builder.with_asset_expect(&config, rng); + // If there is config, apply it. + // If not, use default equipement for this body. + match loadout_config { + Some(asset) => { + loadout_builder = loadout_builder.with_asset_expect(&asset, rng); }, - (Some(preset), None) => { - loadout_builder = loadout_builder.with_preset(preset); - }, - (None, Some(config)) => { - loadout_builder = loadout_builder.with_asset_expect(&config, rng); - }, - // If not, use default equipement for this body - (None, None) => { + None => { loadout_builder = loadout_builder.with_default_equipment(&body); }, } diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index 86b8401b06..dc06ebc758 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -1257,17 +1257,9 @@ fn mini_boss_5(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3) -> Vec "common.items.weapons.axe.malachite_axe-0", - 1 => "common.items.weapons.sword.bloodsteel-1", - _ => "common.items.weapons.bow.velorite", - }, - )), + .with_asset_expect("common.entity.dungeon.tier-5.beastmaster"), ); entities.resize_with(entities.len() + 2, || { EntityInfo::at(tile_wcenter.map(|e| e as f32)) @@ -1292,9 +1284,8 @@ fn mini_boss_5(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3) -> Vec