mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
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:
commit
d88dace5b8
@ -382,7 +382,7 @@ impl<'a> From<&'a Body> for Psyche {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
sight_dist: match body {
|
sight_dist: match body {
|
||||||
Body::BirdLarge(_) => 100.0,
|
Body::BirdLarge(_) => 250.0,
|
||||||
_ => 40.0,
|
_ => 40.0,
|
||||||
},
|
},
|
||||||
listen_dist: 30.0,
|
listen_dist: 30.0,
|
||||||
|
@ -3,6 +3,7 @@ pub const MAX_PICKUP_RANGE: f32 = 5.0;
|
|||||||
pub const MAX_MOUNT_RANGE: f32 = 5.0;
|
pub const MAX_MOUNT_RANGE: f32 = 5.0;
|
||||||
pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0;
|
pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0;
|
||||||
pub const MAX_TRADE_RANGE: f32 = 20.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 GRAVITY: f32 = 25.0;
|
||||||
pub const FRIC_GROUND: f32 = 0.15;
|
pub const FRIC_GROUND: f32 = 0.15;
|
||||||
|
@ -1223,7 +1223,7 @@ fn bird_large() -> impl Action<DefaultState> {
|
|||||||
if !is_deep_water {
|
if !is_deep_water {
|
||||||
goto_2d_flying(
|
goto_2d_flying(
|
||||||
pos,
|
pos,
|
||||||
0.2,
|
0.1,
|
||||||
bearing_dist,
|
bearing_dist,
|
||||||
8.0,
|
8.0,
|
||||||
8.0,
|
8.0,
|
||||||
@ -1237,7 +1237,7 @@ fn bird_large() -> impl Action<DefaultState> {
|
|||||||
|
|
||||||
goto_2d_flying(
|
goto_2d_flying(
|
||||||
pos,
|
pos,
|
||||||
0.2,
|
0.1,
|
||||||
bearing_dist,
|
bearing_dist,
|
||||||
8.0,
|
8.0,
|
||||||
8.0,
|
8.0,
|
||||||
|
@ -3118,7 +3118,7 @@ impl<'a> AgentData<'a> {
|
|||||||
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
||||||
if (self.pos.0.z - tgt_data.pos.0.z) < 35.0 {
|
if (self.pos.0.z - tgt_data.pos.0.z) < 35.0 {
|
||||||
controller.push_basic_input(InputKind::Fly);
|
controller.push_basic_input(InputKind::Fly);
|
||||||
controller.inputs.move_z = 1.0;
|
controller.inputs.move_z = 0.2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !read_data
|
} else if !read_data
|
||||||
|
@ -14,7 +14,10 @@ use common::{
|
|||||||
tool::{AbilityMap, ToolKind},
|
tool::{AbilityMap, ToolKind},
|
||||||
Inventory, LootOwner, Pos, SkillGroupKind,
|
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,
|
event::EventBus,
|
||||||
link::Is,
|
link::Is,
|
||||||
mounting::{Mount, Mounting, Rider, VolumeMounting, VolumePos, VolumeRider},
|
mounting::{Mount, Mounting, Rider, VolumeMounting, VolumePos, VolumeRider},
|
||||||
@ -86,17 +89,25 @@ pub fn handle_npc_interaction(
|
|||||||
subject: Subject,
|
subject: Subject,
|
||||||
) {
|
) {
|
||||||
let state = server.state_mut();
|
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()
|
.ecs()
|
||||||
.write_storage::<comp::Agent>()
|
.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) {
|
||||||
if let Some(interactor_uid) = state.ecs().uid_from_entity(interactor) {
|
agent
|
||||||
agent
|
.inbox
|
||||||
.inbox
|
.push_back(AgentEvent::Talk(interactor_uid, subject));
|
||||||
.push_back(AgentEvent::Talk(interactor_uid, subject));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,22 +557,20 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
|
|||||||
} = bdata;
|
} = bdata;
|
||||||
|
|
||||||
if let Some(msg) = agent.inbox.front() {
|
if let Some(msg) = agent.inbox.front() {
|
||||||
let used = match msg {
|
match msg {
|
||||||
AgentEvent::Talk(by, _) | AgentEvent::TradeAccepted(by) => {
|
AgentEvent::Talk(by, _) | AgentEvent::TradeAccepted(by) => {
|
||||||
if let (Some(target), Some(speaker)) =
|
if agent
|
||||||
(agent.target, get_entity_by_id(*by, bdata.read_data))
|
.target
|
||||||
{
|
.zip(get_entity_by_id(*by, bdata.read_data))
|
||||||
// in combat, speak to players that aren't the current target
|
// in combat, speak to players that aren't the current target
|
||||||
if !target.hostile || target.target != speaker {
|
.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_data.chat_npc_if_allowed_to_speak(
|
||||||
agent,
|
Content::localized("npc-speech-villager_busy"),
|
||||||
event_emitter,
|
agent,
|
||||||
);
|
event_emitter,
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
|
||||||
},
|
},
|
||||||
AgentEvent::TradeInvite(by) => {
|
AgentEvent::TradeInvite(by) => {
|
||||||
controller.push_invite_response(InviteResponse::Decline);
|
controller.push_invite_response(InviteResponse::Decline);
|
||||||
@ -596,7 +594,6 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
|
||||||
},
|
},
|
||||||
AgentEvent::FinishedTrade(result) => {
|
AgentEvent::FinishedTrade(result) => {
|
||||||
// copy pasted from recv_interaction
|
// 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.behavior.unset(BehaviorState::TRADING);
|
||||||
agent.target = None;
|
agent.target = None;
|
||||||
}
|
}
|
||||||
true
|
|
||||||
},
|
},
|
||||||
AgentEvent::UpdatePendingTrade(boxval) => {
|
AgentEvent::UpdatePendingTrade(boxval) => {
|
||||||
// immediately cancel the trade
|
// immediately cancel the trade
|
||||||
@ -638,14 +634,11 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
|
|||||||
agent,
|
agent,
|
||||||
event_emitter,
|
event_emitter,
|
||||||
);
|
);
|
||||||
true
|
|
||||||
},
|
},
|
||||||
AgentEvent::ServerSound(_) | AgentEvent::Hurt => false,
|
AgentEvent::ServerSound(_) | AgentEvent::Hurt => return false,
|
||||||
};
|
};
|
||||||
if used {
|
|
||||||
agent.inbox.pop_front();
|
agent.inbox.pop_front();
|
||||||
}
|
|
||||||
return used;
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user