MithrilMine.java 7.5 KB

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