/** * Faster calculation than checkIfInRange if distance is short and collisionRadius isn't needed. * Not for long distance checks (potential teleports, far away castles, etc) * * @param radius The radius to use as check. * @param obj1 The position 1 to make check on. * @param obj2 The postion 2 to make check on. * @param includeZAxis Include Z check or not. * @return true if both objects are in the given radius. */ public static boolean checkIfInShortRadius( int radius, L2Object obj1, L2Object obj2, boolean includeZAxis) { if (obj1 == null || obj2 == null) return false; if (radius == -1) return true; // not limited int dx = obj1.getX() - obj2.getX(); int dy = obj1.getY() - obj2.getY(); if (includeZAxis) { int dz = obj1.getZ() - obj2.getZ(); return dx * dx + dy * dy + dz * dz <= radius * radius; } return dx * dx + dy * dy <= radius * radius; }
/** * This check includes collision radius of both characters.<br> * Used for accurate checks (skill casts, knownlist, etc). * * @param range The range to use as check. * @param obj1 The position 1 to make check on. * @param obj2 The postion 2 to make check on. * @param includeZAxis Include Z check or not. * @return true if both objects are in the given radius. */ public static boolean checkIfInRange( int range, L2Object obj1, L2Object obj2, boolean includeZAxis) { if (obj1 == null || obj2 == null) return false; if (range == -1) return true; // not limited int rad = 0; if (obj1 instanceof L2Character) rad += ((L2Character) obj1).getTemplate().getCollisionRadius(); if (obj2 instanceof L2Character) rad += ((L2Character) obj2).getTemplate().getCollisionRadius(); double dx = obj1.getX() - obj2.getX(); double dy = obj1.getY() - obj2.getY(); if (includeZAxis) { double dz = obj1.getZ() - obj2.getZ(); double d = dx * dx + dy * dy + dz * dz; return d <= range * range + 2 * range * rad + rad * rad; } double d = dx * dx + dy * dy; return d <= range * range + 2 * range * rad + rad * rad; }