PailakaSongOfIceAndFire.java 13 KB

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