Gladicek

Freya Extreme

Dec 1st, 2012
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 37.95 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package instances.Freya;
  16.  
  17. import java.util.Calendar;
  18. import java.util.List;
  19. import java.util.concurrent.locks.Lock;
  20. import java.util.concurrent.locks.ReentrantLock;
  21. import java.util.logging.Level;
  22.  
  23. import javolution.util.FastList;
  24.  
  25. import com.l2jserver.gameserver.ai.CtrlIntention;
  26. import com.l2jserver.gameserver.model.holders.SkillHolder;
  27. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  28. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  29. import com.l2jserver.gameserver.model.L2CharPosition;
  30. import com.l2jserver.gameserver.model.L2CommandChannel;
  31. import com.l2jserver.gameserver.model.L2Party;
  32. import com.l2jserver.gameserver.model.L2Spawn;
  33. import com.l2jserver.gameserver.model.L2World;
  34. import com.l2jserver.gameserver.model.Location;
  35. import com.l2jserver.gameserver.model.actor.L2Attackable;
  36. import com.l2jserver.gameserver.model.actor.L2Npc;
  37. import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  39. import com.l2jserver.gameserver.model.entity.Instance;
  40. import com.l2jserver.gameserver.model.quest.Quest;
  41. import com.l2jserver.gameserver.model.quest.QuestState;
  42. import com.l2jserver.gameserver.model.quest.State;
  43. import com.l2jserver.gameserver.network.NpcStringId;
  44. import com.l2jserver.gameserver.network.SystemMessageId;
  45. import com.l2jserver.gameserver.network.clientpackets.Say2;
  46. import com.l2jserver.gameserver.network.serverpackets.ExChangeAreaState;
  47. import com.l2jserver.gameserver.network.serverpackets.ExSendUIEvent;
  48. import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  49. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  50. import com.l2jserver.gameserver.network.serverpackets.OnEventTrigger;
  51. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  52. import com.l2jserver.gameserver.taskmanager.DecayTaskManager;
  53. import com.l2jserver.gameserver.util.Broadcast;
  54. import com.l2jserver.gameserver.util.Util;
  55. import com.l2jserver.util.Rnd;
  56.  
  57. /**
  58.  ** @author Gnacik, Gladicek
  59.  *  TODO: Glaciers, Ice Queen Castle room animation (we currently have only "blizzard" effect)
  60.  */
  61.  
  62. public class FreyaExtreme extends Quest
  63. {
  64.     // Debug
  65.     private static final boolean DEBUG = false;
  66.    
  67.     // Instance template ID
  68.     private static final int[] TEMPLATE_ID =
  69.     {
  70.         144
  71.     };
  72.    
  73.     // Instance limits
  74.     private static final int MIN_PLAYERS = 9;
  75.     private static final int MAX_PLAYERS = 27;
  76.     private static final int MIN_LEVEL = 82;
  77.    
  78.     // NPC's
  79.     private static final int JINIA = 32781; // ENTER
  80.     private static final int SIRRA = 32762; // DOOR OPENER
  81.     private static final int KEGOR_EXIT = 49303; // EXIT
  82.    
  83.     // Skills
  84.     private static SkillHolder JINIA_PRAYER = new SkillHolder(6288, 1);
  85.     private static SkillHolder KEGOR_COURAGE = new SkillHolder(6289, 1);
  86.     private static SkillHolder ETERNAL_BLIZZARD1 = new SkillHolder(6274, 1);
  87.     // private static SkillHolder ETERNAL_BLIZZARD2 = new SkillHolder(6275, 1);
  88.     // Epic one with client animation
  89.     private static SkillHolder ETERNAL_BLIZZARD3 = new SkillHolder(6276, 1);
  90.    
  91.     // Glakias Timer
  92.     private static final long TIME_FOR_KILL_GLAKIAS = 260000;
  93.     private static final long FIRST_TIMER_GLAKIAS = 360000;
  94.     private static final long SECOND_TIMER_GLAKIAS = 260000;
  95.    
  96.     // Monsters
  97.     private static final int[] MOBS =
  98.     {
  99.         29177,
  100.         29178,
  101.         29179,
  102.         29180,
  103.         18854,
  104.         18855,
  105.         18856,
  106.         25699,
  107.         25700
  108.     };
  109.     // Doors for Room Animation
  110.     private static int[] emmiters =
  111.     {
  112.         23140202,
  113.         23140204,
  114.         23140206,
  115.         23140208,
  116.         23140212,
  117.         23140214,
  118.         23140216
  119.     };
  120.    
  121.     // Room Animation
  122.     private static int decoration = 0;
  123.    
  124.     // Teleport Coord
  125.     private static final Location TELE_EXIT = new Location(115717, -125734, -3392);
  126.     private static final Location TELE_IN_BATLE = new Location(114694, -113700, -11200);
  127.     private static final Location[] TELE_ENTER =
  128.     {
  129.         new Location(114185, -112435, -11210),
  130.         new Location(114183, -112280, -11210),
  131.         new Location(114024, -112435, -11210),
  132.         new Location(114024, -112278, -11210),
  133.         new Location(113865, -112435, -11210),
  134.         new Location(113865, -112276, -11210)
  135.     };
  136.    
  137.     // Timers
  138.     private static final int TIMER_FIRST_MOVIE = 60000;
  139.     private static final int TIMER_GLAKIAS = 100000;
  140.     private static final int TIMER_BREATHS = 30000;
  141.     // Movies
  142.     private static final int MOVIE_START = 15;
  143.     private static final int MOVIE_SECOND = 16;
  144.     private static final int MOVIE_FREYA = 17;
  145.     private static final int MOVIE_KEGOR = 18;
  146.     private static final int MOVIE_DEATH = 19;
  147.     private static final int MOVIE_FINAL = 20;
  148.     private static final int MOVIE_GLAKIAS = 23;
  149.    
  150.     // Spawns
  151.     private static final Location[] MONUMENTS =
  152.     {
  153.         new Location(113845, -116091, -11168, 8264),
  154.         new Location(113381, -115622, -11168, 8264),
  155.         new Location(113380, -113978, -11168, -8224),
  156.         new Location(113845, -113518, -11168, -8224),
  157.         new Location(115591, -113516, -11168, -24504),
  158.         new Location(116053, -113981, -11168, -24504),
  159.         new Location(116061, -115611, -11168, 24804),
  160.         new Location(115597, -116080, -11168, 24804),
  161.         new Location(112942, -115480, -10960, 52),
  162.         new Location(112940, -115146, -10960, 52),
  163.         new Location(112945, -114453, -10960, 52),
  164.         new Location(112945, -114123, -10960, 52),
  165.         new Location(116497, -114117, -10960, 32724),
  166.         new Location(116499, -114454, -10960, 32724),
  167.         new Location(116501, -115145, -10960, 32724),
  168.         new Location(116502, -115473, -10960, 32724)
  169.     };
  170.    
  171.     private static final Location[] SPAWNS =
  172.     {
  173.         new Location(114713, -115109, -11202, 16456),
  174.         new Location(114008, -115080, -11202, 3568),
  175.         new Location(114422, -115508, -11202, 12400),
  176.         new Location(115023, -115508, -11202, 20016),
  177.         new Location(115459, -115079, -11202, 27936)
  178.     };
  179.    
  180.     private class FreyaWorld extends InstanceWorld
  181.     {
  182.         public Lock lock = new ReentrantLock();
  183.         public List<L2PcInstance> PlayersInInstance = new FastList<>();
  184.         public boolean showed = false;
  185.         public boolean screen_message = false;
  186.         public boolean screen_message2 = false;
  187.         public boolean screen_message3 = false;
  188.        
  189.         int id_freya_first;
  190.         int id_freya_second;
  191.         int id_freya_last;
  192.         int id_glakias;
  193.         int id_ice_knight;
  194.         int id_arch_breath;
  195.         int id_kegor;
  196.         int id_jinia;
  197.         FastList<L2Npc> allmobs = null;
  198.         FastList<L2Npc> monuments = null;
  199.         L2Npc freya;
  200.         L2Npc kegor;
  201.         L2Npc jinia;
  202.         L2Npc kegor_exit;
  203.         L2Npc freya_exit;
  204.        
  205.         public FreyaWorld()
  206.         {
  207.             allmobs = new FastList<>();
  208.             monuments = new FastList<>();
  209.             id_freya_first = 0;
  210.             id_freya_second = 0;
  211.             id_freya_last = 0;
  212.             id_glakias = 0;
  213.             id_ice_knight = 0;
  214.             id_arch_breath = 0;
  215.             id_kegor = 0;
  216.             id_jinia = 0;
  217.         }
  218.     }
  219.    
  220.     @Override
  221.     public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  222.     {
  223.        
  224.         if (DEBUG)
  225.             _log.info(getName() + "onAdvEvent=" + event);
  226.        
  227.         InstanceWorld wrld = null;
  228.         if (npc != null)
  229.             wrld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  230.         else if (player != null)
  231.             wrld = InstanceManager.getInstance().getPlayerWorld(player);
  232.         else
  233.         {
  234.             _log.warning("Freya: onAdvEvent : Unable to get world.");
  235.             return null;
  236.         }
  237.        
  238.         if (wrld != null && wrld instanceof FreyaWorld)
  239.         {
  240.             FreyaWorld world = (FreyaWorld) wrld;
  241.            
  242.             if (event.equalsIgnoreCase("opendoor") && world.status == 0)
  243.             {
  244.                 // Set status
  245.                 world.status = 1;
  246.                 // Open Door
  247.                 InstanceManager.getInstance().getInstance(world.instanceId).getDoor(23140101).openMe();
  248.                 // Schedule Movie
  249.                 startQuestTimer("stage_1_movie", TIMER_FIRST_MOVIE, npc, null);
  250.                 // If you are using GMChar to test, you can skip parts here and schedule
  251.                 // some next timer not stage_1_movie
  252.                 // startQuestTimer("stage_3_begin", TIMER_FIRST_MOVIE, npc, null);
  253.             }
  254.             else if (event.equalsIgnoreCase("teletofreya"))
  255.             {
  256.                 teleportPlayer(player, TELE_IN_BATLE, world.instanceId);
  257.             }
  258.             else if (event.equalsIgnoreCase("exit"))
  259.             {
  260.                 teleportPlayer(player, TELE_EXIT, 0);
  261.             }
  262.             else if (event.equalsIgnoreCase("knight_pillar") && npc != null)
  263.             {
  264.                 npc.setDisplayEffect(1);
  265.             }
  266.             else if (event.equalsIgnoreCase("random_first_attack") && npc != null)
  267.             {
  268.                 if (!world.monuments.isEmpty())
  269.                 {
  270.                     if (world.status < 6 && world.monuments.contains(npc))
  271.                         return null;
  272.                    
  273.                     if (world.status == 6 && world.monuments.contains(npc))
  274.                         npc.setDisplayEffect(2);
  275.                    
  276.                     int playerId = world.allowed.get(Rnd.get(world.allowed.size()));
  277.                     L2PcInstance victim = L2World.getInstance().getPlayer(playerId);
  278.                     if (victim != null && victim.isOnline() && victim.getInstanceId() == world.instanceId && (!(victim.isDead() || victim.isGM() || victim.isInvul() || victim.getAppearance().getInvisible())) && !npc.isDead() && !npc.isImmobilized() && npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE)
  279.                     {
  280.                         ((L2Attackable) npc).addDamageHate(victim, 0, 99);
  281.                         npc.setIsRunning(true);
  282.                         npc.setTarget(victim);
  283.                         npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, victim, null);
  284.                     }
  285.                     else
  286.                         startQuestTimer("random_first_attack", Rnd.get(1000, 2000), npc, null);
  287.                 }
  288.                 else
  289.                 {
  290.                     // Monuments are always in battle time
  291.                     // If world.monuments is empty just delete npc, should not be happend
  292.                     if (npc.getNpcId() == world.id_glakias || npc.getNpcId() == world.id_arch_breath)
  293.                         npc.deleteMe();
  294.                 }
  295.             }
  296.             else if (event.equalsIgnoreCase("stage_1_movie"))
  297.             {
  298.                 // Stop players before movie
  299.                 stopPc(world);
  300.                 // Show movie
  301.                 showMovie(world, MOVIE_START);
  302.                 // Close Door
  303.                 InstanceManager.getInstance().getInstance(world.instanceId).getDoor(23140101).closeMe();
  304.                 startQuestTimer("stage_1_begin", 53500 + 1000, npc, null);
  305.             }
  306.             else if (event.equalsIgnoreCase("stage_1_begin"))
  307.             {
  308.                 // Set status
  309.                 world.status = 2;
  310.                 // Spawn monuments
  311.                 spawnMonuments(world);
  312.                 // Spawn boos
  313.                 world.freya = addSpawn(world.id_freya_first, 114720, -117085, -11088, 15956, false, 0, true, world.instanceId);
  314.                 // Begin stage 1
  315.                 ExShowScreenMessage message1 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_1, 2, 7000);
  316.                 sendScreenMessage(world, message1);
  317.                 // Move freya
  318.                 startQuestTimer("freya_move", 2000, world.freya, null, false);
  319.                 // start ai for cast skill
  320.                 startQuestTimer("cast_skill", 15000, world.freya, null, false);
  321.             }
  322.             else if (event.equalsIgnoreCase("freya_move"))
  323.             {
  324.                 ExShowScreenMessage message2 = new ExShowScreenMessage(NpcStringId.FREYA_HAS_STARTED_TO_MOVE, 2, 5000);
  325.                 sendScreenMessage(world, message2);
  326.                 // Initialize movement
  327.                 world.freya.setIsRunning(true);
  328.                 world.freya.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(114717, -114973, -11200, 0));
  329.                 world.freya.getSpawn().setLocx(114717);
  330.                 world.freya.getSpawn().setLocy(-114973);
  331.                 world.freya.getSpawn().setLocz(-11200);
  332.                 // Spawn Knights
  333.                 spawnMobs(world, world.id_ice_knight);
  334.             }
  335.             else if (event.equalsIgnoreCase("cast_skill"))
  336.             {
  337.                 ExShowScreenMessage message3 = new ExShowScreenMessage(NpcStringId.STRONG_MAGIC_POWER_CAN_BE_FELT_FROM_SOMEWHERE, 2, 4000);
  338.                 sendScreenMessage(world, message3);
  339.                 world.freya.doCast(ETERNAL_BLIZZARD1.getSkill());
  340.                 startQuestTimer("cast_skill", 60000, world.freya, null, false);
  341.             }
  342.             else if (event.equalsIgnoreCase("cast_skill_3stage"))
  343.             {
  344.                 ExShowScreenMessage message4 = new ExShowScreenMessage(NpcStringId.STRONG_MAGIC_POWER_CAN_BE_FELT_FROM_SOMEWHERE, 2, 4000);
  345.                 sendScreenMessage(world, message4);
  346.                 world.freya.doCast(ETERNAL_BLIZZARD3.getSkill());
  347.                 startQuestTimer("cast_skill_3stage", 60000, world.freya, null, false);
  348.             }
  349.             else if (event.equalsIgnoreCase("stage_1_final_movie"))
  350.             {
  351.                 cancelQuestTimer("cast_skill", npc, null);
  352.                 // Delete freya
  353.                 world.freya.deleteMe();
  354.                 // Despawn mobs
  355.                 despawnAll(world);
  356.                 // Stop players before movie
  357.                 stopPc(world);
  358.                 // Show movie
  359.                 showMovie(world, MOVIE_SECOND);
  360.                 startQuestTimer("stage_1_pause", 21100 + 1000, npc, null);
  361.             }
  362.             else if (event.equalsIgnoreCase("stage_1_pause"))
  363.             {
  364.                 // Spawn boss upstairs
  365.                 L2Npc freya = addSpawn(world.id_freya_second, 114723, -117502, -10672, 15956, false, 0, true, world.instanceId);
  366.                 freya.setIsImmobilized(true);
  367.                 freya.setIsInvul(true);
  368.                 freya.disableCoreAI(true);
  369.                 freya.disableAllSkills();
  370.                 world.freya = freya;
  371.                 // Set world status
  372.                 world.status = 4;
  373.                 // Despawn monuments
  374.                 despawnMonuments(world);
  375.                 // 1 min pause for rebuff
  376.                 showTimer(world, false);
  377.                 // Start Stage 2
  378.                 startQuestTimer("stage_2_begin", 60000, npc, null);
  379.             }
  380.             else if (event.equalsIgnoreCase("stage_2_begin"))
  381.             {
  382.                 // Set world status
  383.                 world.status = 5;
  384.                 // Begin stage 2
  385.                 ExShowScreenMessage message5 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_2, 2, 7000);
  386.                 sendScreenMessage(world, message5);
  387.                 // Spawn monuments
  388.                 spawnMonuments(world);
  389.                 // Spawn Knights
  390.                 spawnMobs(world, world.id_ice_knight);
  391.                 // 4 min to Glakias spawn
  392.                 startQuestTimer("stage_2_glakias_movie", TIMER_GLAKIAS, npc, null);
  393.                 // 2 min to Breaths spawn
  394.                 startQuestTimer("stage_2_breaths", TIMER_BREATHS, npc, null);
  395.             }
  396.             else if (event.equalsIgnoreCase("stage_2_breaths"))
  397.             {
  398.                 // Disable new spawns for knights
  399.                 for (L2Npc knight : world.allmobs)
  400.                     knight.getSpawn().stopRespawn();
  401.                 // Spawn Breaths
  402.                 spawnMobs(world, world.id_arch_breath);
  403.             }
  404.             else if (event.equalsIgnoreCase("stage_2_glakias_movie"))
  405.             {
  406.                 showMovie(world, MOVIE_GLAKIAS);
  407.                 showTimerGlakias(world, ((int)FIRST_TIMER_GLAKIAS / 1000), NpcStringId.BATTLE_END_LIMIT_TIME, false);
  408.                 startQuestTimer("stage_2_glakias_spawn", 7000 + 1000, npc, null);
  409.             }
  410.             else if (event.equalsIgnoreCase("stage_2_glakias_spawn"))
  411.             {
  412.                 showTimerGlakias(world, ((int)SECOND_TIMER_GLAKIAS / 1000), NpcStringId.BATTLE_END_LIMIT_TIME, false);
  413.                 addSpawn(world.id_glakias, 114707, -114799, -11199, 15956, false, 0, true, world.instanceId);
  414.                 // Timer for 2 stage, if player not kill Glakias - instance destroyed
  415.                 startQuestTimer("time_for_kill_glakias", TIME_FOR_KILL_GLAKIAS, npc, null);
  416.             }
  417.             else if (event.equalsIgnoreCase("stage_2_pause"))
  418.             {
  419.                 // Despawn mobs
  420.                 despawnAll(world);
  421.                 // Despawn monuments
  422.                 despawnMonuments(world);
  423.                 // 1 min pause for rebuff
  424.                 showTimer(world, false);
  425.                 // Start Stage 3
  426.                 startQuestTimer("stage_3_movie", 60000, npc, null);
  427.             }
  428.             else if (event.equalsIgnoreCase("time_for_kill_glakias"))
  429.             {
  430.                 InstanceManager.getInstance().destroyInstance(world.instanceId);
  431.             }
  432.             else if (event.equalsIgnoreCase("stage_3_movie"))
  433.             {
  434.                 // Delete freya
  435.                 world.freya.deleteMe();
  436.                 // Show movie
  437.                 showMovie(world, MOVIE_FREYA);
  438.                 // Begin Stage 3
  439.                 startQuestTimer("stage_3_begin", 21500 + 1000, npc, null);
  440.             }
  441.             else if (event.equalsIgnoreCase("stage_3_begin"))
  442.             {
  443.                 // Turn on room animation
  444.                 ExChangeAreaState as = new ExChangeAreaState(decoration, 2);
  445.                 Broadcast.toPlayersInInstance(as, world.instanceId);
  446.                 for (int emitter : emmiters)
  447.                 {
  448.                     OnEventTrigger et = new OnEventTrigger(emitter, false);
  449.                     Broadcast.toPlayersInInstance(et, world.instanceId);
  450.                 }  
  451.                 // Spawn monuments
  452.                 spawnMonuments(world);
  453.                 // Spawn Freya
  454.                 world.freya = addSpawn(world.id_freya_last, 114720, -117085, -11088, 15956, false, 0, true, world.instanceId);
  455.                 // Begin stage 2
  456.                 ExShowScreenMessage message6 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_3, 2, 7000);
  457.                 sendScreenMessage(world, message6);
  458.                 // Spawn Knights
  459.                 spawnMobs(world, world.id_arch_breath);
  460.                 // Add monument timers
  461.                 startQuestTimer("stage_3_monuments", 60000, npc, null);
  462.                 // start ai for cast skill
  463.                 startQuestTimer("cast_skill_3stage", 15000, world.freya, null, false);
  464.             }
  465.             else if (event.equalsIgnoreCase("stage_3_monuments"))
  466.             {
  467.                 // Set status
  468.                 world.status = 6;
  469.                 // Monuments start move
  470.                 for (L2Npc monument : world.monuments)
  471.                 {
  472.                     monument.getSpawn().stopRespawn();
  473.                     monument.setIsImmobilized(false);
  474.                     monument.setIsInvul(false);
  475.                     monument.enableAllSkills();
  476.                     monument.disableCoreAI(false);
  477.                     startQuestTimer("random_first_attack", Rnd.get(1000, 10000), monument, null);
  478.                 }
  479.             }
  480.             else if (event.equalsIgnoreCase("finish_world"))
  481.             {
  482.                 cancelQuestTimer("player_buff", npc, null);
  483.                 cancelQuestTimer("cast_skill_3stage", npc, null);
  484.                 cancelQuestTimer("check_for_enemies", npc, null);
  485.                 // Despawn mobs
  486.                 despawnAll(world);
  487.                 // Despawn monuments
  488.                 despawnMonuments(world);
  489.                 // Begin Movie 2
  490.                 startQuestTimer("finish_world2", 100, npc, null);
  491.             }
  492.             else if (event.equalsIgnoreCase("buff_support"))
  493.             {
  494.                 startWorld(world);
  495.                 startQuestTimer("cast_skill_3stage", 15000, npc, null);
  496.                 ExShowScreenMessage message7 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_4, 2, 7000);
  497.                 sendScreenMessage(world, message7);
  498.                 world.kegor = addSpawn(world.id_kegor, 114659, -114796, -11205, 0, false, 0, true, world.instanceId);
  499.                 world.jinia = addSpawn(world.id_jinia, 114751, -114781, -11205, 0, false, 0, true, world.instanceId);
  500.                 world.kegor.setIsInvul(true);
  501.                 world.kegor.setIsRunning(true);
  502.                 world.jinia.setIsInvul(true);
  503.                 world.jinia.setIsRunning(true);
  504.                 startQuestTimer("player_buff", 3000, npc, null);
  505.                 startQuestTimer("check_for_enemies", 5000, npc, null);
  506.             }
  507.             else if (event.equalsIgnoreCase("player_buff"))
  508.             {
  509.                 world.kegor.doCast(KEGOR_COURAGE.getSkill());
  510.                 world.jinia.doCast(JINIA_PRAYER.getSkill());
  511.                 startQuestTimer("player_buff", 30000, npc, null);
  512.             }
  513.             else if (event.equalsIgnoreCase("finish_world2"))
  514.             {
  515.                 world.kegor.deleteMe();
  516.                 world.jinia.deleteMe();
  517.                 despawnAll(world);
  518.                 // Show movie 2
  519.                 showMovie(world, MOVIE_DEATH);
  520.                 // Spawn exit NPC + Freya (dying)
  521.                 startQuestTimer("spawn_exit", 500, npc, null);
  522.                 // Set 5 min time
  523.                 Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
  524.                 if (inst != null)
  525.                     inst.setDuration(300000);
  526.             }
  527.             else if (event.equalsIgnoreCase("finish_world3"))
  528.             {
  529.                 // Show movie 3
  530.                 showMovie(world, MOVIE_FINAL);
  531.                 questSupport2(npc, player);
  532.                 world.kegor_exit.deleteMe();
  533.                 world.freya_exit.deleteMe();
  534.                
  535.             }
  536.             else if (event.equalsIgnoreCase("spawn_exit"))
  537.             {
  538.                 world.kegor_exit = addSpawn(KEGOR_EXIT, 114659, -114796, -11205, 0, false, 0, true, world.instanceId);
  539.                 world.freya_exit = addSpawn(world.id_freya_last, 114785, -114789, -11206, 0, false, 0, true, world.instanceId);
  540.                 world.freya_exit.setIsImmobilized(true);
  541.                 world.freya_exit.setIsInvul(true);
  542.                 world.freya_exit.doDie(world.freya_exit);
  543.                 DecayTaskManager.getInstance().cancelDecayTask(world.freya_exit);
  544.                 world.freya_exit.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  545.                 world.freya_exit.disableCoreAI(true);
  546.                 world.freya_exit.disableAllSkills();
  547.             }
  548.             else if (event.equalsIgnoreCase("check_for_enemies"))
  549.             {
  550.                 {
  551.                     ((L2GuardInstance) world.kegor).addDamageHate(world.freya, 0, 10000);
  552.                     ((L2GuardInstance) world.kegor).getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, world.freya, null);
  553.                     ((L2GuardInstance) world.jinia).addDamageHate(world.freya, 0, 10000);
  554.                     ((L2GuardInstance) world.jinia).getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, world.freya, null);
  555.                 }
  556.                
  557.                 startQuestTimer("check_for_enemies", 5000, npc, null);
  558.             }          
  559.         }      
  560.         else if (npc != null  && npc.getNpcId() == JINIA && Util.isDigit(event) && Util.contains(TEMPLATE_ID, Integer.valueOf(event)))
  561.         {
  562.             try
  563.             {
  564.                 enterInstance(player, Integer.valueOf(event));
  565.             }
  566.             catch (Exception e)
  567.             {
  568.                 _log.log(Level.WARNING, e.getMessage(), e);
  569.             }
  570.             return null;
  571.         }
  572.         return null;
  573.     }
  574.    
  575.     private void sendScreenMessage(FreyaWorld world, ExShowScreenMessage message)
  576.     {
  577.         for (int objId : world.allowed)
  578.         {
  579.             L2PcInstance player = L2World.getInstance().getPlayer(objId);
  580.             if (player != null)
  581.                 player.sendPacket(message);
  582.         }
  583.     }
  584.    
  585.     @Override
  586.     public final String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  587.     {
  588.         if (npc == null || attacker == null)
  589.             return null;
  590.        
  591.         final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  592.         if (tmpWorld instanceof FreyaWorld)
  593.         {
  594.             final FreyaWorld world = (FreyaWorld) tmpWorld;
  595.             // First freya
  596.             if (world.status == 2 && npc.getNpcId() == world.id_freya_first)
  597.             {
  598.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.1))
  599.                 {
  600.                     if (world.lock.tryLock())
  601.                     {
  602.                         try
  603.                         {
  604.                             world.status = 3;
  605.                             startQuestTimer("stage_1_final_movie", 1000, npc, attacker);
  606.                         }
  607.                         finally
  608.                         {
  609.                             world.lock.unlock();
  610.                         }
  611.                     }
  612.                 }
  613.             }
  614.             else if (npc.getNpcId() == world.id_ice_knight && npc.getDisplayEffect() == 1)
  615.             {
  616.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.3))
  617.                     npc.setDisplayEffect(2);
  618.             }
  619.             else if (npc.getNpcId() == world.id_freya_last)
  620.             {
  621.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.25) && !world.showed)
  622.                 {
  623.                     world.showed = true;
  624.                     stopWorld(world);
  625.                     // Show Movie 4
  626.                     showMovie(world, MOVIE_KEGOR);
  627.                     startQuestTimer("buff_support", 27000 + 200, npc, null);
  628.                     cancelQuestTimer("cast_skill_3stage", npc, null);
  629.                 }
  630.             }
  631.             else if (npc.getNpcId() == world.id_glakias)
  632.             {
  633.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.2) && !world.screen_message)
  634.                 {
  635.                     world.screen_message = true;
  636.                     npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.I_CAN_TAKE_IT_NO_LONGER));
  637.                 }
  638.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.4) && !world.screen_message)
  639.                 {
  640.                     world.screen_message = true;
  641.                     npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.ARCHER_HEED_MY_CALL));
  642.                 }
  643.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.6) && !world.screen_message2)
  644.                 {
  645.                     world.screen_message2 = true;
  646.                     ExShowScreenMessage message8 = new ExShowScreenMessage(NpcStringId.THE_SPACE_FEELS_LIKE_ITS_GRADUALLY_STARTING_TO_SHAKE, 2, 7000);
  647.                     sendScreenMessage(world, message8);
  648.                     npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.MY_KNIGHTS_SHOW_YOUR_LOYALTY));
  649.                 }
  650.                 if (npc.getCurrentHp() < (npc.getMaxHp() * 0.8) && !world.screen_message3)
  651.                 {
  652.                     world.screen_message3 = true;
  653.                     npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.ARCHER_GIVE_YOUR_BREATH_FOR_THE_INTRUDER));
  654.                 }
  655.             }
  656.         }
  657.         return super.onAttack(npc, attacker, damage, isPet);
  658.     }
  659.  
  660.     @Override
  661.     public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  662.     {
  663.         if (DEBUG)
  664.             _log.info("onKill [" + npc.getNpcId() + "]" + npc.getName());
  665.        
  666.         InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  667.         if (tmpworld instanceof FreyaWorld)
  668.         {
  669.             FreyaWorld world = (FreyaWorld) tmpworld;
  670.             // Delete corpse, because doesn't look good
  671.             npc.deleteMe();
  672.            
  673.             if (npc.getNpcId() == world.id_ice_knight)
  674.             {
  675.                 // Start timer to change effectId
  676.                 startQuestTimer("knight_pillar", 5000, npc, null);
  677.             }
  678.             else if (npc.getNpcId() == world.id_glakias)
  679.             {
  680.                 // Run Pause before stage 3
  681.                 cancelQuestTimer("time_for_kill_glakias", npc, null);
  682.                 startQuestTimer("stage_2_pause", 500, npc, null);
  683.                 showTimer(world, false);
  684.             }
  685.             else if (npc.getNpcId() == world.id_freya_last)
  686.             {
  687.                 // Finish Instance
  688.                 startQuestTimer("finish_world", 500, npc, null);
  689.                 for (L2PcInstance p : world.PlayersInInstance)
  690.                 {
  691.                     if (p != null)
  692.                     {
  693.                         savePlayerReenter(p);
  694.                         if (DEBUG)
  695.                             _log.info("Save reenter for " + p.getName() + ".");
  696.                     }
  697.                 }
  698.             }
  699.             else if ((npc.getNpcId() == 29179 || npc.getNpcId() == 29180) && killer.isInParty())
  700.             {
  701.                
  702.                 if (killer.getParty().getCommandChannel() != null)
  703.                 {
  704.                     for (L2PcInstance ccm : killer.getParty().getCommandChannel().getMembers())
  705.                     {
  706.                         questSupport(npc, ccm);
  707.                     }
  708.                 }
  709.             }
  710.         }
  711.         return super.onKill(npc, killer, isPet);
  712.     }
  713.    
  714.     private void questSupport(L2Npc npc, L2PcInstance player)
  715.     {
  716.         if (player.isInsideRadius(npc, 2000, false, false))
  717.         {
  718.             final int _fragment = 21723;
  719.             final QuestState st = player.getQuestState("Q10502_FreyaEmbroideredSoulCloak");
  720.             if (st != null && st.getState() == State.STARTED && st.getInt("cond") == 1)
  721.             {
  722.                 if (player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").getQuestItemsCount(_fragment) < 19)
  723.                 {
  724.                     player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").giveItems(_fragment, Rnd.get(1, 2));
  725.                     st.playSound("ItemSound.quest_middle");
  726.                 }
  727.                 else
  728.                 {
  729.                     player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").giveItems(_fragment, 1);
  730.                 }
  731.                 if (player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").getQuestItemsCount(_fragment) >= 20)
  732.                 {
  733.                     player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").set("cond", "2");
  734.                 }
  735.             }
  736.         }
  737.     }
  738.    
  739.     private void questSupport2(L2Npc npc, L2PcInstance player)
  740.     {
  741.         if (player.isInsideRadius(npc, 2000, false, false))
  742.         {
  743.             final QuestState st = player.getQuestState("10286_ReunionWithSirra");
  744.             if (st != null && st.getState() == State.STARTED && st.getInt("cond") == 6)
  745.             {
  746.                 st.playSound("ItemSound.quest_middle");
  747.                 player.getQuestState("10286_ReunionWithSirra").set("cond", "7");
  748.             }
  749.         }
  750.     }
  751.    
  752.     @Override
  753.     public String onSpawn(L2Npc npc)
  754.     {
  755.         if (DEBUG)
  756.             _log.info("OnSpawn");
  757.        
  758.         final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  759.         if (tmpWorld instanceof FreyaWorld)
  760.         {
  761.             startQuestTimer("random_first_attack", 4000, npc, null);
  762.         }
  763.        
  764.         return null;
  765.     }
  766.    
  767.     private final synchronized void enterInstance(L2PcInstance player, int template_id)
  768.     {
  769.         // Check for existing instances for this player
  770.         InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  771.         // Player already in the instance
  772.         if (world != null)
  773.         {
  774.             // but not in our instance
  775.             if (!(world instanceof FreyaWorld))
  776.             {
  777.                 player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  778.                 return;
  779.             }
  780.             // Check if instance still exist, if yes - teleport player
  781.             Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
  782.             if (inst != null)
  783.                 teleportPlayer(player, TELE_ENTER[Rnd.get(TELE_ENTER.length)], world.instanceId);
  784.            
  785.             return;
  786.         }
  787.         {
  788.             // Check
  789.             if (!checkConditions(player))
  790.                 return;
  791.            
  792.             final int instanceId = InstanceManager.getInstance().createDynamicInstance("Freya.xml");
  793.            
  794.             world = new FreyaWorld();
  795.             world.instanceId = instanceId;
  796.             world.templateId = template_id;
  797.             world.status = 0;
  798.            
  799.             InstanceManager.getInstance().addWorld(world);
  800.            
  801.             setupIDs((FreyaWorld) world, template_id);
  802.            
  803.             // And finally teleport party into instance
  804.             if (player.getParty() == null)
  805.             {
  806.                 // Remove buffs, set reenter
  807.                 setupPlayer((FreyaWorld) world, player, template_id);
  808.                 // Port player
  809.                 teleportPlayer(player, TELE_ENTER[Rnd.get(TELE_ENTER.length)], instanceId);
  810.                 return;
  811.             }
  812.             else if (player.getParty().getCommandChannel() == null)
  813.             {
  814.                 for (L2PcInstance partyMember : player.getParty().getMembers())
  815.                 {
  816.                     // Remove buffs, set reenter
  817.                     setupPlayer((FreyaWorld) world, partyMember, template_id);
  818.                     // Port player
  819.                     teleportPlayer(partyMember, TELE_ENTER[Rnd.get(TELE_ENTER.length)], instanceId);
  820.                 }
  821.             }
  822.             else
  823.             {
  824.                 for (L2PcInstance channelMember : player.getParty().getCommandChannel().getMembers())
  825.                 {
  826.                     // Remove buffs, set reenter
  827.                     setupPlayer((FreyaWorld) world, channelMember, template_id);
  828.                     // Port player
  829.                     teleportPlayer(channelMember, TELE_ENTER[Rnd.get(TELE_ENTER.length)], instanceId);
  830.                 }
  831.             }
  832.             _log.info("Freya[" + template_id + "] instance started: " + instanceId + " created by player: " + player.getName());
  833.             return;
  834.         }
  835.     }
  836.    
  837.     private void setupIDs(FreyaWorld world, int template_id)
  838.     {
  839.         {
  840.             world.id_freya_first = 29177;
  841.             world.id_freya_second = 29178;
  842.             world.id_freya_last = 29180;
  843.             world.id_glakias = 25700;
  844.             world.id_ice_knight = 18856;
  845.             world.id_arch_breath = 18854;
  846.         }
  847.     }
  848.    
  849.     private void despawnAll(FreyaWorld world)
  850.     {
  851.         for (L2Npc npc : world.allmobs)
  852.         {
  853.             npc.getSpawn().stopRespawn();
  854.             npc.deleteMe();
  855.         }
  856.        
  857.         world.allmobs.clear();
  858.     }
  859.    
  860.     private void spawnMonuments(FreyaWorld world)
  861.     {
  862.         if (DEBUG)
  863.             _log.info("spawnMonuments");
  864.        
  865.         for (Location loc : MONUMENTS)
  866.         {
  867.             L2Npc npc = addSpawn(world.id_ice_knight, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), false, 0, true, world.instanceId);
  868.             world.monuments.add(npc);
  869.             npc.disableCoreAI(true);
  870.             npc.setIsImmobilized(true);
  871.             npc.setIsInvul(true);
  872.             npc.disableAllSkills();
  873.             npc.setDisplayEffect(1);
  874.             npc.setEnchant(1);
  875.             L2Spawn spawn = npc.getSpawn();
  876.             spawn.getLastSpawn().setSpawn(spawn);
  877.             spawn.setRespawnDelay(20);
  878.             spawn.setAmount(1);
  879.             spawn.startRespawn();
  880.         }
  881.     }
  882.    
  883.     private void despawnMonuments(FreyaWorld world)
  884.     {
  885.         for (L2Npc npc : world.monuments)
  886.         {
  887.             npc.setDisplayEffect(2);
  888.             npc.getSpawn().stopRespawn();
  889.             npc.doDie(npc);
  890.         }
  891.         world.monuments.clear();
  892.     }
  893.    
  894.     private void spawnMobs(FreyaWorld world, int mobId)
  895.     {
  896.         if (DEBUG)
  897.             _log.info("spawnMobs");
  898.        
  899.         for (Location loc : SPAWNS)
  900.         {
  901.             L2Npc npc = addSpawn(mobId, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), false, 0, true, world.instanceId);
  902.             world.allmobs.add(npc);
  903.             npc.setDisplayEffect(1);
  904.             L2Spawn spawn = npc.getSpawn();
  905.             spawn.setRespawnDelay(20);
  906.             spawn.setAmount(1);
  907.             spawn.startRespawn();
  908.         }
  909.     }
  910.    
  911.     private static final void teleportPlayer(L2PcInstance player, Location loc, int instanceId)
  912.     {
  913.         player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  914.         player.setInstanceId(instanceId);
  915.         player.teleToLocation(loc, true);
  916.     }
  917.    
  918.     private void setupPlayer(FreyaWorld world, L2PcInstance player, int template_id)
  919.     {
  920.         // Remove buffs from player
  921.         // player.stopAllEffectsExceptThoseThatLastThroughDeath();
  922.         // Add player to allowed list
  923.         world.allowed.add(player.getObjectId());
  924.         world.PlayersInInstance.add(player);
  925.         if (player.getQuestState("10286_ReunionWithSirra") != null && player.getQuestState("10286_ReunionWithSirra").getState() == State.STARTED && player.getQuestState("10286_ReunionWithSirra").getInt("cond") == 5)
  926.         {
  927.             player.getQuestState("10286_ReunionWithSirra").set("cond", "6");
  928.         }
  929.     }
  930.    
  931.     private boolean checkConditions(L2PcInstance player)
  932.     {
  933.         if (player.isGM())
  934.             return true;
  935.        
  936.         L2Party party = player.getParty();
  937.         if (party == null)
  938.         {
  939.             player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
  940.             return false;
  941.         }
  942.         L2CommandChannel channel = player.getParty().getCommandChannel();
  943.         if (channel != null)
  944.         {
  945.             if (channel.getLeader() != player)
  946.             {
  947.                 player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
  948.                 return false;
  949.             }
  950.             else if (channel.getMemberCount() < MIN_PLAYERS || channel.getMemberCount() > MAX_PLAYERS)
  951.             {
  952.                 player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
  953.                 return false;
  954.             }
  955.             for (L2PcInstance ccMember : channel.getMembers())
  956.             {
  957.                 if (ccMember.getLevel() < MIN_LEVEL)
  958.                 {
  959.                     SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  960.                     sm.addPcName(ccMember);
  961.                     party.broadcastPacket(sm);
  962.                     return false;
  963.                 }
  964.                 if (!Util.checkIfInRange(1000, player, ccMember, true))
  965.                 {
  966.                     SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  967.                     sm.addPcName(ccMember);
  968.                     party.broadcastPacket(sm);
  969.                     return false;
  970.                 }
  971.                 for (int inst : TEMPLATE_ID)
  972.                 {
  973.                     long reentertime = InstanceManager.getInstance().getInstanceTime(ccMember.getObjectId(), inst);
  974.                     if (System.currentTimeMillis() < reentertime)
  975.                     {
  976.                         SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
  977.                         sm.addPcName(ccMember);
  978.                         party.broadcastPacket(sm);
  979.                         return false;
  980.                     }
  981.                 }
  982.                 QuestState st = ccMember.getQuestState("10286_ReunionWithSirra");
  983.                 if (!(st != null && (st.getState() == State.COMPLETED || st.getInt("cond") > 4)))
  984.                 {
  985.                     SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_QUEST_REQUIREMENT_NOT_SUFFICIENT);
  986.                     sm.addPcName(ccMember);
  987.                     party.broadcastPacket(sm);
  988.                     return false;
  989.                 }
  990.             }
  991.         }
  992.         return true;
  993.     }
  994.    
  995.     private void showTimer(FreyaWorld world, boolean hide)
  996.     {
  997.         for (int objId : world.allowed)
  998.         {
  999.             L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1000.             if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
  1001.                 player.sendPacket(new ExSendUIEvent(player, hide, false, 60, 0, "Time remaining until next battle"));
  1002.         }
  1003.     }
  1004.    
  1005.     private void showTimerGlakias(FreyaWorld world, int time, NpcStringId npcString, boolean hide)
  1006.     {
  1007.         for (int objId : world.allowed)
  1008.         {
  1009.             L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1010.             if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
  1011.                 player.sendPacket(new ExSendUIEvent(player, hide, false, time, 0, "Battle end limit time"));
  1012.         }
  1013.     }
  1014.    
  1015.     private void showMovie(FreyaWorld world, int movie)
  1016.     {
  1017.         for (int objId : world.allowed)
  1018.         {
  1019.             L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1020.             if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
  1021.                 player.showQuestMovie(movie);
  1022.         }
  1023.     }
  1024.    
  1025.     private void stopPc(FreyaWorld world)
  1026.     {
  1027.         for (int objId : world.allowed)
  1028.         {
  1029.             L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1030.             if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
  1031.             {
  1032.                 player.abortAttack();
  1033.                 player.abortCast();
  1034.                 player.setTarget(null);
  1035.                 player.stopMove(null);
  1036.                 player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1037.             }
  1038.         }
  1039.     }
  1040.    
  1041.     private void stopWorld(FreyaWorld world)
  1042.     {
  1043.         Instance instance = InstanceManager.getInstance().getInstance(world.instanceId);
  1044.         for (L2Npc npc : instance.getNpcs())
  1045.         {
  1046.             if (npc != null)
  1047.             {
  1048.                 npc.abortAttack();
  1049.                 npc.abortCast();
  1050.                 npc.setTarget(null);
  1051.                 npc.stopMove(null);
  1052.                 npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1053.                 npc.setIsImmobilized(true);
  1054.                 npc.setIsInvul(true);
  1055.                 npc.disableCoreAI(true);
  1056.                 npc.disableAllSkills();
  1057.             }
  1058.         }
  1059.     }
  1060.    
  1061.     private void startWorld(FreyaWorld world)
  1062.     {
  1063.         Instance instance = InstanceManager.getInstance().getInstance(world.instanceId);
  1064.         for (L2Npc npc : instance.getNpcs())
  1065.         {
  1066.             if (npc != null)
  1067.             {
  1068.                 npc.setIsImmobilized(false);
  1069.                 npc.setIsInvul(false);
  1070.                 npc.disableCoreAI(false);
  1071.                 npc.enableAllSkills();
  1072.             }
  1073.         }
  1074.     }
  1075.    
  1076.     @Override
  1077.     public String onFirstTalk(L2Npc npc, L2PcInstance player)
  1078.     {
  1079.         int npcid = npc.getNpcId();
  1080.        
  1081.         if (npcid == KEGOR_EXIT)
  1082.         {
  1083.             return "kegor-extreme.htm";
  1084.         }
  1085.         return null;
  1086.     }
  1087.    
  1088.     // Wednesday 6:30AM
  1089.     private Calendar reuse_date_1 = null;
  1090.     // Saturday 6:30AM
  1091.     private Calendar reuse_date_2 = null;
  1092.     private long nextCalendarReschedule = 0L;
  1093.    
  1094.     private void setReuseCalendars()
  1095.     {
  1096.         if (nextCalendarReschedule > System.currentTimeMillis())
  1097.             return;
  1098.        
  1099.         Calendar currentTime = Calendar.getInstance();
  1100.         reuse_date_1 = Calendar.getInstance();
  1101.        
  1102.         reuse_date_1.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
  1103.         reuse_date_1.set(Calendar.HOUR_OF_DAY, 6);
  1104.         reuse_date_1.set(Calendar.MINUTE, 30);
  1105.         reuse_date_1.set(Calendar.SECOND, 0);
  1106.        
  1107.         if (currentTime.compareTo(reuse_date_1) > 0)
  1108.             reuse_date_1.add(Calendar.DAY_OF_MONTH, 7);
  1109.        
  1110.         reuse_date_2 = Calendar.getInstance();
  1111.        
  1112.         reuse_date_2.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
  1113.         reuse_date_2.set(Calendar.HOUR_OF_DAY, 6);
  1114.         reuse_date_2.set(Calendar.MINUTE, 30);
  1115.         reuse_date_2.set(Calendar.SECOND, 0);
  1116.        
  1117.         if (currentTime.compareTo(reuse_date_2) > 0)
  1118.             reuse_date_2.add(Calendar.DAY_OF_MONTH, 7);
  1119.        
  1120.         if (reuse_date_1.compareTo(reuse_date_2) < 0)
  1121.             nextCalendarReschedule = reuse_date_1.getTimeInMillis();
  1122.         else
  1123.             nextCalendarReschedule = reuse_date_2.getTimeInMillis();
  1124.     }
  1125.    
  1126.     private void savePlayerReenter(L2PcInstance player)
  1127.     {
  1128.         setReuseCalendars();
  1129.        
  1130.         long nextTime = 0L;
  1131.        
  1132.         if (reuse_date_1.compareTo(reuse_date_2) < 0)
  1133.             nextTime = reuse_date_1.getTimeInMillis();
  1134.         else
  1135.             nextTime = reuse_date_2.getTimeInMillis();
  1136.         if (DEBUG)
  1137.             System.out.println(player.getName() + " " + nextTime);
  1138.         for (int INSTANCEID : TEMPLATE_ID)
  1139.             InstanceManager.getInstance().setInstanceTime(player.getObjectId(), INSTANCEID, nextTime);
  1140.         if (DEBUG)
  1141.             System.out.println(player.getName() + " " + nextTime);
  1142.     }
  1143.    
  1144.     public FreyaExtreme(int questId, String name, String descr)
  1145.     {
  1146.         super(questId, name, descr);
  1147.        
  1148.         addStartNpc(JINIA);
  1149.         addTalkId(JINIA);
  1150.         addTalkId(SIRRA);
  1151.         addStartNpc(KEGOR_EXIT);
  1152.         addFirstTalkId(KEGOR_EXIT);
  1153.         addTalkId(KEGOR_EXIT);
  1154.        
  1155.         for (int mob : MOBS)
  1156.         {
  1157.             addAttackId(mob);
  1158.             addKillId(mob);
  1159.             addSpawnId(mob);
  1160.         }
  1161.     }
  1162.    
  1163.     public static void main(String[] args)
  1164.     {
  1165.         new FreyaExtreme(-1, FreyaExtreme.class.getSimpleName(), "instances");
  1166.     }
  1167. }
Advertisement
Add Comment
Please, Sign In to add comment