Merge branch 'timo-attack' into 'master'

Fix wolfs not attacking and adjust movement while attacking

See merge request veloren/veloren!484
This commit is contained in:
Timo Koesters 2019-09-07 10:25:57 +00:00
commit 92c0edcb98
3 changed files with 20 additions and 11 deletions

View File

@ -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;

View File

@ -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,
};
}
}
_ => {}
}

View File

@ -60,7 +60,7 @@ impl AudioFrontend {
pub fn no_audio() -> Self {
Self {
device: "none".to_string(),
device_list: list_devices(),
device_list: Vec::new(),
audio_device: None,
sound_cache: SoundCache::new(),
channels: Vec::new(),