Address comments for MR 3633.

This commit is contained in:
Avi Weinstock 2022-09-22 12:53:35 -04:00
parent c62bc0dd0d
commit 60f5383f8b
2 changed files with 12 additions and 6 deletions

View File

@ -157,8 +157,8 @@ impl Behavior {
}
/// Check if the Behavior is able to trade
pub fn can_trade(&self, alignment: Option<&Alignment>, counterparty: Uid) -> bool {
self.trade_site.is_some() || alignment == Some(&Alignment::Owned(counterparty))
pub fn can_trade(&self, alignment: Option<Alignment>, counterparty: Uid) -> bool {
self.trade_site.is_some() || alignment == Some(Alignment::Owned(counterparty))
}
/// Set a state to the Behavior

View File

@ -167,7 +167,10 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
standard_response_msg()
};
agent_data.chat_npc(msg, event_emitter);
} else if agent.behavior.can_trade(agent_data.alignment, by) {
} else if agent
.behavior
.can_trade(agent_data.alignment.copied(), by)
{
if !agent.behavior.is(BehaviorState::TRADING) {
controller.push_initiate_invite(by, InviteKind::Trade);
agent_data.chat_npc(
@ -250,7 +253,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
}
},
Subject::Trade => {
if agent.behavior.can_trade(agent_data.alignment, by) {
if agent.behavior.can_trade(agent_data.alignment.copied(), by) {
if !agent.behavior.is(BehaviorState::TRADING) {
controller.push_initiate_invite(by, InviteKind::Trade);
agent_data.chat_npc_if_allowed_to_speak(
@ -395,7 +398,10 @@ pub fn handle_inbox_trade_invite(bdata: &mut BehaviorData) -> bool {
}
if let Some(AgentEvent::TradeInvite(with)) = agent.inbox.pop_front() {
if agent.behavior.can_trade(agent_data.alignment, with) {
if agent
.behavior
.can_trade(agent_data.alignment.copied(), with)
{
if !agent.behavior.is(BehaviorState::TRADING) {
// stand still and looking towards the trading player
controller.push_action(ControlAction::Stand);
@ -603,7 +609,7 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
{
// in combat, speak to players that aren't the current target
if !target.hostile || target.target != speaker {
if agent.behavior.can_trade(agent_data.alignment, *by) {
if agent.behavior.can_trade(agent_data.alignment.copied(), *by) {
agent_data.chat_npc_if_allowed_to_speak(
"npc-speech-merchant_busy",
agent,