From 1bff06cde00de842518c2b07ccd868b1ef643d15 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 8 Apr 2024 20:20:16 -0500 Subject: [PATCH] using building bounds and hitBox for mele range --- src/engine/gameManager/CombatManager.java | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index c621180d..56dc7890 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.Bounds; import engine.mbEnums; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; @@ -23,6 +24,8 @@ import engine.powers.effectmodifiers.AbstractEffectModifier; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; import java.util.EnumSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -109,7 +112,29 @@ public enum CombatManager { float distanceSquared = attacker.loc.distanceSquared(target.loc); - if (distanceSquared > attackRange * attackRange) + boolean inRange = false; + + float attackerHitbox = attacker.calcHitBox(); + switch(target.getObjectType()){ + case PlayerCharacter: + case Mob: + float targetHitbox = ((AbstractCharacter)target).calcHitBox(); + if(distanceSquared < ((attackRange + attackerHitbox + targetHitbox) * 2)) + 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 + attackerHitbox) * 2; + float sizeZ = (target.getBounds().getHalfExtents().y + attackRange + attackerHitbox) * 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 (!inRange) return; // take stamina away from attacker