Q00371_ShrieksOfGhosts.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.Q00371_ShrieksOfGhosts;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.QuestState;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * Shrieks of Ghosts (371)
  29. * @author Adry_85
  30. */
  31. public final class Q00371_ShrieksOfGhosts extends Quest
  32. {
  33. private static final class DropInfo
  34. {
  35. public final int _firstChance;
  36. public final int _secondChance;
  37. public DropInfo(int firstChance, int secondChance)
  38. {
  39. _firstChance = firstChance;
  40. _secondChance = secondChance;
  41. }
  42. public int getFirstChance()
  43. {
  44. return _firstChance;
  45. }
  46. public int getSecondChance()
  47. {
  48. return _secondChance;
  49. }
  50. }
  51. // NPCs
  52. private static final int REVA = 30867;
  53. private static final int PATRIN = 30929;
  54. // Items
  55. private static final int ANCIENT_ASH_URN = 5903;
  56. private static final int ANCIENT_PORCELAIN = 6002;
  57. private static final int ANCIENT_PORCELAIN_EXCELLENT = 6003;
  58. private static final int ANCIENT_PORCELAIN_HIGH_QUALITY = 6004;
  59. private static final int ANCIENT_PORCELAIN_LOW_QUALITY = 6005;
  60. private static final int ANCIENT_PORCELAIN_LOWEST_QUALITY = 6006;
  61. // Misc
  62. private static final int MIN_LEVEL = 59;
  63. private static final Map<Integer, DropInfo> MOBS = new HashMap<>();
  64. static
  65. {
  66. MOBS.put(20818, new DropInfo(350, 400)); // hallates_warrior
  67. MOBS.put(20820, new DropInfo(583, 673)); // hallates_knight
  68. MOBS.put(20824, new DropInfo(458, 538)); // hallates_commander
  69. }
  70. public Q00371_ShrieksOfGhosts()
  71. {
  72. super(371, Q00371_ShrieksOfGhosts.class.getSimpleName(), "Shrieks of Ghosts");
  73. addStartNpc(REVA);
  74. addTalkId(REVA, PATRIN);
  75. addKillId(MOBS.keySet());
  76. registerQuestItems(ANCIENT_ASH_URN);
  77. }
  78. @Override
  79. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  80. {
  81. final QuestState qs = getQuestState(player, false);
  82. if (qs == null)
  83. {
  84. return null;
  85. }
  86. String htmltext = null;
  87. switch (event)
  88. {
  89. case "30867-02.htm":
  90. {
  91. qs.startQuest();
  92. htmltext = event;
  93. break;
  94. }
  95. case "30867-05.html":
  96. {
  97. final long ancientAshUrnCount = getQuestItemsCount(player, ANCIENT_ASH_URN);
  98. if (ancientAshUrnCount < 1)
  99. {
  100. htmltext = event;
  101. }
  102. else if (ancientAshUrnCount < 100)
  103. {
  104. giveAdena(player, (ancientAshUrnCount * 1000) + 15000, true);
  105. takeItems(player, ANCIENT_ASH_URN, -1);
  106. htmltext = "30867-06.html";
  107. }
  108. else
  109. {
  110. giveAdena(player, (ancientAshUrnCount * 1000) + 37700, true);
  111. takeItems(player, ANCIENT_ASH_URN, -1);
  112. htmltext = "30867-07.html";
  113. }
  114. break;
  115. }
  116. case "30867-08.html":
  117. case "30929-01.html":
  118. case "30929-02.html":
  119. {
  120. htmltext = event;
  121. break;
  122. }
  123. case "30867-09.html":
  124. {
  125. giveAdena(player, getQuestItemsCount(player, ANCIENT_ASH_URN) * 1000, true);
  126. qs.exitQuest(true, true);
  127. htmltext = "30867-09.html";
  128. break;
  129. }
  130. case "30929-03.html":
  131. {
  132. if (!hasQuestItems(player, ANCIENT_PORCELAIN))
  133. {
  134. htmltext = event;
  135. }
  136. else
  137. {
  138. final int random = getRandom(100);
  139. if (random < 2)
  140. {
  141. giveItems(player, ANCIENT_PORCELAIN_EXCELLENT, 1);
  142. htmltext = "30929-04.html";
  143. }
  144. else if (random < 32)
  145. {
  146. giveItems(player, ANCIENT_PORCELAIN_HIGH_QUALITY, 1);
  147. htmltext = "30929-05.html";
  148. }
  149. else if (random < 62)
  150. {
  151. giveItems(player, ANCIENT_PORCELAIN_LOW_QUALITY, 1);
  152. htmltext = "30929-06.html";
  153. }
  154. else if (random < 77)
  155. {
  156. giveItems(player, ANCIENT_PORCELAIN_LOWEST_QUALITY, 1);
  157. htmltext = "30929-07.html";
  158. }
  159. else
  160. {
  161. htmltext = "30929-08.html";
  162. }
  163. takeItems(player, ANCIENT_PORCELAIN, 1);
  164. }
  165. break;
  166. }
  167. }
  168. return htmltext;
  169. }
  170. @Override
  171. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  172. {
  173. final QuestState qs = getQuestState(killer, false);
  174. if ((qs == null) || !Util.checkIfInRange(1500, npc, killer, true))
  175. {
  176. return null;
  177. }
  178. final DropInfo info = MOBS.get(npc.getId());
  179. final int random = getRandom(1000);
  180. if (random < info.getFirstChance())
  181. {
  182. qs.giveItemRandomly(npc, ANCIENT_ASH_URN, 1, 0, 1.0, true);
  183. }
  184. else if (random < info.getSecondChance())
  185. {
  186. qs.giveItemRandomly(npc, ANCIENT_PORCELAIN, 1, 0, 1.0, true);
  187. }
  188. return super.onKill(npc, killer, isSummon);
  189. }
  190. @Override
  191. public String onTalk(L2Npc npc, L2PcInstance player)
  192. {
  193. QuestState qs = getQuestState(player, true);
  194. String htmltext = getNoQuestMsg(player);
  195. if (qs.isCreated())
  196. {
  197. htmltext = (player.getLevel() >= MIN_LEVEL) ? "30867-01.htm" : "30867-03.htm";
  198. }
  199. else if (qs.isStarted())
  200. {
  201. if (npc.getId() == REVA)
  202. {
  203. htmltext = (hasQuestItems(player, ANCIENT_PORCELAIN)) ? "30867-04.html" : "30867-10.html";
  204. }
  205. else
  206. {
  207. htmltext = "30929-01.html";
  208. }
  209. }
  210. return htmltext;
  211. }
  212. }