From 2a1f0f267444c08069dc4c4cd8280d3c5b5ee09a Mon Sep 17 00:00:00 2001
From: Kemper <9278383-Kemper-@users.noreply.gitlab.com>
Date: Wed, 27 Oct 2021 18:01:21 +0000
Subject: [PATCH] Aim fireballs at feet
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AI aims fireballs at the target’s feet, for a slight improvement
in splash damage.
---
 CHANGELOG.md            |  1 +
 server/src/sys/agent.rs | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 19d718c187..0302ab3aa4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Updated client facing error messages to be localizable strings
 - Nerfed some skill values
 - Tweaked critical chance of legendary weapons
+- Agents using fireball projectiles aim at the feet instead of the eyes
 
 ### Removed
 
diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs
index dcb6fe4400..1e1940a84c 100644
--- a/server/src/sys/agent.rs
+++ b/server/src/sys/agent.rs
@@ -17,6 +17,7 @@ use common::{
             tool::{AbilitySpec, ToolKind},
             ConsumableKind, Item, ItemDesc, ItemKind,
         },
+        projectile::ProjectileConstructor,
         skills::{AxeSkill, BowSkill, HammerSkill, SceptreSkill, Skill, StaffSkill, SwordSkill},
         Agent, Alignment, BehaviorCapability, BehaviorState, Body, CharacterAbility,
         CharacterState, Combo, ControlAction, ControlEvent, Controller, Energy, Health,
@@ -1807,7 +1808,8 @@ impl<'a> AgentData<'a> {
 
         let eye_offset = self.body.map_or(0.0, |b| b.eye_height());
 
-        let tgt_eye_offset = tgt_data.body.map_or(0.0, |b| b.eye_height()) +
+        let tgt_eye_height = tgt_data.body.map_or(0.0, |b| b.eye_height());
+        let tgt_eye_offset = tgt_eye_height +
                    // Special case for jumping attacks to jump at the body
                    // of the target and not the ground around the target
                    // For the ranged it is to shoot at the feet and not
@@ -1854,6 +1856,15 @@ impl<'a> AgentData<'a> {
                 )
             },
             CharacterState::BasicRanged(c) => {
+                let offset_z = match c.static_data.projectile {
+                    // Aim fireballs at feet instead of eyes for splash damage
+                    ProjectileConstructor::Fireball {
+                        damage: _,
+                        radius: _,
+                        energy_regen: _,
+                    } => 0.0,
+                    _ => tgt_eye_offset,
+                };
                 let projectile_speed = c.static_data.projectile_speed;
                 aim_projectile(
                     projectile_speed,
@@ -1864,7 +1875,7 @@ impl<'a> AgentData<'a> {
                     Vec3::new(
                         tgt_data.pos.0.x,
                         tgt_data.pos.0.y,
-                        tgt_data.pos.0.z + tgt_eye_offset,
+                        tgt_data.pos.0.z + offset_z,
                     ),
                 )
             },