Advertisement
Evanth3

Untitled

Aug 27th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.88 KB | None | 0 0
  1. package instances.Valefor.IceQueenEasyInstance;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import l2r.gameserver.data.xml.impl.ItemData;
  7. import l2r.gameserver.enums.CtrlEvent;
  8. import l2r.gameserver.enums.CtrlIntention;
  9. import l2r.gameserver.instancemanager.InstanceManager;
  10. import l2r.gameserver.model.L2Object;
  11. import l2r.gameserver.model.L2World;
  12. import l2r.gameserver.model.actor.L2Attackable;
  13. import l2r.gameserver.model.actor.L2Npc;
  14. import l2r.gameserver.model.actor.L2Summon;
  15. import l2r.gameserver.model.actor.instance.L2PcInstance;
  16. import l2r.gameserver.model.effects.L2EffectType;
  17. import l2r.gameserver.model.entity.Instance;
  18. import l2r.gameserver.model.instancezone.InstanceWorld;
  19. import l2r.gameserver.model.items.instance.L2ItemInstance;
  20. import l2r.gameserver.model.quest.Quest;
  21. import l2r.gameserver.model.quest.QuestState;
  22. import l2r.gameserver.model.skills.L2Skill;
  23. import l2r.gameserver.network.SystemMessageId;
  24. import l2r.gameserver.network.serverpackets.ExSendUIEvent;
  25. import l2r.gameserver.network.serverpackets.NpcHtmlMessage;
  26. import l2r.gameserver.network.serverpackets.SystemMessage;
  27.  
  28. public class IceQueenEasyInstance extends Quest
  29. {
  30.     private class DHSWorld extends InstanceWorld
  31.     {
  32.         public Map<L2Npc, Boolean> npcList = new HashMap<>();
  33.         public L2Npc QUEEN = null;
  34.  
  35.         public long[] storeTime =
  36.                 {
  37.                         0,
  38.                         0
  39.                 };
  40.  
  41.         public DHSWorld()
  42.         {
  43.  
  44.         }
  45.     }
  46.  
  47.     private static final int INSTANCEID = 161; // Instance ID
  48.  
  49.     private static final int STONE = 17700; // Penalty Stones
  50.     private static final int REWARD_STONE = 17900; // Ice Stone Easy
  51.  
  52.     // NPCs
  53.     private static final int ENTRANCE_NPC = 4310;
  54.     private static final int ENDING_NPC = 70000;
  55.  
  56.     // mobs
  57.     private static final int ICE_QUEEN_EASY = 70026; // Boss Id
  58.     private static final int ICE_QUEEN_GUARD_EASY = 70029;
  59.  
  60.     //@formatter:off
  61.     private static final int[] ICE_QUEEN_MOBIDS_EASY = {70032}; // Mobs
  62.  
  63.     // Doors/Walls/Zones
  64.     private static final int[][] ROOM_1_MOBS = {
  65.             {70032, -113544, 87176, -12880},
  66.             {70032, -117352, 87176, -12688},
  67.             {70032, -115432, 87176, -12784}
  68.     };
  69.  
  70.     private static final int[][] ICE_GUARD_SPAWNS_EASY = {{-119541, 87177, -12595}};
  71.  
  72.     private static final int[][] ICE_QUEEN_SPAWNS_EASY = {{70026, -119901, 87177, -12595}};
  73.     private static final int[] ENDING_NPC_SPAWN = {-119541, 87177, -12595};
  74.  
  75.     //@formatter:on
  76.     public class teleCoord
  77.     {
  78.         int instanceId;
  79.         int x;
  80.         int y;
  81.         int z;
  82.     }
  83.  
  84.     public IceQueenEasyInstance()
  85.     {
  86.         super(-1, IceQueenEasyInstance.class.getSimpleName(), "instances");
  87.  
  88.         addStartNpc(ENTRANCE_NPC);
  89.         addStartNpc(ENDING_NPC);
  90.         addTalkId(ENTRANCE_NPC, ENDING_NPC);
  91.         addKillId(ICE_QUEEN_GUARD_EASY, ICE_QUEEN_EASY, 70032);
  92.         addAttackId(ICE_QUEEN_EASY);
  93.         addSkillSeeId(ICE_QUEEN_MOBIDS_EASY);
  94.     }
  95.  
  96.     private boolean checkConditions(L2PcInstance player)
  97.     {
  98.         if (hasQuestItems(player, STONE))
  99.         {
  100.             SystemMessage sm = SystemMessage.getSystemMessage(2100);
  101.             sm.addPcName(player);
  102.             player.broadcastPacket(sm);
  103.             return false;
  104.         }
  105.         return true;
  106.     }
  107.  
  108.     private void teleportplayer(L2PcInstance player, teleCoord teleto)
  109.     {
  110.         player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  111.         player.setInstanceId(teleto.instanceId);
  112.         player.teleToLocation(teleto.x, teleto.y, teleto.z);
  113.     }
  114.  
  115.     protected void enterInstance(L2PcInstance player, String template, teleCoord teleto, L2Npc npc)
  116.     {
  117.  
  118.         final L2ItemInstance reqItem = player.getInventory().getItemByItemId(40111);
  119.         final String reqItemName = ItemData.getInstance().getTemplate(40111).getName();
  120.  
  121.         if (reqItem == null)
  122.         {
  123.             final NpcHtmlMessage html = getHtmlPacket(player, npc, "data/scripts/instances/Valefor/IceQueenEasyInstance/noRequiredItem.html");
  124.             html.replace("%requiredItem%", reqItemName);
  125.             player.sendPacket(html);
  126.             return;
  127.         }
  128.  
  129.         player.destroyItemByItemId("", 40111, 1, player, true);
  130.         // check for existing instances for this player
  131.         InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  132.         // existing instance
  133.         if (world != null)
  134.         {
  135.             if (!(world instanceof DHSWorld))
  136.             {
  137.                 player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON));
  138.                 return;
  139.             }
  140.             return;
  141.         }
  142.         if (checkConditions(player))
  143.         {
  144.             world = new DHSWorld();
  145.             world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
  146.             world.setTemplateId(INSTANCEID);
  147.             world.setStatus(0);
  148.             ((DHSWorld) world).storeTime[0] = System.currentTimeMillis();
  149.             InstanceManager.getInstance().addWorld(world);
  150.             _log.info("Epic Mission as been started " + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
  151.             runTumors((DHSWorld) world);
  152.             // teleport players
  153.             teleto.instanceId = world.getInstanceId();
  154.             teleportplayer(player, teleto);
  155.  
  156.             if (hasQuestItems(player, STONE))
  157.             {
  158.                 SystemMessage sm = SystemMessage.getSystemMessage(2100);
  159.                 sm.addPcName(player);
  160.                 player.broadcastPacket(sm);
  161.                 return;
  162.             }
  163.  
  164.         }
  165.     }
  166.  
  167.     private NpcHtmlMessage getHtmlPacket(L2PcInstance player, L2Npc npc, String htmlFile)
  168.     {
  169.         final NpcHtmlMessage packet = new NpcHtmlMessage(npc.getObjectId());
  170.         packet.setHtml(getHtm(player, player.getHtmlPrefix(), htmlFile));
  171.         return packet;
  172.     }
  173.  
  174.     protected void exitInstance(L2PcInstance player, teleCoord tele)
  175.     {
  176.         player.setInstanceId(0);
  177.         player.teleToLocation(tele.x, tele.y, tele.z);
  178.         L2Summon pet = player.getSummon();
  179.         if (pet != null)
  180.         {
  181.             pet.setInstanceId(0);
  182.             pet.teleToLocation(tele.x, tele.y, tele.z);
  183.         }
  184.     }
  185.  
  186.     protected boolean checkKillProgress(L2Npc mob, DHSWorld world)
  187.     {
  188.         if (world.npcList.containsKey(mob))
  189.         {
  190.             world.npcList.put(mob, true);
  191.         }
  192.         for (boolean isDead : world.npcList.values())
  193.         {
  194.             if (!isDead)
  195.             {
  196.                 return false;
  197.             }
  198.         }
  199.         return true;
  200.     }
  201.  
  202.     protected int[][] getRoomSpawns(int room)
  203.     {
  204.         switch (room)
  205.         {
  206.             case 0:
  207.                 return ROOM_1_MOBS;
  208.         }
  209.         _log.warn("");
  210.         return new int[][]{};
  211.     }
  212.  
  213.     protected void runTumors(DHSWorld world)
  214.     {
  215.         for (int[] mob : getRoomSpawns(world.getStatus()))
  216.         {
  217.             L2Npc npc = addSpawn(mob[0], mob[1], mob[2], mob[3], 0, false, 0, false, world.getInstanceId());
  218.             world.npcList.put(npc, false);
  219.         }
  220.         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());
  221.         mob.disableCoreAI(true);
  222.         mob.setIsImmobilized(true);
  223.         mob.setCurrentHp(mob.getMaxHp() * 1.0);
  224.         world.npcList.put(mob, false);
  225.         world.setStatus(world.getStatus() + 1);
  226.     }
  227.  
  228.     protected void runTwins(DHSWorld world)
  229.     {
  230.         world.setStatus(world.getStatus() + 1);
  231.         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());
  232.         world.QUEEN.setIsMortal(true);
  233.     }
  234.  
  235.     protected void bossSimpleDie(L2Npc boss)
  236.     {
  237.         // killing is only possible one time
  238.         synchronized (this)
  239.         {
  240.             if (boss.isDead())
  241.             {
  242.                 return;
  243.             }
  244.             // now reset currentHp to zero
  245.             boss.setCurrentHp(0);
  246.             boss.setIsDead(true);
  247.         }
  248.  
  249.         // Set target to null and cancel Attack or Cast
  250.         boss.setTarget(null);
  251.  
  252.         // Stop movement
  253.         boss.stopMove(null);
  254.  
  255.         // Stop HP/MP/CP Regeneration task
  256.         boss.getStatus().stopHpMpRegeneration();
  257.  
  258.         boss.stopAllEffectsExceptThoseThatLastThroughDeath();
  259.  
  260.         // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  261.         boss.broadcastStatusUpdate();
  262.  
  263.         // Notify L2Character AI
  264.         boss.getAI().notifyEvent(CtrlEvent.EVT_DEAD);
  265.  
  266.         if (boss.getWorldRegion() != null)
  267.         {
  268.             boss.getWorldRegion().onDeath(boss);
  269.         }
  270.     }
  271.  
  272.     @Override
  273.     public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  274.     {
  275.         if (skill.hasEffectType(L2EffectType.REBALANCE_HP, L2EffectType.HEAL, L2EffectType.HEAL_PERCENT))
  276.         {
  277.             int hate = 2 * skill.getAggroPoints();
  278.             if (hate < 2)
  279.             {
  280.                 hate = 1000;
  281.             }
  282.             ((L2Attackable) npc).addDamageHate(caster, 0, hate);
  283.         }
  284.         return super.onSkillSee(npc, caster, skill, targets, isPet);
  285.     }
  286.  
  287.     @Override
  288.     public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  289.     {
  290.         InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  291.         if (tmpworld instanceof DHSWorld)
  292.         {
  293.             DHSWorld world = (DHSWorld) tmpworld;
  294.             if (world.getStatus() < 1)
  295.             {
  296.                 if (checkKillProgress(npc, world))
  297.                 {
  298.                     runTumors(world);
  299.                 }
  300.             }
  301.             else if (world.getStatus() == 1)
  302.             {
  303.                 if (checkKillProgress(npc, world))
  304.                 {
  305.                     runTwins(world);
  306.                 }
  307.             }
  308.             else if ((world.getStatus() == 2) && ((npc.getId() == ICE_QUEEN_EASY)))
  309.             {
  310.                 if (world.QUEEN.isDead())
  311.                 {
  312.                     world.setStatus(world.getStatus() + 1);
  313.                     // instance end
  314.                     world.storeTime[1] = System.currentTimeMillis();
  315.                     world.QUEEN = null;
  316.                     // player.sendMessageS(player.getName() + " complete instance Cave of Queen !!", 5);
  317.                     addSpawn(ENDING_NPC, ENDING_NPC_SPAWN[0], ENDING_NPC_SPAWN[1], ENDING_NPC_SPAWN[2], 0, false, 0, false, world.getInstanceId());
  318.  
  319.                     for (Integer pc : world.getAllowed())
  320.                     {
  321.                         L2PcInstance killer = L2World.getInstance().getPlayer(pc);
  322.                         if (killer != null)
  323.                         {
  324.                             killer.sendPacket(new ExSendUIEvent(killer, true, true, 0, 0, ""));
  325.                         }
  326.                     }
  327.  
  328.                     Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  329.                     inst.setDuration(3 * 60000);
  330.                     inst.setEmptyDestroyTime(0);
  331.                 }
  332.             }
  333.         }
  334.         return "";
  335.     }
  336.  
  337.     @Override
  338.     public String onTalk(L2Npc npc, L2PcInstance player)
  339.     {
  340.         String htmltext = getNoQuestMsg(player);
  341.         final QuestState st = getQuestState(player, true);
  342.         if (st == null)
  343.         {
  344.             return htmltext;
  345.         }
  346.  
  347.         int npcId = npc.getId();
  348.  
  349.         if (npcId == ENTRANCE_NPC)
  350.         {
  351.             teleCoord tele = new teleCoord();
  352.             tele.x = -111833;
  353.             tele.y = 87179;
  354.             tele.z = -12975;
  355.             enterInstance(player, "IceQueenEasyInstance.xml", tele, npc);
  356.             return "";
  357.         }
  358.  
  359.         else if (npcId == ENDING_NPC)
  360.         {
  361.             InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  362.             Long finishDiff = ((DHSWorld) world).storeTime[1] - ((DHSWorld) world).storeTime[0];
  363.  
  364.             if (finishDiff < 900000)
  365.             {
  366.                 player.getStat().addLevel((byte) 5);
  367.                 st.giveItems(REWARD_STONE, 1);
  368.                 st.giveItems(17700, 1);
  369.             }
  370.  
  371.             world.removeAllowed(player.getObjectId());
  372.             teleCoord tele = new teleCoord();
  373.             tele.instanceId = 0;
  374.             tele.x = 82497;
  375.             tele.y = 148597;
  376.             tele.z = -3469;
  377.             exitInstance(player, tele);
  378.             return "";
  379.         }
  380.         return null;
  381.     }
  382. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement