From ced5293d15506f1bcfa8fca5ba8b39d00a978934 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 21 May 2021 14:33:19 +0300 Subject: [PATCH 1/2] Add tests to loadout builder --- common/src/comp/inventory/loadout_builder.rs | 96 +++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 030851e417..09b9425b8a 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -13,6 +13,7 @@ use crate::{ }; use rand::Rng; use serde::{Deserialize, Serialize}; +use strum_macros::EnumIter; use tracing::warn; /// Builder for character Loadouts, containing weapon and armour items belonging @@ -36,7 +37,7 @@ use tracing::warn; #[derive(Clone)] pub struct LoadoutBuilder(Loadout); -#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, Debug)] +#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, Debug, EnumIter)] pub enum LoadoutConfig { Adlet, Gnarling, @@ -1101,3 +1102,96 @@ impl LoadoutBuilder { pub fn build(self) -> Loadout { self.0 } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::comp::{self, Body}; + use rand::thread_rng; + use strum::IntoEnumIterator; + + // Testing all configs in loadout with weapons of different toolkinds + // + // Things that will be catched - invalid assets paths + // FIXME: if item is used in some branch of rng test may miss it + #[test] + fn test_loadout_configs() { + let test_weapons = vec![ + // Melee + "common.items.weapons.sword.starter", // Sword + "common.items.weapons.axe.starter_axe", // Axe + "common.items.weapons.hammer.starter_hammer", // Hammer + // Ranged + "common.items.weapons.bow.starter", // Bow + "common.items.weapons.staff.starter_staff", // Staff + "common.items.weapons.sceptre.starter_sceptre", // Sceptre + // Other + "common.items.weapons.dagger.starter_dagger", // Dagger + "common.items.weapons.shield.shield_1", // Shield + "common.items.npc_weapons.biped_small.sahagin.wooden_spear", // Spear + // Exotic + "common.items.npc_weapons.unique.beast_claws", // Natural + "common.items.weapons.tool.rake", // Farming + "common.items.tool.pick", // Pick + "common.items.weapons.empty.empty", // Empty + ]; + + for config in LoadoutConfig::iter() { + test_weapons.iter().for_each(|test_weapon| { + LoadoutBuilder::build_loadout( + Body::Humanoid(comp::humanoid::Body::random()), + Some(Item::new_from_asset_expect(test_weapon)), + Some(config), + None, + ); + }); + } + } + + // Testing different species + // + // Things that will be catched - invalid assets paths for + // creating default main hand tool or equipement without config + // + // FIXME: if species has differences of body type (male/female) test may miss it + #[test] + fn test_loadout_species() { + macro_rules! test_species { + // base case + ($species:tt : $body:tt) => { + let mut rng = thread_rng(); + for s in comp::$species::ALL_SPECIES.iter() { + let body = comp::$species::Body::random_with(&mut rng, s); + LoadoutBuilder::build_loadout( + Body::$body(body), + None, + None, + None, + ); + } + }; + // recursive call + ($base:tt : $body:tt, $($species:tt : $nextbody:tt),+ $(,)?) => { + test_species!($base: $body); + test_species!($($species: $nextbody),+); + } + } + + // See `[AllBodies](crate::comp::body::AllBodies)` + test_species!( + humanoid: Humanoid, + quadruped_small: QuadrupedSmall, + quadruped_medium: QuadrupedMedium, + quadruped_low: QuadrupedLow, + bird_medium: BirdMedium, + bird_large: BirdLarge, + fish_small: FishSmall, + fish_medium: FishMedium, + biped_small: BipedSmall, + biped_large: BipedLarge, + theropod: Theropod, + dragon: Dragon, + golem: Golem, + ); + } +} From 4f83a4fa4ad3d6a233316172b1a69c8bd1025d38 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 21 May 2021 19:16:21 +0300 Subject: [PATCH 2/2] Add placeholders for bosses armour --- .../items/npc_armor/biped_large/harvester.ron | 13 ++++ .../items/npc_armor/biped_large/minotaur.ron | 13 ++++ .../npc_armor/biped_large/tidal_warrior.ron | 13 ++++ .../items/npc_armor/biped_large/yeti.ron | 13 ++++ common/src/comp/inventory/loadout_builder.rs | 78 ++++++++++++++----- 5 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 assets/common/items/npc_armor/biped_large/harvester.ron create mode 100644 assets/common/items/npc_armor/biped_large/minotaur.ron create mode 100644 assets/common/items/npc_armor/biped_large/tidal_warrior.ron create mode 100644 assets/common/items/npc_armor/biped_large/yeti.ron diff --git a/assets/common/items/npc_armor/biped_large/harvester.ron b/assets/common/items/npc_armor/biped_large/harvester.ron new file mode 100644 index 0000000000..d2aa76d312 --- /dev/null +++ b/assets/common/items/npc_armor/biped_large/harvester.ron @@ -0,0 +1,13 @@ +ItemDef( + name: "Harvester Shirt", + description: "Made of sunflowers.", + kind: Armor(( + kind: Chest("Harvester"), + stats: ( + protection: Normal(0.0), + poise_resilience: Normal(0.0), + ), + )), + quality: Legendary, + tags: [], +) diff --git a/assets/common/items/npc_armor/biped_large/minotaur.ron b/assets/common/items/npc_armor/biped_large/minotaur.ron new file mode 100644 index 0000000000..f57629d868 --- /dev/null +++ b/assets/common/items/npc_armor/biped_large/minotaur.ron @@ -0,0 +1,13 @@ +ItemDef( + name: "Minotaur Armor", + description: "The best defense is a good offense.", + kind: Armor(( + kind: Chest("Minotaur"), + stats: ( + protection: Normal(0.0), + poise_resilience: Normal(0.0), + ), + )), + quality: Legendary, + tags: [], +) diff --git a/assets/common/items/npc_armor/biped_large/tidal_warrior.ron b/assets/common/items/npc_armor/biped_large/tidal_warrior.ron new file mode 100644 index 0000000000..72e42d6cad --- /dev/null +++ b/assets/common/items/npc_armor/biped_large/tidal_warrior.ron @@ -0,0 +1,13 @@ +ItemDef( + name: "Tidal Warrior Armor", + description: "Made of fish scales.", + kind: Armor(( + kind: Chest("Tidal Warrior"), + stats: ( + protection: Normal(0.0), + poise_resilience: Normal(0.0), + ), + )), + quality: Legendary, + tags: [], +) diff --git a/assets/common/items/npc_armor/biped_large/yeti.ron b/assets/common/items/npc_armor/biped_large/yeti.ron new file mode 100644 index 0000000000..65918a3686 --- /dev/null +++ b/assets/common/items/npc_armor/biped_large/yeti.ron @@ -0,0 +1,13 @@ +ItemDef( + name: "Yeti Hide", + description: "Strong as Yeti itself.", + kind: Armor(( + kind: Chest("Yeti"), + stats: ( + protection: Normal(0.0), + poise_resilience: Normal(0.0), + ), + )), + quality: Legendary, + tags: [], +) diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 09b9425b8a..7abe386a67 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -980,24 +980,60 @@ impl LoadoutBuilder { } } else { match body { - Body::BipedLarge(b) => match b.species { - biped_large::Species::Mindflayer => LoadoutBuilder::new() - .active_mainhand(active_item) - .chest(Some(Item::new_from_asset_expect( - "common.items.npc_armor.biped_large.mindflayer", - ))) - .build(), - _ => LoadoutBuilder::new().active_mainhand(active_item).build(), - }, - Body::Golem(g) => match g.species { - golem::Species::ClayGolem => LoadoutBuilder::new() - .active_mainhand(active_item) - .chest(Some(Item::new_from_asset_expect( - "common.items.npc_armor.golem.claygolem", - ))) - .build(), - _ => LoadoutBuilder::new().active_mainhand(active_item).build(), - }, + Body::BipedLarge(biped_large::Body { + species: biped_large::Species::Mindflayer, + .. + }) => LoadoutBuilder::new() + .active_mainhand(active_item) + .chest(Some(Item::new_from_asset_expect( + "common.items.npc_armor.biped_large.mindflayer", + ))) + .build(), + Body::BipedLarge(biped_large::Body { + species: biped_large::Species::Minotaur, + .. + }) => LoadoutBuilder::new() + .active_mainhand(active_item) + .chest(Some(Item::new_from_asset_expect( + "common.items.npc_armor.biped_large.minotaur", + ))) + .build(), + Body::BipedLarge(biped_large::Body { + species: biped_large::Species::Tidalwarrior, + .. + }) => LoadoutBuilder::new() + .active_mainhand(active_item) + .chest(Some(Item::new_from_asset_expect( + "common.items.npc_armor.biped_large.tidal_warrior", + ))) + .build(), + Body::BipedLarge(biped_large::Body { + species: biped_large::Species::Yeti, + .. + }) => LoadoutBuilder::new() + .active_mainhand(active_item) + .chest(Some(Item::new_from_asset_expect( + "common.items.npc_armor.biped_large.yeti", + ))) + .build(), + Body::BipedLarge(biped_large::Body { + species: biped_large::Species::Harvester, + .. + }) => LoadoutBuilder::new() + .active_mainhand(active_item) + .chest(Some(Item::new_from_asset_expect( + "common.items.npc_armor.biped_large.harvester", + ))) + .build(), + Body::Golem(golem::Body { + species: golem::Species::ClayGolem, + .. + }) => LoadoutBuilder::new() + .active_mainhand(active_item) + .chest(Some(Item::new_from_asset_expect( + "common.items.npc_armor.golem.claygolem", + ))) + .build(), _ => LoadoutBuilder::new().active_mainhand(active_item).build(), } }; @@ -1131,9 +1167,9 @@ mod tests { "common.items.npc_weapons.biped_small.sahagin.wooden_spear", // Spear // Exotic "common.items.npc_weapons.unique.beast_claws", // Natural - "common.items.weapons.tool.rake", // Farming - "common.items.tool.pick", // Pick - "common.items.weapons.empty.empty", // Empty + "common.items.weapons.tool.rake", // Farming + "common.items.tool.pick", // Pick + "common.items.weapons.empty.empty", // Empty ]; for config in LoadoutConfig::iter() {