Q00308_ReedFieldMaintenance.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.Q00308_ReedFieldMaintenance;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import quests.Q00238_SuccessFailureOfBusiness.Q00238_SuccessFailureOfBusiness;
  23. import quests.Q00309_ForAGoodCause.Q00309_ForAGoodCause;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.enums.QuestSound;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.quest.Quest;
  29. import com.l2jserver.gameserver.model.quest.QuestState;
  30. import com.l2jserver.gameserver.network.serverpackets.RadarControl;
  31. import com.l2jserver.gameserver.util.Util;
  32. /**
  33. * Reed Field Maintenance (308)<br>
  34. * Original Jython script by Bloodshed.
  35. * @author Joxit
  36. */
  37. public class Q00308_ReedFieldMaintenance extends Quest
  38. {
  39. // NPC
  40. private static final int KATENSA = 32646;
  41. // Mobs
  42. private static final int AWAKENED_MUCROKIAN = 22655;
  43. private static final Map<Integer, Integer> MUCROKIAN = new HashMap<>();
  44. static
  45. {
  46. MUCROKIAN.put(22650, 218); // Mucrokian Fanatic
  47. MUCROKIAN.put(22651, 258); // Mucrokian Ascetic
  48. MUCROKIAN.put(22652, 248); // Mucrokian Savior
  49. MUCROKIAN.put(22653, 290); // Mucrokian Preacher
  50. MUCROKIAN.put(22654, 220); // Contaminated Mucrokian
  51. MUCROKIAN.put(22655, 124); // Awakened Mucrokian
  52. }
  53. // Items
  54. private static final int MUCROKIAN_HIDE = 14871;
  55. private static final int AWAKENED_MUCROKIAN_HIDE = 14872;
  56. // Rewards
  57. private static final int REC_DYNASTY_EARRINGS_70 = 9985;
  58. private static final int REC_DYNASTY_NECKLACE_70 = 9986;
  59. private static final int REC_DYNASTY_RING_70 = 9987;
  60. private static final int REC_DYNASTY_SIGIL_60 = 10115;
  61. private static final int[] MOIRAI_RECIPES =
  62. {
  63. 15777,
  64. 15780,
  65. 15783,
  66. 15786,
  67. 15789,
  68. 15790,
  69. 15814,
  70. 15813,
  71. 15812
  72. };
  73. private static final int[] MOIRAI_PIECES =
  74. {
  75. 15647,
  76. 15650,
  77. 15653,
  78. 15656,
  79. 15659,
  80. 15692,
  81. 15772,
  82. 15773,
  83. 15774
  84. };
  85. // Misc
  86. private static final int MIN_LEVEL = 82;
  87. public Q00308_ReedFieldMaintenance()
  88. {
  89. super(308, Q00308_ReedFieldMaintenance.class.getSimpleName(), "Reed Field Maintenance");
  90. addStartNpc(KATENSA);
  91. addTalkId(KATENSA);
  92. addKillId(MUCROKIAN.keySet());
  93. }
  94. private boolean canGiveItem(QuestState st, int quanty)
  95. {
  96. long mucrokian = st.getQuestItemsCount(MUCROKIAN_HIDE);
  97. long awakened = st.getQuestItemsCount(AWAKENED_MUCROKIAN_HIDE);
  98. if (awakened > 0)
  99. {
  100. if (awakened >= (quanty / 2))
  101. {
  102. st.takeItems(AWAKENED_MUCROKIAN_HIDE, (quanty / 2));
  103. return true;
  104. }
  105. else if (mucrokian >= (quanty - (awakened * 2)))
  106. {
  107. st.takeItems(AWAKENED_MUCROKIAN_HIDE, awakened);
  108. st.takeItems(MUCROKIAN_HIDE, (quanty - (awakened * 2)));
  109. return true;
  110. }
  111. }
  112. else if (mucrokian >= quanty)
  113. {
  114. st.takeItems(MUCROKIAN_HIDE, quanty);
  115. return true;
  116. }
  117. return false;
  118. }
  119. @Override
  120. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  121. {
  122. final QuestState st = getQuestState(player, false);
  123. if (st == null)
  124. {
  125. return null;
  126. }
  127. String htmltext = null;
  128. switch (event)
  129. {
  130. case "32646-02.htm":
  131. case "32646-03.htm":
  132. case "32646-06.html":
  133. case "32646-07.html":
  134. case "32646-08.html":
  135. case "32646-10.html":
  136. htmltext = event;
  137. break;
  138. case "32646-04.html":
  139. st.startQuest();
  140. player.sendPacket(new RadarControl(0, 2, 77325, 205773, -3432));
  141. htmltext = event;
  142. break;
  143. case "claimreward":
  144. final QuestState q238 = player.getQuestState(Q00238_SuccessFailureOfBusiness.class.getName());
  145. htmltext = ((q238 != null) && q238.isCompleted()) ? "32646-09.html" : "32646-12.html";
  146. break;
  147. case "100":
  148. case "120":
  149. htmltext = onItemExchangeRequest(st, MOIRAI_PIECES[getRandom(MOIRAI_PIECES.length - 1)], Integer.parseInt(event));
  150. break;
  151. case "192":
  152. case "230":
  153. htmltext = onItemExchangeRequest(st, REC_DYNASTY_EARRINGS_70, Integer.parseInt(event));
  154. break;
  155. case "256":
  156. case "308":
  157. htmltext = onItemExchangeRequest(st, REC_DYNASTY_NECKLACE_70, Integer.parseInt(event));
  158. break;
  159. case "128":
  160. case "154":
  161. htmltext = onItemExchangeRequest(st, REC_DYNASTY_RING_70, Integer.parseInt(event));
  162. break;
  163. case "206":
  164. case "246":
  165. htmltext = onItemExchangeRequest(st, REC_DYNASTY_SIGIL_60, Integer.parseInt(event));
  166. break;
  167. case "180":
  168. case "216":
  169. htmltext = onItemExchangeRequest(st, MOIRAI_RECIPES[getRandom(MOIRAI_RECIPES.length - 1)], Integer.parseInt(event));
  170. break;
  171. case "32646-11.html":
  172. st.exitQuest(true, true);
  173. htmltext = event;
  174. break;
  175. }
  176. return htmltext;
  177. }
  178. private String onItemExchangeRequest(QuestState st, int item, int quanty)
  179. {
  180. String htmltext;
  181. if (canGiveItem(st, quanty))
  182. {
  183. if (Util.contains(MOIRAI_PIECES, item))
  184. {
  185. st.giveItems(item, getRandom(1, 4));
  186. }
  187. else
  188. {
  189. st.giveItems(item, 1);
  190. }
  191. st.playSound(QuestSound.ITEMSOUND_QUEST_FINISH);
  192. htmltext = "32646-14.html";
  193. }
  194. else
  195. {
  196. htmltext = "32646-13.html";
  197. }
  198. return htmltext;
  199. }
  200. @Override
  201. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  202. {
  203. final L2PcInstance partyMember = getRandomPartyMember(killer, 1);
  204. if (partyMember != null)
  205. {
  206. final QuestState st = getQuestState(partyMember, false);
  207. float chance = (MUCROKIAN.get(npc.getId()) * Config.RATE_QUEST_DROP);
  208. if (getRandom(1000) < chance)
  209. {
  210. if (npc.getId() == AWAKENED_MUCROKIAN)
  211. {
  212. st.giveItems(AWAKENED_MUCROKIAN_HIDE, 1);
  213. }
  214. else
  215. {
  216. st.giveItems(MUCROKIAN_HIDE, 1);
  217. }
  218. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  219. }
  220. }
  221. return super.onKill(npc, killer, isSummon);
  222. }
  223. @Override
  224. public String onTalk(L2Npc npc, L2PcInstance talker)
  225. {
  226. String htmltext = getNoQuestMsg(talker);
  227. final QuestState st = getQuestState(talker, true);
  228. if (st == null)
  229. {
  230. return htmltext;
  231. }
  232. final QuestState q309 = talker.getQuestState(Q00309_ForAGoodCause.class.getSimpleName());
  233. if ((q309 != null) && q309.isStarted())
  234. {
  235. htmltext = "32646-15.html";
  236. }
  237. else if (st.isStarted())
  238. {
  239. htmltext = (st.hasQuestItems(MUCROKIAN_HIDE) || st.hasQuestItems(AWAKENED_MUCROKIAN_HIDE)) ? "32646-06.html" : "32646-05.html";
  240. }
  241. else
  242. {
  243. htmltext = (talker.getLevel() >= MIN_LEVEL) ? "32646-01.htm" : "32646-00.html";
  244. }
  245. return htmltext;
  246. }
  247. }