mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed NPCs talking to themselves
This commit is contained in:
parent
5614eaa7a5
commit
80e4e8deae
@ -283,7 +283,12 @@ impl Npcs {
|
||||
}
|
||||
|
||||
/// Queries nearby npcs, not garantueed to work if radius > 32.0
|
||||
pub fn nearby(&self, wpos: Vec2<f32>, radius: f32) -> impl Iterator<Item = Actor> + '_ {
|
||||
pub fn nearby(
|
||||
&self,
|
||||
this_npc: Option<NpcId>,
|
||||
wpos: Vec2<f32>,
|
||||
radius: f32,
|
||||
) -> impl Iterator<Item = Actor> + '_ {
|
||||
let chunk_pos = wpos
|
||||
.as_::<i32>()
|
||||
.map2(TerrainChunkSize::RECT_SIZE.as_::<i32>(), |e, sz| {
|
||||
@ -301,6 +306,7 @@ impl Npcs {
|
||||
self.npcs
|
||||
.get(*npc)
|
||||
.map_or(false, |npc| npc.wpos.xy().distance_squared(wpos) < r_sqr)
|
||||
&& Some(*npc) != this_npc
|
||||
})
|
||||
.map(Actor::Npc)
|
||||
})
|
||||
|
@ -452,11 +452,11 @@ fn timeout(time: f64) -> impl FnMut(&mut NpcCtx) -> bool + Clone + Send + Sync {
|
||||
fn socialize() -> impl Action {
|
||||
now(|ctx| {
|
||||
// TODO: Bit odd, should wait for a while after greeting
|
||||
if ctx.rng.gen_bool(0.004) && let Some(other) = ctx
|
||||
if ctx.rng.gen_bool(0.002) && let Some(other) = ctx
|
||||
.state
|
||||
.data()
|
||||
.npcs
|
||||
.nearby(ctx.npc.wpos.xy(), 8.0)
|
||||
.nearby(Some(ctx.npc_id), ctx.npc.wpos.xy(), 8.0)
|
||||
.choose(&mut ctx.rng)
|
||||
{
|
||||
just(move |ctx| ctx.controller.greet(other)).boxed()
|
||||
|
@ -33,8 +33,6 @@ fn on_setup(ctx: EventCtx<SyncNpcs, OnSetup>) {
|
||||
fn on_death(ctx: EventCtx<SyncNpcs, OnDeath>) {
|
||||
let data = &mut *ctx.state.data_mut();
|
||||
|
||||
println!("NPC DIED!");
|
||||
|
||||
// Remove NPC from home population
|
||||
if let Some(home) = data
|
||||
.npcs
|
||||
|
@ -489,7 +489,6 @@ fn handle_rtsim_actions(bdata: &mut BehaviorData) -> bool {
|
||||
bdata.agent.awareness.set_maximally_aware();
|
||||
|
||||
bdata.controller.push_action(ControlAction::Stand);
|
||||
bdata.controller.push_action(ControlAction::Talk);
|
||||
bdata.controller.push_utterance(UtteranceKind::Greeting);
|
||||
bdata
|
||||
.agent_data
|
||||
@ -506,8 +505,10 @@ fn handle_rtsim_actions(bdata: &mut BehaviorData) -> bool {
|
||||
bdata.agent_data.chat_npc(msg, bdata.event_emitter);
|
||||
},
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Handle timed events, like looking at the player we are talking to
|
||||
|
Loading…
Reference in New Issue
Block a user