Merge branch 'crabman/interaction-fix' into 'master'

Allow other behavior nodes to run on failed interaction

See merge request veloren/veloren!4123
This commit is contained in:
Isse 2023-10-02 22:36:23 +00:00
commit d88dace5b8
6 changed files with 39 additions and 34 deletions

View File

@ -382,7 +382,7 @@ impl<'a> From<&'a Body> for Psyche {
},
},
sight_dist: match body {
Body::BirdLarge(_) => 100.0,
Body::BirdLarge(_) => 250.0,
_ => 40.0,
},
listen_dist: 30.0,

View File

@ -3,6 +3,7 @@ pub const MAX_PICKUP_RANGE: f32 = 5.0;
pub const MAX_MOUNT_RANGE: f32 = 5.0;
pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0;
pub const MAX_TRADE_RANGE: f32 = 20.0;
pub const MAX_NPCINTERACT_RANGE: f32 = 30.0;
pub const GRAVITY: f32 = 25.0;
pub const FRIC_GROUND: f32 = 0.15;

View File

@ -1223,7 +1223,7 @@ fn bird_large() -> impl Action<DefaultState> {
if !is_deep_water {
goto_2d_flying(
pos,
0.2,
0.1,
bearing_dist,
8.0,
8.0,
@ -1237,7 +1237,7 @@ fn bird_large() -> impl Action<DefaultState> {
goto_2d_flying(
pos,
0.2,
0.1,
bearing_dist,
8.0,
8.0,

View File

@ -3118,7 +3118,7 @@ impl<'a> AgentData<'a> {
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
if (self.pos.0.z - tgt_data.pos.0.z) < 35.0 {
controller.push_basic_input(InputKind::Fly);
controller.inputs.move_z = 1.0;
controller.inputs.move_z = 0.2;
}
}
} else if !read_data

View File

@ -14,7 +14,10 @@ use common::{
tool::{AbilityMap, ToolKind},
Inventory, LootOwner, Pos, SkillGroupKind,
},
consts::{MAX_MOUNT_RANGE, MAX_SPRITE_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME},
consts::{
MAX_MOUNT_RANGE, MAX_NPCINTERACT_RANGE, MAX_SPRITE_MOUNT_RANGE,
SOUND_TRAVEL_DIST_PER_VOLUME,
},
event::EventBus,
link::Is,
mounting::{Mount, Mounting, Rider, VolumeMounting, VolumePos, VolumeRider},
@ -86,17 +89,25 @@ pub fn handle_npc_interaction(
subject: Subject,
) {
let state = server.state_mut();
if let Some(agent) = state
let within_range = {
let positions = state.ecs().read_storage::<Pos>();
positions
.get(interactor)
.zip(positions.get(npc_entity))
.map_or(false, |(interactor_pos, npc_pos)| {
interactor_pos.0.distance_squared(npc_pos.0) <= MAX_NPCINTERACT_RANGE.powi(2)
})
};
if within_range && let Some(agent) = state
.ecs()
.write_storage::<comp::Agent>()
.get_mut(npc_entity)
.get_mut(npc_entity) && agent.target.is_none()
{
if agent.target.is_none() {
if let Some(interactor_uid) = state.ecs().uid_from_entity(interactor) {
agent
.inbox
.push_back(AgentEvent::Talk(interactor_uid, subject));
}
if let Some(interactor_uid) = state.ecs().uid_from_entity(interactor) {
agent
.inbox
.push_back(AgentEvent::Talk(interactor_uid, subject));
}
}
}

View File

@ -557,22 +557,20 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
} = bdata;
if let Some(msg) = agent.inbox.front() {
let used = match msg {
match msg {
AgentEvent::Talk(by, _) | AgentEvent::TradeAccepted(by) => {
if let (Some(target), Some(speaker)) =
(agent.target, get_entity_by_id(*by, bdata.read_data))
{
if agent
.target
.zip(get_entity_by_id(*by, bdata.read_data))
// in combat, speak to players that aren't the current target
if !target.hostile || target.target != speaker {
agent_data.chat_npc_if_allowed_to_speak(
Content::localized("npc-speech-villager_busy"),
agent,
event_emitter,
);
}
.map_or(false, |(target, speaker)| !target.hostile || target.target != speaker)
{
agent_data.chat_npc_if_allowed_to_speak(
Content::localized("npc-speech-villager_busy"),
agent,
event_emitter,
);
}
true
},
AgentEvent::TradeInvite(by) => {
controller.push_invite_response(InviteResponse::Decline);
@ -596,7 +594,6 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
}
}
}
true
},
AgentEvent::FinishedTrade(result) => {
// copy pasted from recv_interaction
@ -621,7 +618,6 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
agent.behavior.unset(BehaviorState::TRADING);
agent.target = None;
}
true
},
AgentEvent::UpdatePendingTrade(boxval) => {
// immediately cancel the trade
@ -638,14 +634,11 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
agent,
event_emitter,
);
true
},
AgentEvent::ServerSound(_) | AgentEvent::Hurt => false,
AgentEvent::ServerSound(_) | AgentEvent::Hurt => return false,
};
if used {
agent.inbox.pop_front();
}
return used;
agent.inbox.pop_front();
}
false
}