mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Address comments
This commit is contained in:
parent
a30cbaf735
commit
bc1797a240
@ -136,6 +136,30 @@ impl From<BehaviorCapability> for Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Behavior {
|
impl Behavior {
|
||||||
|
/// Builder function
|
||||||
|
/// Set capabilities if Option is Some
|
||||||
|
pub fn maybe_with_capabilities(
|
||||||
|
mut self,
|
||||||
|
maybe_capabilities: Option<BehaviorCapability>,
|
||||||
|
) -> Self {
|
||||||
|
if let Some(capabilities) = maybe_capabilities {
|
||||||
|
self.allow(capabilities)
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builder function
|
||||||
|
/// Set trade_site and TRADE capability if Option is Some
|
||||||
|
pub fn with_trade_site(mut self, trade_site: Option<SiteId>) -> Self {
|
||||||
|
self.trade_site = trade_site;
|
||||||
|
if trade_site.is_some() {
|
||||||
|
self.allow(BehaviorCapability::TRADE);
|
||||||
|
} else {
|
||||||
|
self.deny(BehaviorCapability::TRADE);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set capabilities to the Behavior
|
/// Set capabilities to the Behavior
|
||||||
pub fn allow(&mut self, capabilities: BehaviorCapability) {
|
pub fn allow(&mut self, capabilities: BehaviorCapability) {
|
||||||
self.capabilities.set(capabilities, true)
|
self.capabilities.set(capabilities, true)
|
||||||
@ -281,18 +305,16 @@ pub struct Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Agent {
|
impl Agent {
|
||||||
pub fn set_patrol_origin(mut self, origin: Vec3<f32>) -> Self {
|
pub fn with_patrol_origin(mut self, origin: Vec3<f32>) -> Self {
|
||||||
self.patrol_origin = Some(origin);
|
self.patrol_origin = Some(origin);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_destination(behavior: Behavior, pos: Vec3<f32>) -> Self {
|
pub fn with_destination(mut self, pos: Vec3<f32>) -> Self {
|
||||||
Self {
|
self.psyche = Psyche { aggro: 1.0 };
|
||||||
psyche: Psyche { aggro: 1.0 },
|
self.rtsim_controller = RtSimController::with_destination(pos);
|
||||||
rtsim_controller: RtSimController::with_destination(pos),
|
self.behavior.allow(BehaviorCapability::SPEAK);
|
||||||
behavior,
|
self
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -15,7 +15,7 @@ use common::{
|
|||||||
buff::{BuffCategory, BuffData, BuffKind, BuffSource},
|
buff::{BuffCategory, BuffData, BuffKind, BuffSource},
|
||||||
inventory::item::MaterialStatManifest,
|
inventory::item::MaterialStatManifest,
|
||||||
invite::InviteKind,
|
invite::InviteKind,
|
||||||
BehaviorCapability, ChatType, Inventory, Item, LightEmitter, WaypointArea,
|
ChatType, Inventory, Item, LightEmitter, WaypointArea,
|
||||||
},
|
},
|
||||||
effect::Effect,
|
effect::Effect,
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
@ -31,7 +31,6 @@ use common_net::{
|
|||||||
sync::WorldSyncExt,
|
sync::WorldSyncExt,
|
||||||
};
|
};
|
||||||
use common_sys::state::BuildAreas;
|
use common_sys::state::BuildAreas;
|
||||||
use comp::Behavior;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
||||||
use std::{
|
use std::{
|
||||||
@ -889,7 +888,7 @@ fn handle_spawn(
|
|||||||
if let comp::Alignment::Owned(_) | comp::Alignment::Npc = alignment {
|
if let comp::Alignment::Owned(_) | comp::Alignment::Npc = alignment {
|
||||||
comp::Agent::default()
|
comp::Agent::default()
|
||||||
} else {
|
} else {
|
||||||
comp::Agent::default().set_patrol_origin(pos.0)
|
comp::Agent::default().with_patrol_origin(pos.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
for _ in 0..amount {
|
for _ in 0..amount {
|
||||||
@ -1075,10 +1074,7 @@ fn handle_spawn_airship(
|
|||||||
animated: true,
|
animated: true,
|
||||||
});
|
});
|
||||||
if let Some(pos) = destination {
|
if let Some(pos) = destination {
|
||||||
builder = builder.with(comp::Agent::with_destination(
|
builder = builder.with(comp::Agent::default().with_destination(pos))
|
||||||
Behavior::from(BehaviorCapability::SPEAK),
|
|
||||||
pos,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
builder.build();
|
builder.build();
|
||||||
|
|
||||||
|
@ -225,13 +225,18 @@ pub fn handle_invite_accept(server: &mut Server, entity: specs::Entity) {
|
|||||||
}
|
}
|
||||||
let pricing = agents
|
let pricing = agents
|
||||||
.get(inviter)
|
.get(inviter)
|
||||||
.and_then(|a| a.behavior.trade_site.map(|id| index.get_site_prices(id)))
|
.and_then(|a| {
|
||||||
|
a.behavior
|
||||||
|
.trade_site
|
||||||
|
.and_then(|id| index.get_site_prices(id))
|
||||||
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
agents.get(entity).and_then(|a| {
|
agents.get(entity).and_then(|a| {
|
||||||
a.behavior.trade_site.map(|id| index.get_site_prices(id))
|
a.behavior
|
||||||
|
.trade_site
|
||||||
|
.and_then(|id| index.get_site_prices(id))
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
.flatten();
|
|
||||||
clients.get(inviter).map(|c| {
|
clients.get(inviter).map(|c| {
|
||||||
c.send(ServerGeneral::UpdatePendingTrade(
|
c.send(ServerGeneral::UpdatePendingTrade(
|
||||||
id,
|
id,
|
||||||
|
@ -32,22 +32,21 @@ fn notify_agent_prices(
|
|||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
event: AgentEvent,
|
event: AgentEvent,
|
||||||
) {
|
) {
|
||||||
if let Some(agent) = agents.get_mut(entity) {
|
if let Some((Some(site_id), agent)) = agents.get_mut(entity).map(|a| (a.behavior.trade_site, a))
|
||||||
if let Some(site_id) = agent.behavior.trade_site {
|
{
|
||||||
let prices = index.get_site_prices(site_id);
|
let prices = index.get_site_prices(site_id);
|
||||||
if let AgentEvent::UpdatePendingTrade(boxval) = event {
|
if let AgentEvent::UpdatePendingTrade(boxval) = event {
|
||||||
// Box<(tid, pend, _, inventories)>) = event {
|
// Box<(tid, pend, _, inventories)>) = event {
|
||||||
agent
|
agent
|
||||||
.inbox
|
.inbox
|
||||||
.push_front(AgentEvent::UpdatePendingTrade(Box::new((
|
.push_front(AgentEvent::UpdatePendingTrade(Box::new((
|
||||||
// Prefer using this Agent's price data, but use the counterparty's price
|
// Prefer using this Agent's price data, but use the counterparty's price
|
||||||
// data if we don't have price data
|
// data if we don't have price data
|
||||||
boxval.0,
|
boxval.0,
|
||||||
boxval.1,
|
boxval.1,
|
||||||
prices.unwrap_or(boxval.2),
|
prices.unwrap_or(boxval.2),
|
||||||
boxval.3,
|
boxval.3,
|
||||||
))));
|
))));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,12 +121,8 @@ pub fn handle_process_trade_action(
|
|||||||
prices = prices.or_else(|| {
|
prices = prices.or_else(|| {
|
||||||
agents
|
agents
|
||||||
.get(e)
|
.get(e)
|
||||||
.and_then(|a| {
|
.and_then(|a| a.behavior.trade_site)
|
||||||
a.behavior
|
.and_then(|id| server.index.get_site_prices(id))
|
||||||
.trade_site
|
|
||||||
.map(|id| server.index.get_site_prices(id))
|
|
||||||
})
|
|
||||||
.flatten()
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,18 +193,14 @@ impl<'a> System<'a> for Sys {
|
|||||||
poise,
|
poise,
|
||||||
loadout,
|
loadout,
|
||||||
agent: if entity.has_agency {
|
agent: if entity.has_agency {
|
||||||
let mut behavior = Behavior::default();
|
|
||||||
if can_speak {
|
|
||||||
behavior.allow(BehaviorCapability::SPEAK);
|
|
||||||
}
|
|
||||||
if trade_for_site.is_some() {
|
|
||||||
behavior.allow(BehaviorCapability::TRADE);
|
|
||||||
behavior.trade_site = trade_for_site
|
|
||||||
}
|
|
||||||
Some(comp::Agent::new(
|
Some(comp::Agent::new(
|
||||||
Some(entity.pos),
|
Some(entity.pos),
|
||||||
&body,
|
&body,
|
||||||
behavior,
|
Behavior::default()
|
||||||
|
.maybe_with_capabilities(
|
||||||
|
can_speak.then(|| BehaviorCapability::SPEAK),
|
||||||
|
)
|
||||||
|
.with_trade_site(trade_for_site),
|
||||||
matches!(
|
matches!(
|
||||||
loadout_config,
|
loadout_config,
|
||||||
Some(comp::inventory::loadout_builder::LoadoutConfig::Guard)
|
Some(comp::inventory::loadout_builder::LoadoutConfig::Guard)
|
||||||
|
Loading…
Reference in New Issue
Block a user