Beispiel #1
0
  @Override
  protected boolean thinkActive() {
    NpcInstance actor = getActor();
    Player player;

    // follow the player
    double distance;

    if (targetPlayers != null && targetPlayers.size() > 0 && followTargetIndex > 0) {
      player = targetPlayers.get(followTargetIndex - 1);

      // in case the player set to follow is null, fall back to the first player in the list
      if (player == null) player = targetPlayers.get(0);

      distance = (int) actor.getDistance(player);

      if (distance > maxFollowDistance) {
        if (GeoEngine.canSeeTarget(actor, player, false)) {
          // in case the NPC can see the player
          actor.setRunning();
          Location loc =
              new Location(
                  player.getX() + Rnd.get(-60, 60),
                  player.getY() + Rnd.get(-60, 60),
                  player.getZ());
          actor.followToCharacter(loc, player, minFollowDistance, false);
        } else {
          // in case the NPC cannot see the player, then teleport straight to him
          actor.teleToLocation(player.getLoc().getRandomLoc(100));
        }
        return true;
      }
    }

    return startAttack();
  }