Added LoadoutConfig to better specify loadouts.

This commit is contained in:
Sam 2020-11-20 13:14:46 -06:00 committed by Joshua Barretto
parent 95d300c0e2
commit 0b86943e66
3 changed files with 293 additions and 224 deletions

View File

@ -26,6 +26,13 @@ use rand::Rng;
/// )))
/// .build();
/// ```
pub enum LoadoutConfig {
Guard,
Cultist,
Villager,
}
pub struct LoadoutBuilder(Loadout);
impl LoadoutBuilder {
@ -78,216 +85,294 @@ impl LoadoutBuilder {
mut main_tool: Option<Item>,
is_giant: bool,
map: &AbilityMap,
config: Option<LoadoutConfig>,
) -> Self {
match body {
Body::Golem(golem) => match golem.species {
golem::Species::StoneGolem => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.unique.stone_golems_fist",
));
},
_ => {},
},
Body::BipedLarge(biped_large) => match (biped_large.species, biped_large.body_type) {
(biped_large::Species::Occultsaurok, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.staff.saurok_staff",
));
},
(biped_large::Species::Mightysaurok, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.sword.saurok_sword",
));
},
(biped_large::Species::Slysaurok, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.bow.saurok_bow",
));
},
(biped_large::Species::Ogre, biped_large::BodyType::Male) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.hammer.ogre_hammer",
));
},
(biped_large::Species::Ogre, biped_large::BodyType::Female) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.staff.ogre_staff",
));
},
(biped_large::Species::Troll, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.hammer.troll_hammer",
));
},
(biped_large::Species::Wendigo, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.unique.beast_claws",
));
},
(biped_large::Species::Werewolf, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.unique.beast_claws",
));
},
(biped_large::Species::Cyclops, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.hammer.cyclops_hammer",
));
},
(biped_large::Species::Dullahan, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.sword.dullahan_sword",
));
},
(biped_large::Species::Mindflayer, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.staff.mindflayer_staff",
));
},
},
Body::Humanoid(_) => {
if is_giant {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.sword.zweihander_sword_0",
));
}
},
_ => {},
};
let active_item = if let Some(ItemKind::Tool(_)) = main_tool.as_ref().map(|i| i.kind()) {
main_tool.map(|item| ItemConfig::from((item, map)))
} else {
Some(ItemConfig {
// We need the empty item so npcs can attack
item: Item::new_from_asset_expect("common.items.weapons.empty.empty"),
ability1: Some(CharacterAbility::default()),
ability2: None,
ability3: None,
block_ability: None,
dodge_ability: None,
})
};
let loadout = 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,
let loadout = if let Some(config) = config {
use LoadoutConfig::*;
match config {
Guard => Loadout {
active_item: None,
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",
)),
shoulder: None,
chest: None,
belt: None,
hand: None,
pants: None,
foot: None,
back: None,
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,
},
lantern: None,
glider: None,
head: None,
tabard: None,
},
_ => LoadoutBuilder::animal(body).build(),
},
Body::Golem(golem) => match golem.species {
golem::Species::StoneGolem => Loadout {
Cultist => 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 => 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,
},
}
} else {
match body {
Body::Golem(golem) => match golem.species {
golem::Species::StoneGolem => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.unique.stone_golems_fist",
));
},
_ => {},
},
Body::BipedLarge(biped_large) => match (biped_large.species, biped_large.body_type)
{
(biped_large::Species::Occultsaurok, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.staff.saurok_staff",
));
},
(biped_large::Species::Mightysaurok, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.sword.saurok_sword",
));
},
(biped_large::Species::Slysaurok, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.bow.saurok_bow",
));
},
(biped_large::Species::Ogre, biped_large::BodyType::Male) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.hammer.ogre_hammer",
));
},
(biped_large::Species::Ogre, biped_large::BodyType::Female) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.staff.ogre_staff",
));
},
(biped_large::Species::Troll, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.hammer.troll_hammer",
));
},
(biped_large::Species::Wendigo, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.unique.beast_claws",
));
},
(biped_large::Species::Werewolf, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.unique.beast_claws",
));
},
(biped_large::Species::Cyclops, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.hammer.cyclops_hammer",
));
},
(biped_large::Species::Dullahan, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.sword.dullahan_sword",
));
},
(biped_large::Species::Mindflayer, _) => {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.staff.mindflayer_staff",
));
},
},
Body::Humanoid(_) => {
if is_giant {
main_tool = Some(Item::new_from_asset_expect(
"common.items.npc_weapons.sword.zweihander_sword_0",
));
}
},
_ => {},
};
let active_item = if let Some(ItemKind::Tool(_)) = main_tool.as_ref().map(|i| i.kind())
{
main_tool.map(|item| ItemConfig::from((item, map)))
} else {
Some(ItemConfig {
// We need the empty item so npcs can attack
item: Item::new_from_asset_expect("common.items.weapons.empty.empty"),
ability1: Some(CharacterAbility::default()),
ability2: None,
ability3: None,
block_ability: None,
dodge_ability: None,
})
};
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,
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,
},
_ => LoadoutBuilder::animal(body).build(),
},
Body::BipedLarge(_) => Loadout {
active_item,
second_item: None,
shoulder: None,
@ -305,25 +390,7 @@ impl LoadoutBuilder {
tabard: None,
},
_ => LoadoutBuilder::animal(body).build(),
},
Body::BipedLarge(_) => Loadout {
active_item,
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,
},
_ => LoadoutBuilder::animal(body).build(),
}
};
Self(loadout)

View File

@ -672,9 +672,10 @@ fn handle_spawn(
let body = body();
let map = server.state().ability_map();
let loadout =
LoadoutBuilder::build_loadout(body, alignment, None, false, &map)
.build();
let loadout = LoadoutBuilder::build_loadout(
body, alignment, None, false, &map, None,
)
.build();
drop(map);
let mut entity_base = server

View File

@ -164,6 +164,7 @@ impl<'a> System<'a> for Sys {
main_tool,
entity.is_giant,
&map,
None,
)
.build();