Exemple #1
0
  @Override
  public void setLocation(Point p, boolean teleported) {
    Area r = Area.getArea(p);
    Area cur = area.get();

    if (cur != r) {
      if (cur != null) {
        cur.removeNpc(this);
      }
      r.addNpc(this);
      area.getAndSet(r);
    }
    super.setLocation(p, teleported);
  }
Exemple #2
0
  public void remove() {
    Area cur = area.get();
    cur.removeNpc(this);

    if (!isRemoved() && shouldRespawn && def.respawnTime() > 0) {
      World.getWorld()
          .getDelayedEventHandler()
          .add(
              new DelayedEvent(null, def.respawnTime() * 1000) {

                public void run() {
                  world.registerNpc(new Npc(loc));
                  matchRunning = false;
                }
              });
    }

    removed.set(true);
  }
Exemple #3
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;
  }