Gladicek

Freya

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