mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Loadout Udpate: NpcData part
Actually implement creating npc with new EntitytInfo by chaning CreateNpc.loadout to CreateNpc.inventory and cleaning code in NpcData::from_entity_info.
This commit is contained in:
parent
e1bfa6c7e2
commit
d5b927602a
@ -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
|
||||
|
@ -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::<v1::EntityConfig, v2::EntityConfig>(
|
||||
|
@ -128,7 +128,7 @@ pub enum ServerEvent {
|
||||
skill_set: comp::SkillSet,
|
||||
health: Option<comp::Health>,
|
||||
poise: comp::Poise,
|
||||
loadout: comp::inventory::loadout::Loadout,
|
||||
inventory: comp::inventory::Inventory,
|
||||
body: comp::Body,
|
||||
agent: Option<comp::Agent>,
|
||||
alignment: comp::Alignment,
|
||||
|
@ -185,7 +185,7 @@ pub struct EntityInfo {
|
||||
pub loot: LootSpec<String>,
|
||||
// Loadout
|
||||
pub inventory: Vec<(u32, Item)>,
|
||||
pub loadout: Option<LoadoutBuilder>,
|
||||
pub loadout: LoadoutBuilder,
|
||||
pub make_loadout: Option<fn(LoadoutBuilder, Option<&trade::SiteInformation>) -> LoadoutBuilder>,
|
||||
// Skills
|
||||
pub skillset_asset: Option<String>,
|
||||
@ -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));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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<Health>,
|
||||
poise: Poise,
|
||||
loadout: Loadout,
|
||||
inventory: Inventory,
|
||||
body: Body,
|
||||
agent: impl Into<Option<Agent>>,
|
||||
alignment: Alignment,
|
||||
@ -61,8 +60,6 @@ pub fn handle_create_npc(
|
||||
rtsim_entity: Option<RtSimEntity>,
|
||||
projectile: Option<Projectile>,
|
||||
) {
|
||||
let inventory = Inventory::new_with_loadout(loadout);
|
||||
|
||||
let entity = server
|
||||
.state
|
||||
.create_npc(pos, stats, skill_set, health, poise, inventory, body)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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<comp::Health>,
|
||||
poise: comp::Poise,
|
||||
loadout: comp::inventory::loadout::Loadout,
|
||||
inventory: comp::inventory::Inventory,
|
||||
agent: Option<comp::Agent>,
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user