public double getDistanceToTarget() {
   if (isFollowTarget) {
     VisibleObject target = owner.getTarget();
     if (target != null)
       return MathUtil.getDistance(
           owner.getX(), owner.getY(), owner.getZ(), target.getX(), target.getY(), target.getZ());
   }
   return MathUtil.getDistance(
       owner.getX(), owner.getY(), owner.getZ(), targetX, targetY, targetZ);
 }
 @Override
 protected void handleCreatureMoved(Creature creature) {
   if (creature instanceof Player) {
     final Player player = (Player) creature;
     if (MathUtil.getDistance(getOwner(), player) <= doorId) {
       if (MathUtil.getDistance(
               getOwner(), getPosition().getWorldMapInstance().getDoors().get(doorId))
           <= 30) {
         if (isCollapsed.compareAndSet(false, true)) {
           getPosition().getWorldMapInstance().getDoors().get(doorId).setOpen(true);
         }
       }
     }
   }
 }
  public static final boolean set(final Skill skill, Properties properties) {
    TargetRangeAttribute value = properties.getTargetType();
    int maxcount = properties.getTargetMaxCount();

    switch (value) {
      case AREA:
        int areaCounter = 0;
        final Creature firstTarget = skill.getFirstTarget();
        if (firstTarget == null) {
          return false;
        }
        SortedMap<Double, Creature> sortedMap = new TreeMap<Double, Creature>();
        for (Creature creature : skill.getEffectedList()) {
          sortedMap.put(MathUtil.getDistance(firstTarget, creature), creature);
        }
        skill.getEffectedList().clear();
        for (Creature creature : sortedMap.values()) {
          if (areaCounter >= maxcount) {
            break;
          }
          skill.getEffectedList().add(creature);
          areaCounter++;
        }
    }
    return true;
  }
  protected boolean checkObjectInRange(VisibleObject newObject) {
    // check if Z distance is greater than maxZvisibleDistance
    if (Math.abs(owner.getZ() - newObject.getZ()) > owner.getMaxZVisibleDistance()) {
      return false;
    }

    return MathUtil.isInRange(owner, newObject, owner.getVisibilityDistance());
  }
Exemple #5
0
  private boolean useSkill(boolean checkAnimation, boolean checkproperties) {
    if (checkproperties && !canUseSkill()) return false;

    if (skillMethod != SkillMethod.CHARGE) calculateSkillDuration();

    if (SecurityConfig.MOTION_TIME) {
      // must be after calculateskillduration
      if (checkAnimation && !checkAnimationTime()) {
        log.debug("check animation time failed");
        return false;
      }
    }

    boostSkillCost = 0;

    // notify skill use observers
    if (skillMethod == SkillMethod.CAST || skillMethod == SkillMethod.CHARGE)
      effector.getObserveController().notifySkilluseObservers(this);

    // start casting
    effector.setCasting(this);

    // log skill time if effector instance of player
    // TODO config
    if (effector instanceof Player)
      MotionLoggingService.getInstance()
          .logTime(
              (Player) effector,
              this.getSkillTemplate(),
              this.getHitTime(),
              MathUtil.getDistance(effector, firstTarget));

    // send packets to start casting
    if (skillMethod == SkillMethod.CAST
        || skillMethod == SkillMethod.ITEM
        || skillMethod == SkillMethod.CHARGE) {
      castStartTime = System.currentTimeMillis();
      startCast();
      if (effector instanceof Npc)
        ((NpcAI2) ((Npc) effector).getAi2()).setSubStateIfNot(AISubState.CAST);
    }

    effector.getObserveController().attach(conditionChangeListener);

    if (this.duration > 0) {
      schedule(this.duration);
    } else {
      endCast();
    }
    return true;
  }
 public void SpawnFront(Player player) {
   double radian = Math.toRadians(MathUtil.convertHeadingToDegree(player.getHeading()));
   float x1 = (float) (Math.cos(Math.PI * 0 + radian) * 5);
   float y1 = (float) (Math.sin(Math.PI * 0 + radian) * 5);
   attacktransformedPlayer(
       player,
       (Npc)
           spawn(
               231193,
               (player.getX() + x1),
               (player.getY() + y1),
               player.getZ(),
               (byte) player.getHeading()));
 }
 @Override
 public void moved() {
   double newRange = MathUtil.getDistance(player, creature);
   if (creature == null || creature.getLifeStats().isAlreadyDead()) {
     if (player != null) {
       player.getObserveController().removeObserver(this);
     }
     return;
   }
   if (oldRange > 12 && newRange <= 12) {
     onMove();
   }
   oldRange = newRange;
 }
 public GaleCycloneObserver(Player player, Creature creature) {
   super(ObserverType.MOVE);
   this.player = player;
   this.creature = creature;
   oldRange = MathUtil.getDistance(player, creature);
 }
