Example #1
0
  public static double calculateDistance(L2Object obj1, L2Object obj2, boolean includeZAxis) {
    if (obj1 == null || obj2 == null) return 1000000;

    return calculateDistance(
        obj1.getPosition().getX(),
        obj1.getPosition().getY(),
        obj1.getPosition().getZ(),
        obj2.getPosition().getX(),
        obj2.getPosition().getY(),
        obj2.getPosition().getZ(),
        includeZAxis);
  }
Example #2
0
 @Override
 public String onSkillSee(
     L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet) {
   if (skill.getSkillType() == L2SkillType.AGGDAMAGE && targets.length != 0) {
     for (L2Object obj : targets) {
       if (obj.equals(npc)) {
         npc.broadcastNpcSay(
             ((caster.getAppearance().getSex()) ? "Sister " : "Brother ")
                 + caster.getName()
                 + ", move your weapon away!");
         attack(((L2Attackable) npc), caster);
         break;
       }
     }
   }
   return super.onSkillSee(npc, caster, skill, targets, isPet);
 }
Example #3
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;
  }
Example #4
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;
  }
Example #5
0
 public static final int calculateHeadingFrom(L2Object obj1, L2Object obj2) {
   return calculateHeadingFrom(obj1.getX(), obj1.getY(), obj2.getX(), obj2.getY());
 }
Example #6
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());
 }