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.theobomos;
  
  import com.aionemu.gameserver.model.DialogAction;
  import com.aionemu.gameserver.model.gameobjects.Npc;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_DIALOG_WINDOW;
  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;
  
  /**
   * @author Balthazar
   */
  public class _3031Pirates extends QuestHandler {
  
  	private final static int questId = 3031;
  
  	public _3031Pirates() {
  		super(questId);
  	}
  
  	@Override
  	public void register() {
  		qe.registerQuestNpc(730144).addOnQuestStart(questId);
  		qe.registerQuestNpc(730144).addOnTalkEvent(questId);
  		qe.registerQuestNpc(798172).addOnTalkEvent(questId);
  		qe.registerQuestNpc(214219).addOnKillEvent(questId);
  		qe.registerQuestNpc(214220).addOnKillEvent(questId);
  		qe.registerQuestNpc(214222).addOnKillEvent(questId);
  		qe.registerQuestNpc(214223).addOnKillEvent(questId);
  	}
  
  	@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 == 730144) {
  				switch (env.getDialog()) {
  					case QUEST_SELECT: {
  						return sendQuestDialog(env, 4762);
  					}
  					case SETPRO1: {
  						QuestService.startQuest(env);
  						PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(0, 0));
  						return true;
  					}
  					default:
  						return sendQuestStartDialog(env);
  				}
  			}
  		}
  
  		if (qs == null) {
  			return false;
  		}
  
  		if (qs.getStatus() == QuestStatus.REWARD) {
  			if (targetId == 798172) {
  				if (env.getDialogId() == DialogAction.SELECT_QUEST_REWARD.id()) {
  					return sendQuestDialog(env, 5);
  				}
  				else {
  					return sendQuestEndDialog(env);
  				}
  			}
  		}
  		return false;
  	}
  
  	@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 targetId = 0;
  
  		if (env.getVisibleObject() instanceof Npc) {
  			targetId = ((Npc) env.getVisibleObject()).getNpcId();
  		}
  
  		if (targetId == 214219 || targetId == 214220) {
  			switch (qs.getQuestVarById(1)) {
  				case 0:
  				case 1:
  				case 2:
  				case 3:
  				case 4:
  				case 5:
  				case 6:
  				case 7:
  				case 8:
  				case 9:
  				case 10:
  				case 11:
  				case 12:
  				case 13:
  				case 14: {
  					qs.setQuestVarById(1, qs.getQuestVarById(1) + 1);
  					updateQuestStatus(env);
  
  					if (qs.getQuestVarById(1) == 15 && qs.getQuestVarById(2) == 12) {
  						qs.setStatus(QuestStatus.REWARD);
  						updateQuestStatus(env);
  						return true;
  					}
  					return true;
  				}
  			}
  		}
  		else if (targetId == 214222 || targetId == 214223) {
  			switch (qs.getQuestVarById(2)) {
  				case 0:
  				case 1:
  				case 2:
  				case 3:
  				case 4:
  				case 5:
  				case 6:
  				case 7:
  				case 8:
  				case 9:
  				case 10:
  				case 11: {
  					qs.setQuestVarById(2, qs.getQuestVarById(2) + 1);
  					updateQuestStatus(env);
  
  					if (qs.getQuestVarById(1) == 15 && qs.getQuestVarById(2) == 12) {
  						qs.setStatus(QuestStatus.REWARD);
  						updateQuestStatus(env);
  						return true;
  					}
  					return true;
  				}
  			}
  		}
  		return false;
  	}
  }
  