From fd3c377d1cd32a527ca0f7a628a829426d6750c3 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 22 Apr 2023 21:37:23 -0400 Subject: [PATCH] Taught adlet elder how to use leap --- assets/common/abilities/adlet/elder/leap.ron | 2 +- server/agent/src/action_nodes.rs | 2 +- server/agent/src/attack.rs | 22 ++++++++++++++++- server/agent/src/data.rs | 25 +++++++++++--------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/assets/common/abilities/adlet/elder/leap.ron b/assets/common/abilities/adlet/elder/leap.ron index 271fd23e91..f8f6193bea 100644 --- a/assets/common/abilities/adlet/elder/leap.ron +++ b/assets/common/abilities/adlet/elder/leap.ron @@ -22,6 +22,6 @@ LeapMelee( ))), ), forward_leap_strength: 30.0, - vertical_leap_strength: 25.0, + vertical_leap_strength: 15.0, specifier: Some(ElderLeap), ) \ No newline at end of file diff --git a/server/agent/src/action_nodes.rs b/server/agent/src/action_nodes.rs index b692cd13ca..b149438c5b 100644 --- a/server/agent/src/action_nodes.rs +++ b/server/agent/src/action_nodes.rs @@ -1501,7 +1501,7 @@ impl<'a> AgentData<'a> { abilities, ), Tactic::AdletElder => { - self.handle_adlet_elder(agent, controller, &attack_data, tgt_data, read_data) + self.handle_adlet_elder(agent, controller, &attack_data, tgt_data, read_data, rng) }, } } diff --git a/server/agent/src/attack.rs b/server/agent/src/attack.rs index 67e8c6308e..eb28ee7513 100644 --- a/server/agent/src/attack.rs +++ b/server/agent/src/attack.rs @@ -4723,6 +4723,7 @@ impl<'a> AgentData<'a> { attack_data: &AttackData, tgt_data: &TargetData, read_data: &ReadData, + rng: &mut impl Rng, ) { const TRAP_TIMER: usize = 0; agent.action_state.timers[TRAP_TIMER] -= read_data.dt.0; @@ -4731,6 +4732,10 @@ impl<'a> AgentData<'a> { } let primary = self.extract_ability(AbilityInput::Primary); let secondary = self.extract_ability(AbilityInput::Secondary); + let abilities = [ + self.extract_ability(AbilityInput::Auxiliary(0)), + self.extract_ability(AbilityInput::Auxiliary(1)), + ]; let could_use_input = |input| match input { InputKind::Primary => primary.as_ref().map_or(false, |p| { p.could_use(attack_data, self, tgt_data, read_data, 0.0) @@ -4738,6 +4743,9 @@ impl<'a> AgentData<'a> { InputKind::Secondary => secondary.as_ref().map_or(false, |s| { s.could_use(attack_data, self, tgt_data, read_data, 0.0) }), + InputKind::Ability(x) => abilities[x].as_ref().map_or(false, |a| { + a.could_use(attack_data, self, tgt_data, read_data, 0.0) + }), _ => false, }; let move_forwards = if matches!(self.char_state, CharacterState::DashMelee(s) if s.stage_section != StageSection::Recover) @@ -4750,13 +4758,25 @@ impl<'a> AgentData<'a> { } else if could_use_input(InputKind::Primary) { controller.push_basic_input(InputKind::Primary); false - } else if could_use_input(InputKind::Secondary) { + } else if could_use_input(InputKind::Secondary) && rng.gen_bool(0.5) { controller.push_basic_input(InputKind::Secondary); false + } else if could_use_input(InputKind::Ability(1)) { + controller.push_basic_input(InputKind::Ability(1)); + false } else { true }; + if matches!(self.char_state, CharacterState::LeapMelee(_)) { + let tgt_vec = tgt_data.pos.0.xy() - self.pos.0.xy(); + if tgt_vec.magnitude_squared() > 2_f32.powi(2) { + if let Some(look_dir) = Dir::from_unnormalized(Vec3::from(tgt_vec)) { + controller.inputs.look_dir = look_dir; + } + } + } + if move_forwards && attack_data.dist_sqrd > 2_f32.powi(2) { self.path_toward_target( agent, diff --git a/server/agent/src/data.rs b/server/agent/src/data.rs index d183adb88d..0f34fed635 100644 --- a/server/agent/src/data.rs +++ b/server/agent/src/data.rs @@ -603,23 +603,26 @@ impl AbilityData { desired_energy: f32, ) -> bool { let melee_check = |range: f32, angle, forced_movement: Option| { - let range_inc = forced_movement.map_or(0.0, |fm| match fm { - ForcedMovement::Forward(speed) => speed * 15.0, - ForcedMovement::Reverse(speed) => -speed, + let (range_inc, min_mult) = forced_movement.map_or((0.0, 0.0), |fm| match fm { + ForcedMovement::Forward(speed) => (speed * 15.0, 1.0), + ForcedMovement::Reverse(speed) => (-speed, 1.0), ForcedMovement::Leap { vertical, forward, .. - } => { - let dur = vertical * 2.0 / GRAVITY; - // 0.75 factor to allow for fact that agent looks down as they approach, so - // won't go as far - forward * dur * 0.75 - }, - _ => 0.0, + } => ( + { + let dur = vertical * 2.0 / GRAVITY; + // 0.75 factor to allow for fact that agent looks down as they approach, so + // won't go as far + forward * dur * 0.75 + }, + 0.0, + ), + _ => (0.0, 0.0), }); let body_rad = agent_data.body.map_or(0.0, |b| b.max_radius()); attack_data.dist_sqrd < (range + range_inc + body_rad).powi(2) && attack_data.angle < angle - && attack_data.dist_sqrd > range_inc.powi(2) + && attack_data.dist_sqrd > (range_inc * min_mult).powi(2) }; let energy_check = |energy: f32| { agent_data.energy.current() >= energy