Ejemplo n.º 1
0
  /** notify all observers */
  public void notifyObservers(ObserverType type, Object... object) {
    List<ActionObserver> tempOnceused = Collections.emptyList();
    lock.lock();
    try {
      if (onceUsedObservers.size() > 0) {
        tempOnceused = new ArrayList<ActionObserver>();
        Iterator<ActionObserver> iterator = onceUsedObservers.iterator();
        while (iterator.hasNext()) {
          ActionObserver observer = iterator.next();
          if (observer.getObserverType().matchesObserver(type)) {
            if (observer.tryUse()) {
              tempOnceused.add(observer);
              iterator.remove();
            }
          }
        }
      }
    } finally {
      lock.unlock();
    }

    // notify outside of lock
    for (ActionObserver observer : tempOnceused) {
      notifyAction(type, observer, object);
    }

    if (observers.size() > 0) {
      for (ActionObserver observer : observers) {
        if (observer.getObserverType().matchesObserver(type)) {
          notifyAction(type, observer, object);
        }
      }
    }
  }
  @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;
  }