mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove TRADE capability, use trade_site attribute instead
This commit is contained in:
parent
bc1797a240
commit
d80db38bc9
@ -102,7 +102,6 @@ bitflags::bitflags! {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct BehaviorCapability: u8 {
|
pub struct BehaviorCapability: u8 {
|
||||||
const SPEAK = 0b00000001;
|
const SPEAK = 0b00000001;
|
||||||
const TRADE = 0b00000010;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
@ -149,14 +148,9 @@ impl Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builder function
|
/// 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<SiteId>) -> Self {
|
pub fn with_trade_site(mut self, trade_site: Option<SiteId>) -> Self {
|
||||||
self.trade_site = trade_site;
|
self.trade_site = trade_site;
|
||||||
if trade_site.is_some() {
|
|
||||||
self.allow(BehaviorCapability::TRADE);
|
|
||||||
} else {
|
|
||||||
self.deny(BehaviorCapability::TRADE);
|
|
||||||
}
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +169,9 @@ impl Behavior {
|
|||||||
self.capabilities.contains(capabilities)
|
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
|
/// Set a state to the Behavior
|
||||||
pub fn set(&mut self, state: BehaviorState) { self.state.set(state, true) }
|
pub fn set(&mut self, state: BehaviorState) { self.state.set(state, true) }
|
||||||
|
|
||||||
@ -362,9 +359,7 @@ mod tests {
|
|||||||
b.unset(BehaviorState::TRADING);
|
b.unset(BehaviorState::TRADING);
|
||||||
assert!(!b.is(BehaviorState::TRADING));
|
assert!(!b.is(BehaviorState::TRADING));
|
||||||
// test `from`
|
// 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::SPEAK));
|
||||||
assert!(b.can(BehaviorCapability::TRADE));
|
|
||||||
assert!(b.can(BehaviorCapability::SPEAK | BehaviorCapability::TRADE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -930,7 +930,7 @@ impl<'a> AgentData<'a> {
|
|||||||
event_emitter.emit(ServerEvent::Chat(
|
event_emitter.emit(ServerEvent::Chat(
|
||||||
UnresolvedChatMsg::npc(*self.uid, msg),
|
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();
|
let msg = "npc.speech.merchant_advertisement".to_string();
|
||||||
event_emitter.emit(ServerEvent::Chat(
|
event_emitter.emit(ServerEvent::Chat(
|
||||||
UnresolvedChatMsg::npc(*self.uid, msg),
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
||||||
@ -943,7 +943,7 @@ impl<'a> AgentData<'a> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Subject::Trade => {
|
Subject::Trade => {
|
||||||
if agent.behavior.can(BehaviorCapability::TRADE) {
|
if agent.behavior.can_trade() {
|
||||||
if !agent.behavior.is(BehaviorState::TRADING) {
|
if !agent.behavior.is(BehaviorState::TRADING) {
|
||||||
controller.events.push(ControlEvent::InitiateInvite(
|
controller.events.push(ControlEvent::InitiateInvite(
|
||||||
by,
|
by,
|
||||||
@ -1092,7 +1092,7 @@ impl<'a> AgentData<'a> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(AgentEvent::TradeInvite(with)) => {
|
Some(AgentEvent::TradeInvite(with)) => {
|
||||||
if agent.behavior.can(BehaviorCapability::TRADE) {
|
if agent.behavior.can_trade() {
|
||||||
if !agent.behavior.is(BehaviorState::TRADING) {
|
if !agent.behavior.is(BehaviorState::TRADING) {
|
||||||
// stand still and looking towards the trading player
|
// stand still and looking towards the trading player
|
||||||
controller.actions.push(ControlAction::Stand);
|
controller.actions.push(ControlAction::Stand);
|
||||||
|
Loading…
Reference in New Issue
Block a user