Exemple #9
0
  private boolean checkAnimationTime() {
    if (!(effector instanceof Player) || skillMethod != SkillMethod.CAST) // TODO item skills?
    return true;
    Player player = (Player) effector;

    // if player is without weapon, dont check animation time
    if (player.getEquipment().getMainHandWeaponType() == null) return true;

    /** exceptions for certain skills -herb and mana treatment -traps */
    // dont check herb , mana treatment and concentration enhancement
    switch (this.getSkillId()) {
      case 1803: // bandage heal
      case 1804: // herb treatment
      case 1805:
      case 1825:
      case 1827:
      case 2672:
      case 1823: // mana treatment
      case 1824:
      case 1826:
      case 1828:
      case 2673:
      case 1078: // concentration enhancement
      case 1125:
      case 1468:
      case 11580:
        return true;
    }
    if (this.getSkillTemplate().getSubType() == SkillSubType.SUMMONTRAP) return true;

    Motion motion = this.getSkillTemplate().getMotion();

    if (motion == null || motion.getName() == null) {
      log.warn("missing motion for skillId: " + this.getSkillId());
      return true;
    }

    if (motion.getInstantSkill() && hitTime != 0) {
      log.warn(
          "Instant and hitTime not 0! modified client_skills? player objectid: "
              + player.getObjectId());
      return false;
    } else if (!motion.getInstantSkill() && hitTime == 0) {
      log.warn("modified client_skills! player objectid: " + player.getObjectId());
      return false;
    }

    MotionTime motionTime = DataManager.MOTION_DATA.getMotionTime(motion.getName());

    if (motionTime == null) {
      log.warn(
          "missing motiontime for motionName: "
              + motion.getName()
              + " skillId: "
              + this.getSkillId());
      return true;
    }

    WeaponTypeWrapper weapons =
        new WeaponTypeWrapper(
            player.getEquipment().getMainHandWeaponType(),
            player.getEquipment().getOffHandWeaponType());
    float serverTime = motionTime.getTimeForWeapon(player.getRace(), player.getGender(), weapons);
    int clientTime = hitTime;

    if (serverTime == 0) {
      log.warn(
          "missing weapon time for motionName: "
              + motion.getName()
              + " weapons: "
              + weapons.toString()
              + " skillId: "
              + this.getSkillId());
      return true;
    }

    // adjust client time with ammotime
    long ammoTime = 0;
    double distance = MathUtil.getDistance(effector, firstTarget);
    if (getSkillTemplate().getAmmoSpeed() != 0)
      ammoTime =
          Math.round(distance / getSkillTemplate().getAmmoSpeed() * 1000); // checked with client
    clientTime -= ammoTime;

    // adjust servertime with motion play speed
    if (motion.getSpeed() != 100) {
      serverTime /= 100f;
      serverTime *= (float) motion.getSpeed();
    }

    Stat2 attackSpeed = player.getGameStats().getAttackSpeed();

    // adjust serverTime with attackSpeed
    if (attackSpeed.getBase() != attackSpeed.getCurrent())
      serverTime *= ((float) attackSpeed.getCurrent() / (float) attackSpeed.getBase());

    // tolerance
    if (duration == 0) serverTime *= 0.9f;
    else serverTime *= 0.5f;

    int finalTime = Math.round(serverTime);
    if (motion.getInstantSkill() && hitTime == 0) {
      this.serverTime = (int) ammoTime;
    } else {
      if (clientTime < finalTime) {
        // check for no animation Hacks
        if (SecurityConfig.NO_ANIMATION) {
          float clientTme = clientTime;
          float serverTme = serverTime;
          float checkTme = clientTme / serverTme;
          // check if values are too low
          if (clientTime < 0 || checkTme < SecurityConfig.NO_ANIMATION_VALUE) {
            if (SecurityConfig.NO_ANIMATION_KICK) {
              player.getClientConnection().close(new SM_QUIT_RESPONSE(), false);
              AuditLogger.info(
                  player,
                  "Modified client_skills:"
                      + this.getSkillId()
                      + " (clientTime<finalTime:"
                      + clientTime
                      + "/"
                      + finalTime
                      + ") Kicking Player: "
                      + player.getName());
            } else {
              AuditLogger.info(
                  player,
                  "Modified client_skills:"
                      + this.getSkillId()
                      + " (clientTime<finalTime:"
                      + clientTime
                      + "/"
                      + finalTime
                      + ")");
            }
            return false;
          }
        }
        log.warn(
            "Possible modified client_skills:"
                + this.getSkillId()
                + " (clientTime<finalTime:"
                + clientTime
                + "/"
                + finalTime
                + ") player Name: "
                + player.getName());
      }
      this.serverTime = hitTime;
    }
    player.setNextSkillUse(System.currentTimeMillis() + duration + finalTime);
    return true;
  }
  private void move() {
    /** Demo npc skills - prevent movement while casting */
    if (!owner.canPerformMove() || owner.isCasting()) {
      if (!isStopped) {
        isStopped = true;
        owner.getController().stopMoving();
      }
      return;
    }

    VisibleObject target = owner.getTarget();

    if (isFollowTarget && target != null) {
      setNewDirection(target.getX(), target.getY(), target.getZ());
    }

    float ownerX = owner.getX();
    float ownerY = owner.getY();
    float ownerZ = owner.getZ();

    double dist = MathUtil.getDistance(ownerX, ownerY, ownerZ, targetX, targetY, targetZ);
    if (dist > this.distance) {
      isStopped = false;

      float x2;
      float y2;
      float z2;
      float mod = 1;
      if (dist < speed * 0.5) {
        x2 = (targetX - ownerX);
        y2 = (targetY - ownerY);
        z2 = (targetZ - ownerZ);
      } else {
        x2 = (float) (((targetX - ownerX) / dist) * speed * 0.5);
        y2 = (float) (((targetY - ownerY) / dist) * speed * 0.5);
        z2 = (float) (((targetZ - ownerZ) / dist) * speed * 0.5);
        mod = 0.5f;
      }

      byte heading2 = (byte) (Math.toDegrees(Math.atan2(y2, x2)) / 3);

      if (directionChanged) {
        PacketSendUtility.broadcastPacket(
            owner,
            new SM_MOVE(
                owner.getObjectId(),
                ownerX,
                ownerY,
                ownerZ,
                (x2 / mod),
                (y2 / mod),
                (z2 / mod),
                heading2,
                MovementType.MOVEMENT_START_KEYBOARD));
        directionChanged = false;
      }

      moveCounter++;
      World.getInstance()
          .updatePosition(
              owner, ownerX + x2, ownerY + y2, ownerZ + z2, heading2, moveCounter % 5 == 0);
    } else {
      if (!isStopped) {
        isStopped = true;
        owner.getController().stopMoving();
      }
    }
  }
Exemple #11
0
  protected final boolean checkObjectInRange(VisibleObject owner, VisibleObject newObject) {
    // check if Z distance is greater than maxZvisibleDistance
    if (Math.abs(owner.getZ() - newObject.getZ()) > maxZvisibleDistance) return false;

    return MathUtil.isInRange(owner, newObject, visibilityDistance);
  }