Example #1
0
  /** @param instanceId The id of the instance zone the object is in - id 0 is global */
  public void setInstanceId(int instanceId) {
    if (_instanceId == instanceId) return;

    Instance oldI = InstanceManager.getInstance().getInstance(_instanceId);
    Instance newI = InstanceManager.getInstance().getInstance(instanceId);

    if (newI == null) return;

    if (this instanceof L2PcInstance) {
      if (_instanceId > 0 && oldI != null) {
        oldI.removePlayer(getObjectId());
        if (oldI.isShowTimer()) {
          int startTime = (int) ((System.currentTimeMillis() - oldI.getInstanceStartTime()) / 1000);
          int endTime = (int) ((oldI.getInstanceEndTime() - oldI.getInstanceStartTime()) / 1000);
          if (oldI.isTimerIncrease())
            sendPacket(
                new ExSendUIEvent(this, true, true, startTime, endTime, oldI.getTimerText()));
          else
            sendPacket(
                new ExSendUIEvent(this, true, false, endTime - startTime, 0, oldI.getTimerText()));
        }
      }
      if (instanceId > 0) {
        newI.addPlayer(getObjectId());
        if (newI.isShowTimer()) {
          int startTime = (int) ((System.currentTimeMillis() - newI.getInstanceStartTime()) / 1000);
          int endTime = (int) ((newI.getInstanceEndTime() - newI.getInstanceStartTime()) / 1000);
          if (newI.isTimerIncrease())
            sendPacket(
                new ExSendUIEvent(this, false, true, startTime, endTime, newI.getTimerText()));
          else
            sendPacket(
                new ExSendUIEvent(this, false, false, endTime - startTime, 0, newI.getTimerText()));
        }
      }

      if (((L2PcInstance) this).getPet() != null)
        ((L2PcInstance) this).getPet().setInstanceId(instanceId);
    } else if (this instanceof L2Npc) {
      if (_instanceId > 0 && oldI != null) oldI.removeNpc(((L2Npc) this));
      if (instanceId > 0) newI.addNpc(((L2Npc) this));
    }

    _instanceId = instanceId;

    // If we change it for visible objects, me must clear & revalidates knownlists
    if (_isVisible && _knownList != null) {
      if (this instanceof L2PcInstance) {

        // We don't want some ugly looking disappear/appear effects, so don't update
        // the knownlist here, but players usually enter instancezones through teleporting
        // and the teleport will do the revalidation for us.
      } else {
        decayMe();
        spawnMe();
      }
    }
  }
  @Override
  public final boolean useBypass(String command, L2PcInstance activeChar, L2Character target) {
    try {
      final L2Npc olymanager = activeChar.getLastFolkNPC();

      if (command.startsWith(COMMANDS[0])) // list
      {
        if (!Olympiad.getInstance().inCompPeriod()) {
          activeChar.sendPacket(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
          return false;
        }

        activeChar.sendPacket(new ExOlympiadMatchList());
      } else {
        if ((olymanager == null) || !(olymanager instanceof L2OlympiadManagerInstance)) {
          return false;
        }

        if (!activeChar.inObserverMode()
            && !activeChar.isInsideRadius(olymanager, 300, false, false)) {
          return false;
        }

        if (OlympiadManager.getInstance().isRegisteredInComp(activeChar)) {
          activeChar.sendPacket(
              SystemMessageId
                  .WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
          return false;
        }

        if (!Olympiad.getInstance().inCompPeriod()) {
          activeChar.sendPacket(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
          return false;
        }

        if (activeChar.isOnEvent()) {
          activeChar.sendMessage("You can not observe games while registered on an event");
          return false;
        }

        final int arenaId = Integer.parseInt(command.substring(12).trim());
        final OlympiadGameTask nextArena =
            OlympiadGameManager.getInstance().getOlympiadTask(arenaId);
        if (nextArena != null) {
          activeChar.enterOlympiadObserverMode(
              nextArena.getZone().getSpectatorSpawns().get(0), arenaId);
          activeChar.setInstanceId(
              OlympiadGameManager.getInstance().getOlympiadTask(arenaId).getZone().getInstanceId());
        }
      }
      return true;

    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
    }
    return false;
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    final QuestState st = player.getQuestState(getName());
    if (st == null) {
      return null;
    }

    String htmltext = null;
    switch (event) {
      case "32264-04.html":
        {
          if (player.getLevel() >= MIN_LEVEL) {
            st.startQuest();
            htmltext = event;
          }
          break;
        }
      case "32264-06.html":
        {
          if (st.isCond(1)) {
            htmltext = event;
          }
          break;
        }
      case "32264-07.html":
        {
          if (st.isCond(1)) {
            st.setCond(2);
            htmltext = event;
          }
          break;
        }
      case "32264-09.html":
      case "32264-10.html":
      case "32264-11.html":
        {
          if (st.isCond(2)) {
            htmltext = event;
          }
          break;
        }
      case "32264-12.html":
        {
          if (st.isCond(2)) {
            st.giveItems(ECHO_CRYSTAL_OF_FREE_THOUGHT, 1);
            st.setCond(3, true);
            htmltext = event;
          }
          break;
        }
      case "32264-14.html":
      case "32264-15.html":
        {
          if (st.isCond(3)) {
            htmltext = event;
          }
          break;
        }
      case "32264-17.html":
        {
          if (st.isCond(4) && st.hasQuestItems(PARMES_LETTER)) {
            st.takeItems(PARMES_LETTER, -1);
            st.setCond(5);
            htmltext = event;
          }
          break;
        }
      case "32264-19.html":
        {
          if (st.isCond(5) && st.hasQuestItems(ECHO_CRYSTAL_OF_FREE_THOUGHT)) {
            st.addExpAndSp(250677, 25019);
            st.giveItems(FIRE_STONE + getRandom(4), 4);
            st.exitQuest(false, true);
            htmltext = event;
          }
          break;
        }
      case "32271-03.html":
        {
          if (st.isCond(3)) {
            htmltext = event;
          }
          break;
        }
      case "32271-04.html":
        {
          if (st.isCond(3)) {
            st.giveItems(PARMES_LETTER, 1);
            st.setCond(4, true);
            player.setInstanceId(0);
            player.teleToLocation(INSTANCE_EXIT, true);
            htmltext = event;
          }
          break;
        }
    }
    return htmltext;
  }
 protected static final void teleportPlayer(L2PcInstance player, int[] coords, int instanceId) {
   player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
   player.setInstanceId(instanceId);
   player.teleToLocation(coords[0], coords[1], coords[2], true);
 }