Browse Source

using building bounds and hitBox for mele range

combat-2
FatBoy-DOTC 7 months ago
parent
commit
1bff06cde0
  1. 27
      src/engine/gameManager/CombatManager.java

27
src/engine/gameManager/CombatManager.java

@ -12,6 +12,7 @@ import engine.job.JobContainer; @@ -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; @@ -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 { @@ -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

Loading…
Cancel
Save