@Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    QuestState st = player.getQuestState(qn);
    String htmltext = getNoQuestMsg();
    if (st == null) return htmltext;

    switch (st.getState()) {
      case STATE_CREATED:
        if (player.getLevel() >= 18) htmltext = "30361-03.htm";
        else {
          htmltext = "30361-02.htm";
          st.exitQuest(true);
        }
        break;

      case STATE_STARTED:
        int shards = st.getQuestItemsCount(WIND_SHARD);
        if (shards == 0) htmltext = "30361-05.htm";
        else {
          int reward = 40 * shards + (shards >= 10 ? 2988 : 0);
          htmltext = "30361-07.htm";
          st.takeItems(WIND_SHARD, -1);
          st.rewardItems(57, reward);
        }
        break;
    }
    return htmltext;
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = event;
    QuestState st = player.getQuestState(qn);
    if (st == null) return htmltext;

    if (event.equalsIgnoreCase("30686-2.htm")) {
      st.setState(STATE_STARTED);
      st.set("cond", "1");
      st.playSound(QuestState.SOUND_ACCEPT);
    } else if (event.equalsIgnoreCase("30686-7.htm")) {
      final int count = st.getQuestItemsCount(JADE_CRYSTAL);
      if (count == 0) htmltext = "30686-4.htm";
      else {
        int reward = (count * 425) + 3500;
        if (count >= 100) reward += 7400;

        st.takeItems(JADE_CRYSTAL, -1);
        st.rewardItems(57, reward);
      }
    } else if (event.equalsIgnoreCase("30686-8.htm")) {
      st.playSound(QuestState.SOUND_FINISH);
      st.exitQuest(true);
    }

    return htmltext;
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = event;
    QuestState st = player.getQuestState(qn);
    if (st == null) return htmltext;

    // Manakia
    if (event.equalsIgnoreCase("30515-03.htm")) {
      st.setState(STATE_STARTED);
      st.set("cond", "1");
      st.set("condStone", "1");
      st.playSound(QuestState.SOUND_ACCEPT);
    } else if (event.startsWith("30515-06-")) {
      if (st.getQuestItemsCount(CAVE_BEAST_TOOTH) >= 65
          && st.getQuestItemsCount(DEATH_WAVE_LIGHT) >= 65) {
        htmltext = "30515-06.htm";
        st.playSound(QuestState.SOUND_MIDDLE);

        int[] reward = REWARDS[Integer.parseInt(event.substring(9, 10))];

        st.takeItems(CAVE_BEAST_TOOTH, -1);
        st.takeItems(DEATH_WAVE_LIGHT, -1);

        st.rewardItems(57, reward[2]);
        st.giveItems(reward[0], reward[1]);
      } else htmltext = "30515-07.htm";
    } else if (event.equalsIgnoreCase("30515-08.htm")) {
      st.playSound(QuestState.SOUND_FINISH);
      st.exitQuest(true);
    }
    // Torai
    else if (event.equalsIgnoreCase("30557-02.htm")) {
      if (st.getInt("cond") == 2 && st.hasQuestItems(SEALED_MYSTERIOUS_STONE)) {
        st.set("cond", "3");
        st.takeItems(SEALED_MYSTERIOUS_STONE, -1);
        st.giveItems(MYSTERIOUS_STONE, 1);
        st.playSound(QuestState.SOUND_MIDDLE);
      } else htmltext = "30557-03.htm";
    }
    return htmltext;
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = event;
    QuestState st = player.getQuestState(qn);
    if (st == null) return htmltext;

    if (event.equalsIgnoreCase("31314-03.htm")) {
      st.setState(STATE_STARTED);
      st.set("cond", "1");
      st.playSound(QuestState.SOUND_ACCEPT);
    } else if (event.equalsIgnoreCase("31315-02.htm")) {
      st.set("cond", "2");
      st.playSound(QuestState.SOUND_MIDDLE);
      st.giveItems(SUPPLY_BOX, 1);
    } else if (event.equalsIgnoreCase("31555-02.htm")) {
      st.takeItems(SUPPLY_BOX, 1);
      st.rewardItems(57, 15000);
      st.rewardExpAndSp(50000, 0);
      st.playSound(QuestState.SOUND_FINISH);
      st.exitQuest(false);
    }

    return htmltext;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    QuestState st = player.getQuestState(qn);
    String htmltext = getNoQuestMsg();
    if (st == null) return htmltext;

    switch (st.getState()) {
      case STATE_CREATED:
        if (player.getRace() == Race.Elf) {
          if (player.getLevel() >= 3) htmltext = "30370-03.htm";
          else {
            htmltext = "30370-02.htm";
            st.exitQuest(true);
          }
        } else {
          htmltext = "30370-00.htm";
          st.exitQuest(true);
        }
        break;

      case STATE_STARTED:
        int cond = st.getInt("cond");
        switch (npc.getNpcId()) {
          case NERUPA:
            if (cond >= 1 && cond <= 3) htmltext = "30370-05.htm";
            else if (cond == 4) {
              if (st.getQuestItemsCount(NIGHTSHADE_LEAF) == 1) {
                htmltext = "30370-06.htm";
                st.playSound(QuestState.SOUND_FINISH);
                st.takeItems(NIGHTSHADE_LEAF, 1);
                st.rewardItems(LESSER_HEALING_POTION, 5);
                st.rewardExpAndSp(1000, 0);
                st.exitQuest(false);
              }
            }
            break;

          case UNOREN:
            if (cond == 1) {
              st.set("cond", "2");
              htmltext = "30147-01.htm";
              st.playSound(QuestState.SOUND_MIDDLE);
              st.takeItems(SILVERY_SPIDERSILK, 1);
              st.giveItems(UNOS_RECEIPT, 1);
            } else if (cond == 2) htmltext = "30147-02.htm";
            else if (cond == 4) htmltext = "30147-03.htm";
            break;

          case CREAMEES:
            if (cond == 2) {
              st.set("cond", "3");
              htmltext = "30149-01.htm";
              st.takeItems(UNOS_RECEIPT, 1);
              st.giveItems(CELS_TICKET, 1);
              st.playSound(QuestState.SOUND_MIDDLE);
            } else if (cond == 3) htmltext = "30149-02.htm";
            else if (cond == 4) htmltext = "30149-03.htm";
            break;

          case JULIA:
            if (cond == 3) {
              st.set("cond", "4");
              htmltext = "30152-01.htm";
              st.takeItems(CELS_TICKET, -1);
              st.giveItems(NIGHTSHADE_LEAF, 1);
              st.playSound(QuestState.SOUND_MIDDLE);
            } else if (cond == 4) htmltext = "30152-02.htm";
            break;
        }
        break;

      case STATE_COMPLETED:
        htmltext = getAlreadyCompletedMsg();
        break;
    }

    return htmltext;
  }