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.esterra;
  
  import com.aionemu.gameserver.model.DialogAction;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  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;
  
  /**
   * @author Phantom_KNA
   * @rework FrozenKiller
   */
  public class _15565DefenceofArielsRefuge extends QuestHandler {
  
  	private final static int questId = 15565;
  	int[] mobs = {241285, 241286, 241287, 241288, 241289, 241290};
  
  	public _15565DefenceofArielsRefuge() {
  		super(questId);
  	}
  
  	@Override
  	public void register() {
  		qe.registerQuestNpc(806114).addOnTalkEvent(questId); // Ilisia
  		qe.registerQuestNpc(806114).addOnTalkEvent(questId);
  		qe.registerOnEnterWorld(questId);
  		for (int mob : mobs) {
  			qe.registerQuestNpc(mob).addOnKillEvent(questId);
  		}
  	}
  	
  	@Override
  	public boolean onEnterWorldEvent(QuestEnv env) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		if (qs == null || qs.getStatus() == QuestStatus.NONE) {
  			if (player.getLevel() >= 65 && player.getWorldId() == 210100000) {
  				QuestService.startQuest(env);
  				return true;
  			}
  		}
  		return false;
  	}
  
  	@Override
  	public boolean onDialogEvent(QuestEnv env) {
  		Player player = env.getPlayer();
  		QuestState qs = player.getQuestStateList().getQuestState(questId);
  		int targetId = env.getTargetId();
  		DialogAction dialog = env.getDialog();
  
  		if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
  			if (targetId == 806114) { // Ilisia
  				switch (dialog) {
  					case USE_OBJECT:
  						return sendQuestDialog(env, 10002);
  					case SELECT_QUEST_REWARD:
  						return sendQuestDialog(env, 5);
  					default:
  						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) {
  			int var = qs.getQuestVarById(1);
  			if (var != 9) {
  				return defaultOnKillEvent(env, mobs, var, var + 1, 1);
  			} else {
  				qs.setQuestVarById(0, 10);
  				qs.setStatus(QuestStatus.REWARD);
  				updateQuestStatus(env);
  				return true;
  			}
  		}
  		return false;
  	}
  
  }
  