MithrilMine.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (C) 2004-2013 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.MithrilMine;
  20. import quests.Q10284_AcquisitionOfDivineSword.Q10284_AcquisitionOfDivineSword;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.L2Attackable;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.holders.SkillHolder;
  28. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  29. import com.l2jserver.gameserver.model.quest.Quest;
  30. import com.l2jserver.gameserver.model.quest.QuestState;
  31. import com.l2jserver.gameserver.network.NpcStringId;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.clientpackets.Say2;
  34. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  35. /**
  36. * Mithril Mine instance zone.
  37. * @author Adry_85
  38. */
  39. public final class MithrilMine extends Quest
  40. {
  41. protected class MMWorld extends InstanceWorld
  42. {
  43. long storeTime = 0;
  44. }
  45. private static final int INSTANCEID = 138;
  46. // NPCs
  47. private static final int KEGOR = 18846;
  48. private static final int MITHRIL_MILLIPEDE = 22766;
  49. private static final int KRUN = 32653;
  50. private static final int TARUN = 32654;
  51. // Item
  52. private static final int COLD_RESISTANCE_POTION = 15514;
  53. // Skill
  54. private static SkillHolder BLESS_OF_SWORD = new SkillHolder(6286, 1);
  55. // Location
  56. private static final Location START_LOC = new Location(186852, -173492, -3763, 0, 0);
  57. private static final Location EXIT_LOC = new Location(178823, -184303, -347, 0, 0);
  58. private static final Location[] MOB_SPAWNS = new Location[]
  59. {
  60. new Location(185216, -184112, -3308, -15396),
  61. new Location(185456, -184240, -3308, -19668),
  62. new Location(185712, -184384, -3308, -26696),
  63. new Location(185920, -184544, -3308, -32544),
  64. new Location(185664, -184720, -3308, 27892)
  65. };
  66. // Misc
  67. private int _count = 0;
  68. private L2PcInstance _player = null;
  69. private MithrilMine()
  70. {
  71. super(-1, MithrilMine.class.getSimpleName(), "instances");
  72. addFirstTalkId(KEGOR);
  73. addKillId(KEGOR, MITHRIL_MILLIPEDE);
  74. addSpawnId(KEGOR);
  75. addStartNpc(TARUN, KRUN);
  76. addTalkId(TARUN, KRUN, KEGOR);
  77. }
  78. @Override
  79. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  80. {
  81. switch (event)
  82. {
  83. case "BUFF":
  84. {
  85. if ((player != null) && npc.isInsideRadius(player, 1000, true, false) && npc.isScriptValue(1) && !player.isDead())
  86. {
  87. npc.setTarget(player);
  88. npc.doCast(BLESS_OF_SWORD.getSkill());
  89. }
  90. startQuestTimer("BUFF", 30000, npc, player);
  91. break;
  92. }
  93. case "TIMER":
  94. {
  95. InstanceWorld tmpworld = InstanceManager.getInstance().getPlayerWorld(player);
  96. if (tmpworld instanceof MMWorld)
  97. {
  98. for (Location loc : MOB_SPAWNS)
  99. {
  100. final L2Attackable spawnedMob = (L2Attackable) addSpawn(MITHRIL_MILLIPEDE, loc, false, 0, false, tmpworld.getInstanceId());
  101. spawnedMob.setScriptValue(1);
  102. spawnedMob.setIsRunning(true);
  103. spawnedMob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, npc);
  104. spawnedMob.addDamageHate(npc, 0, 999999);
  105. }
  106. }
  107. break;
  108. }
  109. case "FINISH":
  110. {
  111. if (_count >= 5)
  112. {
  113. npc.setScriptValue(2);
  114. npc.setTarget(player);
  115. npc.setWalking();
  116. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
  117. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.I_CAN_FINALLY_TAKE_A_BREATHER_BY_THE_WAY_WHO_ARE_YOU_HMM_I_THINK_I_KNOW_WHO_SENT_YOU));
  118. InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  119. InstanceManager.getInstance().getInstance(world.getInstanceId()).setDuration(3000);
  120. cancelQuestTimers("FINISH");
  121. }
  122. break;
  123. }
  124. }
  125. return super.onAdvEvent(event, npc, player);
  126. }
  127. @Override
  128. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  129. {
  130. final QuestState qs = player.getQuestState(Q10284_AcquisitionOfDivineSword.class.getSimpleName());
  131. if ((qs != null))
  132. {
  133. if (qs.isMemoState(2))
  134. {
  135. return npc.isScriptValue(0) ? "18846.html" : "18846-01.html";
  136. }
  137. else if (qs.isMemoState(3))
  138. {
  139. final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  140. world.removeAllowed(player.getObjectId());
  141. player.setInstanceId(0);
  142. player.teleToLocation(EXIT_LOC, 0);
  143. qs.giveAdena(296425, true);
  144. qs.addExpAndSp(921805, 82230);
  145. qs.exitQuest(false, true);
  146. return "18846-03.html";
  147. }
  148. }
  149. return super.onFirstTalk(npc, player);
  150. }
  151. @Override
  152. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  153. {
  154. if (npc.getId() == KEGOR)
  155. {
  156. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.HOW_COULD_I_FALL_IN_A_PLACE_LIKE_THIS));
  157. InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  158. InstanceManager.getInstance().getInstance(world.getInstanceId()).setDuration(1000);
  159. }
  160. else
  161. {
  162. if (npc.isScriptValue(1))
  163. {
  164. _count++;
  165. }
  166. if (_count >= 5)
  167. {
  168. final QuestState qs = player.getQuestState(Q10284_AcquisitionOfDivineSword.class.getSimpleName());
  169. if ((qs != null) && qs.isMemoState(2))
  170. {
  171. cancelQuestTimers("BUFF");
  172. qs.setMemoState(3);
  173. qs.setCond(6, true);
  174. }
  175. }
  176. }
  177. return super.onKill(npc, player, isSummon);
  178. }
  179. @Override
  180. public final String onSpawn(L2Npc npc)
  181. {
  182. npc.setRHandId(15280);
  183. startQuestTimer("FINISH", 3000, npc, _player, true);
  184. return super.onSpawn(npc);
  185. }
  186. @Override
  187. public String onTalk(L2Npc npc, L2PcInstance talker)
  188. {
  189. switch (npc.getId())
  190. {
  191. case TARUN:
  192. case KRUN:
  193. {
  194. final QuestState qs = talker.getQuestState(Q10284_AcquisitionOfDivineSword.class.getSimpleName());
  195. if ((qs != null) && qs.isMemoState(2))
  196. {
  197. if (!qs.hasQuestItems(COLD_RESISTANCE_POTION))
  198. {
  199. qs.giveItems(COLD_RESISTANCE_POTION, 1);
  200. }
  201. qs.setCond(4, true);
  202. _player = talker;
  203. enterInstance(talker, "MithrilMine.xml", START_LOC);
  204. }
  205. break;
  206. }
  207. case KEGOR:
  208. {
  209. final QuestState qs = talker.getQuestState(Q10284_AcquisitionOfDivineSword.class.getSimpleName());
  210. if ((qs != null) && qs.isMemoState(2) && qs.hasQuestItems(COLD_RESISTANCE_POTION) && npc.isScriptValue(0))
  211. {
  212. qs.takeItems(COLD_RESISTANCE_POTION, -1);
  213. qs.setCond(5, true);
  214. npc.setScriptValue(1);
  215. startQuestTimer("TIMER", 3000, npc, talker);
  216. startQuestTimer("BUFF", 3500, npc, talker);
  217. return "18846-02.html";
  218. }
  219. break;
  220. }
  221. }
  222. return super.onTalk(npc, talker);
  223. }
  224. protected int enterInstance(L2PcInstance player, String template, Location loc)
  225. {
  226. // check for existing instances for this player
  227. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  228. // existing instance
  229. if (world != null)
  230. {
  231. if (!(world instanceof MMWorld))
  232. {
  233. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  234. return 0;
  235. }
  236. teleportPlayer(player, loc, world.getInstanceId(), false);
  237. return 0;
  238. }
  239. // New instance
  240. world = new MMWorld();
  241. world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
  242. world.setTemplateId(INSTANCEID);
  243. world.setStatus(0);
  244. ((MMWorld) world).storeTime = System.currentTimeMillis();
  245. InstanceManager.getInstance().addWorld(world);
  246. _log.info("Mithril Mine started " + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
  247. // teleport players
  248. teleportPlayer(player, loc, world.getInstanceId(), false);
  249. world.addAllowed(player.getObjectId());
  250. return world.getInstanceId();
  251. }
  252. public static void main(String[] args)
  253. {
  254. new MithrilMine();
  255. }
  256. }