PailakaDevilsLegacy.java 17 KB

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