From 6814ce813493cd622ad9bdc1254c12ba9f207d2a Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 11 Nov 2023 12:40:46 -0500 Subject: [PATCH] Addressed review comments. --- common/src/combat.rs | 10 ++++++++++ common/systems/src/beam.rs | 19 ++++--------------- common/systems/src/melee.rs | 15 ++------------- common/systems/src/projectile.rs | 18 +++++------------- voxygen/src/ui/widgets/item_tooltip.rs | 12 ++++++------ 5 files changed, 27 insertions(+), 47 deletions(-) diff --git a/common/src/combat.rs b/common/src/combat.rs index bc46c73fb2..ff7700f08c 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -1463,3 +1463,13 @@ pub fn compute_protection( .sum::>() }) } + +/// Used to compute the precision multiplier achieved by flanking a target +pub fn precision_mult_from_flank(attack_dir: Vec3, target_ori: Option<&Ori>) -> Option { + let angle = target_ori.map(|t_ori| t_ori.look_dir().angle_between(attack_dir)); + match angle { + Some(angle) if angle < FULL_FLANK_ANGLE => Some(1.0), + Some(angle) if angle < PARTIAL_FLANK_ANGLE => Some(0.5), + Some(_) | None => None, + } +} diff --git a/common/systems/src/beam.rs b/common/systems/src/beam.rs index 470c02fd49..ca8869f600 100644 --- a/common/systems/src/beam.rs +++ b/common/systems/src/beam.rs @@ -233,19 +233,10 @@ impl<'a> System<'a> for Sys { target, ); - let precision_from_flank = { - let beam_dir = beam.bezier.ctrl - beam.bezier.start; - let angle = target_info.ori.map_or(std::f32::consts::PI, |t_ori| { - t_ori.look_dir().angle_between(beam_dir) - }); - if angle < combat::FULL_FLANK_ANGLE { - Some(1.0) - } else if angle < combat::PARTIAL_FLANK_ANGLE { - Some(0.5) - } else { - None - } - }; + let precision_from_flank = combat::precision_mult_from_flank( + beam.bezier.ctrl - beam.bezier.start, + target_info.ori, + ); let precision_from_time = { if let Some(ticks) = beam.hit_durations.get(&target) { @@ -258,8 +249,6 @@ impl<'a> System<'a> for Sys { } }; - // Is there a more idiomatic way to do this (taking the max of 2 - // options)? let precision_mult = precision_from_flank .map(|flank| { precision_from_time.map_or(flank, |head: f32| head.max(flank)) diff --git a/common/systems/src/melee.rs b/common/systems/src/melee.rs index b8dd7516c8..aeca4ad646 100644 --- a/common/systems/src/melee.rs +++ b/common/systems/src/melee.rs @@ -220,18 +220,8 @@ impl<'a> System<'a> for Sys { target, ); - let precision_from_flank = { - let angle = target_ori.map_or(std::f32::consts::PI, |t_ori| { - t_ori.look_dir().angle_between(*ori.look_dir()) - }); - if angle < combat::FULL_FLANK_ANGLE { - Some(1.0) - } else if angle < combat::PARTIAL_FLANK_ANGLE { - Some(0.5) - } else { - None - } - }; + let precision_from_flank = + combat::precision_mult_from_flank(*ori.look_dir(), target_ori); let precision_from_poise = { if let Some(CharacterState::Stunned(data)) = target_char_state { @@ -241,7 +231,6 @@ impl<'a> System<'a> for Sys { } }; - // Is there a more idiomatic way to do this (taking the max of 2 options)? let precision_mult = precision_from_flank .map(|flank| { precision_from_poise.map_or(flank, |head: f32| head.max(flank)) diff --git a/common/systems/src/projectile.rs b/common/systems/src/projectile.rs index 79fc5ec785..8274e05e0e 100644 --- a/common/systems/src/projectile.rs +++ b/common/systems/src/projectile.rs @@ -346,20 +346,13 @@ fn dispatch_hit( .and_then(|cs| cs.attack_immunities()) .map_or(false, |i| i.projectiles); - let precision_from_flank = { - let angle = target_info.ori.map_or(std::f32::consts::PI, |t_ori| { - t_ori.look_dir().angle_between(*projectile_dir) - }); - if angle < combat::FULL_FLANK_ANGLE { - Some(1.0) - } else if angle < combat::PARTIAL_FLANK_ANGLE { - Some(0.5) - } else { - None - } - }; + let precision_from_flank = + combat::precision_mult_from_flank(*projectile_dir, target_info.ori); let precision_from_head = { + // This performs a cylinder and line segment intersection check. The cylinder is + // the upper 10% of an entity's dimensions. The line segment is from the + // projectile's positions on the current and previous tick. let curr_pos = projectile_info.pos.0; let last_pos = projectile_info.pos.0 - projectile_info.vel.0 * read_data.dt.0; let vel = projectile_info.vel.0; @@ -405,7 +398,6 @@ fn dispatch_hit( if headshot { Some(1.0) } else { None } }; - // Is there a more idiomatic way to do this (taking the max of 2 options)? let precision_mult = precision_from_flank .map(|flank| precision_from_head.map_or(flank, |head: f32| head.max(flank))) .or(precision_from_head); diff --git a/voxygen/src/ui/widgets/item_tooltip.rs b/voxygen/src/ui/widgets/item_tooltip.rs index 4f41528d36..a1a436f761 100644 --- a/voxygen/src/ui/widgets/item_tooltip.rs +++ b/voxygen/src/ui/widgets/item_tooltip.rs @@ -1139,8 +1139,8 @@ impl<'a> Widget for ItemTooltip<'a> { .parent(id) .with_style(self.style.desc) .color(text_color) - .down_from(state.ids.stats[3], V_PAD_STATS) - .set(state.ids.stats[4], ui); + .down_from(state.ids.stats[2], V_PAD_STATS) + .set(state.ids.stats[3], ui); // Energy Efficiency let energy_eff_text = if is_primary { @@ -1161,8 +1161,8 @@ impl<'a> Widget for ItemTooltip<'a> { .parent(id) .with_style(self.style.desc) .color(text_color) - .down_from(state.ids.stats[4], V_PAD_STATS) - .set(state.ids.stats[5], ui); + .down_from(state.ids.stats[3], V_PAD_STATS) + .set(state.ids.stats[4], ui); // Buff Strength let buff_str_text = if is_primary { @@ -1183,8 +1183,8 @@ impl<'a> Widget for ItemTooltip<'a> { .parent(id) .with_style(self.style.desc) .color(text_color) - .down_from(state.ids.stats[5], V_PAD_STATS) - .set(state.ids.stats[6], ui); + .down_from(state.ids.stats[4], V_PAD_STATS) + .set(state.ids.stats[5], ui); } }, _ => (),