MithrilMine.java 8.4 KB

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