Q00365_DevilsLegacy.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.Q00365_DevilsLegacy;
  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.holders.SkillHolder;
  25. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  26. import com.l2jserver.gameserver.model.quest.Quest;
  27. import com.l2jserver.gameserver.model.quest.QuestState;
  28. /**
  29. * Devil's Legacy (365)
  30. * @author Adry_85
  31. */
  32. public final class Q00365_DevilsLegacy extends Quest
  33. {
  34. // NPCs
  35. private static final int COLLOB = 30092;
  36. private static final int RANDOLF = 30095;
  37. // Item
  38. private static final int PIRATES_TREASURE_CHEST = 5873;
  39. // Rewards
  40. private static final int ENCHANT_WEAPON_C = 951;
  41. private static final int ENCHANT_ARMOR_C = 952;
  42. private static final int ENCHANT_WEAPON_D = 955;
  43. private static final int ENCHANT_ARMOR_D = 956;
  44. private static final int THREAD = 1868;
  45. private static final int ANIMAL_BONE = 1872;
  46. private static final int COKES = 1879;
  47. private static final int STEEL = 1880;
  48. private static final int COARSE_BONE_POWDER = 1881;
  49. private static final int LEATHER = 1882;
  50. private static final int CORD = 1884;
  51. // Misc
  52. private static final int MIN_LEVEL = 39;
  53. // Skill
  54. private static SkillHolder POISON = new SkillHolder(4035, 2);
  55. // Mobs
  56. private static final Map<Integer, Double> MOBS = new HashMap<>();
  57. static
  58. {
  59. MOBS.put(20836, 0.47); // pirates_zombie
  60. MOBS.put(20845, 0.40); // pirates_zombie_captain
  61. MOBS.put(21629, 0.40); // pirates_zombie_captain_1
  62. MOBS.put(21630, 0.40); // pirates_zombie_captain_2
  63. }
  64. public Q00365_DevilsLegacy()
  65. {
  66. super(365, Q00365_DevilsLegacy.class.getSimpleName(), "Devil's Legacy");
  67. addStartNpc(RANDOLF);
  68. addTalkId(RANDOLF, COLLOB);
  69. addKillId(MOBS.keySet());
  70. registerQuestItems(PIRATES_TREASURE_CHEST);
  71. }
  72. @Override
  73. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  74. {
  75. final QuestState qs = getQuestState(player, false);
  76. String htmltext = null;
  77. if (qs == null)
  78. {
  79. return htmltext;
  80. }
  81. switch (event)
  82. {
  83. case "30095-02.htm":
  84. {
  85. qs.startQuest();
  86. qs.setMemoState(1);
  87. htmltext = event;
  88. break;
  89. }
  90. case "30095-05.html":
  91. {
  92. qs.exitQuest(true, true);
  93. htmltext = event;
  94. break;
  95. }
  96. case "30095-06.html":
  97. {
  98. htmltext = event;
  99. break;
  100. }
  101. case "REWARD":
  102. {
  103. if (!qs.isMemoState(1))
  104. {
  105. htmltext = "30092-04.html";
  106. }
  107. else if (!hasQuestItems(player, PIRATES_TREASURE_CHEST))
  108. {
  109. htmltext = "30092-02.html";
  110. }
  111. else if (player.getAdena() < 600)
  112. {
  113. htmltext = "30092-03.html";
  114. }
  115. else
  116. {
  117. final int itemId;
  118. final int chance;
  119. if (getRandom(100) < 80)
  120. {
  121. chance = getRandom(100);
  122. if (chance < 1)
  123. {
  124. itemId = ENCHANT_WEAPON_D;
  125. }
  126. else if (chance < 4)
  127. {
  128. itemId = ENCHANT_ARMOR_D;
  129. }
  130. else if (chance < 36)
  131. {
  132. itemId = THREAD;
  133. }
  134. else if (chance < 68)
  135. {
  136. itemId = CORD;
  137. }
  138. else
  139. {
  140. itemId = ANIMAL_BONE;
  141. }
  142. htmltext = "30092-05.html";
  143. }
  144. else
  145. {
  146. chance = getRandom(1000);
  147. if (chance < 10)
  148. {
  149. itemId = ENCHANT_WEAPON_C;
  150. }
  151. else if (chance < 40)
  152. {
  153. itemId = ENCHANT_ARMOR_C;
  154. }
  155. else if (chance < 60)
  156. {
  157. itemId = ENCHANT_WEAPON_D;
  158. }
  159. else if (chance < 260)
  160. {
  161. itemId = ENCHANT_ARMOR_D;
  162. }
  163. else if (chance < 445)
  164. {
  165. itemId = COKES;
  166. }
  167. else if (chance < 630)
  168. {
  169. itemId = STEEL;
  170. }
  171. else if (chance < 815)
  172. {
  173. itemId = LEATHER;
  174. }
  175. else
  176. {
  177. itemId = COARSE_BONE_POWDER;
  178. }
  179. npc.setTarget(player);
  180. npc.doCast(POISON.getSkill());
  181. npc.setCurrentMp(npc.getMaxMp());
  182. qs.setMemoState(2);
  183. htmltext = "30092-06.html";
  184. }
  185. takeItems(player, PIRATES_TREASURE_CHEST, 1);
  186. takeItems(player, Inventory.ADENA_ID, 600);
  187. rewardItems(player, itemId, 1);
  188. }
  189. break;
  190. }
  191. }
  192. return htmltext;
  193. }
  194. @Override
  195. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  196. {
  197. final QuestState qs = getRandomPartyMemberState(player, -1, 3, npc);
  198. if (qs != null)
  199. {
  200. giveItemRandomly(qs.getPlayer(), npc, PIRATES_TREASURE_CHEST, 1, 0, MOBS.get(npc.getId()), true);
  201. }
  202. return super.onKill(npc, player, isSummon);
  203. }
  204. @Override
  205. public String onTalk(L2Npc npc, L2PcInstance player)
  206. {
  207. QuestState qs = getQuestState(player, true);
  208. String htmltext = getNoQuestMsg(player);
  209. if (qs == null)
  210. {
  211. return htmltext;
  212. }
  213. switch (npc.getId())
  214. {
  215. case RANDOLF:
  216. {
  217. if (qs.isCreated())
  218. {
  219. htmltext = ((player.getLevel() >= MIN_LEVEL) ? "30095-01.htm" : "30095-03.html");
  220. }
  221. else if (qs.isStarted())
  222. {
  223. if (hasQuestItems(player, PIRATES_TREASURE_CHEST))
  224. {
  225. final long chestCount = getQuestItemsCount(player, PIRATES_TREASURE_CHEST);
  226. giveAdena(player, (chestCount * 400) + 19800, true);
  227. takeItems(player, PIRATES_TREASURE_CHEST, -1);
  228. htmltext = "30095-04.html";
  229. }
  230. else
  231. {
  232. htmltext = "30095-07.html";
  233. }
  234. }
  235. break;
  236. }
  237. case COLLOB:
  238. {
  239. if (qs.isStarted())
  240. {
  241. htmltext = (qs.isMemoState(1) ? "30092-01.html" : "30092-07.html");
  242. }
  243. break;
  244. }
  245. }
  246. return htmltext;
  247. }
  248. }