PailakaDevilsLegacy.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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.Pailaka;
  20. import java.util.List;
  21. import javolution.util.FastList;
  22. import com.l2jserver.gameserver.ThreadPoolManager;
  23. import com.l2jserver.gameserver.ai.CtrlIntention;
  24. import com.l2jserver.gameserver.datatables.SkillTable;
  25. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.L2Playable;
  30. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.entity.Instance;
  33. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  34. import com.l2jserver.gameserver.model.quest.Quest;
  35. import com.l2jserver.gameserver.model.quest.QuestState;
  36. import com.l2jserver.gameserver.model.quest.State;
  37. import com.l2jserver.gameserver.model.skills.L2Skill;
  38. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  39. import com.l2jserver.gameserver.network.SystemMessageId;
  40. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  41. /**
  42. * Pailaka (Devil's Isle) instance zone.
  43. */
  44. public class PailakaDevilsLegacy extends Quest
  45. {
  46. private static final int MIN_LEVEL = 61;
  47. private static final int MAX_LEVEL = 67;
  48. private static final int EXIT_TIME = 5;
  49. private static final int INSTANCE_ID = 44;
  50. protected static final int[] TELEPORT =
  51. {
  52. 76428,
  53. -219038,
  54. -3752
  55. };
  56. private static final int ZONE = 20109;
  57. private static final int SURVIVOR = 32498;
  58. private static final int SUPPORTER = 32501;
  59. private static final int ADVENTURER1 = 32508;
  60. private static final int ADVENTURER2 = 32511;
  61. private static final int KAMS = 18629;
  62. private static final int HIKORO = 18630;
  63. private static final int ALKASO = 18631;
  64. private static final int GERBERA = 18632;
  65. private static final int LEMATAN = 18633;
  66. private static final int FOLLOWERS = 18634;
  67. private static final int TREASURE_BOX = 32495;
  68. private static final int POWDER_KEG = 18622;
  69. private static final int[] MONSTERS =
  70. {
  71. KAMS,
  72. HIKORO,
  73. ALKASO,
  74. GERBERA,
  75. LEMATAN,
  76. FOLLOWERS,
  77. TREASURE_BOX,
  78. POWDER_KEG,
  79. 18623,
  80. 18624,
  81. 18625,
  82. 18626,
  83. 18627
  84. };
  85. private static final int SWORD = 13042;
  86. private static final int ENH_SWORD1 = 13043;
  87. private static final int ENH_SWORD2 = 13044;
  88. private static final int SCROLL_1 = 13046;
  89. private static final int SCROLL_2 = 13047;
  90. private static final int HEALING_POTION = 13033;
  91. private static final int ANTIDOTE_POTION = 13048;
  92. private static final int DIVINE_POTION = 13049;
  93. private static final int DEFENCE_POTION = 13059;
  94. private static final int PAILAKA_KEY = 13150;
  95. private static boolean _isTeleportScheduled = false;
  96. private static boolean _isOnShip = false;
  97. private static L2Npc _lematanNpc = null;
  98. private List<L2Npc> _followerslist;
  99. private static final int[] ITEMS =
  100. {
  101. SWORD,
  102. ENH_SWORD1,
  103. ENH_SWORD2,
  104. SCROLL_1,
  105. SCROLL_2,
  106. HEALING_POTION,
  107. ANTIDOTE_POTION,
  108. DIVINE_POTION,
  109. DEFENCE_POTION,
  110. PAILAKA_KEY
  111. };
  112. // @formatter:off
  113. private static final int[][] DROPLIST =
  114. {
  115. // must be sorted by npcId !
  116. // npcId, itemId, chance, max
  117. { TREASURE_BOX, HEALING_POTION, 20 },
  118. { TREASURE_BOX, DIVINE_POTION, 40 },
  119. { TREASURE_BOX, DEFENCE_POTION, 60 },
  120. { TREASURE_BOX, PAILAKA_KEY, 80 },
  121. { TREASURE_BOX, ANTIDOTE_POTION, 100 }
  122. };
  123. private static final int[][] HP_HERBS_DROPLIST =
  124. {
  125. // itemId, count, chance
  126. { 8602, 1, 10 },
  127. { 8601, 1, 40 },
  128. { 8600, 1, 70 }
  129. };
  130. private static final int[][] MP_HERBS_DROPLIST =
  131. {
  132. // itemId, count, chance
  133. { 8605, 1, 10 },
  134. { 8604, 1, 40 },
  135. { 8603, 1, 70 }
  136. };
  137. private static final int[] REWARDS =
  138. {
  139. 13295,
  140. 13129
  141. };
  142. private static final int[][] FOLLOWERS_SPAWNS =
  143. {
  144. { 85067, -208943, -3336, 20106, 60 },
  145. { 84904, -208944, -3336, 10904, 60 },
  146. { 85062, -208538, -3336, 44884, 60 },
  147. { 84897, -208542, -3336, 52973, 60 },
  148. { 84808, -208633, -3339, 65039, 60 },
  149. { 84808, -208856, -3339, 0, 60 },
  150. { 85144, -208855, -3341, 33380, 60 },
  151. { 85139, -208630, -3339, 31777, 60 }
  152. };
  153. // @formatter:on
  154. private static L2Skill boom_skill = SkillTable.getInstance().getInfo(5714, 1);
  155. private static L2Skill energy_skill = SkillTable.getInstance().getInfo(5712, 1);
  156. private void attackPlayer(L2Attackable npc, L2Playable attacker)
  157. {
  158. npc.setIsRunning(true);
  159. npc.addDamageHate(attacker, 0, 999);
  160. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  161. }
  162. private static final void dropHerb(L2Npc mob, L2PcInstance player, int[][] drop)
  163. {
  164. final int chance = getRandom(100);
  165. for (int[] element : drop)
  166. {
  167. if (chance < element[2])
  168. {
  169. ((L2MonsterInstance) mob).dropItem(player, element[0], element[1]);
  170. return;
  171. }
  172. }
  173. }
  174. private static final void dropItem(L2Npc mob, L2PcInstance player)
  175. {
  176. final int npcId = mob.getId();
  177. final int chance = getRandom(100);
  178. for (int[] drop : DROPLIST)
  179. {
  180. if (npcId == drop[0])
  181. {
  182. if (chance < drop[2])
  183. {
  184. ((L2MonsterInstance) mob).dropItem(player, drop[1], getRandom(1, 6));
  185. return;
  186. }
  187. }
  188. if (npcId < drop[0])
  189. {
  190. return; // not found
  191. }
  192. }
  193. }
  194. protected static final void teleportPlayer(L2PcInstance player, int[] coords, int instanceId)
  195. {
  196. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  197. player.setInstanceId(instanceId);
  198. player.teleToLocation(coords[0], coords[1], coords[2], true);
  199. }
  200. private final synchronized void enterInstance(L2PcInstance player)
  201. {
  202. // check for existing instances for this player
  203. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  204. if (world != null)
  205. {
  206. if (world.getTemplateId() != INSTANCE_ID)
  207. {
  208. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  209. return;
  210. }
  211. Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  212. if (inst != null)
  213. {
  214. teleportPlayer(player, TELEPORT, world.getInstanceId());
  215. }
  216. return;
  217. }
  218. // New instance
  219. final int instanceId = InstanceManager.getInstance().createDynamicInstance("PailakaDevilsLegacy.xml");
  220. world = new InstanceWorld();
  221. world.setInstanceId(instanceId);
  222. world.setTemplateId(INSTANCE_ID);
  223. InstanceManager.getInstance().addWorld(world);
  224. world.addAllowed(player.getObjectId());
  225. teleportPlayer(player, TELEPORT, instanceId);
  226. _lematanNpc = addSpawn(LEMATAN, 88108, -209252, -3744, 64255, false, 0, false, instanceId);
  227. }
  228. @Override
  229. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  230. {
  231. // Must be here, because of player == null
  232. if ((npc.getId() == FOLLOWERS) && event.equals("follower_cast"))
  233. {
  234. if (!npc.isCastingNow() && !npc.isDead() && !_lematanNpc.isDead())
  235. {
  236. npc.setTarget(_lematanNpc);
  237. npc.doCast(energy_skill);
  238. }
  239. startQuestTimer("follower_cast", 2000 + getRandom(100, 1000), npc, null);
  240. return null;
  241. }
  242. else if ((npc.getId() == POWDER_KEG) && event.equalsIgnoreCase("keg_trigger"))
  243. {
  244. onAttack(npc, player, 600, false);
  245. }
  246. final QuestState st = player.getQuestState(getName());
  247. if (st == null)
  248. {
  249. return getNoQuestMsg(player);
  250. }
  251. if (event.equalsIgnoreCase("enter"))
  252. {
  253. enterInstance(player);
  254. if (st.isCond(1))
  255. {
  256. st.setCond(2, true);
  257. return "32498-07.htm";
  258. }
  259. return "32498-09.htm";
  260. }
  261. else if (event.equalsIgnoreCase("32498-05.htm"))
  262. {
  263. if (st.isCond(0))
  264. {
  265. st.startQuest();
  266. }
  267. }
  268. else if (event.equalsIgnoreCase("32501-03.htm"))
  269. {
  270. if (st.isCond(2))
  271. {
  272. giveItems(player, SWORD, 1);
  273. st.setCond(3, true);
  274. }
  275. }
  276. else if (event.equalsIgnoreCase("lematan_teleport"))
  277. {
  278. if ((npc.getId() == LEMATAN) && !npc.isMovementDisabled() && !_isOnShip)
  279. {
  280. // Reduce Hate
  281. ((L2Attackable) npc).reduceHate(player, 9999);
  282. ((L2Attackable) npc).abortAttack();
  283. ((L2Attackable) npc).abortCast();
  284. // Broadcast Escape
  285. npc.broadcastPacket(new MagicSkillUse(npc, 2100, 1, 1000, 0));
  286. // Schedule telport - when Lematan Finish casting
  287. startQuestTimer("lematan_finish_teleport", 1500, npc, player);
  288. }
  289. else
  290. {
  291. _isTeleportScheduled = false;
  292. }
  293. return null;
  294. }
  295. else if ((npc.getId() == LEMATAN) && event.equalsIgnoreCase("lematan_finish_teleport") && !_isOnShip)
  296. {
  297. // Teleport Lematan
  298. npc.teleToLocation(84973, -208721, -3340);
  299. // Set onShip
  300. _isOnShip = true;
  301. // Set Spawn loc to ship. If he loose aggro he should stay on board ;)
  302. npc.getSpawn().setX(84973);
  303. npc.getSpawn().setY(-208721);
  304. npc.getSpawn().setZ(-3340);
  305. // To be sure, reduce again
  306. ((L2Attackable) npc).reduceHate(player, 9999);
  307. // Spawn followers
  308. _followerslist = new FastList<>();
  309. for (int[] SPAWN : FOLLOWERS_SPAWNS)
  310. {
  311. L2Npc _follower = addSpawn(FOLLOWERS, SPAWN[0], SPAWN[1], SPAWN[2], SPAWN[3], false, 0, true, player.getInstanceId());
  312. if (_follower != null)
  313. {
  314. _followerslist.add(_follower);
  315. }
  316. }
  317. return null;
  318. }
  319. return event;
  320. }
  321. @Override
  322. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  323. {
  324. final QuestState st = player.getQuestState(getName());
  325. if ((npc.getId() != ADVENTURER2) || (st == null) || !st.isCompleted())
  326. {
  327. return npc.getId() + ".htm";
  328. }
  329. return "32511-03.htm";
  330. }
  331. @Override
  332. public final String onTalk(L2Npc npc, L2PcInstance player)
  333. {
  334. final QuestState st = player.getQuestState(getName());
  335. if (st == null)
  336. {
  337. return getNoQuestMsg(player);
  338. }
  339. switch (npc.getId())
  340. {
  341. case SURVIVOR:
  342. switch (st.getState())
  343. {
  344. case State.CREATED:
  345. if (player.getLevel() < MIN_LEVEL)
  346. {
  347. return "32498-11.htm";
  348. }
  349. if (player.getLevel() > MAX_LEVEL)
  350. {
  351. return "32498-12.htm";
  352. }
  353. return "32498-01.htm";
  354. case State.STARTED:
  355. if (st.getCond() > 1)
  356. {
  357. return "32498-08.htm";
  358. }
  359. return "32498-06.htm";
  360. case State.COMPLETED:
  361. return "32498-10.htm";
  362. default:
  363. return "32498-01.htm";
  364. }
  365. case SUPPORTER:
  366. if (st.getCond() > 2)
  367. {
  368. return "32501-04.htm";
  369. }
  370. return "32501-01.htm";
  371. case ADVENTURER1:
  372. if (!player.hasSummon())
  373. {
  374. if (hasQuestItems(player, SWORD))
  375. {
  376. if (hasQuestItems(player, SCROLL_1))
  377. {
  378. takeItems(player, SWORD, -1);
  379. takeItems(player, SCROLL_1, -1);
  380. giveItems(player, ENH_SWORD1, 1);
  381. return "32508-03.htm";
  382. }
  383. return "32508-02.htm";
  384. }
  385. if (hasQuestItems(player, ENH_SWORD1))
  386. {
  387. if (hasQuestItems(player, SCROLL_2))
  388. {
  389. takeItems(player, ENH_SWORD1, -1);
  390. takeItems(player, SCROLL_2, -1);
  391. giveItems(player, ENH_SWORD2, 1);
  392. return "32508-05.htm";
  393. }
  394. return "32508-04.htm";
  395. }
  396. if (hasQuestItems(player, ENH_SWORD2))
  397. {
  398. return "32508-06.htm";
  399. }
  400. return "32508-00.htm";
  401. }
  402. return "32508-07.htm";
  403. case ADVENTURER2:
  404. if (!player.hasSummon())
  405. {
  406. st.exitQuest(false, true);
  407. Instance inst = InstanceManager.getInstance().getInstance(npc.getInstanceId());
  408. inst.setDuration(EXIT_TIME * 60000);
  409. inst.setEmptyDestroyTime(0);
  410. if (inst.containsPlayer(player.getObjectId()))
  411. {
  412. player.setVitalityPoints(20000, true);
  413. addExpAndSp(player, 10800000, 950000);
  414. for (int id : REWARDS)
  415. {
  416. giveItems(player, id, 1);
  417. }
  418. }
  419. return "32511-01.htm";
  420. }
  421. return "32511-02.htm";
  422. }
  423. return getNoQuestMsg(player);
  424. }
  425. @Override
  426. public final String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  427. {
  428. if ((npc.getId() == POWDER_KEG) && !npc.isDead())
  429. {
  430. npc.doCast(boom_skill);
  431. if (npc.getKnownList() != null)
  432. {
  433. for (L2Character target : npc.getKnownList().getKnownCharactersInRadius(900))
  434. {
  435. target.reduceCurrentHp(500 + getRandom(0, 200), npc, boom_skill);
  436. if (target instanceof L2MonsterInstance)
  437. {
  438. if (target.getId() == POWDER_KEG)
  439. {
  440. startQuestTimer("keg_trigger", 500, (L2Npc) target, attacker);
  441. }
  442. else
  443. {
  444. if (isSummon)
  445. {
  446. attackPlayer((L2Attackable) npc, attacker.getSummon());
  447. }
  448. else
  449. {
  450. attackPlayer((L2Attackable) npc, attacker);
  451. }
  452. }
  453. }
  454. }
  455. }
  456. if (!npc.isDead())
  457. {
  458. npc.doDie(attacker);
  459. }
  460. }
  461. else if ((npc.getId() == LEMATAN) && (npc.getCurrentHp() < (npc.getMaxHp() / 2)) && !_isTeleportScheduled)
  462. {
  463. startQuestTimer("lematan_teleport", 1000, npc, attacker);
  464. }
  465. else if (npc.getId() == TREASURE_BOX)
  466. {
  467. dropItem(npc, attacker);
  468. npc.doDie(attacker);
  469. }
  470. return super.onAttack(npc, attacker, damage, isSummon);
  471. }
  472. @Override
  473. public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  474. {
  475. final QuestState st = player.getQuestState(getName());
  476. if ((st != null) && st.isStarted())
  477. {
  478. switch (npc.getId())
  479. {
  480. case KAMS:
  481. if (hasQuestItems(player, SWORD))
  482. {
  483. giveItems(player, SCROLL_1, 1);
  484. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  485. }
  486. break;
  487. case ALKASO:
  488. if (hasQuestItems(player, ENH_SWORD1))
  489. {
  490. giveItems(player, SCROLL_2, 1);
  491. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  492. }
  493. break;
  494. case LEMATAN:
  495. if ((_followerslist != null) && !_followerslist.isEmpty())
  496. {
  497. for (L2Npc _follower : _followerslist)
  498. {
  499. _follower.deleteMe();
  500. }
  501. _followerslist.clear();
  502. }
  503. st.setCond(4, true);
  504. addSpawn(ADVENTURER2, 84983, -208736, -3336, 49915, false, 0, false, npc.getInstanceId());
  505. break;
  506. case POWDER_KEG:
  507. case TREASURE_BOX:
  508. case FOLLOWERS:
  509. // do nothing
  510. break;
  511. default:
  512. // hardcoded herb drops
  513. dropHerb(npc, player, HP_HERBS_DROPLIST);
  514. dropHerb(npc, player, MP_HERBS_DROPLIST);
  515. break;
  516. }
  517. }
  518. return super.onKill(npc, player, isSummon);
  519. }
  520. @Override
  521. public final String onSpawn(L2Npc npc)
  522. {
  523. startQuestTimer("follower_cast", 1000 + getRandom(100, 1000), npc, null);
  524. npc.disableCoreAI(true);
  525. return null;
  526. }
  527. @Override
  528. public String onEnterZone(L2Character character, L2ZoneType zone)
  529. {
  530. if ((character instanceof L2PcInstance) && !character.isDead() && !character.isTeleporting() && ((L2PcInstance) character).isOnline())
  531. {
  532. InstanceWorld world = InstanceManager.getInstance().getWorld(character.getInstanceId());
  533. if ((world != null) && (world.getTemplateId() == INSTANCE_ID))
  534. {
  535. ThreadPoolManager.getInstance().scheduleGeneral(new Teleport(character, world.getInstanceId()), 1000);
  536. }
  537. }
  538. return super.onEnterZone(character, zone);
  539. }
  540. static final class Teleport implements Runnable
  541. {
  542. private final L2Character _char;
  543. private final int _instanceId;
  544. public Teleport(L2Character c, int id)
  545. {
  546. _char = c;
  547. _instanceId = id;
  548. }
  549. @Override
  550. public void run()
  551. {
  552. try
  553. {
  554. teleportPlayer((L2PcInstance) _char, TELEPORT, _instanceId);
  555. }
  556. catch (Exception e)
  557. {
  558. e.printStackTrace();
  559. }
  560. }
  561. }
  562. private PailakaDevilsLegacy()
  563. {
  564. super(129, "129_PailakaDevilsLegacy", "Pailaka - Devil's Legacy");
  565. addStartNpc(SURVIVOR);
  566. addFirstTalkId(SURVIVOR, SUPPORTER, ADVENTURER1, ADVENTURER2);
  567. addTalkId(SURVIVOR, SUPPORTER, ADVENTURER1, ADVENTURER2);
  568. addAttackId(TREASURE_BOX, POWDER_KEG, LEMATAN);
  569. addKillId(MONSTERS);
  570. addEnterZoneId(ZONE);
  571. addSpawnId(FOLLOWERS);
  572. registerQuestItems(ITEMS);
  573. }
  574. public static void main(String[] args)
  575. {
  576. new PailakaDevilsLegacy();
  577. }
  578. }