@Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = player.getQuestState(getName());
   String htmltext = getNoQuestMsg(player);
   if (st != null) {
     switch (st.getState()) {
       case State.CREATED:
         {
           htmltext =
               (player.getRace() == Race.DARK_ELF)
                   ? (player.getLevel() >= MIN_LVL) ? "30348-02.htm" : "30348-01.htm"
                   : "30348-00.htm";
           break;
         }
       case State.STARTED:
         {
           if (st.isCond(2) && (st.getQuestItemsCount(DARK_BEZOAR) >= REQUIRED_COUNT)) {
             st.giveItems(LESSER_HEALING_POTION, 5);
             st.addExpAndSp(1000, 0);
             st.exitQuest(false, true);
             htmltext = "30348-05.html";
           } else {
             htmltext = "30348-04.html";
           }
           break;
         }
       case State.COMPLETED:
         {
           htmltext = getAlreadyCompletedMsg(player);
           break;
         }
     }
   }
   return htmltext;
 }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = event;
    final QuestState st = getQuestState(player, false);
    if (st == null) {
      return htmltext;
    }

    switch (event) {
      case "31296-03.html":
        st.startQuest();
        break;
      case "31256-02.html":
        if (st.isCond(1)) {
          st.setCond(2, true);
          st.giveItems(BOX, 1);
        }
        break;
      case "31371-02.html":
        if (st.isCond(2) && st.hasQuestItems(BOX)) {
          st.addExpAndSp(233125, 18142);
          st.exitQuest(false, true);
        } else {
          htmltext = "31371-03.html";
        }
        break;
    }
    return htmltext;
  }
 @Override
 public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
   final QuestState st = player.getQuestState(getName());
   if (st == null) {
     return null;
   }
   String htmltext = event;
   switch (event) {
     case "31517-05.html":
       break;
     case "31517-02.htm":
       st.startQuest();
       break;
     case "Exp":
       if (st.getQuestItemsCount(BLOOD_OF_SAINT) < ITEMS_COUNT_REQUIRED) {
         return "31517-06.html";
       }
       st.addExpAndSp(XP_COUNT, SP_COUNT);
       st.exitQuest(true, true);
       htmltext = "31517-07.html";
       break;
     case "Adena":
       if (st.getQuestItemsCount(BLOOD_OF_SAINT) < ITEMS_COUNT_REQUIRED) {
         return "31517-06.html";
       }
       st.giveAdena(ADENA_COUNT, true);
       st.exitQuest(true, true);
       htmltext = "31517-07.html";
       break;
     default:
       htmltext = null;
       break;
   }
   return htmltext;
 }
  @Override
  public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    QuestState st = player.getQuestState(qn);

    if (st == null) return "<html><body>目前沒有執行任務,或條件不符。</body></html>";

    final int cond = st.getInt("cond");
    if (event.equalsIgnoreCase("31001-05.htm")) {
      if (cond == 0) {
        st.set("cond", "1");
        st.setState(State.STARTED);
        st.playSound("ItemSound.quest_accept");
      }
    } else if (event.equalsIgnoreCase("32576-02.htm")) {
      if (cond == 1) {
        st.giveItems(IDENTITY_CARD, 1);
        st.set("cond", "2");
        st.playSound("ItemSound.quest_middle");
      }
    } else if (event.equalsIgnoreCase("30289-04.htm")) {
      if (cond == 2) {
        st.set("cond", "3");
        player.stopAllEffects();
        SkillTable.getInstance().getInfo(GUARD_DAWN, 1).getEffects(player, player);
      }
    } else if (event.equalsIgnoreCase("30289-07.htm")) {
      if (cond == 3) {
        SkillTable.getInstance().getInfo(GUARD_DAWN, 1).getEffects(player, player);
      }
    } else if (event.equalsIgnoreCase("30289-08.htm")) {
      if (cond == 3) {
        player.stopAllEffects();
      }
    } else if (event.equalsIgnoreCase("30289-11.htm")) {
      if (cond == 3) {
        st.set("cond", "4");
        st.playSound("ItemSound.quest_middle");
        player.stopAllEffects();
      }
    } else if (event.equalsIgnoreCase("30969-03.htm")) {
      if (cond == 4) {
        st.addExpAndSp(52518015, 5817677);
        // st.addExpAndSp(25000000, 2500000); // High Five
        st.unset("cond");
        st.exitQuest(false);
        st.playSound("ItemSound.quest_finish");
      }
    }
    return event;
  }
 @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 "30621-02.html":
     case "30512-02.html":
       {
         htmltext = event;
         break;
       }
     case "30673-03.htm":
       {
         if (st.isCreated()) {
           st.startQuest();
           st.takeItems(LORAINES_CERTIFICATE, -1);
           st.giveItems(METALLOGRAPH, 1);
           htmltext = event;
         }
         break;
       }
     case "30621-03.html":
       {
         if (st.isCond(1)) {
           st.setCond(2, true);
           htmltext = event;
         }
         break;
       }
     case "30512-03.html":
       {
         if (st.isCond(2)) {
           st.giveAdena(93383, true);
           if (player.getLevel() < MIN_LEVEL_FOR_EXP_SP) {
             st.addExpAndSp(285935, 18711);
           }
           st.exitQuest(false, true);
           htmltext = event;
         }
         break;
       }
   }
   return htmltext;
 }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = event;
    final QuestState st = player.getQuestState(getName());
    if (st == null) {
      return htmltext;
    }

    if (npc.getId() == MOUEN) {
      if (event.equalsIgnoreCase("30196-03.htm")) {
        st.startQuest();
      }
    } else if ((npc.getId() == JOHNNY) && event.equalsIgnoreCase("32744-03.htm")) {
      st.giveAdena(83056, true);
      st.addExpAndSp(477496, 58743);
      st.exitQuest(false, true);
    }
    return htmltext;
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    final QuestState st = player.getQuestState(getName());
    if (st == null) {
      return null;
    }

    String htmltext = event;
    switch (event) {
      case "30291-02a.html":
      case "30291-04.html":
      case "30291-05.html":
      case "30291-06.html":
      case "30068-08.html":
      case "30068-09.html":
      case "30068-10.html":
        break;
      case "30068-03.htm":
        st.startQuest();
        break;
      case "30068-04.html":
        st.setCond(2, true);
        break;
      case "30291-07.html":
        st.unset("talk");
        st.setCond(3, true);
        break;
      case "30068-11.html":
        st.giveItems(BADGE_TEMPLE_EXECUTOR, 1);
        st.giveAdena(16924, true);
        if (player.getLevel() < MAX_REWARD_LEVEL) {
          st.addExpAndSp(30000, 2000);
        }
        st.exitQuest(false, true);
        break;
      default:
        htmltext = null;
        break;
    }
    return htmltext;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = getQuestState(player, true);
    if (st == null) {
      return htmltext;
    }

    final QuestState st2 = player.getQuestState(Q00017_LightAndDarkness.class.getSimpleName());
    if ((st2 != null) && !st2.isCompleted()) {
      return "31517-04.html";
    }

    switch (st.getState()) {
      case State.COMPLETED:
        htmltext = getAlreadyCompletedMsg(player);
        break;
      case State.CREATED:
        htmltext = (player.getLevel() >= 62) ? "31517-00.htm" : "31517-05.html";
        break;
      case State.STARTED:
        final int npcId = npc.getId();
        if (npcId == HIERARCH) {
          if (st.isCond(6)) {
            st.addExpAndSp(865187, 69172);
            st.exitQuest(false, true);
            htmltext = "31517-03.html";
          } else {
            htmltext = "31517-02a.html";
          }
        } else if ((npcId - 31511) == st.getCond()) {
          htmltext = npcId + "-00.html";
        } else {
          htmltext = npcId + "-01.html";
        }
        break;
    }
    return htmltext;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    QuestState st = getQuestState(player, true);
    if (st == null) {
      return htmltext;
    }

    switch (st.getState()) {
      case State.COMPLETED:
        htmltext = "32557-0a.html";
        break;
      case State.CREATED:
        st = player.getQuestState(Q10273_GoodDayToFly.class.getSimpleName());
        if (st == null) {
          htmltext = "32557-00.html";
        } else {
          htmltext =
              ((player.getLevel() >= 75) && st.isCompleted()) ? "32557-01.htm" : "32557-00.html";
        }
        break;
      case State.STARTED:
        if ((st.getQuestItemsCount(RED)
                + st.getQuestItemsCount(BLUE)
                + st.getQuestItemsCount(GREEN))
            >= 8) {
          htmltext = "32557-05.html";
          st.giveItems(13728, 1);
          st.addExpAndSp(25160, 2525);
          st.exitQuest(false, true);
        } else {
          htmltext = "32557-04.html";
        }
        break;
    }
    return htmltext;
  }
  @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;
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    QuestState st = player.getQuestState(getName());

    if (st == null) {
      return null;
    }
    String htmltext = null;
    switch (event) {
      case "30512-02.htm":
      case "30673-02.html":
      case "30673-03.html":
        {
          htmltext = event;
          break;
        }
      case "30512-03.htm":
        {
          st.startQuest();
          htmltext = event;
          break;
        }
      case "30673-04.html":
        {
          st.setCond(2, true);
          htmltext = event;
          break;
        }
      case "30621-02.html":
        {
          if (player.getLevel() < 43) {
            st.addExpAndSp(60000, 3000);
          }
          st.giveAdena(18100, true);
          st.exitQuest(false, true);
          htmltext = event;
          break;
        }
      case "Contract":
        {
          final Quest quest =
              QuestManager.getInstance().getQuest("184_Nikolas_Cooperation_Contract");
          st = player.getQuestState("184_Nikolas_Cooperation_Contract");
          if ((quest != null) && (st == null)) {
            st = quest.newQuestState(player);
            st.setState(State.STARTED);
            quest.notifyEvent("30621-01.htm", npc, player);
          }
          break;
        }
      case "Consideration":
        {
          final Quest quest =
              QuestManager.getInstance().getQuest("185_Nikolas_Cooperation_Consideration");
          st = player.getQuestState("185_Nikolas_Cooperation_Consideration");
          if ((quest != null) && (st == null)) {
            st = quest.newQuestState(player);
            st.setState(State.STARTED);
            quest.notifyEvent("30621-01.htm", npc, player);
          }
          break;
        }
    }
    return htmltext;
  }
  @Override
  public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    final QuestState st = player.getQuestState(qn);
    if (st == null) {
      return getNoQuestMsg(player);
    }

    final int cond = st.getInt("cond");
    if (event.equalsIgnoreCase("enter")) {
      enterInstance(player);
      return null;
    } else if (event.equalsIgnoreCase("32497-03.htm")) {
      if (cond == 0) {
        st.set("cond", "1");
        st.setState(State.STARTED);
        st.playSound("ItemSound.quest_accept");
      }
    } else if (event.equalsIgnoreCase("32500-06.htm")) {
      if (cond == 1) {
        st.set("cond", "2");
        st.playSound("ItemSound.quest_itemget");
        st.giveItems(SWORD, 1);
        st.giveItems(BOOK1, 1);
      }
    } else if (event.equalsIgnoreCase("32507-04.htm")) {
      if (cond == 3) {
        st.set("cond", "4");
        st.playSound("ItemSound.quest_middle");
        st.takeItems(SWORD, -1);
        st.takeItems(WATER_ESSENCE, -1);
        st.takeItems(BOOK2, -1);
        st.giveItems(BOOK3, 1);
        st.giveItems(ENH_SWORD1, 1);
      }
    } else if (event.equalsIgnoreCase("32507-08.htm")) {
      if (cond == 6) {
        st.set("cond", "7");
        st.playSound("ItemSound.quest_itemget");
        st.takeItems(ENH_SWORD1, -1);
        st.takeItems(BOOK5, -1);
        st.takeItems(FIRE_ESSENCE, -1);
        st.giveItems(ENH_SWORD2, 1);
        st.giveItems(BOOK6, 1);
      }
    } else if (event.equalsIgnoreCase("32510-02.htm")) {
      st.unset("cond");
      st.playSound("ItemSound.quest_finish");
      st.exitQuest(false);

      Instance inst = InstanceManager.getInstance().getInstance(npc.getInstanceId());
      inst.setDuration(EXIT_TIME * 60000);
      inst.setEmptyDestroyTime(0);

      if (inst.containsPlayer(player.getObjectId())) {
        player.setVitalityPoints(20000, true);
        st.addExpAndSp(810000, 50000);
        for (int id : REWARDS) {
          st.giveItems(id, 1);
        }
      }
    }
    return event;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = player.getQuestState(getName());
    if (st == null) {
      return htmltext;
    }

    switch (npc.getId()) {
      case NATOOLS:
        switch (st.getState()) {
          case State.STARTED:
            switch (st.getCond()) {
              case 1:
                htmltext = "30894-01.html";
                break;
              default:
                htmltext = "30894-04.html";
                break;
            }
            break;
          case State.COMPLETED:
            htmltext = getAlreadyCompletedMsg(player);
            break;
        }
        break;
      case RAYMOND:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 1:
              htmltext = "30289-01.html";
              break;
            case 2:
              if (st.isSet("talk")) {
                htmltext = "30289-03.html";
              } else {
                st.takeItems(CRYPTOGRAM_OF_THE_ANGEL_SEARCH, -1);
                st.set("talk", "1");
                htmltext = "30289-02.html";
              }
              break;
            case 3:
            case 4:
            case 5:
              htmltext = "30289-06.html";
              break;
            case 6:
              st.giveAdena(92676, true);
              if (player.getLevel() <= MAX_REWARD_LEVEL) {
                st.addExpAndSp(223036, 13091);
              }
              st.exitQuest(false, true);
              htmltext = "30289-07.html";
              break;
          }
        }
        break;
      case CASIAN:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 1:
            case 2:
              htmltext = "30612-01.html";
              break;
            case 3:
              if (st.getInt("talk") == 1) {
                htmltext = "30612-03.html";
              } else if (st.getInt("talk") == 2) {
                htmltext = "30612-06.html";
              } else {
                htmltext = "30612-02.html";
                st.set("talk", "1");
              }
              break;
            case 4:
            case 5:
            case 6:
              htmltext = "30612-09.html";
              break;
          }
        }
        break;
      case ROCK:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 5:
              htmltext = "32368-02.html";
              break;
            case 6:
              htmltext = "32368-05.html";
              break;
            default:
              htmltext = "32368-01.html";
              break;
          }
        }
        break;
    }
    return htmltext;
  }