content: /**
   * This file is part of Aion-Lightning <aion-lightning.org>.
   *
   *  Aion-Lightning is free software: you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation, either version 3 of the License, or
   *  (at your option) any later version.
   *
   *  Aion-Lightning is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details. *
   *  You should have received a copy of the GNU General Public License
   *  along with Aion-Lightning.
   *  If not, see <http://www.gnu.org/licenses/>.
   */
  package quest.ishalgen;
  
  import com.aionemu.gameserver.model.DialogAction;
  import com.aionemu.gameserver.model.gameobjects.Item;
  import com.aionemu.gameserver.model.gameobjects.Npc;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_ITEM_USAGE_ANIMATION;
  import com.aionemu.gameserver.questEngine.handlers.HandlerResult;
  import com.aionemu.gameserver.questEngine.handlers.QuestHandler;
  import com.aionemu.gameserver.questEngine.model.QuestEnv;
  import com.aionemu.gameserver.questEngine.model.QuestState;
  import com.aionemu.gameserver.questEngine.model.QuestStatus;
  import com.aionemu.gameserver.services.QuestService;
  import com.aionemu.gameserver.utils.PacketSendUtility;
  import com.aionemu.gameserver.utils.ThreadPoolManager;
  
  /**
   * @author Rhys2002
   * @modified Hellboy
   * @rework FrozenKiller (5.6)
   */
  public class _2136TheLostAxe extends QuestHandler {
  
  	private final static int questId = 2136;
  	private final static int[] npc_ids = { 700146, 790009 };
  
  	public _2136TheLostAxe() {
  		super(questId);
  	}
  
  	@Override
  	public void register() {
  		qe.registerQuestItem(182203130, questId);
  		for (int npc_id : npc_ids) {
  			qe.registerQuestNpc(npc_id).addOnTalkEvent(questId);
  		}
  	}
  
  	@Override
  	public boolean onDialogEvent(final QuestEnv env) {
  		final Player player = env.getPlayer();
  		int targetId = env.getTargetId();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		DialogAction dialog = env.getDialog();
  
  		if (qs == null || qs.getStatus() == QuestStatus.NONE) {
  			return false;
  		}
  		
  		if (qs.getStatus() == QuestStatus.START) {
  			int var = qs.getQuestVarById(0);
  			if (targetId == 790009) {
  				switch (dialog) {
  					case QUEST_SELECT:
  						if (var == 1) {
  							return sendQuestDialog(env, 1011);
  						}
  					case SETPRO1:
  						if (var == 1) {
  							qs.setStatus(QuestStatus.REWARD);
  							updateQuestStatus(env);
  							return sendQuestDialog(env, 6);
  						}
  					case SETPRO2:
  						if (var == 1) {
  							qs.setStatus(QuestStatus.REWARD);
  							updateQuestStatus(env);
  							removeQuestItem(env, 182203130, 1);
  							return sendQuestDialog(env, 5);
  						}
  					default:
  						break;
  				}
  			}
  			else if (targetId == 700146) {
  				switch (dialog) {
  					case USE_OBJECT:
  						if (var == 0) {
  							playQuestMovie(env, 59);
  							qs.setQuestVarById(0, 1);
  							updateQuestStatus(env);
  							QuestService.addNewSpawn(220010000, player.getInstanceId(), 790009, 1080.1555f, 2374.5107f, 247.75f, (byte) 73);
  							return true;
  						}
  					default:
  						break;
  				}
  			}
  		} else if (qs.getStatus() == QuestStatus.REWARD) {
  			if (targetId == 790009) {
  				final Npc npc = (Npc) env.getVisibleObject();
  				ThreadPoolManager.getInstance().schedule(new Runnable() {
  
  					@Override
  					public void run() {
  						npc.getController().onDelete();
  					}
  				}, 10000);
  				return sendQuestEndDialog(env);
  			}
  		}
  		return false;
  	}
  
  	@Override
  	public HandlerResult onItemUseEvent(final QuestEnv env, final Item item) { // TODO Dialog before Quest Start
  		final Player player = env.getPlayer();
  		final int id = item.getItemTemplate().getTemplateId();
  		final int itemObjId = item.getObjectId();
  		
  		if (id != 182203130) {
  			return HandlerResult.UNKNOWN;
  		}
  		
  		PacketSendUtility.broadcastPacket(player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 100, 0, 0), true);
  		ThreadPoolManager.getInstance().schedule(new Runnable() {
  			@Override
  			public void run() {
  				PacketSendUtility.broadcastPacket(player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 0, 0, 1), true);
  				player.getInventory().decreaseByObjectId(itemObjId, 1);
  				QuestService.startQuest(env);
  			}
  		}, 100);
  		return HandlerResult.SUCCESS;
  	}
  }
  