PailakaSongOfIceAndFire.java 13 KB

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