mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Make npcs attack in a smarter way
This commit is contained in:
parent
9f83130466
commit
f3593371ea
@ -65,6 +65,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
Agent::Enemy { bearing, target } => {
|
||||
const SIGHT_DIST: f32 = 30.0;
|
||||
const MIN_ATTACK_DIST: f32 = 3.5;
|
||||
let mut choose_new = false;
|
||||
|
||||
if let Some((Some(target_pos), Some(target_stats), Some(target_character))) =
|
||||
@ -81,16 +82,11 @@ impl<'a> System<'a> for Sys {
|
||||
let dist = Vec2::<f32>::from(target_pos.0 - pos.0).magnitude();
|
||||
if target_stats.is_dead {
|
||||
choose_new = true;
|
||||
} else if dist < 6.0 {
|
||||
// Fight and slowly move closer
|
||||
} else if dist < MIN_ATTACK_DIST {
|
||||
// Fight (and slowly move closer)
|
||||
controller.move_dir =
|
||||
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.5;
|
||||
|
||||
if rand::random::<f32>() < 0.05 {
|
||||
controller.primary = true;
|
||||
} else {
|
||||
controller.primary = false;
|
||||
}
|
||||
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.01;
|
||||
controller.primary = true;
|
||||
} else if dist < SIGHT_DIST {
|
||||
controller.move_dir =
|
||||
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.96;
|
||||
|
@ -114,7 +114,6 @@ impl<'a> System<'a> for Sys {
|
||||
|| character.movement == Run
|
||||
|| character.movement == Jump)
|
||||
{
|
||||
// TODO: Check if wield ability exists
|
||||
if let Wield { time_left } = character.action {
|
||||
if time_left == Duration::default() {
|
||||
character.action = Attack {
|
||||
@ -152,6 +151,20 @@ impl<'a> System<'a> for Sys {
|
||||
});
|
||||
}
|
||||
}
|
||||
None => {
|
||||
// Attack
|
||||
if controller.primary
|
||||
&& (character.movement == Stand
|
||||
|| character.movement == Run
|
||||
|| character.movement == Jump)
|
||||
&& !character.action.is_attack()
|
||||
{
|
||||
character.action = Attack {
|
||||
time_left: ATTACK_DURATION,
|
||||
applied: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user