LibraryOfSages.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package instances.LibraryOfSages;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  26. import com.l2jserver.gameserver.network.NpcStringId;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.clientpackets.Say2;
  29. /**
  30. * Library of Sages instance zone.
  31. * @author Adry_85
  32. */
  33. public final class LibraryOfSages extends AbstractNpcAI
  34. {
  35. protected class LoSWorld extends InstanceWorld
  36. {
  37. protected L2Npc elcadia = null;
  38. protected long storeTime = 0;
  39. }
  40. private static final int TEMPLATE_ID = 156;
  41. // NPCs
  42. private static final int SOPHIA1 = 32596;
  43. private static final int PILE_OF_BOOKS1 = 32809;
  44. private static final int PILE_OF_BOOKS2 = 32810;
  45. private static final int PILE_OF_BOOKS3 = 32811;
  46. private static final int PILE_OF_BOOKS4 = 32812;
  47. private static final int PILE_OF_BOOKS5 = 32813;
  48. private static final int SOPHIA2 = 32861;
  49. private static final int SOPHIA3 = 32863;
  50. private static final int ELCADIA_INSTANCE = 32785;
  51. // Locations
  52. private static final Location START_LOC = new Location(37063, -49813, -1128);
  53. private static final Location EXIT_LOC = new Location(37063, -49813, -1128, 0, 0);
  54. private static final Location LIBRARY_LOC = new Location(37355, -50065, -1127);
  55. // NpcString
  56. private static final NpcStringId[] ELCADIA_DIALOGS =
  57. {
  58. NpcStringId.I_MUST_ASK_LIBRARIAN_SOPHIA_ABOUT_THE_BOOK,
  59. NpcStringId.THIS_LIBRARY_ITS_HUGE_BUT_THERE_ARENT_MANY_USEFUL_BOOKS_RIGHT,
  60. NpcStringId.AN_UNDERGROUND_LIBRARY_I_HATE_DAMP_AND_SMELLY_PLACES,
  61. NpcStringId.THE_BOOK_THAT_WE_SEEK_IS_CERTAINLY_HERE_SEARCH_INCH_BY_INCH
  62. };
  63. private LibraryOfSages()
  64. {
  65. super(LibraryOfSages.class.getSimpleName(), "instances");
  66. addFirstTalkId(SOPHIA2, ELCADIA_INSTANCE, PILE_OF_BOOKS1, PILE_OF_BOOKS2, PILE_OF_BOOKS3, PILE_OF_BOOKS4, PILE_OF_BOOKS5);
  67. addStartNpc(SOPHIA1, SOPHIA2, SOPHIA3);
  68. addTalkId(SOPHIA1, SOPHIA2, SOPHIA3);
  69. }
  70. @Override
  71. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  72. {
  73. InstanceWorld tmpworld = InstanceManager.getInstance().getPlayerWorld(player);
  74. if (!(tmpworld instanceof LoSWorld))
  75. {
  76. return null;
  77. }
  78. LoSWorld world = (LoSWorld) tmpworld;
  79. switch (event)
  80. {
  81. case "TELEPORT2":
  82. {
  83. teleportPlayer(player, LIBRARY_LOC, world.getInstanceId());
  84. world.elcadia.teleToLocation(LIBRARY_LOC.getX(), LIBRARY_LOC.getY(), LIBRARY_LOC.getZ(), 0, world.getInstanceId());
  85. break;
  86. }
  87. case "EXIT":
  88. {
  89. cancelQuestTimer("FOLLOW", npc, player);
  90. player.teleToLocation(EXIT_LOC);
  91. world.elcadia.deleteMe();
  92. break;
  93. }
  94. case "FOLLOW":
  95. {
  96. npc.setIsRunning(true);
  97. npc.getAI().startFollow(player);
  98. broadcastNpcSay(npc, Say2.NPC_ALL, ELCADIA_DIALOGS[getRandom(ELCADIA_DIALOGS.length)]);
  99. startQuestTimer("FOLLOW", 10000, npc, player);
  100. break;
  101. }
  102. case "ENTER":
  103. {
  104. cancelQuestTimer("FOLLOW", npc, player);
  105. teleportPlayer(player, START_LOC, world.getInstanceId());
  106. world.elcadia.teleToLocation(START_LOC.getX(), START_LOC.getY(), START_LOC.getZ(), 0, world.getInstanceId());
  107. break;
  108. }
  109. }
  110. return super.onAdvEvent(event, npc, player);
  111. }
  112. @Override
  113. public String onTalk(L2Npc npc, L2PcInstance talker)
  114. {
  115. enterInstance(talker, "LibraryOfSages.xml");
  116. return super.onTalk(npc, talker);
  117. }
  118. protected int enterInstance(L2PcInstance player, String template)
  119. {
  120. // check for existing instances for this player
  121. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  122. // existing instance
  123. if (world != null)
  124. {
  125. if (!(world instanceof LoSWorld))
  126. {
  127. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  128. return 0;
  129. }
  130. teleportPlayer(player, START_LOC, world.getInstanceId(), false);
  131. spawnNPC(player, (LoSWorld) world);
  132. return 0;
  133. }
  134. // New instance
  135. world = new LoSWorld();
  136. world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
  137. world.setTemplateId(TEMPLATE_ID);
  138. world.setStatus(0);
  139. ((LoSWorld) world).storeTime = System.currentTimeMillis();
  140. InstanceManager.getInstance().addWorld(world);
  141. _log.info("Library of Sages started " + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
  142. // teleport players
  143. teleportPlayer(player, START_LOC, world.getInstanceId(), false);
  144. world.addAllowed(player.getObjectId());
  145. spawnNPC(player, (LoSWorld) world);
  146. return world.getInstanceId();
  147. }
  148. protected void spawnNPC(L2PcInstance player, LoSWorld world)
  149. {
  150. final L2Npc npc = addSpawn(ELCADIA_INSTANCE, player.getX(), player.getY(), player.getZ(), 0, false, 0, false, player.getInstanceId());
  151. world.elcadia = npc;
  152. startQuestTimer("FOLLOW", 3000, npc, player);
  153. }
  154. public static void main(String[] args)
  155. {
  156. new LibraryOfSages();
  157. }
  158. }