diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 9ef11f572d..a777055891 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -102,7 +102,6 @@ bitflags::bitflags! { #[derive(Default)] pub struct BehaviorCapability: u8 { const SPEAK = 0b00000001; - const TRADE = 0b00000010; } } bitflags::bitflags! { @@ -149,14 +148,9 @@ impl Behavior { } /// Builder function - /// Set trade_site and TRADE capability if Option is Some + /// Set trade_site if Option is Some pub fn with_trade_site(mut self, trade_site: Option) -> Self { self.trade_site = trade_site; - if trade_site.is_some() { - self.allow(BehaviorCapability::TRADE); - } else { - self.deny(BehaviorCapability::TRADE); - } self } @@ -175,6 +169,9 @@ impl Behavior { self.capabilities.contains(capabilities) } + /// Check if the Behavior is able to trade + pub fn can_trade(&self) -> bool { self.trade_site.is_some() } + /// Set a state to the Behavior pub fn set(&mut self, state: BehaviorState) { self.state.set(state, true) } @@ -362,9 +359,7 @@ mod tests { b.unset(BehaviorState::TRADING); assert!(!b.is(BehaviorState::TRADING)); // test `from` - let b = Behavior::from(BehaviorCapability::SPEAK | BehaviorCapability::TRADE); + let b = Behavior::from(BehaviorCapability::SPEAK); assert!(b.can(BehaviorCapability::SPEAK)); - assert!(b.can(BehaviorCapability::TRADE)); - assert!(b.can(BehaviorCapability::SPEAK | BehaviorCapability::TRADE)); } } diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 1110c5bfd1..574d806a0d 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -930,7 +930,7 @@ impl<'a> AgentData<'a> { event_emitter.emit(ServerEvent::Chat( UnresolvedChatMsg::npc(*self.uid, msg), )); - } else if agent.behavior.can(BehaviorCapability::TRADE) { + } else if agent.behavior.can_trade() { let msg = "npc.speech.merchant_advertisement".to_string(); event_emitter.emit(ServerEvent::Chat( UnresolvedChatMsg::npc(*self.uid, msg), @@ -943,7 +943,7 @@ impl<'a> AgentData<'a> { } }, Subject::Trade => { - if agent.behavior.can(BehaviorCapability::TRADE) { + if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { controller.events.push(ControlEvent::InitiateInvite( by, @@ -1092,7 +1092,7 @@ impl<'a> AgentData<'a> { } }, Some(AgentEvent::TradeInvite(with)) => { - if agent.behavior.can(BehaviorCapability::TRADE) { + if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { // stand still and looking towards the trading player controller.actions.push(ControlAction::Stand);