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 ai.worlds.upper_abyss;
  
  import com.aionemu.gameserver.ai2.AI2Actions;
  import com.aionemu.gameserver.ai2.AIName;
  import com.aionemu.gameserver.ai2.NpcAI2;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_DIALOG_WINDOW;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_SYSTEM_MESSAGE;
  import com.aionemu.gameserver.utils.PacketSendUtility;
  import com.aionemu.gameserver.utils.ThreadPoolManager;
  import com.aionemu.gameserver.world.World;
  import com.aionemu.gameserver.world.knownlist.Visitor;
  
  @AIName("miren_crystal_sword")
  public class Miren_Crystal_SwordAI2 extends NpcAI2 {
  
  	@Override
  	protected void handleDialogStart(Player player) {
  		if (player.getInventory().getFirstItemByItemId(185000247) != null) { // Spirit Of Miren's Pendant.
  			PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(getObjectId(), 10));
  		}
  		else {
  			PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(getObjectId(), 27));
  			// Spirit of Miren's Pendant is required to break this seal.
  			PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_Ab1_Named_Spawn_Fail02);
  		}
  	}
  
  	@Override
  	public boolean onDialogSelect(final Player player, int dialogId, int questId, int extendedRewardIndex) {
  		if (dialogId == 10000 && player.getInventory().decreaseByItemId(185000247, 1)) { // Spirit of Miren's Pendant.
  			switch (getNpcId()) {
  				case 702842: // Miren's Crystal Sword [Elyos]
  					announceSpiritOfMiren30Min();
  					ThreadPoolManager.getInstance().schedule(new Runnable() {
  
  						@Override
  						public void run() {
  							spawn(883662, getOwner().getX(), getOwner().getY(), getOwner().getZ(), (byte) getOwner().getHeading()); // Spirit Of Miren.
  						}
  					}, 1800000); // 30 Minutes.
  					break;
  				case 702843: // Miren's Crystal Sword [Asmodians]
  					announceSpiritOfMiren30Min();
  					ThreadPoolManager.getInstance().schedule(new Runnable() {
  
  						@Override
  						public void run() {
  							spawn(884028, getOwner().getX(), getOwner().getY(), getOwner().getZ(), (byte) getOwner().getHeading()); // Spirit Of Miren.
  						}
  					}, 1800000); // 30 Minutes.
  					break;
  			}
  		}
  		// Spirit Of Miren's Pendant has broken the seal.
  		PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_Ab1_Lamiren_Named_Spawn_Item);
  		PacketSendUtility.sendPacket(player, new SM_DIALOG_WINDOW(getObjectId(), 0));
  		AI2Actions.deleteOwner(this);
  		AI2Actions.scheduleRespawn(this);
  		return true;
  	}
  
  	private void announceSpiritOfMiren30Min() {
  		World.getInstance().doOnAllPlayers(new Visitor<Player>() {
  
  			@Override
  			public void visit(Player player) {
  				// Spirit of Miren will be summoned from Miren's Crystal Sword in 30 minutes.
  				PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_Ab1_Lamiren_Named_Spawn_System);
  			}
  		});
  	}
  }
  