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.verteron;
  
  import com.aionemu.gameserver.model.DialogAction;
  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.skillengine.SkillEngine;
  import com.aionemu.gameserver.utils.PacketSendUtility;
  import com.aionemu.gameserver.world.zone.ZoneName;
  
  /**
   * @author FrozenKiller
   */
  public class _14114RevolutionIntervention extends QuestHandler {
  
  	private final static int questId = 14114;
  
  	public _14114RevolutionIntervention() {
  		super(questId);
  	}
  
  	@Override
  	public void register() {
  		qe.registerQuestNpc(203098).addOnQuestStart(questId);
  		qe.registerQuestNpc(203098).addOnTalkEvent(questId); // Spatalos
  		qe.registerQuestNpc(203183).addOnTalkEvent(questId); // Khidia
  		qe.registerOnEnterZone(ZoneName.get("LF1A_SENSORYAREA_Q1023_SPG_206008_2_210030000"), questId);
  		qe.registerOnQuestTimerEnd(questId);
  		qe.registerOnDie(questId);
  		qe.registerOnEnterWorld(questId);
  		qe.registerOnMovieEndQuest(23, questId);
  	}
  
  	@Override
  	public boolean onZoneMissionEndEvent(QuestEnv env) {
  		return defaultOnZoneMissionEndEvent(env, 1013);
  	}
  
  	@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) {
  			if (targetId == 203098) { // Spatalos
  				if (dialog == DialogAction.QUEST_SELECT) {
  					return sendQuestDialog(env, 4762);
  				}
  				else {
  					return sendQuestStartDialog(env);
  				}
  			}
  		}
  		else if (qs.getStatus() == QuestStatus.START) {
  			int var = qs.getQuestVarById(0);
  			if (targetId == 203183) { // Khidia
  				switch (dialog) {
  					case QUEST_SELECT: {
  						if (var == 0) {
  							return sendQuestDialog(env, 1011);
  						}
  						else if (var == 2) {
  							return sendQuestDialog(env, 1352);
  						}
  						else if (var == 3) {
  							return sendQuestDialog(env, 1693);
  						}
  					}
  					case SETPRO1: {
  						SkillEngine.getInstance().applyEffectDirectly(8197, player, player, 0);
  						QuestService.questTimerStart(env, 300);
  						updateQuestStatus(env);
  						return defaultCloseDialog(env, 0, 1); // 1
  					}
  					case SETPRO2: {
  						return defaultCloseDialog(env, 2, 3); // 3
  					}
  					case CHECK_USER_HAS_QUEST_ITEM: {
  						return checkQuestItems(env, 3, 4, false, 10000, 10001);
  					}
  					case SETPRO3: {
  						qs.setStatus(QuestStatus.REWARD);
  						updateQuestStatus(env);
  						PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 0));
  						return true;
  					}
  					default:
  						break;
  				}
  			}
  		}
  		else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
  			if (targetId == 203098) {
  				if (dialog == DialogAction.QUEST_SELECT) {
  					return sendQuestDialog(env, 2375);
  				}
  				else {
  					return sendQuestEndDialog(env);
  				}
  			}
  		}
  		return false;
  	}
  
  	@Override
  	public boolean onQuestTimerEndEvent(QuestEnv env) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		if (qs != null && qs.getStatus() == QuestStatus.START) {
  			int var = qs.getQuestVarById(0);
  			if ((var > 1) && (var < 2)) {
  				changeQuestStep(env, var, 1, false);
  				return true;
  			}
  		}
  		return false;
  	}
  
  	@Override
  	public boolean onDieEvent(QuestEnv env) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		if (qs != null && qs.getStatus() == QuestStatus.START) {
  			int var = qs.getQuestVarById(0);
  			if (var == 1) {
  				QuestService.questTimerEnd(env);
  				return this.onQuestTimerEndEvent(env);
  			}
  		}
  		return false;
  	}
  
  	@Override
  	public boolean onEnterWorldEvent(QuestEnv env) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		if (qs != null && qs.getStatus() == QuestStatus.START) {
  			int var = qs.getQuestVarById(0);
  			if (var == 1) {
  				QuestService.questTimerEnd(env);
  				return this.onQuestTimerEndEvent(env);
  			}
  		}
  		return false;
  	}
  
  	@Override
  	public boolean onMovieEndEvent(QuestEnv env, int movieId) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		if (qs != null && movieId == 23) {
  			qs.setQuestVar(2);
  			player.getEffectController().removeEffect(8197);
  			updateQuestStatus(env);
  			return true;
  		}
  		return false;
  	}
  
  	@Override
  	public boolean onEnterZoneEvent(QuestEnv env, ZoneName zoneName) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		if (qs != null && qs.getStatus() == QuestStatus.START) {
  			int var = qs.getQuestVarById(0);
  			if (zoneName == ZoneName.get("LF1A_SENSORYAREA_Q1023_SPG_206008_2_210030000")) {
  				if (var == 1) {
  					QuestService.questTimerEnd(env);
  					playQuestMovie(env, 23);
  					return true;
  				}
  			}
  		}
  		return false;
  	}
  }
  