forked from MagicBane/Server
add hitbox to abs vs abs range checks
This commit is contained in:
@@ -86,9 +86,9 @@ public enum CombatManager {
|
|||||||
|
|
||||||
// heck if character can even attack yet
|
// heck if character can even attack yet
|
||||||
|
|
||||||
if (attacker.getTimestamps().containsKey("Attack" + slot.name()))
|
//if (attacker.getTimestamps().containsKey("Attack" + slot.name()))
|
||||||
if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name()))
|
// if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name()))
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
// check if character is in range to attack target
|
// check if character is in range to attack target
|
||||||
|
|
||||||
@@ -114,19 +114,19 @@ public enum CombatManager {
|
|||||||
|
|
||||||
boolean inRange = false;
|
boolean inRange = false;
|
||||||
|
|
||||||
float attackerHitbox = attacker.calcHitBox();
|
attackRange += attacker.calcHitBox();
|
||||||
switch(target.getObjectType()){
|
switch(target.getObjectType()){
|
||||||
case PlayerCharacter:
|
case PlayerCharacter:
|
||||||
case Mob:
|
case Mob:
|
||||||
float targetHitbox = ((AbstractCharacter)target).calcHitBox();
|
attackRange += ((AbstractCharacter)target).calcHitBox();
|
||||||
if(distanceSquared < ((attackRange + attackerHitbox + targetHitbox) * 2))
|
if(distanceSquared < attackRange * 2)
|
||||||
inRange = true;
|
inRange = true;
|
||||||
break;
|
break;
|
||||||
case Building:
|
case Building:
|
||||||
float locX = target.loc.x - target.getBounds().getHalfExtents().x;
|
float locX = target.loc.x - target.getBounds().getHalfExtents().x;
|
||||||
float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
|
float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
|
||||||
float sizeX = (target.getBounds().getHalfExtents().x + attackRange + attackerHitbox) * 2;
|
float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2;
|
||||||
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange + attackerHitbox) * 2;
|
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2;
|
||||||
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ);
|
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ);
|
||||||
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z)))
|
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z)))
|
||||||
inRange = true;
|
inRange = true;
|
||||||
@@ -134,8 +134,7 @@ public enum CombatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!inRange)
|
if (inRange) {
|
||||||
return;
|
|
||||||
|
|
||||||
// take stamina away from attacker
|
// take stamina away from attacker
|
||||||
|
|
||||||
@@ -343,6 +342,7 @@ public enum CombatManager {
|
|||||||
((PlayerCharacter) attacker).setWeaponPower(dpj);
|
((PlayerCharacter) attacker).setWeaponPower(dpj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//calculate next allowed attack and update the timestamp
|
//calculate next allowed attack and update the timestamp
|
||||||
|
|
||||||
long delay = 20 * 100;
|
long delay = 20 * 100;
|
||||||
|
|||||||
Reference in New Issue
Block a user