@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 "30894-02.html":
      case "30289-03.html":
      case "30289-04.html":
      case "30612-03.html":
      case "30612-04.html":
      case "30612-06.html":
      case "30612-07.html":
        break;
      case "30894-01.html":
        st.startQuest();
        break;
      case "30894-03.html":
        st.giveItems(CRYPTOGRAM_OF_THE_ANGEL_SEARCH, 1);
        st.setCond(2, true);
        break;
      case "30289-05.html":
        st.unset("talk");
        st.setCond(3, true);
        break;
      case "30612-05.html":
        st.set("talk", "2");
        break;
      case "30612-08.html":
        st.unset("talk");
        st.setCond(4, true);
        break;
      case "32368-04.html":
        if (isAngelSpawned) {
          return "32368-03.html";
        }
        addSpawn(FALLEN_ANGEL, npc.getX() + 100, npc.getY() + 100, npc.getZ(), 0, false, 120000);
        isAngelSpawned = true;
        startQuestTimer("despawn", 120000, null, player);
        break;
      case "despawn":
        if (isAngelSpawned) {
          isAngelSpawned = false;
        }
      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 = 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 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 = "";
    QuestState st = player.getQuestState(getName());

    if (st == null) return null;

    switch (npc.getNpcId()) {
      case 13001:
        if (antharasAI() != null) {
          int status = GrandBossManager.getInstance().getBossStatus(29019);
          int statusW = GrandBossManager.getInstance().getBossStatus(29066);
          int statusN = GrandBossManager.getInstance().getBossStatus(29067);
          int statusS = GrandBossManager.getInstance().getBossStatus(29068);

          if (status == 2 || statusW == 2 || statusN == 2 || statusS == 2)
            htmltext = "13001-02.htm";
          else if (status == 3 || statusW == 3 || statusN == 3 || statusS == 3)
            htmltext = "13001-01.htm";
          else if (status == 0
              || status == 1) // If entrance to see Antharas is unlocked (he is Dormant or Waiting)
          {
            if (st.hasQuestItems(3865)) {
              // st.takeItems(3865, 1); // No longer consumed in h5
              L2BossZone zone = GrandBossManager.getInstance().getZone(179700, 113800, -7709);

              if (zone != null) zone.allowPlayerEntry(player, 30);

              player.teleToLocation(179700 + Rnd.get(700), 113800 + Rnd.get(2100), -7709);

              if (status == 0) {
                L2GrandBossInstance antharas = GrandBossManager.getInstance().getBoss(29019);
                antharasAI().notifyEvent("waiting", antharas, player);
              }
            } else htmltext = "13001-03.htm";
          }
        }
        break;

      case 31859:
        player.teleToLocation(79800 + Rnd.get(600), 151200 + Rnd.get(1100), -3534);
        break;

      case 31385:
        if (valakasAI() != null) {
          int status = GrandBossManager.getInstance().getBossStatus(29028);

          if (status == 0 || status == 1) {
            if (playerCount >= 200) htmltext = "31385-03.htm";
            else if (st.getInt("allowEnter") == 1) {
              st.unset("allowEnter");
              L2BossZone zone = GrandBossManager.getInstance().getZone(212852, -114842, -1632);

              if (zone != null) zone.allowPlayerEntry(player, 30);

              player.teleToLocation(204328 + Rnd.get(600), -111874 + Rnd.get(600), 70);

              playerCount++;

              if (status == 0) {
                L2GrandBossInstance valakas = GrandBossManager.getInstance().getBoss(29028);
                valakasAI().startQuestTimer("1001", Config.Valakas_Wait_Time, valakas, null);
                GrandBossManager.getInstance().setBossStatus(29028, 1);
              }
            } else htmltext = "31385-04.htm";
          } else if (status == 2) htmltext = "31385-02.htm";
          else htmltext = "31385-01.htm";
        } else htmltext = "31385-01.htm";
        break;

      case 31384:
        DoorTable.getInstance().getDoor(24210004).openMe();
        break;

      case 31686:
        DoorTable.getInstance().getDoor(24210006).openMe();
        break;

      case 31687:
        DoorTable.getInstance().getDoor(24210005).openMe();
        break;

      case 31540:
        if (playerCount < 50) htmltext = "31540-01.htm";
        else if (playerCount < 100) htmltext = "31540-02.htm";
        else if (playerCount < 150) htmltext = "31540-03.htm";
        else if (playerCount < 200) htmltext = "31540-04.htm";
        else htmltext = "31540-05.htm";
        break;

      case 31759:
        player.teleToLocation(150037 + Rnd.get(500), -57720 + Rnd.get(500), -2976);
        break;
    }

    return htmltext;
  }