fixed agent code for staff rework

This commit is contained in:
jiminycrick 2020-10-16 18:27:57 -07:00 committed by Robin Gilh
parent 66b1fe67dc
commit be1596a703

View File

@ -378,9 +378,8 @@ impl<'a> System<'a> for Sys {
min_tgt_dist: 1.25,
},
) {
inputs.move_dir = Vec2::from(bearing)
.try_normalized()
.unwrap_or(Vec2::zero())
inputs.move_dir =
bearing.xy().try_normalized().unwrap_or(Vec2::zero())
* speed
* 0.2; //Let small/slow animals flee slower than the player
inputs.jump.set_state(bearing.z > 1.5);
@ -395,21 +394,22 @@ impl<'a> System<'a> for Sys {
|| dist_sqrd < (MIN_ATTACK_DIST * scale).powf(2.0)
{
// Close-range attack
inputs.move_dir = Vec2::from(tgt_pos.0 - pos.0)
inputs.move_dir = (tgt_pos.0 - pos.0)
.xy()
.try_normalized()
.unwrap_or(Vec2::unit_y())
* 0.1;
match tactic {
Tactic::Melee
| Tactic::Staff
Tactic::Sword
| Tactic::Melee
| Tactic::Hammer
| Tactic::StoneGolemBoss => inputs.primary.set_state(true),
Tactic::Sword => {
inputs.primary.set_state(true);
},
Tactic::Staff => {
if energy.current() > 10 {
if energy.current() > 600 && thread_rng().gen::<f32>() > 0.6
{
inputs.ability3.set_state(true)
} else if energy.current() > 10 {
inputs.secondary.set_state(true)
} else {
inputs.primary.set_state(true)
@ -431,7 +431,7 @@ impl<'a> System<'a> for Sys {
if can_see_tgt {
if let Tactic::RangedPowerup = tactic {
if *powerup > 2.0 {
if *powerup > 1.5 {
inputs.primary.set_state(false);
*powerup = 0.0;
} else {
@ -446,18 +446,13 @@ impl<'a> System<'a> for Sys {
*powerup += dt.0;
}
} else if let Tactic::Staff = tactic {
if *powerup > 2.5 {
if *powerup > 1.5 {
inputs.primary.set_state(false);
*powerup = 0.0;
} else {
inputs.primary.set_state(true);
*powerup += dt.0;
}
if energy.current() > 400 {
inputs.ability3.set_state(true);
} else {
inputs.secondary.set_state(true);
}
} else if let Tactic::Hammer = tactic {
if *powerup > 5.0 {
inputs.secondary.set_state(true);
@ -492,14 +487,41 @@ impl<'a> System<'a> for Sys {
min_tgt_dist: 1.25,
},
) {
inputs.move_dir = Vec2::from(bearing)
if can_see_tgt {
match tactic {
Tactic::RangedPowerup => {
inputs.move_dir = bearing
.xy()
.rotated_z(thread_rng().gen_range(0.5, 1.57))
.try_normalized()
.unwrap_or(Vec2::zero())
* speed;
},
Tactic::Staff => {
inputs.move_dir = bearing
.xy()
.rotated_z(thread_rng().gen_range(-1.57, -0.5))
.try_normalized()
.unwrap_or(Vec2::zero())
* speed;
},
_ => {
inputs.move_dir = bearing
.xy()
.try_normalized()
.unwrap_or(Vec2::zero())
* speed;
},
}
} else {
inputs.move_dir =
bearing.xy().try_normalized().unwrap_or(Vec2::zero())
* speed;
inputs.jump.set_state(bearing.z > 1.5);
inputs.swimup.set_state(bearing.z > 0.5);
inputs.swimdown.set_state(bearing.z < 0.5);
}
}
if dist_sqrd < 16.0f32.powf(2.0)
&& matches!(tactic, Tactic::Melee)