@Override
  public String onTalk(NpcInstance npc, QuestState st) {
    String htmltext = "noquest";
    int npcId = npc.getNpcId();
    int cond = st.getCond();

    if (npcId == Droph)
      if (cond == 0) {
        if (st.getPlayer().getLevel() >= 79) htmltext = "droph_q307_1.htm";
        else {
          htmltext = "droph_q307_0.htm";
          st.exitCurrentQuest(true);
        }
      } else if (cond == 1) {
        if (st.getQuestItemsCount(CaveExplorationText1Sheet) >= 1
            && st.getQuestItemsCount(CaveExplorationText2Sheet) >= 1
            && st.getQuestItemsCount(CaveExplorationText3Sheet) >= 1)
          if (ServerVariables.getLong("HekatonPrimeRespawn", 0) < System.currentTimeMillis())
            htmltext = "droph_q307_3.htm";
          else htmltext = "droph_q307_4.htm";
        else htmltext = "droph_q307_2a.htm";
      } else if (cond == 2) {
        htmltext = "droph_q307_5.htm";
        st.giveItems(DrophsSupportItems, 1);
        st.playSound(SOUND_FINISH);
        st.exitCurrentQuest(true);
      }
    return htmltext;
  }
 @Override
 public String onTalk(NpcInstance npc, QuestState st) {
   String htmltext = "noquest";
   int npcId = npc.getNpcId();
   int cond = st.getCond();
   if (npcId == THEODRIC) {
     if (cond == 0) {
       if (st.getPlayer().getLevel() < 84) htmltext = "antharas_watchman_theodric_q10504_00.htm";
       else if (st.getQuestItemsCount(PORTAL_STONE) < 1)
         htmltext = "antharas_watchman_theodric_q10504_00a.htm";
       else if (st.isNowAvailable()) htmltext = "antharas_watchman_theodric_q10504_01.htm";
       else htmltext = "antharas_watchman_theodric_q10504_09.htm";
     } else if (cond == 1) {
       if (st.getQuestItemsCount(CLEAR_CRYSTAL) < 1) {
         htmltext = "antharas_watchman_theodric_q10504_08.htm";
         st.giveItems(CLEAR_CRYSTAL, 1);
       } else htmltext = "antharas_watchman_theodric_q10504_05.htm";
     } else if (cond == 2) {
       if (st.getQuestItemsCount(FILLED_CRYSTAL_ANTHARAS) >= 1) {
         htmltext = "antharas_watchman_theodric_q10504_07.htm";
         st.takeAllItems(FILLED_CRYSTAL_ANTHARAS);
         st.giveItems(JEWEL_OF_ANTHARAS, 1);
         st.playSound(SOUND_FINISH);
         st.exitCurrentQuest(this);
       } else htmltext = "antharas_watchman_theodric_q10504_06.htm";
     }
   }
   return htmltext;
 }
 @Override
 public String onEvent(String event, QuestState st, NpcInstance npc) {
   Player player = st.getPlayer();
   String htmltext = event;
   if (event.equalsIgnoreCase("priest_wood_q10292_3.htm")) {
     st.setCond(1);
     st.setState(STARTED);
     st.playSound(SOUND_ACCEPT);
   } else if (event.equalsIgnoreCase("priest_wood_q10292_4.htm")) enterInstance(st, 145);
   else if (event.equalsIgnoreCase("witness_of_dawn_q10292_2.htm")) {
     st.setCond(2);
     st.playSound(SOUND_MIDDLE);
   } else if (event.equalsIgnoreCase("elcadia_abyssal_saintess_q10292_2.htm")) {
     st.setCond(3);
     st.playSound(SOUND_MIDDLE);
   } else if (event.equalsIgnoreCase("elcadia_abyssal_saintess_q10292_9.htm")) {
     st.setCond(7);
     st.playSound(SOUND_MIDDLE);
   } else if (event.equalsIgnoreCase("hardin_q10292_1.htm")) {
     st.setCond(8);
     st.playSound(SOUND_MIDDLE);
   } else if (event.equalsIgnoreCase("spawnTestMobs")) {
     int reflectId = player.getReflectionId();
     st.set("CreatureOfTheDusk1", 1);
     st.set("CreatureOfTheDusk2", 1);
     addSpawnToInstance(CREATURE_OF_THE_DUSK_1, 89416, -237992, -9632, 0, 0, reflectId);
     addSpawnToInstance(CREATURE_OF_THE_DUSK_2, 89416, -238136, -9632, 0, 0, reflectId);
     return null;
   }
   return htmltext;
 }
  private void alertLetterReceived(QuestState st) {
    if (st == null) return;

    st.getPlayer()
        .sendPacket(
            new ExShowScreenMessage(
                LETTER_ALERT_STRING,
                7000,
                ExShowScreenMessage.ScreenMessageAlign.TOP_CENTER,
                true));

    st.showQuestionMark(10779);

    st.playSound(SOUND_TUTORIAL);

    st.giveItems(SOE_OREN, 1);

    st.getPlayer().setVar("@received_navari_letter_6th", true);
  }
 @Override
 public String onEvent(String event, QuestState st, NpcInstance npc) {
   String htmltext = event;
   if (event.equalsIgnoreCase("droph_q307_2.htm")) {
     st.setCond(1);
     st.setState(STARTED);
   } else if (event.equalsIgnoreCase("loc1")) {
     htmltext = "droph_q307_2a_1.htm";
     RadarControlPacket rc = new RadarControlPacket(0, 1, GorgolosLoc);
     st.getPlayer().sendPacket(rc);
   } else if (event.equalsIgnoreCase("loc2")) {
     htmltext = "droph_q307_2a_2.htm";
     RadarControlPacket rc = new RadarControlPacket(0, 1, LastTitanUtenusLoc);
     st.getPlayer().sendPacket(rc);
   } else if (event.equalsIgnoreCase("loc3")) {
     htmltext = "droph_q307_2a_3.htm";
     RadarControlPacket rc = new RadarControlPacket(0, 1, GiantMarpanakLoc);
     st.getPlayer().sendPacket(rc);
   } else if (event.equalsIgnoreCase("summon_rb")) {
     if (ServerVariables.getLong("HekatonPrimeRespawn", 0) < System.currentTimeMillis()
         && st.getQuestItemsCount(CaveExplorationText1Sheet) >= 1
         && st.getQuestItemsCount(CaveExplorationText2Sheet) >= 1
         && st.getQuestItemsCount(CaveExplorationText3Sheet) >= 1) {
       st.takeItems(CaveExplorationText1Sheet, 1);
       st.takeItems(CaveExplorationText2Sheet, 1);
       st.takeItems(CaveExplorationText3Sheet, 1);
       ServerVariables.set(
           "HekatonPrimeRespawn", System.currentTimeMillis() + HekatonPrimeRespawn);
       NpcInstance boss =
           st.addSpawn(
               HekatonPrime,
               HekatonPrimeLoc.x,
               HekatonPrimeLoc.y,
               HekatonPrimeLoc.z,
               HekatonPrimeLoc.h,
               0,
               0);
       boss.getMinionList().spawnMinions();
       htmltext = "droph_q307_3a.htm";
     } else htmltext = "droph_q307_2b.htm";
   }
   return htmltext;
 }
 @Override
 public String onTalk(NpcInstance npc, QuestState st) {
   String htmltext = "noquest";
   int npcId = npc.getNpcId();
   int cond = st.getCond();
   int id = st.getState();
   Player player = st.getPlayer();
   if (!player.isBaseClassActive()) return "no_subclass_allowed.htm";
   switch (npcId) {
     case WOOD:
       if (cond == 0) {
         QuestState qs = player.getQuestState(_198_SevenSignsEmbryo.class);
         if (player.getLevel() >= 81 && qs != null && qs.isCompleted())
           htmltext = "priest_wood_q10292_0.htm";
         else {
           htmltext = "priest_wood_q10292_0n.htm";
           st.exitCurrentQuest(true);
         }
       } else if (cond == 1) htmltext = "priest_wood_q10292_3.htm";
       else if (cond > 1 && !st.isCompleted())
         htmltext = "priest_wood_q10292_5.htm"; // TODO: Отредактировать диалог по оффу
       else if (st.isCompleted()) htmltext = "priest_wood_q10292_6.htm";
       break;
     case FRANZ:
       if (cond == 1) htmltext = "witness_of_dawn_q10292_0.htm";
       else if (cond == 2) htmltext = "witness_of_dawn_q10292_4.htm";
       break;
     case ELCARDIA:
       if (cond == 2) htmltext = "elcadia_abyssal_saintess_q10292_0.htm";
       else if (cond == 3) htmltext = "elcadia_abyssal_saintess_q10292_2.htm";
       else if (cond == 4) {
         htmltext = "elcadia_abyssal_saintess_q10292_3.htm";
         st.takeItems(ELCARDIAS_MARK, -1);
         st.playSound(SOUND_MIDDLE);
         st.setCond(5);
       } else if (cond == 5) htmltext = "elcadia_abyssal_saintess_q10292_5.htm";
       else if (cond == 6) htmltext = "elcadia_abyssal_saintess_q10292_6.htm";
       else if (cond == 7) htmltext = "elcadia_abyssal_saintess_q10292_9.htm";
       else if (cond == 8) {
         htmltext = "elcadia_abyssal_saintess_q10292_10.htm";
         st.addExpAndSp(10000000, 1000000);
         st.setState(COMPLETED);
         st.exitCurrentQuest(false);
         st.playSound(SOUND_FINISH);
       }
       break;
     case HARDIN:
       if (cond == 7) htmltext = "hardin_q10292_0.htm";
       else if (cond == 8) htmltext = "hardin_q10292_2.htm";
       break;
   }
   return htmltext;
 }
 @Override
 public String onTalk(NpcInstance npc, QuestState st) {
   int npcId = npc.getNpcId();
   int cond = st.getCond();
   String htmltext = "noquest";
   if (npcId == ENDRIGO) {
     if (st.isCompleted()) htmltext = "warden_endrigo_q10380_03.htm";
     else if (st.isStarted()) {
       if (cond == 1) htmltext = "warden_endrigo_q10380_07.htm";
       else if (cond == 2) htmltext = "warden_endrigo_q10380_08.htm";
     } else {
       if (checkStartCondition(st.getPlayer())) htmltext = "warden_endrigo_q10380_01.htm";
       else htmltext = "warden_endrigo_q10380_02.htm";
     }
   }
   return htmltext;
 }
  @Override
  public String onTalk(NpcInstance npc, QuestState st) {
    int _state = st.getState();
    int npcId = npc.getNpcId();
    if (_state == CREATED) {
      if (npcId != Jeremy) return "noquest";
      if (st.getPlayer().getLevel() < 73) {
        st.exitCurrentQuest(true);
        return "jeremy_q0625_0103.htm";
      }
      if (st.getQuestItemsCount(Soy_Sauce_Jar) == 0) {
        st.exitCurrentQuest(true);
        return "jeremy_q0625_0102.htm";
      }
      st.setCond(0);
      return "jeremy_q0625_0101.htm";
    }

    if (_state != STARTED) return "noquest";
    int cond = st.getCond();

    if (npcId == Jeremy) {
      if (cond == 1) return "jeremy_q0625_0105.htm";
      if (cond == 2) return "jeremy_q0625_0202.htm";
      if (cond == 3) return "jeremy_q0625_0201.htm";
    }

    if (npcId == Yetis_Table) {
      if (ServerVariables.getLong(_625_TheFinestIngredientsPart2.class.getSimpleName(), 0)
              + 3 * 60 * 60 * 1000
          > System.currentTimeMillis()) return "yetis_table_q0625_0204.htm";
      if (cond == 1) return "yetis_table_q0625_0101.htm";
      if (cond == 2) {
        if (BumbalumpSpawned()) return "yetis_table_q0625_0202.htm";
        ThreadPoolManager.getInstance().schedule(new BumbalumpSpawner(), 1000);
        return "yetis_table_q0625_0201.htm";
      }
      if (cond == 3) return "yetis_table_q0625_0204.htm";
    }

    return "noquest";
  }
  @Override
  public String onEvent(String event, QuestState st, NpcInstance npc) {
    Player player = st.getPlayer();
    if (player == null) return null;

    String htmltext = event;

    System.out.println("quest event " + event.toString());

    int classId = player.getClassId().getId();
    if (event.startsWith("UC")) {
      if (checkStartCondition(player)) {
        Quest q = QuestManager.getQuest(10779);
        player.processQuestEvent(q.getName(), "start_quest", null);
      }

      htmltext = "";
    }

    if (event.equalsIgnoreCase("start_quest") || event.equalsIgnoreCase("start_quest_7s")) {
      st.setCond(1);
      st.setState(STARTED);
      alertLetterReceived(st);
      st.showQuestHTML(st.getQuest(), "queen_letter.htm");

      htmltext = "";
    }

    if (event.equalsIgnoreCase("start_quest_delay")) {
      st.startQuestTimer("start_quest_7s", 7000);
      // only start quest after 7s to avoid crash on enterworld
      htmltext = "";
    }

    if (event.equalsIgnoreCase("Quest _10779_LetterFromTheQueen_SeaOfSpores to_oren")) {
      // System.out.println("in Quest _10779_LetterFromTheQueen_SeaOfSpores to_dion");
      if (st.getCond() == 1) {
        if (getItemCountById(player, SOE_OREN) > 0) {
          st.takeItems(SOE_OREN, 1);
          player.teleToLocation(83633, 53064, -1456);
          player.sendPacket(TutorialCloseHtmlPacket.STATIC);
        } else {
          player.sendMessage("Không tìm thấy Scroll of Escape: Town of Oren");
        }
      }
      htmltext = "";
    }
    // System.out.println("out " + event);
    if (event.equalsIgnoreCase("Quest _10779_LetterFromTheQueen_SeaOfSpores close_window")) {
      // System.out.println("in Quest _10779_LetterFromTheQueen_SeaOfSpores close_window");
      player.sendPacket(TutorialCloseHtmlPacket.STATIC);
      htmltext = "";
    }

    // Question mark clicked
    if (event.startsWith("QM")) {
      int MarkId = Integer.valueOf(event.substring(2));
      // System.out.println("Mark id " + MarkId);
      if (MarkId == 10779) {
        if (player.getRace() == Race.ERTHEIA) st.showQuestHTML(st.getQuest(), "queen_letter.htm");
        htmltext = "";
      }
    }

    if (event.equalsIgnoreCase("30191-3.htm")) {
      st.giveItems(SOE_SEA_OF_SPORES, 1);
      st.setCond(2);

      htmltext = "30191-3.htm";
    }

    if (event.equalsIgnoreCase("33845-2.htm")) {
      st.giveItems(STEEL_DOOR_COIN, 37, true);
      st.giveItems(SCROLL_EWB, 3, true);
      st.addExpAndSp(635250, 152);
      st.setState(COMPLETED);
      st.exitCurrentQuest(false);
      st.playSound(SOUND_FINISH);
      st.getPlayer()
          .sendPacket(
              new ExShowScreenMessage(
                  NEXT_LETTER_STRING,
                  7000,
                  ExShowScreenMessage.ScreenMessageAlign.TOP_CENTER,
                  true));

      htmltext = "33845-2.htm";
    }

    if (htmltext.isEmpty()) return null;
    else return htmltext;
  }