Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package instances.Freya;
- import java.util.Calendar;
- import java.util.List;
- import java.util.concurrent.locks.Lock;
- import java.util.concurrent.locks.ReentrantLock;
- import java.util.logging.Level;
- import javolution.util.FastList;
- import com.l2jserver.gameserver.ai.CtrlIntention;
- import com.l2jserver.gameserver.model.holders.SkillHolder;
- import com.l2jserver.gameserver.instancemanager.InstanceManager;
- import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
- import com.l2jserver.gameserver.model.L2CharPosition;
- import com.l2jserver.gameserver.model.L2CommandChannel;
- import com.l2jserver.gameserver.model.L2Party;
- import com.l2jserver.gameserver.model.L2Spawn;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.Location;
- import com.l2jserver.gameserver.model.actor.L2Attackable;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.entity.Instance;
- import com.l2jserver.gameserver.model.quest.Quest;
- import com.l2jserver.gameserver.model.quest.QuestState;
- import com.l2jserver.gameserver.model.quest.State;
- import com.l2jserver.gameserver.network.NpcStringId;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.clientpackets.Say2;
- import com.l2jserver.gameserver.network.serverpackets.ExChangeAreaState;
- import com.l2jserver.gameserver.network.serverpackets.ExSendUIEvent;
- import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
- import com.l2jserver.gameserver.network.serverpackets.NpcSay;
- import com.l2jserver.gameserver.network.serverpackets.OnEventTrigger;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.taskmanager.DecayTaskManager;
- import com.l2jserver.gameserver.util.Broadcast;
- import com.l2jserver.gameserver.util.Util;
- import com.l2jserver.util.Rnd;
- /**
- ** @author Gnacik, Gladicek
- * TODO: Glaciers, Ice Queen Castle room animation (we currently have only "blizzard" effect)
- */
- public class FreyaExtreme extends Quest
- {
- // Debug
- private static final boolean DEBUG = false;
- // Instance template ID
- private static final int[] TEMPLATE_ID =
- {
- 144
- };
- // Instance limits
- private static final int MIN_PLAYERS = 9;
- private static final int MAX_PLAYERS = 27;
- private static final int MIN_LEVEL = 82;
- // NPC's
- private static final int JINIA = 32781; // ENTER
- private static final int SIRRA = 32762; // DOOR OPENER
- private static final int KEGOR_EXIT = 49303; // EXIT
- // Skills
- private static SkillHolder JINIA_PRAYER = new SkillHolder(6288, 1);
- private static SkillHolder KEGOR_COURAGE = new SkillHolder(6289, 1);
- private static SkillHolder ETERNAL_BLIZZARD1 = new SkillHolder(6274, 1);
- // private static SkillHolder ETERNAL_BLIZZARD2 = new SkillHolder(6275, 1);
- // Epic one with client animation
- private static SkillHolder ETERNAL_BLIZZARD3 = new SkillHolder(6276, 1);
- // Glakias Timer
- private static final long TIME_FOR_KILL_GLAKIAS = 260000;
- private static final long FIRST_TIMER_GLAKIAS = 360000;
- private static final long SECOND_TIMER_GLAKIAS = 260000;
- // Monsters
- private static final int[] MOBS =
- {
- 29177,
- 29178,
- 29179,
- 29180,
- 18854,
- 18855,
- 18856,
- 25699,
- 25700
- };
- // Doors for Room Animation
- private static int[] emmiters =
- {
- 23140202,
- 23140204,
- 23140206,
- 23140208,
- 23140212,
- 23140214,
- 23140216
- };
- // Room Animation
- private static int decoration = 0;
- // Teleport Coord
- private static final Location TELE_EXIT = new Location(115717, -125734, -3392);
- private static final Location TELE_IN_BATLE = new Location(114694, -113700, -11200);
- private static final Location[] TELE_ENTER =
- {
- new Location(114185, -112435, -11210),
- new Location(114183, -112280, -11210),
- new Location(114024, -112435, -11210),
- new Location(114024, -112278, -11210),
- new Location(113865, -112435, -11210),
- new Location(113865, -112276, -11210)
- };
- // Timers
- private static final int TIMER_FIRST_MOVIE = 60000;
- private static final int TIMER_GLAKIAS = 100000;
- private static final int TIMER_BREATHS = 30000;
- // Movies
- private static final int MOVIE_START = 15;
- private static final int MOVIE_SECOND = 16;
- private static final int MOVIE_FREYA = 17;
- private static final int MOVIE_KEGOR = 18;
- private static final int MOVIE_DEATH = 19;
- private static final int MOVIE_FINAL = 20;
- private static final int MOVIE_GLAKIAS = 23;
- // Spawns
- private static final Location[] MONUMENTS =
- {
- new Location(113845, -116091, -11168, 8264),
- new Location(113381, -115622, -11168, 8264),
- new Location(113380, -113978, -11168, -8224),
- new Location(113845, -113518, -11168, -8224),
- new Location(115591, -113516, -11168, -24504),
- new Location(116053, -113981, -11168, -24504),
- new Location(116061, -115611, -11168, 24804),
- new Location(115597, -116080, -11168, 24804),
- new Location(112942, -115480, -10960, 52),
- new Location(112940, -115146, -10960, 52),
- new Location(112945, -114453, -10960, 52),
- new Location(112945, -114123, -10960, 52),
- new Location(116497, -114117, -10960, 32724),
- new Location(116499, -114454, -10960, 32724),
- new Location(116501, -115145, -10960, 32724),
- new Location(116502, -115473, -10960, 32724)
- };
- private static final Location[] SPAWNS =
- {
- new Location(114713, -115109, -11202, 16456),
- new Location(114008, -115080, -11202, 3568),
- new Location(114422, -115508, -11202, 12400),
- new Location(115023, -115508, -11202, 20016),
- new Location(115459, -115079, -11202, 27936)
- };
- private class FreyaWorld extends InstanceWorld
- {
- public Lock lock = new ReentrantLock();
- public List<L2PcInstance> PlayersInInstance = new FastList<>();
- public boolean showed = false;
- public boolean screen_message = false;
- public boolean screen_message2 = false;
- public boolean screen_message3 = false;
- int id_freya_first;
- int id_freya_second;
- int id_freya_last;
- int id_glakias;
- int id_ice_knight;
- int id_arch_breath;
- int id_kegor;
- int id_jinia;
- FastList<L2Npc> allmobs = null;
- FastList<L2Npc> monuments = null;
- L2Npc freya;
- L2Npc kegor;
- L2Npc jinia;
- L2Npc kegor_exit;
- L2Npc freya_exit;
- public FreyaWorld()
- {
- allmobs = new FastList<>();
- monuments = new FastList<>();
- id_freya_first = 0;
- id_freya_second = 0;
- id_freya_last = 0;
- id_glakias = 0;
- id_ice_knight = 0;
- id_arch_breath = 0;
- id_kegor = 0;
- id_jinia = 0;
- }
- }
- @Override
- public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
- {
- if (DEBUG)
- _log.info(getName() + "onAdvEvent=" + event);
- InstanceWorld wrld = null;
- if (npc != null)
- wrld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
- else if (player != null)
- wrld = InstanceManager.getInstance().getPlayerWorld(player);
- else
- {
- _log.warning("Freya: onAdvEvent : Unable to get world.");
- return null;
- }
- if (wrld != null && wrld instanceof FreyaWorld)
- {
- FreyaWorld world = (FreyaWorld) wrld;
- if (event.equalsIgnoreCase("opendoor") && world.status == 0)
- {
- // Set status
- world.status = 1;
- // Open Door
- InstanceManager.getInstance().getInstance(world.instanceId).getDoor(23140101).openMe();
- // Schedule Movie
- startQuestTimer("stage_1_movie", TIMER_FIRST_MOVIE, npc, null);
- // If you are using GMChar to test, you can skip parts here and schedule
- // some next timer not stage_1_movie
- // startQuestTimer("stage_3_begin", TIMER_FIRST_MOVIE, npc, null);
- }
- else if (event.equalsIgnoreCase("teletofreya"))
- {
- teleportPlayer(player, TELE_IN_BATLE, world.instanceId);
- }
- else if (event.equalsIgnoreCase("exit"))
- {
- teleportPlayer(player, TELE_EXIT, 0);
- }
- else if (event.equalsIgnoreCase("knight_pillar") && npc != null)
- {
- npc.setDisplayEffect(1);
- }
- else if (event.equalsIgnoreCase("random_first_attack") && npc != null)
- {
- if (!world.monuments.isEmpty())
- {
- if (world.status < 6 && world.monuments.contains(npc))
- return null;
- if (world.status == 6 && world.monuments.contains(npc))
- npc.setDisplayEffect(2);
- int playerId = world.allowed.get(Rnd.get(world.allowed.size()));
- L2PcInstance victim = L2World.getInstance().getPlayer(playerId);
- 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)
- {
- ((L2Attackable) npc).addDamageHate(victim, 0, 99);
- npc.setIsRunning(true);
- npc.setTarget(victim);
- npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, victim, null);
- }
- else
- startQuestTimer("random_first_attack", Rnd.get(1000, 2000), npc, null);
- }
- else
- {
- // Monuments are always in battle time
- // If world.monuments is empty just delete npc, should not be happend
- if (npc.getNpcId() == world.id_glakias || npc.getNpcId() == world.id_arch_breath)
- npc.deleteMe();
- }
- }
- else if (event.equalsIgnoreCase("stage_1_movie"))
- {
- // Stop players before movie
- stopPc(world);
- // Show movie
- showMovie(world, MOVIE_START);
- // Close Door
- InstanceManager.getInstance().getInstance(world.instanceId).getDoor(23140101).closeMe();
- startQuestTimer("stage_1_begin", 53500 + 1000, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_1_begin"))
- {
- // Set status
- world.status = 2;
- // Spawn monuments
- spawnMonuments(world);
- // Spawn boos
- world.freya = addSpawn(world.id_freya_first, 114720, -117085, -11088, 15956, false, 0, true, world.instanceId);
- // Begin stage 1
- ExShowScreenMessage message1 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_1, 2, 7000);
- sendScreenMessage(world, message1);
- // Move freya
- startQuestTimer("freya_move", 2000, world.freya, null, false);
- // start ai for cast skill
- startQuestTimer("cast_skill", 15000, world.freya, null, false);
- }
- else if (event.equalsIgnoreCase("freya_move"))
- {
- ExShowScreenMessage message2 = new ExShowScreenMessage(NpcStringId.FREYA_HAS_STARTED_TO_MOVE, 2, 5000);
- sendScreenMessage(world, message2);
- // Initialize movement
- world.freya.setIsRunning(true);
- world.freya.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(114717, -114973, -11200, 0));
- world.freya.getSpawn().setLocx(114717);
- world.freya.getSpawn().setLocy(-114973);
- world.freya.getSpawn().setLocz(-11200);
- // Spawn Knights
- spawnMobs(world, world.id_ice_knight);
- }
- else if (event.equalsIgnoreCase("cast_skill"))
- {
- ExShowScreenMessage message3 = new ExShowScreenMessage(NpcStringId.STRONG_MAGIC_POWER_CAN_BE_FELT_FROM_SOMEWHERE, 2, 4000);
- sendScreenMessage(world, message3);
- world.freya.doCast(ETERNAL_BLIZZARD1.getSkill());
- startQuestTimer("cast_skill", 60000, world.freya, null, false);
- }
- else if (event.equalsIgnoreCase("cast_skill_3stage"))
- {
- ExShowScreenMessage message4 = new ExShowScreenMessage(NpcStringId.STRONG_MAGIC_POWER_CAN_BE_FELT_FROM_SOMEWHERE, 2, 4000);
- sendScreenMessage(world, message4);
- world.freya.doCast(ETERNAL_BLIZZARD3.getSkill());
- startQuestTimer("cast_skill_3stage", 60000, world.freya, null, false);
- }
- else if (event.equalsIgnoreCase("stage_1_final_movie"))
- {
- cancelQuestTimer("cast_skill", npc, null);
- // Delete freya
- world.freya.deleteMe();
- // Despawn mobs
- despawnAll(world);
- // Stop players before movie
- stopPc(world);
- // Show movie
- showMovie(world, MOVIE_SECOND);
- startQuestTimer("stage_1_pause", 21100 + 1000, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_1_pause"))
- {
- // Spawn boss upstairs
- L2Npc freya = addSpawn(world.id_freya_second, 114723, -117502, -10672, 15956, false, 0, true, world.instanceId);
- freya.setIsImmobilized(true);
- freya.setIsInvul(true);
- freya.disableCoreAI(true);
- freya.disableAllSkills();
- world.freya = freya;
- // Set world status
- world.status = 4;
- // Despawn monuments
- despawnMonuments(world);
- // 1 min pause for rebuff
- showTimer(world, false);
- // Start Stage 2
- startQuestTimer("stage_2_begin", 60000, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_2_begin"))
- {
- // Set world status
- world.status = 5;
- // Begin stage 2
- ExShowScreenMessage message5 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_2, 2, 7000);
- sendScreenMessage(world, message5);
- // Spawn monuments
- spawnMonuments(world);
- // Spawn Knights
- spawnMobs(world, world.id_ice_knight);
- // 4 min to Glakias spawn
- startQuestTimer("stage_2_glakias_movie", TIMER_GLAKIAS, npc, null);
- // 2 min to Breaths spawn
- startQuestTimer("stage_2_breaths", TIMER_BREATHS, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_2_breaths"))
- {
- // Disable new spawns for knights
- for (L2Npc knight : world.allmobs)
- knight.getSpawn().stopRespawn();
- // Spawn Breaths
- spawnMobs(world, world.id_arch_breath);
- }
- else if (event.equalsIgnoreCase("stage_2_glakias_movie"))
- {
- showMovie(world, MOVIE_GLAKIAS);
- showTimerGlakias(world, ((int)FIRST_TIMER_GLAKIAS / 1000), NpcStringId.BATTLE_END_LIMIT_TIME, false);
- startQuestTimer("stage_2_glakias_spawn", 7000 + 1000, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_2_glakias_spawn"))
- {
- showTimerGlakias(world, ((int)SECOND_TIMER_GLAKIAS / 1000), NpcStringId.BATTLE_END_LIMIT_TIME, false);
- addSpawn(world.id_glakias, 114707, -114799, -11199, 15956, false, 0, true, world.instanceId);
- // Timer for 2 stage, if player not kill Glakias - instance destroyed
- startQuestTimer("time_for_kill_glakias", TIME_FOR_KILL_GLAKIAS, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_2_pause"))
- {
- // Despawn mobs
- despawnAll(world);
- // Despawn monuments
- despawnMonuments(world);
- // 1 min pause for rebuff
- showTimer(world, false);
- // Start Stage 3
- startQuestTimer("stage_3_movie", 60000, npc, null);
- }
- else if (event.equalsIgnoreCase("time_for_kill_glakias"))
- {
- InstanceManager.getInstance().destroyInstance(world.instanceId);
- }
- else if (event.equalsIgnoreCase("stage_3_movie"))
- {
- // Delete freya
- world.freya.deleteMe();
- // Show movie
- showMovie(world, MOVIE_FREYA);
- // Begin Stage 3
- startQuestTimer("stage_3_begin", 21500 + 1000, npc, null);
- }
- else if (event.equalsIgnoreCase("stage_3_begin"))
- {
- // Turn on room animation
- ExChangeAreaState as = new ExChangeAreaState(decoration, 2);
- Broadcast.toPlayersInInstance(as, world.instanceId);
- for (int emitter : emmiters)
- {
- OnEventTrigger et = new OnEventTrigger(emitter, false);
- Broadcast.toPlayersInInstance(et, world.instanceId);
- }
- // Spawn monuments
- spawnMonuments(world);
- // Spawn Freya
- world.freya = addSpawn(world.id_freya_last, 114720, -117085, -11088, 15956, false, 0, true, world.instanceId);
- // Begin stage 2
- ExShowScreenMessage message6 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_3, 2, 7000);
- sendScreenMessage(world, message6);
- // Spawn Knights
- spawnMobs(world, world.id_arch_breath);
- // Add monument timers
- startQuestTimer("stage_3_monuments", 60000, npc, null);
- // start ai for cast skill
- startQuestTimer("cast_skill_3stage", 15000, world.freya, null, false);
- }
- else if (event.equalsIgnoreCase("stage_3_monuments"))
- {
- // Set status
- world.status = 6;
- // Monuments start move
- for (L2Npc monument : world.monuments)
- {
- monument.getSpawn().stopRespawn();
- monument.setIsImmobilized(false);
- monument.setIsInvul(false);
- monument.enableAllSkills();
- monument.disableCoreAI(false);
- startQuestTimer("random_first_attack", Rnd.get(1000, 10000), monument, null);
- }
- }
- else if (event.equalsIgnoreCase("finish_world"))
- {
- cancelQuestTimer("player_buff", npc, null);
- cancelQuestTimer("cast_skill_3stage", npc, null);
- cancelQuestTimer("check_for_enemies", npc, null);
- // Despawn mobs
- despawnAll(world);
- // Despawn monuments
- despawnMonuments(world);
- // Begin Movie 2
- startQuestTimer("finish_world2", 100, npc, null);
- }
- else if (event.equalsIgnoreCase("buff_support"))
- {
- startWorld(world);
- startQuestTimer("cast_skill_3stage", 15000, npc, null);
- ExShowScreenMessage message7 = new ExShowScreenMessage(NpcStringId.BEGIN_STAGE_4, 2, 7000);
- sendScreenMessage(world, message7);
- world.kegor = addSpawn(world.id_kegor, 114659, -114796, -11205, 0, false, 0, true, world.instanceId);
- world.jinia = addSpawn(world.id_jinia, 114751, -114781, -11205, 0, false, 0, true, world.instanceId);
- world.kegor.setIsInvul(true);
- world.kegor.setIsRunning(true);
- world.jinia.setIsInvul(true);
- world.jinia.setIsRunning(true);
- startQuestTimer("player_buff", 3000, npc, null);
- startQuestTimer("check_for_enemies", 5000, npc, null);
- }
- else if (event.equalsIgnoreCase("player_buff"))
- {
- world.kegor.doCast(KEGOR_COURAGE.getSkill());
- world.jinia.doCast(JINIA_PRAYER.getSkill());
- startQuestTimer("player_buff", 30000, npc, null);
- }
- else if (event.equalsIgnoreCase("finish_world2"))
- {
- world.kegor.deleteMe();
- world.jinia.deleteMe();
- despawnAll(world);
- // Show movie 2
- showMovie(world, MOVIE_DEATH);
- // Spawn exit NPC + Freya (dying)
- startQuestTimer("spawn_exit", 500, npc, null);
- // Set 5 min time
- Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
- if (inst != null)
- inst.setDuration(300000);
- }
- else if (event.equalsIgnoreCase("finish_world3"))
- {
- // Show movie 3
- showMovie(world, MOVIE_FINAL);
- questSupport2(npc, player);
- world.kegor_exit.deleteMe();
- world.freya_exit.deleteMe();
- }
- else if (event.equalsIgnoreCase("spawn_exit"))
- {
- world.kegor_exit = addSpawn(KEGOR_EXIT, 114659, -114796, -11205, 0, false, 0, true, world.instanceId);
- world.freya_exit = addSpawn(world.id_freya_last, 114785, -114789, -11206, 0, false, 0, true, world.instanceId);
- world.freya_exit.setIsImmobilized(true);
- world.freya_exit.setIsInvul(true);
- world.freya_exit.doDie(world.freya_exit);
- DecayTaskManager.getInstance().cancelDecayTask(world.freya_exit);
- world.freya_exit.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- world.freya_exit.disableCoreAI(true);
- world.freya_exit.disableAllSkills();
- }
- else if (event.equalsIgnoreCase("check_for_enemies"))
- {
- {
- ((L2GuardInstance) world.kegor).addDamageHate(world.freya, 0, 10000);
- ((L2GuardInstance) world.kegor).getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, world.freya, null);
- ((L2GuardInstance) world.jinia).addDamageHate(world.freya, 0, 10000);
- ((L2GuardInstance) world.jinia).getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, world.freya, null);
- }
- startQuestTimer("check_for_enemies", 5000, npc, null);
- }
- }
- else if (npc != null && npc.getNpcId() == JINIA && Util.isDigit(event) && Util.contains(TEMPLATE_ID, Integer.valueOf(event)))
- {
- try
- {
- enterInstance(player, Integer.valueOf(event));
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, e.getMessage(), e);
- }
- return null;
- }
- return null;
- }
- private void sendScreenMessage(FreyaWorld world, ExShowScreenMessage message)
- {
- for (int objId : world.allowed)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if (player != null)
- player.sendPacket(message);
- }
- }
- @Override
- public final String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
- {
- if (npc == null || attacker == null)
- return null;
- final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
- if (tmpWorld instanceof FreyaWorld)
- {
- final FreyaWorld world = (FreyaWorld) tmpWorld;
- // First freya
- if (world.status == 2 && npc.getNpcId() == world.id_freya_first)
- {
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.1))
- {
- if (world.lock.tryLock())
- {
- try
- {
- world.status = 3;
- startQuestTimer("stage_1_final_movie", 1000, npc, attacker);
- }
- finally
- {
- world.lock.unlock();
- }
- }
- }
- }
- else if (npc.getNpcId() == world.id_ice_knight && npc.getDisplayEffect() == 1)
- {
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.3))
- npc.setDisplayEffect(2);
- }
- else if (npc.getNpcId() == world.id_freya_last)
- {
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.25) && !world.showed)
- {
- world.showed = true;
- stopWorld(world);
- // Show Movie 4
- showMovie(world, MOVIE_KEGOR);
- startQuestTimer("buff_support", 27000 + 200, npc, null);
- cancelQuestTimer("cast_skill_3stage", npc, null);
- }
- }
- else if (npc.getNpcId() == world.id_glakias)
- {
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.2) && !world.screen_message)
- {
- world.screen_message = true;
- npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.I_CAN_TAKE_IT_NO_LONGER));
- }
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.4) && !world.screen_message)
- {
- world.screen_message = true;
- npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.ARCHER_HEED_MY_CALL));
- }
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.6) && !world.screen_message2)
- {
- world.screen_message2 = true;
- ExShowScreenMessage message8 = new ExShowScreenMessage(NpcStringId.THE_SPACE_FEELS_LIKE_ITS_GRADUALLY_STARTING_TO_SHAKE, 2, 7000);
- sendScreenMessage(world, message8);
- npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.MY_KNIGHTS_SHOW_YOUR_LOYALTY));
- }
- if (npc.getCurrentHp() < (npc.getMaxHp() * 0.8) && !world.screen_message3)
- {
- world.screen_message3 = true;
- npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getNpcId(), NpcStringId.ARCHER_GIVE_YOUR_BREATH_FOR_THE_INTRUDER));
- }
- }
- }
- return super.onAttack(npc, attacker, damage, isPet);
- }
- @Override
- public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
- {
- if (DEBUG)
- _log.info("onKill [" + npc.getNpcId() + "]" + npc.getName());
- InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
- if (tmpworld instanceof FreyaWorld)
- {
- FreyaWorld world = (FreyaWorld) tmpworld;
- // Delete corpse, because doesn't look good
- npc.deleteMe();
- if (npc.getNpcId() == world.id_ice_knight)
- {
- // Start timer to change effectId
- startQuestTimer("knight_pillar", 5000, npc, null);
- }
- else if (npc.getNpcId() == world.id_glakias)
- {
- // Run Pause before stage 3
- cancelQuestTimer("time_for_kill_glakias", npc, null);
- startQuestTimer("stage_2_pause", 500, npc, null);
- showTimer(world, false);
- }
- else if (npc.getNpcId() == world.id_freya_last)
- {
- // Finish Instance
- startQuestTimer("finish_world", 500, npc, null);
- for (L2PcInstance p : world.PlayersInInstance)
- {
- if (p != null)
- {
- savePlayerReenter(p);
- if (DEBUG)
- _log.info("Save reenter for " + p.getName() + ".");
- }
- }
- }
- else if ((npc.getNpcId() == 29179 || npc.getNpcId() == 29180) && killer.isInParty())
- {
- if (killer.getParty().getCommandChannel() != null)
- {
- for (L2PcInstance ccm : killer.getParty().getCommandChannel().getMembers())
- {
- questSupport(npc, ccm);
- }
- }
- }
- }
- return super.onKill(npc, killer, isPet);
- }
- private void questSupport(L2Npc npc, L2PcInstance player)
- {
- if (player.isInsideRadius(npc, 2000, false, false))
- {
- final int _fragment = 21723;
- final QuestState st = player.getQuestState("Q10502_FreyaEmbroideredSoulCloak");
- if (st != null && st.getState() == State.STARTED && st.getInt("cond") == 1)
- {
- if (player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").getQuestItemsCount(_fragment) < 19)
- {
- player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").giveItems(_fragment, Rnd.get(1, 2));
- st.playSound("ItemSound.quest_middle");
- }
- else
- {
- player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").giveItems(_fragment, 1);
- }
- if (player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").getQuestItemsCount(_fragment) >= 20)
- {
- player.getQuestState("Q10502_FreyaEmbroideredSoulCloak").set("cond", "2");
- }
- }
- }
- }
- private void questSupport2(L2Npc npc, L2PcInstance player)
- {
- if (player.isInsideRadius(npc, 2000, false, false))
- {
- final QuestState st = player.getQuestState("10286_ReunionWithSirra");
- if (st != null && st.getState() == State.STARTED && st.getInt("cond") == 6)
- {
- st.playSound("ItemSound.quest_middle");
- player.getQuestState("10286_ReunionWithSirra").set("cond", "7");
- }
- }
- }
- @Override
- public String onSpawn(L2Npc npc)
- {
- if (DEBUG)
- _log.info("OnSpawn");
- final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
- if (tmpWorld instanceof FreyaWorld)
- {
- startQuestTimer("random_first_attack", 4000, npc, null);
- }
- return null;
- }
- private final synchronized void enterInstance(L2PcInstance player, int template_id)
- {
- // Check for existing instances for this player
- InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
- // Player already in the instance
- if (world != null)
- {
- // but not in our instance
- if (!(world instanceof FreyaWorld))
- {
- player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
- return;
- }
- // Check if instance still exist, if yes - teleport player
- Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
- if (inst != null)
- teleportPlayer(player, TELE_ENTER[Rnd.get(TELE_ENTER.length)], world.instanceId);
- return;
- }
- {
- // Check
- if (!checkConditions(player))
- return;
- final int instanceId = InstanceManager.getInstance().createDynamicInstance("Freya.xml");
- world = new FreyaWorld();
- world.instanceId = instanceId;
- world.templateId = template_id;
- world.status = 0;
- InstanceManager.getInstance().addWorld(world);
- setupIDs((FreyaWorld) world, template_id);
- // And finally teleport party into instance
- if (player.getParty() == null)
- {
- // Remove buffs, set reenter
- setupPlayer((FreyaWorld) world, player, template_id);
- // Port player
- teleportPlayer(player, TELE_ENTER[Rnd.get(TELE_ENTER.length)], instanceId);
- return;
- }
- else if (player.getParty().getCommandChannel() == null)
- {
- for (L2PcInstance partyMember : player.getParty().getMembers())
- {
- // Remove buffs, set reenter
- setupPlayer((FreyaWorld) world, partyMember, template_id);
- // Port player
- teleportPlayer(partyMember, TELE_ENTER[Rnd.get(TELE_ENTER.length)], instanceId);
- }
- }
- else
- {
- for (L2PcInstance channelMember : player.getParty().getCommandChannel().getMembers())
- {
- // Remove buffs, set reenter
- setupPlayer((FreyaWorld) world, channelMember, template_id);
- // Port player
- teleportPlayer(channelMember, TELE_ENTER[Rnd.get(TELE_ENTER.length)], instanceId);
- }
- }
- _log.info("Freya[" + template_id + "] instance started: " + instanceId + " created by player: " + player.getName());
- return;
- }
- }
- private void setupIDs(FreyaWorld world, int template_id)
- {
- {
- world.id_freya_first = 29177;
- world.id_freya_second = 29178;
- world.id_freya_last = 29180;
- world.id_glakias = 25700;
- world.id_ice_knight = 18856;
- world.id_arch_breath = 18854;
- }
- }
- private void despawnAll(FreyaWorld world)
- {
- for (L2Npc npc : world.allmobs)
- {
- npc.getSpawn().stopRespawn();
- npc.deleteMe();
- }
- world.allmobs.clear();
- }
- private void spawnMonuments(FreyaWorld world)
- {
- if (DEBUG)
- _log.info("spawnMonuments");
- for (Location loc : MONUMENTS)
- {
- L2Npc npc = addSpawn(world.id_ice_knight, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), false, 0, true, world.instanceId);
- world.monuments.add(npc);
- npc.disableCoreAI(true);
- npc.setIsImmobilized(true);
- npc.setIsInvul(true);
- npc.disableAllSkills();
- npc.setDisplayEffect(1);
- npc.setEnchant(1);
- L2Spawn spawn = npc.getSpawn();
- spawn.getLastSpawn().setSpawn(spawn);
- spawn.setRespawnDelay(20);
- spawn.setAmount(1);
- spawn.startRespawn();
- }
- }
- private void despawnMonuments(FreyaWorld world)
- {
- for (L2Npc npc : world.monuments)
- {
- npc.setDisplayEffect(2);
- npc.getSpawn().stopRespawn();
- npc.doDie(npc);
- }
- world.monuments.clear();
- }
- private void spawnMobs(FreyaWorld world, int mobId)
- {
- if (DEBUG)
- _log.info("spawnMobs");
- for (Location loc : SPAWNS)
- {
- L2Npc npc = addSpawn(mobId, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), false, 0, true, world.instanceId);
- world.allmobs.add(npc);
- npc.setDisplayEffect(1);
- L2Spawn spawn = npc.getSpawn();
- spawn.setRespawnDelay(20);
- spawn.setAmount(1);
- spawn.startRespawn();
- }
- }
- private static final void teleportPlayer(L2PcInstance player, Location loc, int instanceId)
- {
- player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- player.setInstanceId(instanceId);
- player.teleToLocation(loc, true);
- }
- private void setupPlayer(FreyaWorld world, L2PcInstance player, int template_id)
- {
- // Remove buffs from player
- // player.stopAllEffectsExceptThoseThatLastThroughDeath();
- // Add player to allowed list
- world.allowed.add(player.getObjectId());
- world.PlayersInInstance.add(player);
- if (player.getQuestState("10286_ReunionWithSirra") != null && player.getQuestState("10286_ReunionWithSirra").getState() == State.STARTED && player.getQuestState("10286_ReunionWithSirra").getInt("cond") == 5)
- {
- player.getQuestState("10286_ReunionWithSirra").set("cond", "6");
- }
- }
- private boolean checkConditions(L2PcInstance player)
- {
- if (player.isGM())
- return true;
- L2Party party = player.getParty();
- if (party == null)
- {
- player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
- return false;
- }
- L2CommandChannel channel = player.getParty().getCommandChannel();
- if (channel != null)
- {
- if (channel.getLeader() != player)
- {
- player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
- return false;
- }
- else if (channel.getMemberCount() < MIN_PLAYERS || channel.getMemberCount() > MAX_PLAYERS)
- {
- player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
- return false;
- }
- for (L2PcInstance ccMember : channel.getMembers())
- {
- if (ccMember.getLevel() < MIN_LEVEL)
- {
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
- sm.addPcName(ccMember);
- party.broadcastPacket(sm);
- return false;
- }
- if (!Util.checkIfInRange(1000, player, ccMember, true))
- {
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
- sm.addPcName(ccMember);
- party.broadcastPacket(sm);
- return false;
- }
- for (int inst : TEMPLATE_ID)
- {
- long reentertime = InstanceManager.getInstance().getInstanceTime(ccMember.getObjectId(), inst);
- if (System.currentTimeMillis() < reentertime)
- {
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
- sm.addPcName(ccMember);
- party.broadcastPacket(sm);
- return false;
- }
- }
- QuestState st = ccMember.getQuestState("10286_ReunionWithSirra");
- if (!(st != null && (st.getState() == State.COMPLETED || st.getInt("cond") > 4)))
- {
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_QUEST_REQUIREMENT_NOT_SUFFICIENT);
- sm.addPcName(ccMember);
- party.broadcastPacket(sm);
- return false;
- }
- }
- }
- return true;
- }
- private void showTimer(FreyaWorld world, boolean hide)
- {
- for (int objId : world.allowed)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
- player.sendPacket(new ExSendUIEvent(player, hide, false, 60, 0, "Time remaining until next battle"));
- }
- }
- private void showTimerGlakias(FreyaWorld world, int time, NpcStringId npcString, boolean hide)
- {
- for (int objId : world.allowed)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
- player.sendPacket(new ExSendUIEvent(player, hide, false, time, 0, "Battle end limit time"));
- }
- }
- private void showMovie(FreyaWorld world, int movie)
- {
- for (int objId : world.allowed)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
- player.showQuestMovie(movie);
- }
- }
- private void stopPc(FreyaWorld world)
- {
- for (int objId : world.allowed)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
- {
- player.abortAttack();
- player.abortCast();
- player.setTarget(null);
- player.stopMove(null);
- player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- }
- }
- }
- private void stopWorld(FreyaWorld world)
- {
- Instance instance = InstanceManager.getInstance().getInstance(world.instanceId);
- for (L2Npc npc : instance.getNpcs())
- {
- if (npc != null)
- {
- npc.abortAttack();
- npc.abortCast();
- npc.setTarget(null);
- npc.stopMove(null);
- npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- npc.setIsImmobilized(true);
- npc.setIsInvul(true);
- npc.disableCoreAI(true);
- npc.disableAllSkills();
- }
- }
- }
- private void startWorld(FreyaWorld world)
- {
- Instance instance = InstanceManager.getInstance().getInstance(world.instanceId);
- for (L2Npc npc : instance.getNpcs())
- {
- if (npc != null)
- {
- npc.setIsImmobilized(false);
- npc.setIsInvul(false);
- npc.disableCoreAI(false);
- npc.enableAllSkills();
- }
- }
- }
- @Override
- public String onFirstTalk(L2Npc npc, L2PcInstance player)
- {
- int npcid = npc.getNpcId();
- if (npcid == KEGOR_EXIT)
- {
- return "kegor-extreme.htm";
- }
- return null;
- }
- // Wednesday 6:30AM
- private Calendar reuse_date_1 = null;
- // Saturday 6:30AM
- private Calendar reuse_date_2 = null;
- private long nextCalendarReschedule = 0L;
- private void setReuseCalendars()
- {
- if (nextCalendarReschedule > System.currentTimeMillis())
- return;
- Calendar currentTime = Calendar.getInstance();
- reuse_date_1 = Calendar.getInstance();
- reuse_date_1.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
- reuse_date_1.set(Calendar.HOUR_OF_DAY, 6);
- reuse_date_1.set(Calendar.MINUTE, 30);
- reuse_date_1.set(Calendar.SECOND, 0);
- if (currentTime.compareTo(reuse_date_1) > 0)
- reuse_date_1.add(Calendar.DAY_OF_MONTH, 7);
- reuse_date_2 = Calendar.getInstance();
- reuse_date_2.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
- reuse_date_2.set(Calendar.HOUR_OF_DAY, 6);
- reuse_date_2.set(Calendar.MINUTE, 30);
- reuse_date_2.set(Calendar.SECOND, 0);
- if (currentTime.compareTo(reuse_date_2) > 0)
- reuse_date_2.add(Calendar.DAY_OF_MONTH, 7);
- if (reuse_date_1.compareTo(reuse_date_2) < 0)
- nextCalendarReschedule = reuse_date_1.getTimeInMillis();
- else
- nextCalendarReschedule = reuse_date_2.getTimeInMillis();
- }
- private void savePlayerReenter(L2PcInstance player)
- {
- setReuseCalendars();
- long nextTime = 0L;
- if (reuse_date_1.compareTo(reuse_date_2) < 0)
- nextTime = reuse_date_1.getTimeInMillis();
- else
- nextTime = reuse_date_2.getTimeInMillis();
- if (DEBUG)
- System.out.println(player.getName() + " " + nextTime);
- for (int INSTANCEID : TEMPLATE_ID)
- InstanceManager.getInstance().setInstanceTime(player.getObjectId(), INSTANCEID, nextTime);
- if (DEBUG)
- System.out.println(player.getName() + " " + nextTime);
- }
- public FreyaExtreme(int questId, String name, String descr)
- {
- super(questId, name, descr);
- addStartNpc(JINIA);
- addTalkId(JINIA);
- addTalkId(SIRRA);
- addStartNpc(KEGOR_EXIT);
- addFirstTalkId(KEGOR_EXIT);
- addTalkId(KEGOR_EXIT);
- for (int mob : MOBS)
- {
- addAttackId(mob);
- addKillId(mob);
- addSpawnId(mob);
- }
- }
- public static void main(String[] args)
- {
- new FreyaExtreme(-1, FreyaExtreme.class.getSimpleName(), "instances");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment