@Override
  public boolean onKillEvent(QuestEnv env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null || qs.getStatus() != QuestStatus.START) return false;

    int var = qs.getQuestVarById(0);
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();

    switch (targetId) {
      case 217249:
        if (qs.getQuestVarById(0) == 1) {
          Npc npc = (Npc) env.getVisibleObject();
          qs.setQuestVarById(0, var + 1);
          updateQuestStatus(env);
          QuestService.addNewSpawn(
              player.getWorldId(),
              player.getInstanceId(),
              282204,
              npc.getX(),
              npc.getY(),
              npc.getZ(),
              npc.getHeading());
        }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestEnv env) {
    final Player player = env.getPlayer();
    int targetId = 0;
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (env.getDialogId() == DialogAction.QUEST_ACCEPT_1.id()) {
        QuestService.startQuest(env);
        PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(0, 0));
        return true;
      } else PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(0, 0));
    } else if (qs.getStatus() == QuestStatus.START) {
      if (targetId == 278592) {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 1352);
        else if (env.getDialog() == DialogAction.SETPRO1) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          return true;
        }
      } else if (targetId == 203933) {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 1693);
        else if (env.getDialog() == DialogAction.SETPRO2) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          return true;
        }
      } else if (targetId == 203991) {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 2375);
        else if (env.getDialogId() == DialogAction.SELECT_QUEST_REWARD.id()) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          qs.setStatus(QuestStatus.REWARD);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          return sendQuestEndDialog(env);
        }
      }
    } else if (qs.getStatus() == QuestStatus.REWARD && targetId == 203991) {
      return sendQuestEndDialog(env);
    }
    return false;
  }
  private void checkDialog(Player player) {
    int npcId = getNpcId();
    List<Integer> relatedQuests = QuestEngine.getInstance().getQuestNpc(npcId).getOnTalkEvent();
    boolean playerHasQuest = false;
    boolean playerCanStartQuest = false;
    if (!relatedQuests.isEmpty()) {
      for (int questId : relatedQuests) {
        QuestState qs = player.getQuestStateList().getQuestState(questId);
        if (qs != null
            && (qs.getStatus() == QuestStatus.START || qs.getStatus() == QuestStatus.REWARD)) {
          playerHasQuest = true;
          break;
        } else if (qs == null || qs.getStatus() == QuestStatus.NONE || qs.canRepeat()) {
          if (QuestService.checkStartConditions(
              new QuestEnv(getOwner(), player, questId, 0), true)) {
            playerCanStartQuest = true;
            continue;
          }
        }
      }
    }

    if (playerHasQuest) {
      boolean isRewardStep = false;
      for (int questId : relatedQuests) {
        QuestState qs = player.getQuestStateList().getQuestState(questId);
        if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(getObjectId(), rewardDialogId, questId));
          isRewardStep = true;
          break;
        }
      }
      if (!isRewardStep) {
        PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(getObjectId(), questDialogId));
      }
    } else if (playerCanStartQuest) {
      PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(getObjectId(), startingDialogId));
    } else {
      PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(getObjectId(), 1011, 0));
    }
  }
  @Override
  public boolean onDialogEvent(QuestEnv env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    DialogAction dialog = env.getDialog();
    int targetId = env.getTargetId();

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 205492) {
        if (dialog == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 4762);
        else return sendQuestStartDialog(env);
      }
    } else if (qs.getStatus() == QuestStatus.START) {
      int var = qs.getQuestVarById(0);
      switch (targetId) {
        case 282203:
          {
            switch (dialog) {
              case QUEST_SELECT:
                {
                  if (var == 0) return sendQuestDialog(env, 1011);
                }
              case SETPRO1:
                {
                  final Npc npc = (Npc) env.getVisibleObject();
                  npc.getController().scheduleRespawn();
                  npc.getController().onDelete();
                  QuestService.addNewSpawn(
                      player.getWorldId(),
                      player.getInstanceId(),
                      217249,
                      npc.getX(),
                      npc.getY(),
                      npc.getZ(),
                      npc.getHeading());
                  return defaultCloseDialog(env, 0, 1);
                }
            }
          }

        case 282204:
          {
            switch (dialog) {
              case QUEST_SELECT:
                {
                  if (var == 2) return sendQuestDialog(env, 1693);
                }
              case SET_SUCCEED:
                {
                  qs.setStatus(QuestStatus.REWARD);
                  updateQuestStatus(env);
                  return closeDialogWindow(env);
                }
            }
          }
      }
    } else if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 205492)
        switch (dialog) {
          case USE_OBJECT:
            {
              return sendQuestDialog(env, 10002);
            }
          default:
            {
              return sendQuestEndDialog(env);
            }
        }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestEnv env) {
    final Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);

    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    if (targetId == 0) {
      if (env.getDialogId() == DialogAction.QUEST_ACCEPT_1.id()) {
        QuestService.startQuest(env);
        PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(0, 0));
        return true;
      }
    } else if (targetId == 798190) {
      if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 0) {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 1352);
        else if (env.getDialog() == DialogAction.SETPRO1) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          return true;
        } else return sendQuestStartDialog(env);
      }
    } else if (targetId == 798191) {
      if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 1) {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 1693);
        else if (env.getDialog() == DialogAction.SETPRO2) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          return true;
        } else return sendQuestStartDialog(env);
      }
    } else if (targetId == 798192) {
      if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 2) {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 2034);
        else if (env.getDialog() == DialogAction.SETPRO3) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          return true;
        } else return sendQuestStartDialog(env);
      }
    } else if (targetId == 798193) {
      if (qs != null) {
        if (env.getDialog() == DialogAction.QUEST_SELECT && qs.getStatus() == QuestStatus.START) {
          return sendQuestDialog(env, 2375);
        } else if (env.getDialogId() == DialogAction.SELECT_QUEST_REWARD.id()
            && qs.getStatus() != QuestStatus.COMPLETE
            && qs.getStatus() != QuestStatus.NONE) {
          removeQuestItem(env, 182208043, 1);
          qs.setQuestVar(1);
          qs.setStatus(QuestStatus.REWARD);
          updateQuestStatus(env);
          return sendQuestEndDialog(env);
        } else return sendQuestEndDialog(env);
      }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestEnv env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    DialogAction dialog = env.getDialog();
    int targetId = env.getTargetId();

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 205579) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 4762);
        } else if (dialog == DialogAction.QUEST_ACCEPT_SIMPLE) {
          QuestService.questTimerStart(env, 780);
          return sendQuestStartDialog(env);
        } else {
          return sendQuestStartDialog(env);
        }
      }
    } else if (qs != null && qs.getStatus() == QuestStatus.START) {
      int var = qs.getQuestVarById(0);
      if (targetId == 205798) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 1011);
        } else if (dialog == DialogAction.SETPRO1) {
          return defaultCloseDialog(env, 0, 1);
        }
      }
      if (targetId == 205799 && var == 1) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 1352);
        } else if (dialog == DialogAction.SETPRO2) {
          return defaultCloseDialog(env, 1, 2);
        }
      }
      if (targetId == 205800 && var == 2) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 1693);
        } else if (dialog == DialogAction.SETPRO3) {
          return defaultCloseDialog(env, 2, 3);
        }
      }
      if (targetId == 205801 && var == 3) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 2034);
        } else if (dialog == DialogAction.SETPRO4) {
          return defaultCloseDialog(env, 3, 4);
        }
      }
      if (targetId == 205579 && var == 4) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 2375);
        } else if (dialog == DialogAction.SETPRO5) {
          return defaultCloseDialog(env, 4, 5);
        }
      }
      if (targetId == 205579 && var == 5) {
        if (dialog == DialogAction.QUEST_SELECT) {
          return sendQuestDialog(env, 2716);
        } else if (dialog == DialogAction.CHECK_USER_HAS_QUEST_ITEM_SIMPLE) {
          return checkQuestItems(env, 5, 6, true, 10002, 10001);
        }
      }
    } else if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 205579) {
        if (dialog == DialogAction.SELECT_QUEST_REWARD) {
          QuestService.questTimerEnd(env);
          return sendQuestDialog(env, 5);
        } else {
          return sendQuestEndDialog(env);
        }
      }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestEnv env) {
    final Player player = env.getPlayer();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);

    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 203711) // Miriya
      {
        if (env.getDialog() == DialogAction.QUEST_SELECT) return sendQuestDialog(env, 4762);
        else return sendQuestStartDialog(env);
      }
      return false;
    }

    int var = qs.getQuestVarById(0);

    if (qs.getStatus() == QuestStatus.REWARD) {

      if (targetId == 203711
          && player.getInventory().getItemCountByItemId(182206081) == 1) // Miriya
      {
        if (env.getDialog() == DialogAction.USE_OBJECT) return sendQuestDialog(env, 10002);
        else if (env.getDialogId() == DialogAction.SELECT_QUEST_REWARD.id())
          return sendQuestDialog(env, 5);
        else return sendQuestEndDialog(env);
      }
      return false;
    } else if (qs.getStatus() == QuestStatus.START) {
      if (targetId == 798321) // Koruchinerk
      {
        switch (env.getDialog()) {
          case QUEST_SELECT:
            if (var == 0) return sendQuestDialog(env, 1011);
            if (var == 1) return sendQuestDialog(env, 1352);
          case CHECK_USER_HAS_QUEST_ITEM:
            if (var == 1) {
              if (QuestService.collectItemCheck(env, true)) {
                if (!giveQuestItem(env, 182206080, 1)) return true;
                qs.setQuestVarById(0, var + 1);
                updateQuestStatus(env);
                return sendQuestDialog(env, 10000);
              } else return sendQuestDialog(env, 10001);
            }
          case SETPRO1:
            if (var == 0) qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
        }
        return false;
      } else if (targetId == 279005
          && player.getInventory().getItemCountByItemId(182206080) == 1) // Kohrunerk
      {
        switch (env.getDialog()) {
          case QUEST_SELECT:
            if (var == 2) return sendQuestDialog(env, 1693);
          case SET_SUCCEED:
            if (var == 2) removeQuestItem(env, 182206080, 1);
            if (!giveQuestItem(env, 182206081, 1)) return true;
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return true;
        }
      }
      return false;
    }
    return false;
  }