From cc7188b4040515b6eb5fe454c8dfc7e68bf77507 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 22 May 2024 19:40:25 -0500 Subject: [PATCH] invalid range check for ranged characters attacking a building --- src/engine/gameManager/CombatManager.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 775bdf0a..1778cf21 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -12,6 +12,7 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.AttackJob; import engine.jobs.DeferredPowerJob; +import engine.math.Vector3f; import engine.mbEnums; import engine.net.client.ClientConnection; import engine.net.client.msg.TargetedActionMsg; @@ -163,14 +164,19 @@ public enum CombatManager { inRange = true; break; case Building: - float locX = target.loc.x - target.getBounds().getHalfExtents().x; - float locZ = target.loc.z - target.getBounds().getHalfExtents().y; - float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2; - float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2; - Rectangle2D.Float rect = new Rectangle2D.Float(locX, locZ, sizeX, sizeZ); - if (rect.contains(new Point2D.Float(attacker.loc.x, attacker.loc.z))) - inRange = true; - break; + if(attackRange > 15){ + if(attacker.loc.distanceSquared(target.loc) < (attackRange * attackRange)) + inRange = true; + }else { + float locX = target.loc.x - target.getBounds().getHalfExtents().x; + float locZ = target.loc.z - target.getBounds().getHalfExtents().y; + float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2; + float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2; + Rectangle2D.Float rect = new Rectangle2D.Float(locX, locZ, sizeX, sizeZ); + if (rect.contains(new Point2D.Float(attacker.loc.x, attacker.loc.z))) + inRange = true; + break; + } } //get delay for the auto attack job