PailakaSongOfIceAndFire.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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 com.l2jserver.gameserver.ThreadPoolManager;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.enums.QuestSound;
  23. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.entity.Instance;
  29. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  30. import com.l2jserver.gameserver.model.quest.Quest;
  31. import com.l2jserver.gameserver.model.quest.QuestState;
  32. import com.l2jserver.gameserver.model.quest.State;
  33. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  34. import com.l2jserver.gameserver.network.NpcStringId;
  35. import com.l2jserver.gameserver.network.SystemMessageId;
  36. import com.l2jserver.gameserver.network.clientpackets.Say2;
  37. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  38. import com.l2jserver.gameserver.util.Broadcast;
  39. /**
  40. * Pailaka (Forgotten Temple) instance zone.
  41. */
  42. public class PailakaSongOfIceAndFire extends Quest
  43. {
  44. private static final int MIN_LEVEL = 36;
  45. private static final int MAX_LEVEL = 42;
  46. private static final int EXIT_TIME = 5;
  47. private static final int INSTANCE_ID = 43;
  48. protected static final int[] TELEPORT =
  49. {
  50. -52875,
  51. 188232,
  52. -4696
  53. };
  54. private static final int ZONE = 20108;
  55. private static final int ADLER1 = 32497;
  56. private static final int ADLER2 = 32510;
  57. private static final int SINAI = 32500;
  58. private static final int INSPECTOR = 32507;
  59. private static final int HILLAS = 18610;
  60. private static final int PAPION = 18609;
  61. private static final int KINSUS = 18608;
  62. private static final int GARGOS = 18607;
  63. private static final int ADIANTUM = 18620;
  64. private static final int BLOOM = 18616;
  65. private static final int BOTTLE = 32492;
  66. private static final int BRAZIER = 32493;
  67. private static final int[] MONSTERS =
  68. {
  69. HILLAS,
  70. PAPION,
  71. KINSUS,
  72. GARGOS,
  73. ADIANTUM,
  74. BLOOM,
  75. BOTTLE,
  76. BRAZIER,
  77. 18611,
  78. 18612,
  79. 18613,
  80. 18614,
  81. 18615
  82. };
  83. private static final int SWORD = 13034;
  84. private static final int ENH_SWORD1 = 13035;
  85. private static final int ENH_SWORD2 = 13036;
  86. private static final int BOOK1 = 13130;
  87. private static final int BOOK2 = 13131;
  88. private static final int BOOK3 = 13132;
  89. private static final int BOOK4 = 13133;
  90. private static final int BOOK5 = 13134;
  91. private static final int BOOK6 = 13135;
  92. private static final int BOOK7 = 13136;
  93. private static final int WATER_ESSENCE = 13038;
  94. private static final int FIRE_ESSENCE = 13039;
  95. private static final int SHIELD_POTION = 13032;
  96. private static final int HEAL_POTION = 13033;
  97. private static final int FIRE_ENHANCER = 13040;
  98. private static final int WATER_ENHANCER = 13041;
  99. private static final int[] ITEMS =
  100. {
  101. SWORD,
  102. ENH_SWORD1,
  103. ENH_SWORD2,
  104. BOOK1,
  105. BOOK2,
  106. BOOK3,
  107. BOOK4,
  108. BOOK5,
  109. BOOK6,
  110. BOOK7,
  111. WATER_ESSENCE,
  112. FIRE_ESSENCE,
  113. SHIELD_POTION,
  114. HEAL_POTION,
  115. FIRE_ENHANCER,
  116. WATER_ENHANCER
  117. };
  118. // @formatter:off
  119. private static final int[][] DROPLIST =
  120. {
  121. // must be sorted by npcId !
  122. // npcId, itemId, chance
  123. {
  124. BLOOM, SHIELD_POTION, 30
  125. },
  126. {
  127. BLOOM, HEAL_POTION, 80
  128. },
  129. {
  130. BOTTLE, SHIELD_POTION, 10
  131. },
  132. {
  133. BOTTLE, WATER_ENHANCER, 40
  134. },
  135. {
  136. BOTTLE, HEAL_POTION, 80
  137. },
  138. {
  139. BRAZIER, SHIELD_POTION, 10
  140. },
  141. {
  142. BRAZIER, FIRE_ENHANCER, 40
  143. },
  144. {
  145. BRAZIER, HEAL_POTION, 80
  146. }
  147. };
  148. /**
  149. * itemId, count, chance
  150. */
  151. private static final int[][] HP_HERBS_DROPLIST =
  152. {
  153. {
  154. 8602, 1, 10
  155. },
  156. {
  157. 8601, 1, 40
  158. },
  159. {
  160. 8600, 1, 70
  161. }
  162. };
  163. /**
  164. * itemId, count, chance
  165. */
  166. private static final int[][] MP_HERBS_DROPLIST =
  167. {
  168. {
  169. 8605, 1, 10
  170. },
  171. {
  172. 8604, 1, 40
  173. },
  174. {
  175. 8603, 1, 70
  176. }
  177. };
  178. // @formatter:on
  179. private static final int[] REWARDS =
  180. {
  181. 13294,
  182. 13293,
  183. 13129
  184. };
  185. /** Flag for "see creature". */
  186. private boolean _seenCreature = false;
  187. private static final void dropHerb(L2Npc mob, L2PcInstance player, int[][] drop)
  188. {
  189. final int chance = getRandom(100);
  190. for (int[] element : drop)
  191. {
  192. if (chance < element[2])
  193. {
  194. ((L2MonsterInstance) mob).dropItem(player, element[0], element[1]);
  195. return;
  196. }
  197. }
  198. }
  199. private static final void dropItem(L2Npc mob, L2PcInstance player)
  200. {
  201. final int npcId = mob.getId();
  202. final int chance = getRandom(100);
  203. for (int[] drop : DROPLIST)
  204. {
  205. if (npcId == drop[0])
  206. {
  207. if (chance < drop[2])
  208. {
  209. ((L2MonsterInstance) mob).dropItem(player, drop[1], getRandom(1, 6));
  210. return;
  211. }
  212. }
  213. if (npcId < drop[0])
  214. {
  215. return; // not found
  216. }
  217. }
  218. }
  219. protected static final void teleportPlayer(L2PcInstance player, int[] coords, int instanceId)
  220. {
  221. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  222. player.setInstanceId(instanceId);
  223. player.teleToLocation(coords[0], coords[1], coords[2], true);
  224. }
  225. private final synchronized void enterInstance(L2PcInstance player)
  226. {
  227. // check for existing instances for this player
  228. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  229. if (world != null)
  230. {
  231. if (world.getTemplateId() != INSTANCE_ID)
  232. {
  233. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  234. return;
  235. }
  236. Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  237. if (inst != null)
  238. {
  239. teleportPlayer(player, TELEPORT, world.getInstanceId());
  240. }
  241. return;
  242. }
  243. // New instance
  244. final int instanceId = InstanceManager.getInstance().createDynamicInstance("PailakaSongOfIceAndFire.xml");
  245. world = new InstanceWorld();
  246. world.setInstanceId(instanceId);
  247. world.setTemplateId(INSTANCE_ID);
  248. InstanceManager.getInstance().addWorld(world);
  249. world.addAllowed(player.getObjectId());
  250. teleportPlayer(player, TELEPORT, instanceId);
  251. }
  252. @Override
  253. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  254. {
  255. final QuestState st = player.getQuestState(getName());
  256. if (st == null)
  257. {
  258. return getNoQuestMsg(player);
  259. }
  260. switch (event)
  261. {
  262. case "enter":
  263. enterInstance(player);
  264. return null;
  265. case "32497-03.htm":
  266. if (!st.isStarted())
  267. {
  268. st.startQuest();
  269. }
  270. break;
  271. case "32500-06.htm":
  272. if (st.isCond(1))
  273. {
  274. st.setCond(2, true);
  275. giveItems(player, SWORD, 1);
  276. giveItems(player, BOOK1, 1);
  277. }
  278. break;
  279. case "32507-04.htm":
  280. if (st.isCond(3))
  281. {
  282. st.setCond(4, true);
  283. takeItems(player, SWORD, -1);
  284. takeItems(player, WATER_ESSENCE, -1);
  285. takeItems(player, BOOK2, -1);
  286. giveItems(player, BOOK3, 1);
  287. giveItems(player, ENH_SWORD1, 1);
  288. }
  289. break;
  290. case "32507-08.htm":
  291. if (st.isCond(6))
  292. {
  293. st.setCond(7, true);
  294. takeItems(player, ENH_SWORD1, -1);
  295. takeItems(player, BOOK5, -1);
  296. takeItems(player, FIRE_ESSENCE, -1);
  297. giveItems(player, ENH_SWORD2, 1);
  298. giveItems(player, BOOK6, 1);
  299. }
  300. break;
  301. case "32510-02.htm":
  302. st.exitQuest(false, true);
  303. Instance inst = InstanceManager.getInstance().getInstance(npc.getInstanceId());
  304. inst.setDuration(EXIT_TIME * 60000);
  305. inst.setEmptyDestroyTime(0);
  306. if (inst.containsPlayer(player.getObjectId()))
  307. {
  308. player.setVitalityPoints(20000, true);
  309. addExpAndSp(player, 810000, 50000);
  310. for (int id : REWARDS)
  311. {
  312. giveItems(player, id, 1);
  313. }
  314. }
  315. break;
  316. case "GARGOS_LAUGH":
  317. {
  318. Broadcast.toKnownPlayers(npc, new NpcSay(npc.getObjectId(), Say2.NPC_SHOUT, npc.getTemplate().getIdTemplate(), NpcStringId.OHHOHOH));
  319. break;
  320. }
  321. }
  322. return event;
  323. }
  324. @Override
  325. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  326. {
  327. return npc.getId() + ".htm";
  328. }
  329. @Override
  330. public final String onTalk(L2Npc npc, L2PcInstance player)
  331. {
  332. final QuestState st = player.getQuestState(getName());
  333. if (st == null)
  334. {
  335. return getNoQuestMsg(player);
  336. }
  337. switch (npc.getId())
  338. {
  339. case ADLER1:
  340. switch (st.getState())
  341. {
  342. case State.CREATED:
  343. if (player.getLevel() < MIN_LEVEL)
  344. {
  345. return "32497-05.htm";
  346. }
  347. if (player.getLevel() > MAX_LEVEL)
  348. {
  349. return "32497-06.htm";
  350. }
  351. return "32497-01.htm";
  352. case State.STARTED:
  353. if (st.getCond() > 1)
  354. {
  355. return "32497-00.htm";
  356. }
  357. return "32497-03.htm";
  358. case State.COMPLETED:
  359. return "32497-07.htm";
  360. default:
  361. return "32497-01.htm";
  362. }
  363. case SINAI:
  364. if (st.getCond() > 1)
  365. {
  366. return "32500-00.htm";
  367. }
  368. return "32500-01.htm";
  369. case INSPECTOR:
  370. switch (st.getCond())
  371. {
  372. case 1:
  373. return "32507-01.htm";
  374. case 2:
  375. return "32507-02.htm";
  376. case 3:
  377. return "32507-03.htm";
  378. case 4:
  379. case 5:
  380. return "32507-05.htm";
  381. case 6:
  382. return "32507-06.htm";
  383. default:
  384. return "32507-09.htm";
  385. }
  386. case ADLER2:
  387. if (st.isCompleted())
  388. {
  389. return "32510-00.htm";
  390. }
  391. else if (st.isCond(9))
  392. {
  393. return "32510-01.htm";
  394. }
  395. }
  396. return getNoQuestMsg(player);
  397. }
  398. @Override
  399. public final String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  400. {
  401. if (!npc.isDead())
  402. {
  403. npc.doDie(attacker);
  404. }
  405. return super.onAttack(npc, attacker, damage, isSummon);
  406. }
  407. @Override
  408. public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  409. {
  410. final QuestState st = player.getQuestState(getName());
  411. if ((st != null) && st.isStarted())
  412. {
  413. switch (npc.getId())
  414. {
  415. case HILLAS:
  416. if (st.isCond(2))
  417. {
  418. st.setCond(3);
  419. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  420. takeItems(player, BOOK1, -1);
  421. giveItems(player, BOOK2, 1);
  422. giveItems(player, WATER_ESSENCE, 1);
  423. }
  424. addSpawn(PAPION, -53903, 181484, -4555, 30456, false, 0, false, npc.getInstanceId());
  425. break;
  426. case PAPION:
  427. if (st.isCond(4))
  428. {
  429. st.setCond(5);
  430. takeItems(player, BOOK3, -1);
  431. giveItems(player, BOOK4, 1);
  432. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  433. }
  434. addSpawn(KINSUS, -61415, 181418, -4818, 63852, false, 0, false, npc.getInstanceId());
  435. break;
  436. case KINSUS:
  437. if (st.isCond(5))
  438. {
  439. st.setCond(6);
  440. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  441. takeItems(player, BOOK4, -1);
  442. giveItems(player, BOOK5, 1);
  443. giveItems(player, FIRE_ESSENCE, 1);
  444. }
  445. addSpawn(GARGOS, -61354, 183624, -4821, 63613, false, 0, false, npc.getInstanceId());
  446. break;
  447. case GARGOS:
  448. if (st.isCond(7))
  449. {
  450. st.setCond(8);
  451. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  452. takeItems(player, BOOK6, -1);
  453. giveItems(player, BOOK7, 1);
  454. }
  455. addSpawn(ADIANTUM, -53297, 185027, -4617, 1512, false, 0, false, npc.getInstanceId());
  456. break;
  457. case ADIANTUM:
  458. if (st.isCond(8))
  459. {
  460. st.setCond(9);
  461. playSound(player, QuestSound.ITEMSOUND_QUEST_MIDDLE);
  462. takeItems(player, BOOK7, -1);
  463. addSpawn(ADLER2, -53297, 185027, -4617, 33486, false, 0, false, npc.getInstanceId());
  464. }
  465. break;
  466. case BOTTLE:
  467. case BRAZIER:
  468. case BLOOM:
  469. dropItem(npc, player);
  470. break;
  471. default:
  472. // hardcoded herb drops
  473. dropHerb(npc, player, HP_HERBS_DROPLIST);
  474. dropHerb(npc, player, MP_HERBS_DROPLIST);
  475. break;
  476. }
  477. }
  478. return super.onKill(npc, player, isSummon);
  479. }
  480. @Override
  481. public String onExitZone(L2Character character, L2ZoneType zone)
  482. {
  483. if ((character instanceof L2PcInstance) && !character.isDead() && !character.isTeleporting() && ((L2PcInstance) character).isOnline())
  484. {
  485. InstanceWorld world = InstanceManager.getInstance().getWorld(character.getInstanceId());
  486. if ((world != null) && (world.getTemplateId() == INSTANCE_ID))
  487. {
  488. ThreadPoolManager.getInstance().scheduleGeneral(new Teleport(character, world.getInstanceId()), 1000);
  489. }
  490. }
  491. return super.onExitZone(character, zone);
  492. }
  493. @Override
  494. public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon)
  495. {
  496. if (!_seenCreature && creature.isPlayer())
  497. {
  498. _seenCreature = true;
  499. startQuestTimer("GARGOS_LAUGH", 1000, npc, creature.getActingPlayer());
  500. }
  501. return super.onSeeCreature(npc, creature, isSummon);
  502. }
  503. static final class Teleport implements Runnable
  504. {
  505. private final L2Character _char;
  506. private final int _instanceId;
  507. public Teleport(L2Character c, int id)
  508. {
  509. _char = c;
  510. _instanceId = id;
  511. }
  512. @Override
  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. private PailakaSongOfIceAndFire()
  526. {
  527. super(128, "128_PailakaSongOfIceAndFire", "Pailaka - Song of Ice and Fire");
  528. addStartNpc(ADLER1);
  529. addFirstTalkId(ADLER1, ADLER2, SINAI, INSPECTOR);
  530. addTalkId(ADLER1, ADLER2, SINAI, INSPECTOR);
  531. addAttackId(BOTTLE, BRAZIER);
  532. addKillId(MONSTERS);
  533. addExitZoneId(ZONE);
  534. addSeeCreatureId(GARGOS);
  535. registerQuestItems(ITEMS);
  536. }
  537. public static void main(String[] args)
  538. {
  539. new PailakaSongOfIceAndFire();
  540. }
  541. }