mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Adress review
This commit is contained in:
parent
9a2fde557c
commit
e004fba9da
@ -1,3 +1,5 @@
|
|||||||
|
/// Template file for EntityConfig, check documentation in code for more
|
||||||
|
/// By the time of writing this comment it lives in common/src/generation.rs
|
||||||
(
|
(
|
||||||
name: Name("Paddy"),
|
name: Name("Paddy"),
|
||||||
body: RandomWith("humanoid"),
|
body: RandomWith("humanoid"),
|
||||||
|
@ -38,6 +38,10 @@ impl Default for AlignmentMark {
|
|||||||
fn default() -> Self { Self::Alignment(Alignment::Wild) }
|
fn default() -> Self { Self::Alignment(Alignment::Wild) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// - TwoHanded(ItemSpec) for one 2h or 1h weapon,
|
||||||
|
/// - Paired(ItemSpec) for two 1h weapons aka berserker mode,
|
||||||
|
/// - Mix { mainhand: ItemSpec, offhand: ItemSpec, }
|
||||||
|
/// for two different 1h weapons.
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub enum Hands {
|
pub enum Hands {
|
||||||
TwoHanded(ItemSpec),
|
TwoHanded(ItemSpec),
|
||||||
@ -51,7 +55,7 @@ pub enum Hands {
|
|||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub enum LoadoutAsset {
|
pub enum LoadoutAsset {
|
||||||
Loadout(String),
|
Loadout(String),
|
||||||
Choice(Vec<(f32, String)>),
|
Choice(Vec<(u32, String)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
@ -207,7 +211,7 @@ impl EntityInfo {
|
|||||||
name: None,
|
name: None,
|
||||||
scale: 1.0,
|
scale: 1.0,
|
||||||
loot: LootSpec::Nothing,
|
loot: LootSpec::Nothing,
|
||||||
inventory: vec![],
|
inventory: Vec::new(),
|
||||||
loadout: LoadoutBuilder::empty(),
|
loadout: LoadoutBuilder::empty(),
|
||||||
make_loadout: None,
|
make_loadout: None,
|
||||||
skillset_asset: None,
|
skillset_asset: None,
|
||||||
@ -302,9 +306,9 @@ impl EntityInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
/// Return EntityInfo with LoadoutBuilder overwritten
|
/// Return EntityInfo with LoadoutBuilder overwritten
|
||||||
// NOTE: helpder function, think twice before exposing it
|
// NOTE: helper function, think twice before exposing it
|
||||||
|
#[must_use]
|
||||||
fn with_loadout<R>(
|
fn with_loadout<R>(
|
||||||
mut self,
|
mut self,
|
||||||
loadout: LoadoutKind,
|
loadout: LoadoutKind,
|
||||||
@ -331,6 +335,9 @@ impl EntityInfo {
|
|||||||
} => {
|
} => {
|
||||||
self = self.with_loadout_asset(base_asset, &mut rng);
|
self = self.with_loadout_asset(base_asset, &mut rng);
|
||||||
self = self.with_hands(hands, config_asset, &mut rng);
|
self = self.with_hands(hands, config_asset, &mut rng);
|
||||||
|
// FIXME: this shouldn't always overwrite
|
||||||
|
// inventory. Think about this when we get to
|
||||||
|
// entity config inheritance.
|
||||||
self.inventory = inventory
|
self.inventory = inventory
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(num, i)| (num, Item::new_from_asset_expect(&i)))
|
.map(|(num, i)| (num, Item::new_from_asset_expect(&i)))
|
||||||
@ -341,9 +348,9 @@ impl EntityInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
/// Return EntityInfo with LoadoutBuilder overwritten
|
/// Return EntityInfo with LoadoutBuilder overwritten
|
||||||
// NOTE: helpder function, think twice before exposing it
|
// NOTE: helper function, think twice before exposing it
|
||||||
|
#[must_use]
|
||||||
fn with_default_equip(mut self) -> Self {
|
fn with_default_equip(mut self) -> Self {
|
||||||
let loadout_builder = LoadoutBuilder::from_default(&self.body);
|
let loadout_builder = LoadoutBuilder::from_default(&self.body);
|
||||||
self.loadout = loadout_builder;
|
self.loadout = loadout_builder;
|
||||||
@ -351,9 +358,9 @@ impl EntityInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
/// Return EntityInfo with LoadoutBuilder overwritten
|
/// Return EntityInfo with LoadoutBuilder overwritten
|
||||||
// NOTE: helpder function, think twice before exposing it
|
// NOTE: helper function, think twice before exposing it
|
||||||
|
#[must_use]
|
||||||
fn with_loadout_asset<R>(mut self, loadout: LoadoutAsset, rng: &mut R) -> Self
|
fn with_loadout_asset<R>(mut self, loadout: LoadoutAsset, rng: &mut R) -> Self
|
||||||
where
|
where
|
||||||
R: rand::Rng,
|
R: rand::Rng,
|
||||||
@ -364,6 +371,9 @@ impl EntityInfo {
|
|||||||
self.loadout = loadout;
|
self.loadout = loadout;
|
||||||
},
|
},
|
||||||
LoadoutAsset::Choice(assets) => {
|
LoadoutAsset::Choice(assets) => {
|
||||||
|
// TODO:
|
||||||
|
// choose_weighted allocates WeightedIndex,
|
||||||
|
// possible optimizaiton with using Lottery
|
||||||
let (_p, asset) = assets
|
let (_p, asset) = assets
|
||||||
.choose_weighted(rng, |(p, _asset)| *p)
|
.choose_weighted(rng, |(p, _asset)| *p)
|
||||||
.expect("rng error");
|
.expect("rng error");
|
||||||
@ -376,9 +386,9 @@ impl EntityInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
/// Return EntityInfo with weapons applied to LoadoutBuilder
|
/// Return EntityInfo with weapons applied to LoadoutBuilder
|
||||||
// NOTE: helpder function, think twice before exposing it
|
// NOTE: helper function, think twice before exposing it
|
||||||
|
#[must_use]
|
||||||
fn with_hands<R>(mut self, hands: Hands, config_asset: Option<&str>, rng: &mut R) -> Self
|
fn with_hands<R>(mut self, hands: Hands, config_asset: Option<&str>, rng: &mut R) -> Self
|
||||||
where
|
where
|
||||||
R: rand::Rng,
|
R: rand::Rng,
|
||||||
@ -633,12 +643,8 @@ mod tests {
|
|||||||
},
|
},
|
||||||
LoadoutAsset::Choice(assets) => {
|
LoadoutAsset::Choice(assets) => {
|
||||||
for (p, asset) in assets {
|
for (p, asset) in assets {
|
||||||
if p <= 0.0 {
|
if p == 0 {
|
||||||
#[rustfmt::skip]
|
panic!("Weight of loadout asset is zero in {config_asset}");
|
||||||
panic!(
|
|
||||||
"Weight of asset is less or equal to 0.0 in {}",
|
|
||||||
config_asset
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
validate_loadout_asset(LoadoutAsset::Loadout(asset), config_asset);
|
validate_loadout_asset(LoadoutAsset::Loadout(asset), config_asset);
|
||||||
}
|
}
|
||||||
|
@ -621,13 +621,13 @@ fn handle_make_npc(
|
|||||||
Err(_err) => return Err(format!("Failed to load entity config: {}", entity_config)),
|
Err(_err) => return Err(format!("Failed to load entity config: {}", entity_config)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut loadout_rng = rand::thread_rng();
|
||||||
for _ in 0..number {
|
for _ in 0..number {
|
||||||
let comp::Pos(pos) = position(server, target, "target")?;
|
let comp::Pos(pos) = position(server, target, "target")?;
|
||||||
let loadout_rng = rand::thread_rng();
|
|
||||||
let entity_info = EntityInfo::at(pos).with_entity_config(
|
let entity_info = EntityInfo::at(pos).with_entity_config(
|
||||||
config.clone(),
|
config.clone(),
|
||||||
Some(&entity_config),
|
Some(&entity_config),
|
||||||
loadout_rng,
|
&mut loadout_rng,
|
||||||
);
|
);
|
||||||
|
|
||||||
match NpcData::from_entity_info(entity_info) {
|
match NpcData::from_entity_info(entity_info) {
|
||||||
|
@ -448,9 +448,16 @@ impl NpcData {
|
|||||||
let loadout = loadout_builder.build();
|
let loadout = loadout_builder.build();
|
||||||
let mut inventory = comp::inventory::Inventory::new_with_loadout(loadout);
|
let mut inventory = comp::inventory::Inventory::new_with_loadout(loadout);
|
||||||
for (num, mut item) in items {
|
for (num, mut item) in items {
|
||||||
// I don't think we can produce any helpful error there.
|
tracing::warn!(
|
||||||
let _ = item.set_amount(num);
|
"error during creating inventory for {name} at {pos}: {e:?}",
|
||||||
let _ = inventory.push(item);
|
name = &stats.name,
|
||||||
|
e = item.set_amount(num)
|
||||||
|
);
|
||||||
|
tracing::warn!(
|
||||||
|
"error during creating inventory for {name} at {pos}: {e:?}",
|
||||||
|
name = &stats.name,
|
||||||
|
e = inventory.push(item)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory
|
inventory
|
||||||
|
Loading…
Reference in New Issue
Block a user