mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Guards target village criminals
This commit is contained in:
parent
ad4bca3e52
commit
bf5336f97f
@ -1376,15 +1376,15 @@ impl<'a> AgentData<'a> {
|
|||||||
|
|
||||||
// Search area
|
// Search area
|
||||||
// TODO: REMOVE THIS BEFORE MERGE
|
// TODO: REMOVE THIS BEFORE MERGE
|
||||||
if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
//if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
||||||
let is_village_guard = agent_stats.name == *"Guard".to_string();
|
// let is_village_guard = agent_stats.name == *"Guard".to_string();
|
||||||
if is_village_guard {
|
// if is_village_guard {
|
||||||
self.chat_general(
|
// self.chat_general(
|
||||||
"I am a guard, searching for target".to_string(),
|
// "I am a guard, searching for target".to_string(),
|
||||||
event_emitter,
|
// event_emitter,
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
let target = self.cached_spatial_grid.0
|
let target = self.cached_spatial_grid.0
|
||||||
.in_circle_aabr(self.pos.0.xy(), SEARCH_DIST)
|
.in_circle_aabr(self.pos.0.xy(), SEARCH_DIST)
|
||||||
@ -1398,97 +1398,80 @@ impl<'a> AgentData<'a> {
|
|||||||
(entity, pos, health, stats, inventory, read_data.alignments.get(entity), read_data.char_states.get(entity))
|
(entity, pos, health, stats, inventory, read_data.alignments.get(entity), read_data.char_states.get(entity))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.filter(|(e, e_pos, e_health, e_stats, e_inventory, e_alignment, char_state)| {
|
.filter(|(e, e_pos, e_health, _e_stats, _e_inventory, _e_alignment, char_state)| {
|
||||||
let mut search_dist = SEARCH_DIST;
|
// Filter based on sight and hearing
|
||||||
let mut listen_dist = MAX_LISTEN_DIST;
|
let mut search_dist = SEARCH_DIST;
|
||||||
if char_state.map_or(false, |c_s| c_s.is_stealthy()) {
|
let mut listen_dist = MAX_LISTEN_DIST;
|
||||||
// TODO: make sneak more effective based on a stat like e_stats.fitness
|
if char_state.map_or(false, |c_s| c_s.is_stealthy()) {
|
||||||
search_dist *= SNEAK_COEFFICIENT;
|
// TODO: make sneak more effective based on a stat like e_stats.fitness
|
||||||
listen_dist *= SNEAK_COEFFICIENT;
|
search_dist *= SNEAK_COEFFICIENT;
|
||||||
}
|
listen_dist *= SNEAK_COEFFICIENT;
|
||||||
((self.within_range_of(search_dist, e_pos.0) && self.within_view_angle(e_pos.0, controller)) || self.within_range_of(listen_dist, e_pos.0)) // TODO implement proper sound system for agents
|
}
|
||||||
&& e != self.entity
|
((self.within_range_of(search_dist, e_pos.0) && self.within_view_angle(e_pos.0, controller)) || self.within_range_of(listen_dist, e_pos.0)) // TODO implement proper sound system for agents
|
||||||
&& !e_health.is_dead
|
&& e != self.entity
|
||||||
&& !invulnerability_is_in_buffs(read_data.buffs.get(*e))
|
&& !e_health.is_dead
|
||||||
&& (try_owner_alignment(self.alignment, read_data).and_then(|a| try_owner_alignment(*e_alignment, read_data).map(|b| a.hostile_towards(*b))).unwrap_or(false) || (
|
&& !invulnerability_is_in_buffs(read_data.buffs.get(*e))
|
||||||
if let Some(rtsim_entity) = &self.rtsim_entity {
|
})
|
||||||
if can_speak(agent) {
|
.filter_map(|(e, e_pos, e_health, e_stats, e_inventory, e_alignment, _char_state)| {
|
||||||
if rtsim_entity.brain.remembers_fight_with_character(&e_stats.name) {
|
if try_owner_alignment(self.alignment, &read_data).and_then(|a| try_owner_alignment(e_alignment, &read_data).map(|b| a.hostile_towards(*b))).unwrap_or(false) {
|
||||||
remember_fight(agent, e_stats.name.clone(), read_data.time.0);
|
Some((e, e_pos))
|
||||||
let msg = format!("{}! How dare you cross me again!", e_stats.name.clone());
|
} else if let Some(rtsim_entity) = &self.rtsim_entity {
|
||||||
self.chat_general(msg, event_emitter);
|
if can_speak(agent) && rtsim_entity.brain.remembers_fight_with_character(&e_stats.name) {
|
||||||
true
|
remember_fight(agent, e_stats.name.clone(), read_data.time.0);
|
||||||
} else {
|
let msg = format!("{}! How dare you cross me again!", e_stats.name.clone());
|
||||||
false
|
self.chat_general(msg, event_emitter);
|
||||||
}
|
Some((e, e_pos))
|
||||||
} else {
|
} else {
|
||||||
false
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(alignment) = self.alignment {
|
||||||
false
|
if matches!(alignment, Alignment::Npc) && e_inventory.equipped_items().filter(|item| item.tags().contains(&ItemTag::Cultist)).count() > 2 {
|
||||||
|
if can_speak(agent) {
|
||||||
|
if self.rtsim_entity.is_some() {
|
||||||
|
remember_fight(agent, e_stats.name.clone(), read_data.time.0);
|
||||||
}
|
}
|
||||||
) ||
|
let msg = "npc.speech.villager_cultist_alarm".to_string();
|
||||||
(
|
self.chat_general(msg, event_emitter);
|
||||||
self.alignment.map_or(false, |alignment| {
|
self.emit_villager_alarm(read_data.time.0, event_emitter);
|
||||||
if matches!(alignment, Alignment::Npc) && e_inventory.equipped_items().filter(|item| item.tags().contains(&ItemTag::Cultist)).count() > 2 {
|
}
|
||||||
if can_speak(agent) {
|
Some((e, e_pos))
|
||||||
if self.rtsim_entity.is_some() {
|
} else {
|
||||||
remember_fight(agent, e_stats.name.clone(), read_data.time.0);
|
None
|
||||||
}
|
}
|
||||||
let msg = "npc.speech.villager_cultist_alarm".to_string();
|
} else if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
||||||
self.chat_general(msg, event_emitter);
|
|
||||||
self.emit_villager_alarm(read_data.time.0, event_emitter);
|
|
||||||
}
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
))
|
|
||||||
|
|
||||||
})
|
|
||||||
.filter_map(|(e, e_pos, e_health, _e_stats, _e_inventory, e_alignment, _char_state)| {
|
|
||||||
// TODO: REMOVE THIS BEFORE MERGE
|
|
||||||
if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
|
||||||
let is_village_guard = agent_stats.name == *"Guard".to_string();
|
let is_village_guard = agent_stats.name == *"Guard".to_string();
|
||||||
if is_village_guard {
|
if is_village_guard {
|
||||||
println!("{}", "I am a guard, made it to the filter_map".to_string());
|
e_alignment.map(|alignment| {
|
||||||
}
|
let is_npc = matches!(alignment, Alignment::Npc);
|
||||||
}
|
if is_npc && e_health.last_change.0 < DAMAGE_MEMORY_DURATION {
|
||||||
if entity_was_attacked(e, &read_data) {
|
if let comp::HealthSource::Damage { by: Some(by), .. } = e_health.last_change.1.cause {
|
||||||
if let Some(alignment) = e_alignment {
|
get_entity_by_id(by.id(), read_data).map(|attacker| {
|
||||||
let is_npc = matches!(alignment, Alignment::Npc);
|
read_data.positions.get(attacker).map(|a_pos| (attacker, a_pos))
|
||||||
|
}).flatten()
|
||||||
if is_npc {
|
} else {
|
||||||
if let comp::HealthSource::Damage { by: Some(by), .. } = e_health.last_change.1.cause {
|
None
|
||||||
get_entity_by_id(by.id(), read_data)
|
}
|
||||||
.and_then(|attacker| {
|
|
||||||
println!("attacker data: {:?}", Some(attacker).zip(read_data.positions.get(attacker)));
|
|
||||||
Some(attacker).zip(read_data.positions.get(attacker))
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Some(e).zip(Some(e_pos))
|
None
|
||||||
}
|
}
|
||||||
} else {
|
}).flatten()
|
||||||
Some(e).zip(Some(e_pos))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Some(e).zip(Some(e_pos))
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Some(e).zip(Some(e_pos))
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Can we even see them?
|
// Can we even see them?
|
||||||
.filter(|(_e, e_pos)| {
|
.filter(|(_e, e_pos)| {
|
||||||
// TODO: REMOVE THIS BEFORE MERGE
|
// TODO: REMOVE THIS BEFORE MERGE
|
||||||
if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
//if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
||||||
let is_village_guard = agent_stats.name == *"Guard".to_string();
|
// let is_village_guard = agent_stats.name == *"Guard".to_string();
|
||||||
if is_village_guard {
|
// if is_village_guard {
|
||||||
println!("looking at: {:?} at {:?}", _e, e_pos);
|
// println!("looking at: {:?} at {:?}", _e, e_pos);
|
||||||
println!("can we see them: {:?}", read_data.terrain.ray(self.pos.0 + Vec3::unit_z(), e_pos.0 + Vec3::unit_z()).until(Block::is_opaque).cast().0 >= e_pos.0.distance(self.pos.0));
|
// println!("can we see them: {:?}", read_data.terrain.ray(self.pos.0 + Vec3::unit_z(), e_pos.0 + Vec3::unit_z()).until(Block::is_opaque).cast().0 >= e_pos.0.distance(self.pos.0));
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
read_data.terrain
|
read_data.terrain
|
||||||
.ray(self.pos.0 + Vec3::unit_z(), e_pos.0 + Vec3::unit_z())
|
.ray(self.pos.0 + Vec3::unit_z(), e_pos.0 + Vec3::unit_z())
|
||||||
@ -1509,13 +1492,13 @@ impl<'a> AgentData<'a> {
|
|||||||
selected_at: read_data.time.0,
|
selected_at: read_data.time.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: REMOVE THIS BEFORE MERGE
|
//// TODO: REMOVE THIS BEFORE MERGE
|
||||||
if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
//if let Some(agent_stats) = read_data.stats.get(*self.entity) {
|
||||||
let is_village_guard = agent_stats.name == *"Guard".to_string();
|
// let is_village_guard = agent_stats.name == *"Guard".to_string();
|
||||||
if is_village_guard {
|
// if is_village_guard {
|
||||||
println!("guard's target is: {:?}", agent.target);
|
// println!("guard's target is: {:?}", agent.target);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attack(
|
fn attack(
|
||||||
|
Loading…
Reference in New Issue
Block a user