예제 #1
0
  public void updatePosition() {
    long now = GameEngine.getAccurateTimestamp();
    Player victim = findVictim();

    if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && victim != null) {
      resetPath();

      victim.resetPath();
      victim.resetAll();
      victim.setStatus(Action.FIGHTING_MOB);
      victim.getActionSender().sendSound("underattack");
      victim.getActionSender().sendMessage("You are under attack!");

      if (victim.isSleeping()) {
        victim.getActionSender().sendWakeUp(false, false);
        victim.getActionSender().sendFatigue(victim.getFatigue());
      }

      this.setLocation(victim.getLocation(), true);

      for (Player p : getViewArea().getPlayersInView()) {
        p.removeWatchedNpc(this);
      }

      victim.setBusy(true);
      victim.setSprite(9);
      victim.setOpponent(this);
      victim.setCombatTimer();

      setBusy(true);
      setSprite(8);
      setOpponent(victim);
      setCombatTimer();
      FightEvent fighting = new FightEvent(victim, this, true);
      fighting.setLastRun(0);
      World.getWorld().getDelayedEventHandler().add(fighting);
    }

    if (now - lastMovement > 2200) {
      lastMovement = now;
      int rand = DataConversions.random(0, 1);
      if (!isBusy() && finishedPath() && rand == 1 && !isRemoved()) {
        int newX = DataConversions.random(loc.minX(), loc.maxX());
        int newY = DataConversions.random(loc.minY(), loc.maxY());
        setPath(new Path(getX(), getY(), newX, newY));
      }
    }

    super.updatePosition();
  }
예제 #2
0
  private Player findVictim() {
    if (goingToAttack) {
      return null;
    }
    if (hasRan()) {
      return null;
    }

    long now = GameEngine.getAccurateTimestamp();

    if (getChasing() != null) {
      return null;
    }
    /*
    if(getViewArea().getPlayersInView() == null) {
    	return null;
    } */

    try {
      Iterable<Player> viewablePlayers = Area.getViewablePlayers(this.getLocation(), 2);
      if (viewablePlayers == null) return null;

      for (Player p : viewablePlayers) {
        if (p.inCombat()) {
          continue;
        } // || !p.nextTo(this) || p.isNonaggro()
        if (p.isBusy()
            || p.isNonaggro()
            || now - p.getCombatTimer()
                < (p.getCombatState() == CombatState.RUNNING
                        || p.getCombatState() == CombatState.WAITING
                    ? 3000
                    : 1500)
            || !p.nextTo(this)
            || !p.getLocation().inBounds(loc.minX - 4, loc.minY - 4, loc.maxX + 4, loc.maxY + 4)) {
          continue;
        } // || !p.nextTo(this)  || p.isNonaggro()
        if (!(p.isBusy()
                || p.isNonaggro()
                || now - p.getCombatTimer()
                    < (p.getCombatState() == CombatState.RUNNING
                            || p.getCombatState() == CombatState.WAITING
                        ? 3000
                        : 1500))
            || !p.nextTo(this)) {
          if (p.getCombatLevel() <= ((this.getCombatLevel() * 2) + 1) || location.inWilderness()) {
            return p;
          }
        }
      }
    } catch (Exception e) {
      // e.printStackTrace();
    }
    /*
    ActiveTile[][] tiles = getViewArea().getViewedArea(2, 2, 2, 2);
    for (int x = 0; x < tiles.length; x++) {
        for (int y = 0; y < tiles[x].length; y++) {
            ActiveTile t = tiles[x][y];
            if (t != null) {
                for (Player p : t.getPlayers()) {
                    if (p.inCombat()) {
                        continue;
                    }
                    if (p.isBusy() || p.isNonaggro() || now - p.getCombatTimer() < (p.getCombatState() == CombatState.RUNNING || p.getCombatState() == CombatState.WAITING ? 3000 : 1500) || !p.nextTo(this) || !p.getLocation().inBounds(loc.minX - 4, loc.minY - 4, loc.maxX + 4, loc.maxY + 4)) {
                        continue;
                    }
                    if (!(p.isBusy() || p.isNonaggro() || now - p.getCombatTimer() < (p.getCombatState() == CombatState.RUNNING || p.getCombatState() == CombatState.WAITING ? 3000 : 1500) || !p.nextTo(this))) {
                        if (p.getCombatLevel() <= ((this.getCombatLevel() * 2) + 1) || location.inWilderness()) {
                            return p;
                        }
                    }
                }
            }
        }
    } */
    return null;
  }