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 instance;
  
  import java.util.Set;
  
  import com.aionemu.commons.utils.Rnd;
  import com.aionemu.gameserver.instance.handlers.GeneralInstanceHandler;
  import com.aionemu.gameserver.instance.handlers.InstanceID;
  import com.aionemu.gameserver.model.EmotionType;
  import com.aionemu.gameserver.model.drop.DropItem;
  import com.aionemu.gameserver.model.gameobjects.Creature;
  import com.aionemu.gameserver.model.gameobjects.Npc;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_DIE;
  import com.aionemu.gameserver.network.aion.serverpackets.SM_EMOTION;
  import com.aionemu.gameserver.services.drop.DropRegistrationService;
  import com.aionemu.gameserver.utils.PacketSendUtility;
  import com.aionemu.gameserver.world.WorldMapInstance;
  
  /**
   * @author Rinzler
   */
  @InstanceID(301330000)
  public class LuckyDanuarReliquaryInstance extends GeneralInstanceHandler {
  
  	@Override
  	public void onInstanceCreate(WorldMapInstance instance) {
  		super.onInstanceCreate(instance);
  		int queen = Rnd.get(1, 2);
  		switch (queen) {
  			case 1:
  				spawn(231304, 256.0678f, 268.65024f, 241.88057f, (byte) 92); // Cursed Queen's Modor.
  				break;
  			case 2:
  				spawn(231305, 256.0678f, 268.65024f, 241.88057f, (byte) 92); // Enraged Queen's Modor.
  				break;
  		}
  	}
  
  	@Override
  	public void onDropRegistered(Npc npc) {
  		Set<DropItem> dropItems = DropRegistrationService.getInstance().getCurrentDropMap().get(npc.getObjectId());
  		int npcId = npc.getNpcId();
  		switch (npcId) {
  			case 231304: // Cursed Queen's Modor.
  			case 231305: // Enraged Queen's Modor.
  				int index = dropItems.size() + 1;
  				for (Player player : instance.getPlayersInside()) {
  					if (player.isOnline()) {
  						dropItems.add(DropRegistrationService.getInstance().regDropItem(index++, player.getObjectId(), npcId, 188052388, 1)); // Modor's Equipment Box.
  					}
  				}
  				break;
  		}
  	}
  
  	@Override
  	public void onDie(Npc npc) {
  		switch (npc.getObjectTemplate().getTemplateId()) {
  			case 284383: // Clone's Modor.
  			case 284384: // Clone's Modor.
  				despawnNpc(npc);
  				break;
  			case 231304: // Cursed Queen's Modor.
  			case 231305: // Enraged Queen's Modor.
  				despawnNpc(npc);
  				spawn(730843, 256.45197f, 257.91986f, 241.78688f, (byte) 90); // Lucky Danuar Reliquary Exit.
  				spawn(701795, 256.39725f, 255.52034f, 241.78006f, (byte) 90); // Lucky Danuar Reliquary Box.
  				break;
  		}
  	}
  
  	private void despawnNpc(Npc npc) {
  		if (npc != null) {
  			npc.getController().onDelete();
  		}
  	}
  
  	@Override
  	public boolean onDie(final Player player, Creature lastAttacker) {
  		PacketSendUtility.broadcastPacket(player, new SM_EMOTION(player, EmotionType.DIE, 0, player.equals(lastAttacker) ? 0 : lastAttacker.getObjectId()), true);
  		PacketSendUtility.sendPacket(player, new SM_DIE(player.haveSelfRezEffect(), player.haveSelfRezItem(), 0, 8));
  		return true;
  	}
  }
  