diff --git a/.gitlab/scripts/code-quality.sh b/.gitlab/scripts/code-quality.sh index a8556c3942..3016bc0a7f 100755 --- a/.gitlab/scripts/code-quality.sh +++ b/.gitlab/scripts/code-quality.sh @@ -1,5 +1,5 @@ #!/bin/bash -time cargo clippy --all-targets --locked --features="bin_cmd_doc_gen,bin_compression,bin_csv,bin_graphviz,bin_bot,asset_tweak" -- -D warnings && +time cargo clippy --all-targets --locked --features="bin_cmd_doc_gen,bin_compression,bin_csv,bin_graphviz,bin_bot,bin_entity_migrate, asset_tweak" -- -D warnings && # Ensure that the veloren-voxygen default-publish feature builds as it excludes some default features time cargo clippy -p veloren-voxygen --locked --no-default-features --features="default-publish" -- -D warnings && time cargo fmt --all -- --check diff --git a/common/src/bin/entity_migrate.rs b/common/src/bin/entity_migrate.rs index cc8a77fd9e..3d3113449c 100644 --- a/common/src/bin/entity_migrate.rs +++ b/common/src/bin/entity_migrate.rs @@ -272,7 +272,7 @@ fn convert_loop(from: &str, to: &str, old_ver: &str, new_ver: &str) { let root = Path::new(from); let files = Walk::Dir { path: Path::new("").to_owned(), - content: walk_tree(&root, &root).unwrap(), + content: walk_tree(root, root).unwrap(), }; if old_ver == "v1" && new_ver == "v2" { walk_with_migrate::( diff --git a/common/src/event.rs b/common/src/event.rs index f5dd7d6e4e..34d36f3017 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -128,7 +128,7 @@ pub enum ServerEvent { skill_set: comp::SkillSet, health: Option, poise: comp::Poise, - loadout: comp::inventory::loadout::Loadout, + inventory: comp::inventory::Inventory, body: comp::Body, agent: Option, alignment: comp::Alignment, diff --git a/common/src/generation.rs b/common/src/generation.rs index 8637ee5050..f100c721d8 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -185,7 +185,7 @@ pub struct EntityInfo { pub loot: LootSpec, // Loadout pub inventory: Vec<(u32, Item)>, - pub loadout: Option, + pub loadout: LoadoutBuilder, pub make_loadout: Option) -> LoadoutBuilder>, // Skills pub skillset_asset: Option, @@ -212,7 +212,7 @@ impl EntityInfo { scale: 1.0, loot: LootSpec::Nothing, inventory: vec![], - loadout: None, + loadout: LoadoutBuilder::empty(), make_loadout: None, skillset_asset: None, pet: None, @@ -322,7 +322,7 @@ impl EntityInfo { // NOTE: helpder function, think twice before exposing it fn with_default_equip(mut self) -> Self { let loadout_builder = LoadoutBuilder::from_default(&self.body); - self.loadout = Some(loadout_builder); + self.loadout = loadout_builder; self } @@ -335,7 +335,7 @@ impl EntityInfo { LoadoutAsset::Loadout(asset) => { let mut rng = rand::thread_rng(); let loadout = LoadoutBuilder::from_asset_expect(&asset, Some(&mut rng)); - self.loadout = Some(loadout); + self.loadout = loadout; }, LoadoutAsset::Choice(assets) => { let mut rng = rand::thread_rng(); @@ -343,8 +343,8 @@ impl EntityInfo { .choose_weighted(&mut rng, |(p, _asset)| *p) .expect("rng error"); - let loadout = LoadoutBuilder::from_asset_expect(&asset, Some(&mut rng)); - self.loadout = Some(loadout); + let loadout = LoadoutBuilder::from_asset_expect(asset, Some(&mut rng)); + self.loadout = loadout; }, } @@ -352,20 +352,16 @@ impl EntityInfo { } #[must_use] - /// Return EntityInfo, create new loadout if needed + /// Return EntityInfo with weapons applied to LoadoutBuilder // NOTE: helpder function, think twice before exposing it fn with_hands(mut self, hands: Hands, config_asset: Option<&str>) -> Self { let rng = &mut rand::thread_rng(); - if self.loadout.is_none() { - self.loadout = Some(LoadoutBuilder::empty()); - } - match hands { Hands::TwoHanded(main_tool) => { let tool = main_tool.try_to_item(config_asset.unwrap_or("??"), rng); if let Some(tool) = tool { - self.loadout = self.loadout.map(|l| l.active_mainhand(Some(tool))); + self.loadout = self.loadout.active_mainhand(Some(tool)); } }, Hands::Paired(tool) => { @@ -375,20 +371,21 @@ impl EntityInfo { let second_tool = tool.try_to_item(config_asset.unwrap_or("??"), rng); if let Some(main_tool) = main_tool { - self.loadout = self.loadout.map(|l| l.active_mainhand(Some(main_tool))); + self.loadout = self.loadout.active_mainhand(Some(main_tool)); } if let Some(second_tool) = second_tool { - self.loadout = self.loadout.map(|l| l.active_offhand(Some(second_tool))); + self.loadout = self.loadout.active_offhand(Some(second_tool)); } }, Hands::Mix { mainhand, offhand } => { let main_tool = mainhand.try_to_item(config_asset.unwrap_or("??"), rng); let second_tool = offhand.try_to_item(config_asset.unwrap_or("??"), rng); + if let Some(main_tool) = main_tool { - self.loadout = self.loadout.map(|l| l.active_mainhand(Some(main_tool))); + self.loadout = self.loadout.active_mainhand(Some(main_tool)); } if let Some(second_tool) = second_tool { - self.loadout = self.loadout.map(|l| l.active_offhand(Some(second_tool))); + self.loadout = self.loadout.active_offhand(Some(second_tool)); } }, } diff --git a/common/src/states/basic_summon.rs b/common/src/states/basic_summon.rs index 08c1e24575..317e4b183f 100644 --- a/common/src/states/basic_summon.rs +++ b/common/src/states/basic_summon.rs @@ -179,7 +179,7 @@ impl CharacterBehavior for Data { skill_set, health, poise: comp::Poise::new(body), - loadout, + inventory: comp::Inventory::new_with_loadout(loadout), body, agent: Some( comp::Agent::from_body(&body) diff --git a/server/src/cmd.rs b/server/src/cmd.rs index c9a4787b08..83c7bc6900 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -631,7 +631,7 @@ fn handle_make_npc( return Err("Waypoint spawning is not implemented".to_owned()); }, NpcData::Data { - loadout, + inventory, pos, stats, skill_set, @@ -643,8 +643,6 @@ fn handle_make_npc( scale, loot, } => { - let inventory = Inventory::new_with_loadout(loadout); - let mut entity_builder = server .state .create_npc(pos, stats, skill_set, health, poise, inventory, body) diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 3402009ac3..2df15f1795 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -7,7 +7,6 @@ use common::{ aura::{Aura, AuraKind, AuraTarget}, beam, buff::{BuffCategory, BuffData, BuffKind, BuffSource}, - inventory::loadout::Loadout, shockwave, Agent, Alignment, Anchor, Body, Health, Inventory, ItemDrop, LightEmitter, Object, Ori, PidController, Poise, Pos, Projectile, Scale, SkillSet, Stats, Vel, WaypointArea, @@ -51,7 +50,7 @@ pub fn handle_create_npc( skill_set: SkillSet, health: Option, poise: Poise, - loadout: Loadout, + inventory: Inventory, body: Body, agent: impl Into>, alignment: Alignment, @@ -61,8 +60,6 @@ pub fn handle_create_npc( rtsim_entity: Option, projectile: Option, ) { - let inventory = Inventory::new_with_loadout(loadout); - let entity = server .state .create_npc(pos, stats, skill_set, health, poise, inventory, body) diff --git a/server/src/events/mod.rs b/server/src/events/mod.rs index 82c733389e..56ad177b26 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -155,7 +155,7 @@ impl Server { skill_set, health, poise, - loadout, + inventory, body, agent, alignment, @@ -171,7 +171,7 @@ impl Server { skill_set, health, poise, - loadout, + inventory, body, agent, alignment, diff --git a/server/src/rtsim/tick.rs b/server/src/rtsim/tick.rs index e97dd6985a..234a20824a 100644 --- a/server/src/rtsim/tick.rs +++ b/server/src/rtsim/tick.rs @@ -151,7 +151,7 @@ impl<'a> System<'a> for Sys { skill_set, health, poise, - loadout, + inventory, agent, body, alignment, @@ -163,7 +163,7 @@ impl<'a> System<'a> for Sys { skill_set, health, poise, - loadout, + inventory, agent, body, alignment, diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 2a4ff94060..a16670d620 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -25,8 +25,9 @@ use common::{ resources::{Time, TimeOfDay}, slowjob::SlowJobPool, terrain::TerrainGrid, - LoadoutBuilder, SkillSetBuilder, + SkillSetBuilder, }; + use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{SerializedTerrainChunk, ServerGeneral}; use common_state::TerrainChanges; @@ -250,7 +251,7 @@ impl<'a> System<'a> for Sys { skill_set, health, poise, - loadout, + inventory, agent, body, alignment, @@ -263,7 +264,7 @@ impl<'a> System<'a> for Sys { skill_set, health, poise, - loadout, + inventory, agent, body, alignment, @@ -391,7 +392,7 @@ pub enum NpcData { skill_set: comp::SkillSet, health: Option, poise: comp::Poise, - loadout: comp::inventory::loadout::Loadout, + inventory: comp::inventory::Inventory, agent: Option, body: comp::Body, alignment: comp::Alignment, @@ -402,7 +403,7 @@ pub enum NpcData { } impl NpcData { - pub fn from_entity_info(entity: EntityInfo, loadout_rng: &mut impl Rng) -> Self { + pub fn from_entity_info(entity: EntityInfo, _loadout_rng: &mut impl Rng) -> Self { let EntityInfo { // flags is_waypoint, @@ -417,9 +418,8 @@ impl NpcData { loot, // tools and skills skillset_asset, - main_tool, - second_tool, - loadout_asset, + loadout: mut loadout_builder, + inventory: items, make_loadout, trading_information: economy, // unused @@ -442,34 +442,20 @@ impl NpcData { } }; - let loadout = { - let mut loadout_builder = LoadoutBuilder::empty(); - - // If main tool is passed, use it. Otherwise fallback to default tool - if let Some(main_tool) = main_tool { - loadout_builder = loadout_builder.active_mainhand(Some(main_tool)); - } else { - loadout_builder = loadout_builder.with_default_maintool(&body); - } - - // If second tool is passed, use it as well - if let Some(second_tool) = second_tool { - loadout_builder = loadout_builder.active_offhand(Some(second_tool)); - } - - // If there is config, apply it. - // If not, use default equipement for this body. - if let Some(asset) = loadout_asset { - loadout_builder = loadout_builder.with_asset_expect(&asset, loadout_rng); - } else { - loadout_builder = loadout_builder.with_default_equipment(&body); - } - + let inventory = { // Evaluate lazy function for loadout creation if let Some(make_loadout) = make_loadout { loadout_builder = loadout_builder.with_creator(make_loadout, economy.as_ref()); } - loadout_builder.build() + let loadout = loadout_builder.build(); + let mut inventory = comp::inventory::Inventory::new_with_loadout(loadout); + for (num, mut item) in items { + // I don't think we can produce any helpful error there. + let _ = item.set_amount(num); + let _ = inventory.push(item); + } + + inventory }; let health_level = skill_set @@ -519,7 +505,7 @@ impl NpcData { skill_set, health, poise, - loadout, + inventory, agent, body, alignment,