Assigns spawned npcs loadout with new method

This commit is contained in:
Snowram 2020-11-21 01:25:33 +01:00 committed by Joshua Barretto
parent b950447bed
commit 3bcffe1bf7
5 changed files with 119 additions and 143 deletions

View File

@ -1,6 +1,7 @@
use crate::{
comp::{self, humanoid, Alignment, Body, Item},
npc::{self, NPC_NAMES},
loadout_builder::LoadoutConfig,
};
use vek::*;
@ -22,6 +23,7 @@ pub struct EntityInfo {
pub scale: f32,
pub level: Option<u32>,
pub loot_drop: Option<Item>,
pub config: Option<LoadoutConfig>,
}
impl EntityInfo {
@ -39,6 +41,7 @@ impl EntityInfo {
scale: 1.0,
level: None,
loot_drop: None,
config: None,
}
}
@ -104,6 +107,11 @@ impl EntityInfo {
self
}
pub fn with_config(mut self, config: LoadoutConfig) -> Self {
self.config = Some(config);
self
}
pub fn with_automatic_name(mut self) -> Self {
self.name = match &self.body {
Body::Humanoid(body) => Some(get_npc_name(&NPC_NAMES.humanoid, body.species)),

View File

@ -110,36 +110,115 @@ impl LoadoutBuilder {
Cultist => Loadout {
active_item: None,
second_item: None,
shoulder: None,
chest: None,
belt: None,
hand: None,
pants: None,
foot: None,
back: None,
shoulder: Some(Item::new_from_asset_expect(
"common.items.armor.shoulder.cultist_shoulder_purple",
)),
chest: Some(Item::new_from_asset_expect(
"common.items.armor.chest.cultist_chest_purple",
)),
belt: Some(Item::new_from_asset_expect(
"common.items.armor.belt.cultist_belt",
)),
hand: Some(Item::new_from_asset_expect(
"common.items.armor.hand.cultist_hands_purple",
)),
pants: Some(Item::new_from_asset_expect(
"common.items.armor.pants.cultist_legs_purple",
)),
foot: Some(Item::new_from_asset_expect(
"common.items.armor.foot.cultist_boots",
)),
back: Some(Item::new_from_asset_expect(
"common.items.armor.back.dungeon_purple-0",
)),
ring: None,
neck: None,
lantern: None,
lantern: match rand::thread_rng().gen_range(0, 3) {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
},
glider: None,
head: None,
tabard: None,
},
Villager => Loadout {
active_item: None,
second_item: None,
shoulder: None,
chest: None,
belt: None,
hand: None,
pants: None,
foot: None,
back: None,
ring: None,
neck: None,
lantern: None,
glider: None,
head: None,
tabard: None,
Villager => {
if is_giant {
Loadout {
active_item: None,
second_item: None,
shoulder: Some(Item::new_from_asset_expect(
"common.items.armor.shoulder.plate_0",
)),
chest: Some(Item::new_from_asset_expect(match alignment {
Alignment::Enemy => "common.items.npc_armor.chest.plate_red_0",
_ => "common.items.npc_armor.chest.plate_green_0",
})),
belt: Some(Item::new_from_asset_expect(
"common.items.armor.belt.plate_0",
)),
hand: Some(Item::new_from_asset_expect(
"common.items.armor.hand.plate_0",
)),
pants: Some(Item::new_from_asset_expect(match alignment {
Alignment::Enemy => "common.items.npc_armor.pants.plate_red_0",
_ => "common.items.npc_armor.pants.plate_green_0",
})),
foot: Some(Item::new_from_asset_expect(
"common.items.armor.foot.plate_0",
)),
back: None,
ring: None,
neck: None,
lantern: Some(Item::new_from_asset_expect(
"common.items.lantern.black_0",
)),
glider: None,
head: None,
tabard: None,
}
} else {
Loadout {
active_item: None,
second_item: None,
shoulder: None,
chest: Some(Item::new_from_asset_expect(
match rand::thread_rng().gen_range(0, 10) {
0 => "common.items.armor.chest.worker_green_0",
1 => "common.items.armor.chest.worker_green_1",
2 => "common.items.armor.chest.worker_red_0",
3 => "common.items.armor.chest.worker_red_1",
4 => "common.items.armor.chest.worker_purple_0",
5 => "common.items.armor.chest.worker_purple_1",
6 => "common.items.armor.chest.worker_yellow_0",
7 => "common.items.armor.chest.worker_yellow_1",
8 => "common.items.armor.chest.worker_orange_0",
_ => "common.items.armor.chest.worker_orange_1",
},
)),
belt: Some(Item::new_from_asset_expect(
"common.items.armor.belt.leather_0",
)),
hand: None,
pants: Some(Item::new_from_asset_expect(
"common.items.armor.pants.worker_blue_0",
)),
foot: Some(Item::new_from_asset_expect(
match rand::thread_rng().gen_range(0, 2) {
0 => "common.items.armor.foot.leather_0",
_ => "common.items.armor.starter.sandals_0",
},
)),
back: None,
ring: None,
neck: None,
lantern: Some(Item::new_from_asset_expect(
"common.items.lantern.black_0",
)),
glider: None,
head: None,
tabard: None,
}
}
},
}
} else {
@ -236,122 +315,6 @@ impl LoadoutBuilder {
};
match body {
Body::Humanoid(_) => match alignment {
Alignment::Npc => {
if is_giant {
Loadout {
active_item,
second_item: None,
shoulder: Some(Item::new_from_asset_expect(
"common.items.armor.shoulder.plate_0",
)),
chest: Some(Item::new_from_asset_expect(match alignment {
Alignment::Enemy => "common.items.npc_armor.chest.plate_red_0",
_ => "common.items.npc_armor.chest.plate_green_0",
})),
belt: Some(Item::new_from_asset_expect(
"common.items.armor.belt.plate_0",
)),
hand: Some(Item::new_from_asset_expect(
"common.items.armor.hand.plate_0",
)),
pants: Some(Item::new_from_asset_expect(match alignment {
Alignment::Enemy => "common.items.npc_armor.pants.plate_red_0",
_ => "common.items.npc_armor.pants.plate_green_0",
})),
foot: Some(Item::new_from_asset_expect(
"common.items.armor.foot.plate_0",
)),
back: None,
ring: None,
neck: None,
lantern: Some(Item::new_from_asset_expect(
"common.items.lantern.black_0",
)),
glider: None,
head: None,
tabard: None,
}
} else {
Loadout {
active_item,
second_item: None,
shoulder: None,
chest: Some(Item::new_from_asset_expect(
match rand::thread_rng().gen_range(0, 10) {
0 => "common.items.armor.chest.worker_green_0",
1 => "common.items.armor.chest.worker_green_1",
2 => "common.items.armor.chest.worker_red_0",
3 => "common.items.armor.chest.worker_red_1",
4 => "common.items.armor.chest.worker_purple_0",
5 => "common.items.armor.chest.worker_purple_1",
6 => "common.items.armor.chest.worker_yellow_0",
7 => "common.items.armor.chest.worker_yellow_1",
8 => "common.items.armor.chest.worker_orange_0",
_ => "common.items.armor.chest.worker_orange_1",
},
)),
belt: Some(Item::new_from_asset_expect(
"common.items.armor.belt.leather_0",
)),
hand: None,
pants: Some(Item::new_from_asset_expect(
"common.items.armor.pants.worker_blue_0",
)),
foot: Some(Item::new_from_asset_expect(
match rand::thread_rng().gen_range(0, 2) {
0 => "common.items.armor.foot.leather_0",
_ => "common.items.armor.starter.sandals_0",
},
)),
back: None,
ring: None,
neck: None,
lantern: Some(Item::new_from_asset_expect(
"common.items.lantern.black_0",
)),
glider: None,
head: None,
tabard: None,
}
}
},
Alignment::Enemy => Loadout {
active_item,
second_item: None,
shoulder: Some(Item::new_from_asset_expect(
"common.items.armor.shoulder.cultist_shoulder_purple",
)),
chest: Some(Item::new_from_asset_expect(
"common.items.armor.chest.cultist_chest_purple",
)),
belt: Some(Item::new_from_asset_expect(
"common.items.armor.belt.cultist_belt",
)),
hand: Some(Item::new_from_asset_expect(
"common.items.armor.hand.cultist_hands_purple",
)),
pants: Some(Item::new_from_asset_expect(
"common.items.armor.pants.cultist_legs_purple",
)),
foot: Some(Item::new_from_asset_expect(
"common.items.armor.foot.cultist_boots",
)),
back: Some(Item::new_from_asset_expect(
"common.items.armor.back.dungeon_purple-0",
)),
ring: None,
neck: None,
lantern: match rand::thread_rng().gen_range(0, 3) {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
},
glider: None,
head: None,
tabard: None,
},
_ => LoadoutBuilder::animal(body).build(),
},
Body::Golem(golem) => match golem.species {
golem::Species::StoneGolem => Loadout {
active_item,

View File

@ -158,13 +158,15 @@ impl<'a> System<'a> for Sys {
scale = 2.0 + rand::random::<f32>();
}
let config = entity.config;
let loadout = LoadoutBuilder::build_loadout(
body,
alignment,
main_tool,
entity.is_giant,
&map,
None,
config,
)
.build();

View File

@ -584,10 +584,12 @@ impl Floor {
.map(|e| (RandomField::new(room.seed.wrapping_add(10 + e)).get(Vec3::from(tile_pos)) % 32) as i32 - 16)
.map(|e| e as f32 / 16.0),
)
//.do_if(is_giant, |e| e.into_giant())
//.do_if(is_giant, |e| e.into_giant())
.with_body(comp::Body::Humanoid(comp::humanoid::Body::random()))
.with_alignment(comp::Alignment::Enemy)
.with_loot_drop(comp::Item::new_from_asset_expect(chosen)).with_evel(dynamic_rng.gen_range(
.with_config(common::loadout_builder::LoadoutConfig::Cultist)
.with_loot_drop(comp::Item::new_from_asset_expect(chosen))
.with_level(dynamic_rng.gen_range(
(room.difficulty as f32).powf(1.25) + 3.0,
(room.difficulty as f32).powf(1.5) + 4.0,
).round() as u32);

View File

@ -930,6 +930,7 @@ impl Settlement {
//_ => "common.items.npc_weapons.bow.starter_bow", TODO: Re-Add this when we have a better way of distributing npc_weapons here
},
))
.with_config(common::loadout_builder::LoadoutConfig::Villager)
})
.do_if(is_dummy, |e| e.with_name("Training Dummy"))
.do_if(!is_dummy, |e| e.with_automatic_name());