@Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 799032) // Gefeios
      {
        if (env.getDialogId() == 26) {
          return sendQuestDialog(env, 1011);
        } else return defaultQuestStartDialog(env);
      }
    }

    if (qs == null) return false;

    if (qs == null || qs.getStatus() == QuestStatus.COMPLETE) {
      if (targetId == 799032) // Gefeios
      {
        if (env.getDialogId() == 26) {
          return sendQuestDialog(env, 1011);
        } else return defaultQuestStartDialog(env);
      }
    }

    if (qs.getStatus() == QuestStatus.START) {
      switch (targetId) {
        case 799032: // Gefeios
          switch (env.getDialogId()) {
            case 26:
              return sendQuestDialog(env, 2375);
            case 2034:
              return sendQuestDialog(env, 2034);
            case 34:
              // Siel's Supreme Mace (1)
              // Noxallon Ingot (1)
              if (QuestService.collectItemCheck(env, true)) {
                player.getInventory().removeFromBagByItemId(100100679, 1); // Siel's Supreme Mace
                player.getInventory().removeFromBagByItemId(186000095, 1); // Noxallon Ingot
                qs.setStatus(QuestStatus.REWARD);
                updateQuestStatus(env);
                return sendQuestDialog(env, 5);
              } else {
                //
                return sendQuestDialog(env, 2716);
              }
          }
          break;
          //
        default:
          return defaultQuestStartDialog(env);
      }
    } else if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 799032) // Gefeios
      return defaultQuestEndDialog(env);
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestCookie 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() == 1002) {
        QuestService.startQuest(env, QuestStatus.START);
        PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(0, 0));
        return true;
      }
    } else if (targetId == 278556) {
      if (qs != null) {
        if (env.getDialogId() == 26 && qs.getStatus() == QuestStatus.START) {
          return sendQuestDialog(env, 2375);
        } else if (env.getDialogId() == 1009) {
          player.getInventory().removeFromBagByItemId(182206038, 1);
          qs.setQuestVar(1);
          qs.setStatus(QuestStatus.REWARD);
          updateQuestStatus(env);
          return defaultQuestEndDialog(env);
        } else return defaultQuestEndDialog(env);
      }
    }
    return false;
  }
  @Override
  public boolean onKillEvent(QuestCookie env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null || qs.getStatus() != QuestStatus.START) return false;

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

    switch (targetId) {
      case 216592:
        if (qs.getQuestVarById(0) == 8) {
          @SuppressWarnings("unused")
          final int instanceId = player.getInstanceId();
          QuestService.addNewSpawn(
              300150000,
              player.getInstanceId(),
              799341,
              (float) 561.8763,
              (float) 192.25128,
              (float) 135.88919,
              (byte) 30,
              true);
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          return true;
        }
    }
    return false;
  }
  @Override
  public boolean onKillEvent(QuestCookie env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null || qs.getStatus() != QuestStatus.START) return false;

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

    switch (targetId) {
      case 216590:
        if (qs.getQuestVarById(0) == 1) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          QuestService.questTimerEnd(env);
          updateQuestStatus(env);
          return true;
        }
        break;
      case 216735:
        if (qs.getQuestVarById(0) == 2) {
          qs.setStatus(QuestStatus.REWARD);
          updateQuestStatus(env);
          return true;
        }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);

    if (defaultQuestNoneDialog(env, 798384, 182206109, 1)) return true;

    if (qs == null) return false;

    int var = qs.getQuestVarById(0);

    if (qs.getStatus() == QuestStatus.START) {
      switch (env.getTargetId()) {
        case 203740:
          switch (env.getDialogId()) {
            case 26:
              if (var == 0) return sendQuestDialog(env, 1352);
            case 10000:
              return defaultCloseDialog(env, 0, 1, 0, 0, 182206109, 1);
          }
          break;
        case 798384:
          switch (env.getDialogId()) {
            case 26:
              if (var == 1) return sendQuestDialog(env, 2375);
            case 34:
              return defaultQuestItemCheck(env, 1, 2, true, 5, 2716);
          }
          break;
      }
    }
    return defaultQuestRewardDialog(env, 798384, 0);
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    int removeItem = 0;
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    int var = 0;

    if (qs != null) var = qs.getQuestVarById(0);

    if (qs == null
        || qs.getStatus() == QuestStatus.NONE
        || qs.getStatus() == QuestStatus.COMPLETE) {
      if (env.getTargetId() == 278645) {
        switch (env.getDialogId()) {
          case 26:
            if (QuestService.checkLevelRequirement(questId, player.getCommonData().getLevel()))
              return sendQuestDialog(env, 1011);
            else return sendQuestDialog(env, 3398);
          case 1011:
          case 1352:
          case 1693:
          case 2034:
            int i = 0;
            for (int id : Items[0]) {
              if (id == env.getDialogId()) break;
              i++;
            }
            removeItem = Items[1][i];
            var = i;

            if (player.getInventory().getItemCountByItemId(removeItem) > 0) {
              if (qs == null) {
                qs = new QuestState(questId, QuestStatus.REWARD, 0, 0);
                player.getQuestStateList().addQuest(questId, qs);
              } else qs.setStatus(QuestStatus.REWARD);
              qs.setQuestVar(var);
              defaultQuestRemoveItem(env, removeItem, 1);
              return sendQuestDialog(env, var + 5);
            } else return sendQuestDialog(env, 1009);
        }
      }
    }

    if (qs == null) return false;

    return defaultQuestRewardDialog(env, 278645, 0, var);
  }
 @Override
 public boolean onDialogEvent(QuestCookie env) {
   final Player player = env.getPlayer();
   int targetId = 0;
   if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
   final QuestState qs = player.getQuestStateList().getQuestState(questId);
   QuestTemplate template = questsData.getQuestById(questId);
   if (targetId == 278639) {
     if (qs == null || qs.getStatus() == QuestStatus.NONE) {
       if (env.getDialogId() == 2) {
         PlayerClass playerClass = player.getCommonData().getPlayerClass();
         PlayerClass startPC = null;
         try {
           startPC = PlayerClass.getStartingClassFor(playerClass);
         } catch (IllegalArgumentException e) {
           startPC = playerClass; // already a start class
         }
         if (startPC == PlayerClass.MAGE || startPC == PlayerClass.PRIEST) {
           QuestService.startQuest(env, QuestStatus.START);
           return sendQuestDialog(env, 1011);
         } else {
           return sendQuestDialog(env, 3739);
         }
       }
     } else if (qs != null && qs.getStatus() == QuestStatus.START) {
       if (env.getDialogId() == 2) {
         return sendQuestDialog(env, 1011);
       } else if (env.getDialogId() == 1011) {
         if (player.getInventory().getItemCountByItemId(186000003) >= 16) {
           qs.setQuestVarById(0, 0);
           qs.setStatus(QuestStatus.REWARD);
           updateQuestStatus(env);
           return sendQuestDialog(env, 5);
         } else {
           return sendQuestDialog(env, 1009);
         }
       } else if (env.getDialogId() == 1352) {
         if (player.getInventory().getItemCountByItemId(186000003) >= 32) {
           qs.setQuestVarById(0, 1);
           qs.setStatus(QuestStatus.REWARD);
           updateQuestStatus(env);
           return sendQuestDialog(env, 6);
         } else {
           return sendQuestDialog(env, 1009);
         }
       }
     } else if (qs.getStatus() == QuestStatus.COMPLETE) {
       if (env.getDialogId() == 2) {
         if ((qs.getCompleteCount() <= template.getMaxRepeatCount())) {
           QuestService.startQuest(env, QuestStatus.START);
           return sendQuestDialog(env, 1011);
         } else return sendQuestDialog(env, 1008);
       }
     } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
       return defaultQuestEndDialog(env, qs.getQuestVarById(0));
     }
   }
   return false;
 }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 278152) // Darkhum
      {
        if (env.getDialogId() == 26) {
          return sendQuestDialog(env, 1011);
        } else return defaultQuestStartDialog(env);
      }
    }

    if (qs == null) return false;

    if (qs == null || qs.getStatus() == QuestStatus.COMPLETE) {
      if (targetId == 278152) // Darkhum
      {
        if (env.getDialogId() == 26) {
          return sendQuestDialog(env, 1011);
        } else return defaultQuestStartDialog(env);
      }
    }

    if (qs.getStatus() == QuestStatus.START) {
      switch (targetId) {
        case 278152: // Darkhum
          switch (env.getDialogId()) {
            case 26:
              return sendQuestDialog(env, 2375);
            case 2034:
              return sendQuestDialog(env, 2034);
            case 34:
              // Collect Crystal Fragment (1)
              if (QuestService.collectItemCheck(env, true)) {
                player.getInventory().removeFromBagByItemId(182209834, 1); // Crystal Fragment
                qs.setStatus(QuestStatus.REWARD);
                updateQuestStatus(env);
                return sendQuestDialog(env, 5);
              } else {
                //
                return sendQuestDialog(env, 2716);
              }
          }
          break;
          //
        default:
          return defaultQuestStartDialog(env);
      }
    } else if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 278152) // Darkhum
      return defaultQuestEndDialog(env);
    }
    return false;
  }
 @Override
 public boolean onLvlUpEvent(QuestCookie env) {
   Player player = env.getPlayer();
   QuestState qs = player.getQuestStateList().getQuestState(questId);
   boolean lvlCheck =
       QuestService.checkLevelRequirement(questId, player.getCommonData().getLevel());
   if (qs != null || !lvlCheck) return false;
   QuestService.startQuest(env, QuestStatus.START);
   return true;
 }
 @Override
 public HandlerResult onBonusApplyEvent(QuestCookie env, int index, AbstractInventoryBonus bonus) {
   if (!(bonus instanceof CoinBonus)) return HandlerResult.UNKNOWN;
   Player player = env.getPlayer();
   QuestState qs = player.getQuestStateList().getQuestState(questId);
   if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
     if (index == 0 && qs.getQuestVarById(0) == 0 || index == 1 && qs.getQuestVarById(0) == 1)
       return HandlerResult.SUCCESS;
   }
   return HandlerResult.FAILED;
 }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    int targetId = 0;

    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (targetId == 799523) {
      if (qs == null || qs.getStatus() == QuestStatus.NONE) {
        if (env.getDialogId() == 26) return sendQuestDialog(env, 1011);
        else return defaultQuestStartDialog(env);
      }
    } else if (targetId == 798029) {
      if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 0) {
        if (env.getDialogId() == 26) return sendQuestDialog(env, 2375);
        else if (env.getDialogId() == 34) {
          if (QuestService.collectItemCheck(env, true)) {
            qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 5);
          } else return sendQuestDialog(env, 2716);
        } else return defaultQuestStartDialog(env);
      } else if (qs != null && qs.getStatus() == QuestStatus.REWARD)
        return defaultQuestEndDialog(env);
    } else if (targetId == 700853) {
      if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 0) {
        if (env.getDialogId() == -1
            && (player.getInventory().getItemCountByItemId(185000103) > 0
                && player.getInventory().getItemCountByItemId(185000107) >= 3)) {
          if (!ItemService.addItems(
              player, Collections.singletonList(new QuestItems(182212020, 1)))) return true;
          final int targetObjectId = env.getVisibleObject().getObjectId();
          PacketSendUtility.sendPacket(
              player, new SM_USE_OBJECT(player.getObjectId(), targetObjectId, 3000, 0));
          PacketSendUtility.broadcastPacket(
              player, new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId), true);
          player.getInventory().removeFromBagByItemId(185000103, 1);
          player.getInventory().removeFromBagByItemId(185000107, 3);
        }
      }
    }

    return false;
  }
 @Override
 public boolean onMovieEndEvent(QuestCookie env, int movieId) {
   if (movieId != 442) return false;
   Player player = env.getPlayer();
   QuestState qs = player.getQuestStateList().getQuestState(questId);
   if (qs == null || qs.getStatus() != QuestStatus.START || qs.getQuestVars().getQuestVars() != 8)
     return false;
   QuestService.addNewSpawn(
       300150000,
       player.getInstanceId(),
       216592,
       (float) 561.8763,
       (float) 192.25128,
       (float) 135.88919,
       (byte) 30,
       true);
   return true;
 }
  @Override
  public boolean onDieEvent(QuestCookie env) {
    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null || qs.getStatus() != QuestStatus.START) return false;
    int var = qs.getQuestVars().getQuestVars();
    if (var == 8) {
      qs.setQuestVar(7);
      updateQuestStatus(env);
      PacketSendUtility.sendPacket(
          player,
          new SM_SYSTEM_MESSAGE(
              SystemMessageId.QUEST_FAILED_$1,
              DataManager.QUEST_DATA.getQuestById(questId).getName()));
    }

    return false;
  }
  @Override
  public HandlerResult onItemUseEvent(final QuestCookie env, Item item) {
    final Player player = env.getPlayer();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    if (id == 186000107) {
      if (!ZoneService.getInstance().isInsideZone(player, ZoneName.DEBILKARIM_FORGE_300160000))
        return HandlerResult.FAILED;
      if (qs == null) return HandlerResult.UNKNOWN;
      if (qs.getQuestVarById(0) != 0) return HandlerResult.FAILED;
      if (player.getInventory().getItemCountByItemId(100900716) == 0
          || player.getInventory().getItemCountByItemId(186000099) == 0
          || player.getInventory().getItemCountByItemId(186000106) < 20
          || player.getInventory().getItemCountByItemId(186000107) == 0)
        return HandlerResult.FAILED;
      PacketSendUtility.broadcastPacket(
          player,
          new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 3000, 0, 0),
          true);
      ThreadPoolManager.getInstance()
          .schedule(
              new Runnable() {
                @Override
                public void run() {
                  ItemService.addItems(
                      player, Collections.singletonList(new QuestItems(182209634, 1)));
                  PacketSendUtility.broadcastPacket(
                      player,
                      new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 0, 1, 0),
                      true);
                  player.getInventory().removeFromBagByItemId(186000099, 1);
                  player.getInventory().removeFromBagByItemId(186000106, 20);
                  player.getInventory().removeFromBagByItemId(186000107, 1);
                  qs.setStatus(QuestStatus.REWARD);
                  updateQuestStatus(env);
                }
              },
              3000);
      return HandlerResult.SUCCESS;
    }
    return HandlerResult.UNKNOWN;
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (targetId == 204777) {
      if (qs == null || qs.getStatus() == QuestStatus.NONE) {
        if (env.getDialogId() == 26) return sendQuestDialog(env, 4762);
        else return defaultQuestStartDialog(env);
      }
    }
    if (qs == null) return false;

    int var = qs.getQuestVarById(0);
    if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 204777) {
        if (env.getDialogId() == -1) return sendQuestDialog(env, 10002);
        else if (env.getDialogId() == 1009) return sendQuestDialog(env, 5);
        else return defaultQuestEndDialog(env);
      }
    } else if (qs.getStatus() != QuestStatus.START) {
      return false;
    }
    if (targetId == 700324) {
      switch (env.getDialogId()) {
        case -1:
          if (var >= 0 && var < 4) {
            if (player.getInventory().getItemCountByItemId(182204489) >= 1) {
              qs.setQuestVarById(0, var + 1);
              updateQuestStatus(env);
              return true;
            }
          } else if (var == 4) {
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return true;
          }
          return false;
      }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (targetId == 798946) {
      if (qs == null || qs.getStatus() == QuestStatus.NONE) {
        if (env.getDialogId() == 26) return sendQuestDialog(env, 4762);
        else return defaultQuestStartDialog(env);
      } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
        if (env.getDialogId() == -1) return sendQuestDialog(env, 10002);
        else if (env.getDialogId() == 1009) return sendQuestDialog(env, 5);
        else return defaultQuestEndDialog(env);
      }
    } else if (targetId == 799521) {
      if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 0) {
        if (env.getDialogId() == 26) return sendQuestDialog(env, 1011);
        else if (env.getDialogId() == 10000) {
          qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
          updateQuestStatus(env);
          PacketSendUtility.sendPacket(
              player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
          QuestService.questTimerStart(env, 300);
          @SuppressWarnings("unused")
          final int instanceId = player.getInstanceId();
          QuestService.addNewSpawn(
              300170000,
              player.getInstanceId(),
              216590,
              (float) 938.3348,
              (float) 240.31474,
              (float) 227.6818,
              (byte) 28,
              true);
          return true;
        } else return defaultQuestStartDialog(env);
      }
    }

    return false;
  }
 @Override
 public boolean onDialogEvent(QuestCookie env) {
   final Player player = env.getPlayer();
   int targetId = 0;
   if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
   QuestState qs = player.getQuestStateList().getQuestState(questId);
   if (targetId == 799032) {
     if (qs == null || qs.getStatus() == QuestStatus.NONE) {
       if (env.getDialogId() == 26) return sendQuestDialog(env, 4762);
       else return defaultQuestStartDialog(env);
     } else if (qs != null && qs.getStatus() == QuestStatus.START && qs.getQuestVarById(0) == 0) {
       if (env.getDialogId() == -1) {
         if (QuestService.collectItemCheck(env, false)) return sendQuestDialog(env, 2716);
       } else return defaultQuestStartDialog(env);
     } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
       if (env.getDialogId() == -1) return sendQuestDialog(env, 10002);
       else if (env.getDialogId() == 1009) return sendQuestDialog(env, 5);
       else return defaultQuestEndDialog(env);
     }
   }
   return false;
 }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    if (!super.defaultQuestOnDialogInitStart(env)) return false;

    Player player = env.getPlayer();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    int var = qs.getQuestVarById(0);

    if (qs.getStatus() == QuestStatus.START) {
      if (env.getTargetId() == 203081) {
        switch (env.getDialogId()) {
          case 26:
            if (var == 0) return sendQuestDialog(env, 1011);
            else if (var == 13) return sendQuestDialog(env, 1352);
          case 10000:
            return defaultCloseDialog(env, 0, 1);
          case 10001:
            return defaultCloseDialog(env, 13, 14);
        }
      }
    }
    return defaultQuestRewardDialog(env, 203081, 0);
  }
  @Override
  public boolean onDialogEvent(final QuestCookie env) {
    final Player player = env.getPlayer();
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);

    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 798926) // Outremus Start
      {
        if (env.getDialogId() == 26) return sendQuestDialog(env, 1011);
        else qs.setStatus(QuestStatus.REWARD);
        updateQuestStatus(env);
        return defaultQuestStartDialog(env);
      }
    }
    if (qs == null) return false;
    if (targetId == 798941 && qs.getStatus() == QuestStatus.REWARD) // Pilomenes
    {
      return sendQuestDialog(env, 2375);
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    if (player.getLevel() <= 46) return false;
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    QuestTemplate template = questsData.getQuestById(questId);

    if (targetId == 798174) {
      if (qs == null || qs.getStatus() == QuestStatus.NONE) {
        if (env.getDialogId() == 2) {
          PlayerClass playerClass = player.getCommonData().getPlayerClass();
          if (playerClass == PlayerClass.MAGE
              || playerClass == PlayerClass.SORCERER
              || playerClass == PlayerClass.SPIRIT_MASTER) {
            QuestService.startQuest(env, QuestStatus.START);
            return sendQuestDialog(env, 1011);
          } else {
            return sendQuestDialog(env, 3739);
          }
        }
      } else if (qs != null && qs.getStatus() == QuestStatus.START) {
        if (env.getDialogId() == 2) {
          return sendQuestDialog(env, 1011);
        } else if (env.getDialogId() == 10000) {
          if (player.getInventory().getItemCountByItemId(186000005) >= 2000) {
            qs.setQuestVarById(1, 0);
            player.getInventory().removeFromBagByItemId(186000005, 2000);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 5);
          } else {
            return sendQuestDialog(env, 1009);
          }
        } else if (env.getDialogId() == 10001) {
          if (player.getInventory().getItemCountByItemId(186000005) >= 400) {
            qs.setQuestVarById(1, 1);
            player.getInventory().removeFromBagByItemId(186000005, 400);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 6);
          } else {
            return sendQuestDialog(env, 1009);
          }
        } else if (env.getDialogId() == 10002) {
          if (player.getInventory().getItemCountByItemId(186000005) >= 1000) {
            qs.setQuestVarById(1, 2);
            player.getInventory().removeFromBagByItemId(186000005, 1000);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 7);
          } else {
            return sendQuestDialog(env, 1009);
          }
        } else if (env.getDialogId() == 10003) {
          if (player.getInventory().getItemCountByItemId(186000005) >= 200) {
            qs.setQuestVarById(1, 3);
            player.getInventory().removeFromBagByItemId(186000005, 200);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 8);
          } else {
            return sendQuestDialog(env, 1009);
          }
        }
      } else if (qs.getStatus() == QuestStatus.COMPLETE) {
        if (env.getDialogId() == 2) {
          if ((qs.getCompleteCount() <= template.getMaxRepeatCount())) {
            QuestService.startQuest(env, QuestStatus.START);
            return sendQuestDialog(env, 1011);
          } else return sendQuestDialog(env, 1008);
        }
      } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
        return defaultQuestEndDialog(env, qs.getQuestVarById(1));
      }
    }
    return false;
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    Player player = env.getPlayer();

    if (defaultQuestNoneDialog(env, questStartNpc, 4762)) return true;

    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null) return false;

    int var = qs.getQuestVarById(0);
    if (qs.getStatus() == QuestStatus.START) {
      switch (env.getTargetId()) {
        case secondNpc:
          switch (env.getDialogId()) {
            case 26:
              if (var == 0) return sendQuestDialog(env, 1011);
              else if (var == 2) return sendQuestDialog(env, 4080);
            case 10009:
              if (player.getInventory().decreaseKinah(251000)) {
                defaultQuestGiveItem(env, 152020248, 1);
                return defaultCloseDialog(env, var, 1, recipesItemIds[0], 1, 0, 0);
              } else return sendQuestDialog(env, 4400);
            case 10019:
              if (player.getInventory().decreaseKinah(334500)) {
                defaultQuestGiveItem(env, 152020248, 1);
                return defaultCloseDialog(env, var, 1, recipesItemIds[1], 1, 0, 0);
              } else return sendQuestDialog(env, 4400);
          }
          break;
        case questStartNpc:
          switch (env.getDialogId()) {
            case 26:
              if (var == 1) return sendQuestDialog(env, 1352);
            case 34:
              if (var == 1) {
                if (QuestService.collectItemCheck(env, true)) {
                  qs.setStatus(QuestStatus.REWARD);
                  updateQuestStatus(env);
                  return sendQuestDialog(env, 5);
                } else {
                  int checkFailId = 3398;
                  if (player.getRecipeList().isRecipePresent(recipesIds[0])
                      || player.getRecipeList().isRecipePresent(recipesIds[1])) checkFailId = 2716;
                  else if (player.getInventory().getItemCountByItemId(recipesItemIds[0]) > 0
                      || player.getInventory().getItemCountByItemId(recipesItemIds[1]) > 0)
                    checkFailId = 3057;

                  if (checkFailId == 3398) {
                    qs.setQuestVar(2);
                    updateQuestStatus(env);
                  }
                  return sendQuestDialog(env, checkFailId);
                }
              }
              break;
          }
          break;
      }
    }
    return defaultQuestRewardDialog(env, questStartNpc, 0);
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    // Instanceof
    final Player player = env.getPlayer();
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);

    // ------------------------------------------------------------
    // NPC Quest :
    // 0 - Start to //Garath
    if (qs == null || qs.getStatus() == QuestStatus.NONE) {
      if (targetId == 798208) // Garath
      {
        // Get HACTION_QUEST_SELECT in the eddit-HyperLinks.xml
        if (env.getDialogId() == 26)
          // Send HTML_PAGE_SELECT_NONE to eddit-HtmlPages.xml
          return sendQuestDialog(env, 4762);
        else return defaultQuestStartDialog(env);
      }
    }

    if (qs == null) return false;

    int var = qs.getQuestVarById(0);

    if (qs.getStatus() == QuestStatus.START) {
      switch (targetId) {
        case 799322: // Herka
          switch (env.getDialogId()) {
              // Get HACTION_QUEST_SELECT in the eddit-HyperLinks.xml
            case 26:
              // Send select1 to eddit-HtmlPages.xml
              return sendQuestDialog(env, 1011);
              // Get HACTION_SETPRO1 in the eddit-HyperLinks.xml
            case 10000:
              qs.setQuestVarById(0, var + 1);
              updateQuestStatus(env);
              PacketSendUtility.sendPacket(
                  player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
              return true;
          }
        case 799506: // Faithful Respondent Utra
          if (var == 1) {
            switch (env.getDialogId()) {
                // Get HACTION_QUEST_SELECT in the eddit-HyperLinks.xml
              case 26:
                // Send select2 to eddit-HtmlPages.xml
                return sendQuestDialog(env, 1352);
                // Get HACTION_SETPRO2 in the eddit-HyperLinks.xml
              case 10001:
                qs.setQuestVarById(0, var + 1);
                updateQuestStatus(env);
                PacketSendUtility.sendPacket(
                    player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
                return true;
            }
          }
          // Report The Result To Garath.
        case 798208: // Garath
          switch (env.getDialogId()) {
              // Get HACTION_QUEST_SELECT in the eddit-HyperLinks.xml
            case 26:
              // Send select1 to eddit-HtmlPages.xml
              return sendQuestDialog(env, 2375);
            case 2034:
              // Send select2 to eddit-HtmlPages.xml
              return sendQuestDialog(env, 2034);
              // Get HACTION_CHECK_USER_HAS_QUEST_ITEM in the eddit-HyperLinks.xml
            case 34:
              // Collect Spirit's Incense Burner (1)
              // Collect Scroll Of Repose (1)
              if (QuestService.collectItemCheck(env, true)) {
                player.getInventory().removeFromBagByItemId(182209718, 1);
                player.getInventory().removeFromBagByItemId(182209719, 1);
                qs.setStatus(QuestStatus.REWARD);
                updateQuestStatus(env);
                return sendQuestDialog(env, 5);
              } else {
                // Send check_user_item_fail to eddit-HtmlPages.xml
                return sendQuestDialog(env, 2716);
              }
          }
          break;
          // No match
        default:
          return defaultQuestStartDialog(env);
      }
    } else if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 798208) // Garath
      return defaultQuestEndDialog(env);
    }
    return false;
  }
 @Override
 public boolean onDialogEvent(QuestCookie env) {
   final Player player = env.getPlayer();
   int targetId = 0;
   if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
   QuestState qs = player.getQuestStateList().getQuestState(questId);
   if (qs == null || qs.getStatus() == QuestStatus.NONE) {
     if (targetId == 799340) // Athana
     {
       switch (env.getDialogId()) {
         case 26:
           return sendQuestDialog(env, 4762);
         case 1007:
           return sendQuestDialog(env, 4);
         case 1002:
           if (!ItemService.addItems(
               player, Collections.singletonList(new QuestItems(182207932, 1))))
             ; // Piece Of Zikel
           if (QuestService.startQuest(env, QuestStatus.START)) return sendQuestDialog(env, 1003);
           else return false;
         case 1003:
           return sendQuestDialog(env, 1004);
       }
     }
   }
   if (qs == null || qs.getStatus() == QuestStatus.COMPLETE) {
     if (targetId == 798317) // Usener
     {
       if (env.getDialogId() == 26) {
         return sendQuestDialog(env, 1352);
       } else return defaultQuestStartDialog(env);
     }
   }
   if (qs.getStatus() == QuestStatus.START) {
     switch (targetId) {
         // Usener
       case 798317:
         switch (env.getDialogId()) {
             // Get HACTION_QUEST_SELECT in the eddit-HyperLinks.xml
           case 26:
             // Send select1 to eddit-HtmlPages.xml
             return sendQuestDialog(env, 2375);
           case 2034:
             // Send select2 to eddit-HtmlPages.xml
             return sendQuestDialog(env, 2034);
             // Get HACTION_CHECK_USER_HAS_QUEST_ITEM in the eddit-HyperLinks.xml
           case 34:
             // Piece Of Zikel (1)
             // Athana's Dagger (1)
             // Kinah (8000000)
             if (QuestService.collectItemCheck(env, true)) {
               player.getInventory().removeFromBagByItemId(182207932, 1); // Piece Of Zikel
               player.getInventory().removeFromBagByItemId(100200845, 1); // Athana's Dagger
               player.getInventory().removeFromBagByItemId(182400001, 8000000); // Kinah
               qs.setStatus(QuestStatus.REWARD);
               updateQuestStatus(env);
               return sendQuestDialog(env, 5);
             } else {
               //
               return sendQuestDialog(env, 2716);
             }
         }
         break;
         // No match
       default:
         return defaultQuestStartDialog(env);
     }
   } else if (qs.getStatus() == QuestStatus.REWARD) {
     if (targetId == 798317) // Usener
     return defaultQuestEndDialog(env);
   }
   return false;
 }
 @Override
 public boolean onDialogEvent(QuestCookie env) {
   final Player player = env.getPlayer();
   final QuestState qs = player.getQuestStateList().getQuestState(questId);
   int targetId = 0;
   if (player.getCommonData().getLevel() < 21) return false;
   if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
   if (targetId == 798125) {
     if (qs == null || qs.getStatus() == QuestStatus.NONE) {
       if (env.getDialogId() == 26) return sendQuestDialog(env, 1011);
       else return defaultQuestStartDialog(env);
     } else if (qs.getStatus() == QuestStatus.START) {
       long itemCount;
       long itemCount1;
       long itemCount2;
       if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 0) {
         return sendQuestDialog(env, 2375);
       } else if (env.getDialogId() == 34 && qs.getQuestVarById(0) == 0) {
         itemCount = player.getInventory().getItemCountByItemId(182204227);
         itemCount1 = player.getInventory().getItemCountByItemId(182204228);
         itemCount2 = player.getInventory().getItemCountByItemId(182204229);
         if (itemCount > 4 && itemCount1 > 4 && itemCount2 > 4) {
           player.getInventory().removeFromBagByItemId(182204227, 5);
           player.getInventory().removeFromBagByItemId(182204228, 5);
           player.getInventory().removeFromBagByItemId(182204229, 5);
           qs.setStatus(QuestStatus.REWARD);
           updateQuestStatus(env);
           return sendQuestDialog(env, 5);
         } else {
           return sendQuestDialog(env, 2716);
         }
       } else return defaultQuestEndDialog(env);
     } else if (qs.getStatus() == QuestStatus.REWARD) {
       if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 5) {
         return sendQuestDialog(env, 5);
       } else if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 6) {
         return sendQuestDialog(env, 6);
       } else if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 7) {
         return sendQuestDialog(env, 7);
       } else {
         return defaultQuestEndDialog(env);
       }
     } else {
       return defaultQuestEndDialog(env);
     }
   } else if (targetId == 700317) {
     long itemCount;
     itemCount = player.getInventory().getItemCountByItemId(182204227);
     if (qs != null
         && qs.getStatus() == QuestStatus.START
         && qs.getQuestVarById(0) == 0
         && itemCount < 5) {
       final int targetObjectId = env.getVisibleObject().getObjectId();
       PacketSendUtility.broadcastPacket(
           player, new SM_EMOTION(player, EmotionType.NEUTRALMODE2, 0, targetObjectId), true);
       ThreadPoolManager.getInstance()
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   PacketSendUtility.broadcastPacket(
                       player,
                       new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId),
                       true);
                 }
               },
               3000);
       return true;
     } else {
       return defaultQuestEndDialog(env);
     }
   } else if (targetId == 700318) {
     long itemCount1;
     itemCount1 = player.getInventory().getItemCountByItemId(182204228);
     if (qs != null
         && qs.getStatus() == QuestStatus.START
         && qs.getQuestVarById(0) == 0
         && itemCount1 < 5) {
       final int targetObjectId = env.getVisibleObject().getObjectId();
       PacketSendUtility.broadcastPacket(
           player, new SM_EMOTION(player, EmotionType.NEUTRALMODE2, 0, targetObjectId), true);
       ThreadPoolManager.getInstance()
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   PacketSendUtility.broadcastPacket(
                       player,
                       new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId),
                       true);
                 }
               },
               3000);
       return true;
     } else {
       return defaultQuestEndDialog(env);
     }
   } else if (targetId == 700319) {
     long itemCount2;
     itemCount2 = player.getInventory().getItemCountByItemId(182204229);
     if (qs != null
         && qs.getStatus() == QuestStatus.START
         && qs.getQuestVarById(0) == 0
         && itemCount2 < 5) {
       final int targetObjectId = env.getVisibleObject().getObjectId();
       PacketSendUtility.broadcastPacket(
           player, new SM_EMOTION(player, EmotionType.NEUTRALMODE2, 0, targetObjectId), true);
       ThreadPoolManager.getInstance()
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   PacketSendUtility.broadcastPacket(
                       player,
                       new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId),
                       true);
                 }
               },
               3000);
       return true;
     } else {
       return defaultQuestEndDialog(env);
     }
   } else {
     return defaultQuestEndDialog(env);
   }
 }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null) return false;

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

    if (qs.getStatus() == QuestStatus.REWARD) {
      if (targetId == 799226) {
        if (env.getDialogId() == -1) return sendQuestDialog(env, 10002);
        else if (env.getDialogId() == 1009) return sendQuestDialog(env, 5);
        else return defaultQuestEndDialog(env);
      }
      return false;
    } else if (qs.getStatus() != QuestStatus.START) {
      return false;
    }
    if (targetId == 799226) {
      switch (env.getDialogId()) {
        case 26:
          if (var == 0) return sendQuestDialog(env, 1011);
          else if (var == 3) return sendQuestDialog(env, 2034);
        case 10000:
          if (var == 0) {
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
        case 10003:
          if (var == 3) {
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
      }
    } else if (targetId == 799292) {
      switch (env.getDialogId()) {
        case 26:
          if (var == 1) return sendQuestDialog(env, 1352);
          else if (var == 2) return sendQuestDialog(env, 1693);
          else if (var == 5) return sendQuestDialog(env, 2716);
          else if (var == 11) return sendQuestDialog(env, 1608);
          break;
        case 34:
          if (QuestService.collectItemCheck(env, true)) {
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          } else return sendQuestDialog(env, 10001);
        case 10001:
          if (var == 1) {
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
        case 10005:
          if (var == 5) {
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
        case 10255:
          if (var == 11) {
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
      }
    } else if (targetId == 700810) {
      if (var == 2) return true;
    } else if (targetId == 204057) {
      switch (env.getDialogId()) {
        case 26:
          if (var == 4) return sendQuestDialog(env, 2375);
        case 10004:
          if (var == 4) {
            if (!ItemService.addItems(
                player, Collections.singletonList(new QuestItems(182207611, 1)))) return true;
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
      }
    } else if (targetId == 799341) {
      switch (env.getDialogId()) {
        case 26:
          if (var == 9) return sendQuestDialog(env, 4080);
        case 10009:
          if (var == 9) {
            if (!ItemService.addItems(
                player, Collections.singletonList(new QuestItems(182207613, 1)))) return true;
            player.getInventory().removeFromBagByItemId(182207611, 1);
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
      }
    } else if (targetId == 799513
        || targetId == 799514
        || targetId == 799515
        || targetId == 799516) // FIXME: Var !
    {
      switch (env.getDialogId()) {
        case 26:
          if (var == 7) return sendQuestDialog(env, 4080);
        case 10009:
          if (var == 7) {
            PacketSendUtility.sendPacket(player, new SM_PLAY_MOVIE(0, 442));
            qs.setQuestVar(8);
            updateQuestStatus(env);
            PacketSendUtility.sendPacket(
                player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
            return true;
          }
      }
    } else if (targetId == 730243) {
      switch (env.getDialogId()) {
        case -1:
          if (var >= 6) return sendQuestDialog(env, 3057);
          break;
        case 26:
          if (var == 6) return sendQuestDialog(env, 3057);
          break;
        case 10006:
          if (var == 6) {
            qs.setQuestVarById(0, var + 1);
            updateQuestStatus(env);
            WorldMapInstance newInstance = InstanceService.getNextAvailableInstance(300150000);
            InstanceService.registerPlayerWithInstance(newInstance, player);
            TeleportService.teleportTo(
                player,
                300150000,
                newInstance.getInstanceId(),
                561.8651f,
                221.91483f,
                134.53333f,
                (byte) 90);
            return true;
          } else if (var > 6) {
            WorldMapInstance newInstance = InstanceService.getNextAvailableInstance(300150000);
            InstanceService.registerPlayerWithInstance(newInstance, player);
            TeleportService.teleportTo(
                player,
                300150000,
                newInstance.getInstanceId(),
                561.8651f,
                221.91483f,
                134.53333f,
                (byte) 90);
            return true;
          }
      }
    } else if (targetId == 700706) {
      switch (env.getDialogId()) {
        case -1:
          if (var == 10) {
            final int targetObjectId = env.getVisibleObject().getObjectId();
            PacketSendUtility.sendPacket(
                player, new SM_USE_OBJECT(player.getObjectId(), targetObjectId, 3000, 0));
            PacketSendUtility.broadcastPacket(
                player, new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId), true);
            qs.setQuestVar(11);
            updateQuestStatus(env);
            TeleportService.teleportTo(
                player, 300150000, 561.8651f, 221.91483f, 134.53333f, (byte) 90);
          }
      }
    }

    return false;
  }