Q00648_AnIceMerchantsDream.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * Copyright (C) 2004-2015 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 quests.Q00648_AnIceMerchantsDream;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import quests.Q00115_TheOtherSideOfTruth.Q00115_TheOtherSideOfTruth;
  23. import com.l2jserver.gameserver.enums.QuestSound;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.quest.Quest;
  27. import com.l2jserver.gameserver.model.quest.QuestState;
  28. /**
  29. * An Ice Merchant's Dream (648)
  30. * @author netvirus, Adry_85
  31. */
  32. public final class Q00648_AnIceMerchantsDream extends Quest
  33. {
  34. private static class DropInfo
  35. {
  36. private final double _firstChance;
  37. private final double _secondChance;
  38. public DropInfo(double firstChance, double secondChance)
  39. {
  40. _firstChance = firstChance;
  41. _secondChance = secondChance;
  42. }
  43. public double getFirstChance()
  44. {
  45. return _firstChance;
  46. }
  47. public double getSecondChance()
  48. {
  49. return _secondChance;
  50. }
  51. }
  52. // NPCs
  53. private static final int RAFFORTY = 32020;
  54. private static final int ICE_SHELF = 32023;
  55. // Items
  56. private static final int SILVER_HEMOCYTE = 8057;
  57. private static final int SILVER_ICE_CRYSTAL = 8077;
  58. private static final int BLACK_ICE_CRYSTAL = 8078;
  59. // Misc
  60. private static final int MIN_LVL = 53;
  61. // Monsters
  62. private static final Map<Integer, DropInfo> MONSTERS = new HashMap<>();
  63. static
  64. {
  65. MONSTERS.put(22080, new DropInfo(0.285, 0.048)); // Massive Maze Bandersnatch
  66. MONSTERS.put(22081, new DropInfo(0.443, 0.0)); // Lost Watcher
  67. MONSTERS.put(22082, new DropInfo(0.510, 0.0)); // Elder Lost Watcher
  68. MONSTERS.put(22083, new DropInfo(0.477, 0.049)); // Baby Panthera
  69. MONSTERS.put(22084, new DropInfo(0.477, 0.049)); // Panthera
  70. MONSTERS.put(22085, new DropInfo(0.420, 0.043)); // Lost Gargoyle
  71. MONSTERS.put(22086, new DropInfo(0.490, 0.050)); // Lost Gargoyle Youngling
  72. MONSTERS.put(22087, new DropInfo(0.787, 0.081)); // Pronghorn Spirit
  73. MONSTERS.put(22088, new DropInfo(0.480, 0.049)); // Pronghorn
  74. MONSTERS.put(22089, new DropInfo(0.550, 0.056)); // Ice Tarantula
  75. MONSTERS.put(22090, new DropInfo(0.570, 0.058)); // Frost Tarantula
  76. MONSTERS.put(22091, new DropInfo(0.623, 0.0)); // Lost Iron Golem
  77. MONSTERS.put(22092, new DropInfo(0.623, 0.0)); // Frost Iron Golem
  78. MONSTERS.put(22093, new DropInfo(0.910, 0.093)); // Lost Buffalo
  79. MONSTERS.put(22094, new DropInfo(0.553, 0.057)); // Frost Buffalo
  80. MONSTERS.put(22095, new DropInfo(0.593, 0.061)); // Ursus Cub
  81. MONSTERS.put(22096, new DropInfo(0.593, 0.061)); // Ursus
  82. MONSTERS.put(22097, new DropInfo(0.693, 0.071)); // Lost Yeti
  83. MONSTERS.put(22098, new DropInfo(0.717, 0.074)); // Frost Yeti
  84. }
  85. public Q00648_AnIceMerchantsDream()
  86. {
  87. super(648, Q00648_AnIceMerchantsDream.class.getSimpleName(), "An Ice Merchants Dream");
  88. addStartNpc(RAFFORTY);
  89. addTalkId(RAFFORTY, ICE_SHELF);
  90. addKillId(MONSTERS.keySet());
  91. registerQuestItems(SILVER_HEMOCYTE, SILVER_ICE_CRYSTAL, BLACK_ICE_CRYSTAL);
  92. }
  93. @Override
  94. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  95. {
  96. final QuestState st = getQuestState(player, false);
  97. final QuestState q115 = player.getQuestState(Q00115_TheOtherSideOfTruth.class.getSimpleName());
  98. if (st == null)
  99. {
  100. return null;
  101. }
  102. String htmltext = null;
  103. switch (event)
  104. {
  105. case "ACCEPT":
  106. {
  107. st.startQuest();
  108. if ((q115 != null) && (q115.isCompleted()))
  109. {
  110. htmltext = "32020-04.htm";
  111. }
  112. else
  113. {
  114. st.setCond(2);
  115. htmltext = "32020-05.htm";
  116. }
  117. break;
  118. }
  119. case "ASK":
  120. {
  121. if (st.getCond() >= 1)
  122. {
  123. htmltext = ((q115 != null) && !q115.isCompleted()) ? "32020-14.html" : "32020-15.html";
  124. }
  125. break;
  126. }
  127. case "LATER":
  128. {
  129. if (st.getCond() >= 1)
  130. {
  131. htmltext = ((q115 != null) && !q115.isCompleted()) ? "32020-19.html" : "32020-20.html";
  132. }
  133. break;
  134. }
  135. case "REWARD":
  136. {
  137. if (st.getCond() >= 1)
  138. {
  139. final long silverCryCount = getQuestItemsCount(player, SILVER_ICE_CRYSTAL);
  140. final long blackCryCount = getQuestItemsCount(player, BLACK_ICE_CRYSTAL);
  141. if ((silverCryCount + blackCryCount) > 0)
  142. {
  143. giveAdena(player, (silverCryCount * 300) + (blackCryCount * 1200), true);
  144. takeItems(player, -1, SILVER_ICE_CRYSTAL, BLACK_ICE_CRYSTAL);
  145. htmltext = ((q115 != null) && !q115.isCompleted()) ? "32020-16.html" : "32020-17.html";
  146. }
  147. else
  148. {
  149. htmltext = "32020-18.html";
  150. }
  151. }
  152. break;
  153. }
  154. case "QUIT":
  155. {
  156. if (st.getCond() >= 1)
  157. {
  158. if ((q115 != null) && !q115.isCompleted())
  159. {
  160. htmltext = "32020-21.html";
  161. st.exitQuest(true, true);
  162. }
  163. else
  164. {
  165. htmltext = "32020-22.html";
  166. }
  167. }
  168. break;
  169. }
  170. case "32020-06.html":
  171. case "32020-07.html":
  172. case "32020-08.html":
  173. case "32020-09.html":
  174. {
  175. if (st.getCond() >= 1)
  176. {
  177. htmltext = event;
  178. }
  179. break;
  180. }
  181. case "32020-23.html":
  182. {
  183. if (st.getCond() >= 1)
  184. {
  185. st.exitQuest(true, true);
  186. htmltext = event;
  187. }
  188. break;
  189. }
  190. case "32023-04.html":
  191. {
  192. if ((st.getCond() >= 1) && hasQuestItems(player, SILVER_ICE_CRYSTAL) && (st.getInt("ex") == 0))
  193. {
  194. st.set("ex", ((getRandom(4) + 1) * 10));
  195. htmltext = event;
  196. }
  197. break;
  198. }
  199. case "32023-05.html":
  200. {
  201. if ((st.getCond() >= 1) && hasQuestItems(player, SILVER_ICE_CRYSTAL) && (st.getInt("ex") > 0))
  202. {
  203. takeItems(player, SILVER_ICE_CRYSTAL, 1);
  204. int val = (st.getInt("ex") + 1);
  205. st.set("ex", val);
  206. playSound(player, QuestSound.ITEMSOUND_BROKEN_KEY);
  207. htmltext = event;
  208. }
  209. break;
  210. }
  211. case "32023-06.html":
  212. {
  213. if ((st.getCond() >= 1) && hasQuestItems(player, SILVER_ICE_CRYSTAL) && (st.getInt("ex") > 0))
  214. {
  215. takeItems(player, SILVER_ICE_CRYSTAL, 1);
  216. int val = (st.getInt("ex") + 2);
  217. st.set("ex", val);
  218. playSound(player, QuestSound.ITEMSOUND_BROKEN_KEY);
  219. htmltext = event;
  220. }
  221. break;
  222. }
  223. case "REPLY4":
  224. {
  225. if ((st.getCond() >= 1) && (st.getInt("ex") > 0))
  226. {
  227. int ex = st.getInt("ex");
  228. int val1 = ex / 10;
  229. int val2 = ex - (val1 * 10);
  230. if (val1 == val2)
  231. {
  232. htmltext = "32023-07.html";
  233. giveItems(player, BLACK_ICE_CRYSTAL, 1);
  234. playSound(player, QuestSound.ITEMSOUND_ENCHANT_SUCCESS);
  235. }
  236. else
  237. {
  238. htmltext = "32023-08.html";
  239. playSound(player, QuestSound.ITEMSOUND_ENCHANT_FAILED);
  240. }
  241. st.set("ex", 0);
  242. }
  243. break;
  244. }
  245. case "REPLY5":
  246. {
  247. if ((st.getCond() >= 1) && (st.getInt("ex") > 0))
  248. {
  249. int ex = st.getInt("ex");
  250. int val1 = ex / 10;
  251. int val2 = ((ex - (val1 * 10)) + 2);
  252. if (val1 == val2)
  253. {
  254. htmltext = "32023-07.html";
  255. giveItems(player, BLACK_ICE_CRYSTAL, 1);
  256. playSound(player, QuestSound.ITEMSOUND_ENCHANT_SUCCESS);
  257. }
  258. else
  259. {
  260. htmltext = "32023-08.html";
  261. playSound(player, QuestSound.ITEMSOUND_ENCHANT_FAILED);
  262. }
  263. st.set("ex", 0);
  264. }
  265. break;
  266. }
  267. }
  268. return htmltext;
  269. }
  270. @Override
  271. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  272. {
  273. final QuestState st = getRandomPartyMemberState(killer, -1, 3, npc);
  274. if (st != null)
  275. {
  276. final DropInfo info = MONSTERS.get(npc.getId());
  277. if (st.getCond() >= 1)
  278. {
  279. giveItemRandomly(st.getPlayer(), npc, SILVER_ICE_CRYSTAL, 1, 0, info.getFirstChance(), true);
  280. }
  281. if (info.getSecondChance() > 0)
  282. {
  283. final QuestState st2 = st.getPlayer().getQuestState(Q00115_TheOtherSideOfTruth.class.getSimpleName());
  284. if ((st.getCond() >= 2) && (st2 != null) && st2.isCompleted())
  285. {
  286. giveItemRandomly(st.getPlayer(), npc, SILVER_HEMOCYTE, 1, 0, info.getSecondChance(), true);
  287. }
  288. }
  289. }
  290. return super.onKill(npc, killer, isSummon);
  291. }
  292. @Override
  293. public String onTalk(L2Npc npc, L2PcInstance player)
  294. {
  295. final QuestState st = getQuestState(player, true);
  296. final QuestState st2 = player.getQuestState(Q00115_TheOtherSideOfTruth.class.getSimpleName());
  297. String htmltext = getNoQuestMsg(player);
  298. switch (npc.getId())
  299. {
  300. case RAFFORTY:
  301. {
  302. if (st.isCreated())
  303. {
  304. if (player.getLevel() < MIN_LVL)
  305. {
  306. htmltext = "32020-01.htm";
  307. }
  308. else
  309. {
  310. htmltext = ((st2 != null) && (st2.isCompleted())) ? "32020-02.htm" : "32020-03.htm";
  311. }
  312. }
  313. else if (st.isStarted())
  314. {
  315. final long hasQuestItems = getQuestItemsCount(player, SILVER_ICE_CRYSTAL, BLACK_ICE_CRYSTAL);
  316. if ((st2 != null) && st2.isCompleted())
  317. {
  318. htmltext = (hasQuestItems > 0) ? "32020-13.html" : "32020-11.html";
  319. if (st.isCond(1))
  320. {
  321. st.setCond(2, true);
  322. }
  323. }
  324. else
  325. {
  326. htmltext = (hasQuestItems > 0) ? "32020-12.html" : "32020-10.html";
  327. }
  328. }
  329. break;
  330. }
  331. case ICE_SHELF:
  332. {
  333. // TODO: In High Five this quest have an updated reward system.
  334. if (st.isStarted())
  335. {
  336. if (hasQuestItems(player, SILVER_ICE_CRYSTAL))
  337. {
  338. final int val = st.getInt("ex") % 10;
  339. if (val == 0)
  340. {
  341. htmltext = "32023-03.html";
  342. st.set("ex", 0);
  343. }
  344. else
  345. {
  346. htmltext = "32023-09.html";
  347. }
  348. }
  349. else
  350. {
  351. htmltext = "32023-02.html";
  352. }
  353. }
  354. else
  355. {
  356. htmltext = "32023-01.html";
  357. }
  358. break;
  359. }
  360. }
  361. return htmltext;
  362. }
  363. }