PailakaSongOfIceAndFire.java 14 KB

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