Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package instances.Valefor.IceQueenEasyInstance;
- import java.util.HashMap;
- import java.util.Map;
- import l2r.gameserver.data.xml.impl.ItemData;
- import l2r.gameserver.enums.CtrlEvent;
- import l2r.gameserver.enums.CtrlIntention;
- import l2r.gameserver.instancemanager.InstanceManager;
- import l2r.gameserver.model.L2Object;
- import l2r.gameserver.model.L2World;
- import l2r.gameserver.model.actor.L2Attackable;
- import l2r.gameserver.model.actor.L2Npc;
- import l2r.gameserver.model.actor.L2Summon;
- import l2r.gameserver.model.actor.instance.L2PcInstance;
- import l2r.gameserver.model.effects.L2EffectType;
- import l2r.gameserver.model.entity.Instance;
- import l2r.gameserver.model.instancezone.InstanceWorld;
- import l2r.gameserver.model.items.instance.L2ItemInstance;
- import l2r.gameserver.model.quest.Quest;
- import l2r.gameserver.model.quest.QuestState;
- import l2r.gameserver.model.skills.L2Skill;
- import l2r.gameserver.network.SystemMessageId;
- import l2r.gameserver.network.serverpackets.ExSendUIEvent;
- import l2r.gameserver.network.serverpackets.NpcHtmlMessage;
- import l2r.gameserver.network.serverpackets.SystemMessage;
- public class IceQueenEasyInstance extends Quest
- {
- private class DHSWorld extends InstanceWorld
- {
- public Map<L2Npc, Boolean> npcList = new HashMap<>();
- public L2Npc QUEEN = null;
- public long[] storeTime =
- {
- 0,
- 0
- };
- public DHSWorld()
- {
- }
- }
- private static final int INSTANCEID = 161; // Instance ID
- private static final int STONE = 17700; // Penalty Stones
- private static final int REWARD_STONE = 17900; // Ice Stone Easy
- // NPCs
- private static final int ENTRANCE_NPC = 4310;
- private static final int ENDING_NPC = 70000;
- // mobs
- private static final int ICE_QUEEN_EASY = 70026; // Boss Id
- private static final int ICE_QUEEN_GUARD_EASY = 70029;
- //@formatter:off
- private static final int[] ICE_QUEEN_MOBIDS_EASY = {70032}; // Mobs
- // Doors/Walls/Zones
- private static final int[][] ROOM_1_MOBS = {
- {70032, -113544, 87176, -12880},
- {70032, -117352, 87176, -12688},
- {70032, -115432, 87176, -12784}
- };
- private static final int[][] ICE_GUARD_SPAWNS_EASY = {{-119541, 87177, -12595}};
- private static final int[][] ICE_QUEEN_SPAWNS_EASY = {{70026, -119901, 87177, -12595}};
- private static final int[] ENDING_NPC_SPAWN = {-119541, 87177, -12595};
- //@formatter:on
- public class teleCoord
- {
- int instanceId;
- int x;
- int y;
- int z;
- }
- public IceQueenEasyInstance()
- {
- super(-1, IceQueenEasyInstance.class.getSimpleName(), "instances");
- addStartNpc(ENTRANCE_NPC);
- addStartNpc(ENDING_NPC);
- addTalkId(ENTRANCE_NPC, ENDING_NPC);
- addKillId(ICE_QUEEN_GUARD_EASY, ICE_QUEEN_EASY, 70032);
- addAttackId(ICE_QUEEN_EASY);
- addSkillSeeId(ICE_QUEEN_MOBIDS_EASY);
- }
- private boolean checkConditions(L2PcInstance player)
- {
- if (hasQuestItems(player, STONE))
- {
- SystemMessage sm = SystemMessage.getSystemMessage(2100);
- sm.addPcName(player);
- player.broadcastPacket(sm);
- return false;
- }
- return true;
- }
- private void teleportplayer(L2PcInstance player, teleCoord teleto)
- {
- player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- player.setInstanceId(teleto.instanceId);
- player.teleToLocation(teleto.x, teleto.y, teleto.z);
- }
- protected void enterInstance(L2PcInstance player, String template, teleCoord teleto, L2Npc npc)
- {
- final L2ItemInstance reqItem = player.getInventory().getItemByItemId(40111);
- final String reqItemName = ItemData.getInstance().getTemplate(40111).getName();
- if (reqItem == null)
- {
- final NpcHtmlMessage html = getHtmlPacket(player, npc, "data/scripts/instances/Valefor/IceQueenEasyInstance/noRequiredItem.html");
- html.replace("%requiredItem%", reqItemName);
- player.sendPacket(html);
- return;
- }
- player.destroyItemByItemId("", 40111, 1, player, true);
- // check for existing instances for this player
- InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
- // existing instance
- if (world != null)
- {
- if (!(world instanceof DHSWorld))
- {
- player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON));
- return;
- }
- return;
- }
- if (checkConditions(player))
- {
- world = new DHSWorld();
- world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
- world.setTemplateId(INSTANCEID);
- world.setStatus(0);
- ((DHSWorld) world).storeTime[0] = System.currentTimeMillis();
- InstanceManager.getInstance().addWorld(world);
- _log.info("Epic Mission as been started " + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
- runTumors((DHSWorld) world);
- // teleport players
- teleto.instanceId = world.getInstanceId();
- teleportplayer(player, teleto);
- if (hasQuestItems(player, STONE))
- {
- SystemMessage sm = SystemMessage.getSystemMessage(2100);
- sm.addPcName(player);
- player.broadcastPacket(sm);
- return;
- }
- }
- }
- private NpcHtmlMessage getHtmlPacket(L2PcInstance player, L2Npc npc, String htmlFile)
- {
- final NpcHtmlMessage packet = new NpcHtmlMessage(npc.getObjectId());
- packet.setHtml(getHtm(player, player.getHtmlPrefix(), htmlFile));
- return packet;
- }
- protected void exitInstance(L2PcInstance player, teleCoord tele)
- {
- player.setInstanceId(0);
- player.teleToLocation(tele.x, tele.y, tele.z);
- L2Summon pet = player.getSummon();
- if (pet != null)
- {
- pet.setInstanceId(0);
- pet.teleToLocation(tele.x, tele.y, tele.z);
- }
- }
- protected boolean checkKillProgress(L2Npc mob, DHSWorld world)
- {
- if (world.npcList.containsKey(mob))
- {
- world.npcList.put(mob, true);
- }
- for (boolean isDead : world.npcList.values())
- {
- if (!isDead)
- {
- return false;
- }
- }
- return true;
- }
- protected int[][] getRoomSpawns(int room)
- {
- switch (room)
- {
- case 0:
- return ROOM_1_MOBS;
- }
- _log.warn("");
- return new int[][]{};
- }
- protected void runTumors(DHSWorld world)
- {
- for (int[] mob : getRoomSpawns(world.getStatus()))
- {
- L2Npc npc = addSpawn(mob[0], mob[1], mob[2], mob[3], 0, false, 0, false, world.getInstanceId());
- world.npcList.put(npc, false);
- }
- L2Npc mob = addSpawn(ICE_QUEEN_GUARD_EASY, ICE_GUARD_SPAWNS_EASY[world.getStatus()][0], ICE_GUARD_SPAWNS_EASY[world.getStatus()][1], ICE_GUARD_SPAWNS_EASY[world.getStatus()][2], 0, false, 0, false, world.getInstanceId());
- mob.disableCoreAI(true);
- mob.setIsImmobilized(true);
- mob.setCurrentHp(mob.getMaxHp() * 1.0);
- world.npcList.put(mob, false);
- world.setStatus(world.getStatus() + 1);
- }
- protected void runTwins(DHSWorld world)
- {
- world.setStatus(world.getStatus() + 1);
- world.QUEEN = addSpawn(ICE_QUEEN_SPAWNS_EASY[0][0], ICE_QUEEN_SPAWNS_EASY[0][1], ICE_QUEEN_SPAWNS_EASY[0][2], ICE_QUEEN_SPAWNS_EASY[0][3], 0, false, 0, false, world.getInstanceId());
- world.QUEEN.setIsMortal(true);
- }
- protected void bossSimpleDie(L2Npc boss)
- {
- // killing is only possible one time
- synchronized (this)
- {
- if (boss.isDead())
- {
- return;
- }
- // now reset currentHp to zero
- boss.setCurrentHp(0);
- boss.setIsDead(true);
- }
- // Set target to null and cancel Attack or Cast
- boss.setTarget(null);
- // Stop movement
- boss.stopMove(null);
- // Stop HP/MP/CP Regeneration task
- boss.getStatus().stopHpMpRegeneration();
- boss.stopAllEffectsExceptThoseThatLastThroughDeath();
- // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
- boss.broadcastStatusUpdate();
- // Notify L2Character AI
- boss.getAI().notifyEvent(CtrlEvent.EVT_DEAD);
- if (boss.getWorldRegion() != null)
- {
- boss.getWorldRegion().onDeath(boss);
- }
- }
- @Override
- public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
- {
- if (skill.hasEffectType(L2EffectType.REBALANCE_HP, L2EffectType.HEAL, L2EffectType.HEAL_PERCENT))
- {
- int hate = 2 * skill.getAggroPoints();
- if (hate < 2)
- {
- hate = 1000;
- }
- ((L2Attackable) npc).addDamageHate(caster, 0, hate);
- }
- return super.onSkillSee(npc, caster, skill, targets, isPet);
- }
- @Override
- public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
- {
- InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
- if (tmpworld instanceof DHSWorld)
- {
- DHSWorld world = (DHSWorld) tmpworld;
- if (world.getStatus() < 1)
- {
- if (checkKillProgress(npc, world))
- {
- runTumors(world);
- }
- }
- else if (world.getStatus() == 1)
- {
- if (checkKillProgress(npc, world))
- {
- runTwins(world);
- }
- }
- else if ((world.getStatus() == 2) && ((npc.getId() == ICE_QUEEN_EASY)))
- {
- if (world.QUEEN.isDead())
- {
- world.setStatus(world.getStatus() + 1);
- // instance end
- world.storeTime[1] = System.currentTimeMillis();
- world.QUEEN = null;
- // player.sendMessageS(player.getName() + " complete instance Cave of Queen !!", 5);
- addSpawn(ENDING_NPC, ENDING_NPC_SPAWN[0], ENDING_NPC_SPAWN[1], ENDING_NPC_SPAWN[2], 0, false, 0, false, world.getInstanceId());
- for (Integer pc : world.getAllowed())
- {
- L2PcInstance killer = L2World.getInstance().getPlayer(pc);
- if (killer != null)
- {
- killer.sendPacket(new ExSendUIEvent(killer, true, true, 0, 0, ""));
- }
- }
- Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
- inst.setDuration(3 * 60000);
- inst.setEmptyDestroyTime(0);
- }
- }
- }
- return "";
- }
- @Override
- public String onTalk(L2Npc npc, L2PcInstance player)
- {
- String htmltext = getNoQuestMsg(player);
- final QuestState st = getQuestState(player, true);
- if (st == null)
- {
- return htmltext;
- }
- int npcId = npc.getId();
- if (npcId == ENTRANCE_NPC)
- {
- teleCoord tele = new teleCoord();
- tele.x = -111833;
- tele.y = 87179;
- tele.z = -12975;
- enterInstance(player, "IceQueenEasyInstance.xml", tele, npc);
- return "";
- }
- else if (npcId == ENDING_NPC)
- {
- InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
- Long finishDiff = ((DHSWorld) world).storeTime[1] - ((DHSWorld) world).storeTime[0];
- if (finishDiff < 900000)
- {
- player.getStat().addLevel((byte) 5);
- st.giveItems(REWARD_STONE, 1);
- st.giveItems(17700, 1);
- }
- world.removeAllowed(player.getObjectId());
- teleCoord tele = new teleCoord();
- tele.instanceId = 0;
- tele.x = 82497;
- tele.y = 148597;
- tele.z = -3469;
- exitInstance(player, tele);
- return "";
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement