Beispiel #1
0
 /** Clear all observers */
 public void clear() {
   lock.lock();
   try {
     onceUsedObservers.clear();
   } finally {
     lock.unlock();
   }
   observers.clear();
   attackCalcObservers.clear();
 }
Beispiel #2
0
  /**
   * @see ru.catssoftware.gameserver.pathfinding.PathFinding#findPath(int, int, int, int, int, int,
   *     int, boolean)
   */
  @Override
  public List<AbstractNodeLoc> findPath(
      int x, int y, int z, int tx, int ty, int tz, int instanceId, boolean playable) {
    int gx = (x - L2World.MAP_MIN_X) >> 4;
    int gy = (y - L2World.MAP_MIN_Y) >> 4;
    if (!GeoData.getInstance().hasGeo(x, y)) {
      return null;
    }
    short gz = GeoData.getInstance().getHeight(x, y, z);
    int gtx = (tx - L2World.MAP_MIN_X) >> 4;
    int gty = (ty - L2World.MAP_MIN_Y) >> 4;
    if (!GeoData.getInstance().hasGeo(tx, ty)) {
      return null;
    }
    short gtz = GeoData.getInstance().getHeight(tx, ty, tz);
    CellNodeBuffer buffer =
        alloc(64 + (2 * Math.max(Math.abs(gx - gtx), Math.abs(gy - gty))), playable);
    if (buffer == null) {
      return null;
    }

    boolean debug = playable && Config.DEBUG_PATH;

    if (debug) {
      if (_debugItems == null) {
        _debugItems = new FastList<L2ItemInstance>();
      } else {
        for (L2ItemInstance item : _debugItems) {
          if (item == null) {
            continue;
          }
          item.decayMe();
        }

        _debugItems.clear();
      }
    }

    FastList<AbstractNodeLoc> path = null;
    try {
      CellNode result = buffer.findPath(gx, gy, gz, gtx, gty, gtz);

      if (debug) {
        for (CellNode n : buffer.debugPath()) {
          if (n.getCost() < 0) {
            dropDebugItem(1831, (int) (-n.getCost() * 10), n.getLoc());
          } else {
            // known nodes
            dropDebugItem(PcInventory.ADENA_ID, (int) (n.getCost() * 10), n.getLoc());
          }
        }
      }

      if (result == null) {
        _findFails++;
        return null;
      }

      path = constructPath(result);
    } catch (Exception e) {
      _log.log(Level.WARNING, "", e);
      return null;
    } finally {
      buffer.free();
    }

    if ((path.size() < 3) || (Config.MAX_POSTFILTER_PASSES <= 0)) {
      _findSuccess++;
      return path;
    }

    long timeStamp = System.currentTimeMillis();
    _postFilterUses++;
    if (playable) {
      _postFilterPlayableUses++;
    }

    int currentX, currentY, currentZ;
    ListIterator<AbstractNodeLoc> middlePoint, endPoint;
    AbstractNodeLoc locMiddle, locEnd;
    boolean remove;
    int pass = 0;
    do {
      pass++;
      _postFilterPasses++;

      remove = false;
      middlePoint = path.listIterator();
      endPoint = path.listIterator(1);
      locEnd = null;
      currentX = x;
      currentY = y;
      currentZ = z;

      while (endPoint.hasNext()) {
        locEnd = endPoint.next();
        locMiddle = middlePoint.next();
        if (GeoData.getInstance()
            .canMoveFromToTarget(
                currentX,
                currentY,
                currentZ,
                locEnd.getX(),
                locEnd.getY(),
                locEnd.getZ(),
                instanceId)) {
          middlePoint.remove();
          remove = true;
          if (debug) {
            dropDebugItem(735, 1, locMiddle);
          }
        } else {
          currentX = locMiddle.getX();
          currentY = locMiddle.getY();
          currentZ = locMiddle.getZ();
        }
      }
    }
    // only one postfilter pass for AI
    while (playable && remove && (path.size() > 2) && (pass < Config.MAX_POSTFILTER_PASSES));

    if (debug) {
      middlePoint = path.listIterator();
      while (middlePoint.hasNext()) {
        locMiddle = middlePoint.next();
        dropDebugItem(65, 1, locMiddle);
      }
    }

    _findSuccess++;
    _postFilterElapsed += System.currentTimeMillis() - timeStamp;
    return path;
  }
  @Override
  public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = event;

    // Timer. Spawns Naia Lock
    if (event.equalsIgnoreCase("spawn_lock")) {
      htmltext = null;
      _lock = (L2MonsterInstance) addSpawn(LOCK, 16409, 244438, 11620, -1048, false, 0, false);
      _counter = 90;
    }

    // Timer. Depending of _challengeState despans all spawned spores, or spores, reached assembly
    // point
    else if (event.equalsIgnoreCase("despawn_total")) {
      // Spores is not attacked too long - despawn them all, reinit values
      if (_challengeState == STATE_SPORE_IDLE_TOO_LONG) {
        for (L2Npc spore : _sporeSpawn) {
          if ((spore != null) && !spore.isDead()) {
            spore.deleteMe();
          }
        }
        _sporeSpawn.clear();
        initSporeChallenge();
      }
      // Spores are moving to assembly point. Despawn all reached, check for reached spores count.
      else if ((_challengeState == STATE_SPORE_CHALLENGE_SUCCESSFULL) && (_winIndex >= 0)) {
        // Requirements are met, despawn all spores, spawn Epidos
        if ((_despawnedSporesCount >= 10) || _sporeSpawn.isEmpty()) {
          if (!_sporeSpawn.isEmpty()) {
            for (L2Npc spore : _sporeSpawn) {
              if ((spore != null) && !spore.isDead()) {
                spore.deleteMe();
              }
            }
          }
          _sporeSpawn.clear();
          _despawnedSporesCount = 0;
          int[] coords = SPORES_MERGE_POSITION[_winIndex];
          addSpawn(EPIDOSES[_winIndex], coords[0], coords[1], coords[2], 0, false, 0, false);
          initSporeChallenge();
        }
        // Requirements aren't met, despawn reached spores
        else {
          Iterator<L2Npc> it = _sporeSpawn.iterator();
          while (it.hasNext()) {
            L2Npc spore = it.next();
            if ((spore != null)
                && !spore.isDead()
                && (spore.getX() == spore.getSpawn().getX())
                && (spore.getY() == spore.getSpawn().getY())) {
              spore.deleteMe();
              it.remove();
              _despawnedSporesCount++;
            }
          }

          startQuestTimer("despawn_total", 3000, null, null);
        }
      }
    }

    if (npc == null) {
      return null;
    }

    final int npcId = npc.getId();

    if (event.equalsIgnoreCase("despawn_spore")
        && !npc.isDead()
        && (_challengeState == STATE_SPORE_CHALLENGE_IN_PROGRESS)) {
      htmltext = null;

      _sporeSpawn.remove(npc);
      npc.deleteMe();

      if (npcId == SPORE_BASIC) {
        spawnRandomSpore();
        spawnRandomSpore();
      } else if ((npcId >= SPORE_FIRE) && (npcId <= SPORE_EARTH)) {
        _despawnedSporesCount++;

        if (_despawnedSporesCount < SELF_DESPAWN_LIMIT) {
          spawnOppositeSpore(npcId);
        } else {
          _challengeState = STATE_SPORE_IDLE_TOO_LONG;
          startQuestTimer("despawn_total", 60000, null, null);
        }
      }
    } else if (event.equalsIgnoreCase("18492-05.htm")) {
      if ((_lock == null) || (_lock.getCurrentHp() > (_lock.getMaxHp() / 10))) {
        htmltext = null;
        if (_lock != null) {
          _lock.deleteMe();
          _lock = null;
        }
        cancelQuestTimers("spawn_lock");
        startQuestTimer("spawn_lock", 300000, null, null);
        npc.setTarget(player);
        npc.doCast(SkillData.getInstance().getSkill(5527, 1));
      }
    } else if (event.equalsIgnoreCase("teleport") && (_lock != null)) {
      htmltext = null;
      L2Party party = player.getParty();
      if (party != null) {
        if (Util.checkIfInRange(3000, party.getLeader(), npc, true)) {
          for (L2PcInstance partyMember : party.getMembers()) {
            if (Util.checkIfInRange(2000, partyMember, npc, true)) {
              partyMember.teleToLocation(-47271, 246098, -9120, true);
            }
          }
          _lock.deleteMe();
          _lock = null;
          cancelQuestTimers("spawn_lock");
          startQuestTimer("spawn_lock", 1200000, null, null);
        } else {
          npc.setTarget(player);
          npc.doCast(SkillData.getInstance().getSkill(5527, 1));
        }
      } else {
        player.teleToLocation(-47271, 246098, -9120);
        _lock.deleteMe();
        _lock = null;
        cancelQuestTimers("spawn_lock");
        startQuestTimer("spawn_lock", 1200000, null, null);
      }
    } else if (event.equalsIgnoreCase("go")
        && _activeRooms.containsKey(npcId)
        && !_activeRooms.get(npcId)) {
      htmltext = null;
      L2Party party = player.getParty();

      if (party != null) {
        removeForeigners(npcId, party);
        startRoom(npcId);
        ThreadPoolManager.getInstance().scheduleGeneral(new StopRoomTask(npcId), 300000);
      } else {
        player.sendPacket(SystemMessageId.CAN_OPERATE_MACHINE_WHEN_IN_PARTY);
      }
    }
    return htmltext;
  }