Exemple #1
0
  /**
   * 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;
  }
Exemple #2
0
  /**
   * 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;
  }
Exemple #3
0
 public static final int calculateHeadingFrom(L2Object obj1, L2Object obj2) {
   return calculateHeadingFrom(obj1.getX(), obj1.getY(), obj2.getX(), obj2.getY());
 }
Exemple #4
0
 /**
  * @param obj1
  * @param obj2
  * @return degree value of object 2 to the horizontal line with object 1 being the origin
  */
 public static double calculateAngleFrom(L2Object obj1, L2Object obj2) {
   return calculateAngleFrom(obj1.getX(), obj1.getY(), obj2.getX(), obj2.getY());
 }