Q00367_ElectrifyingRecharge.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.Q00367_ElectrifyingRecharge;
  20. import com.l2jserver.gameserver.enums.QuestSound;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.holders.SkillHolder;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.QuestState;
  26. import com.l2jserver.gameserver.model.skills.Skill;
  27. /**
  28. * Electrifying Recharge! (367)
  29. * @author Adry_85, jurchiks
  30. */
  31. public final class Q00367_ElectrifyingRecharge extends Quest
  32. {
  33. // NPC
  34. private static final int LORAIN = 30673;
  35. // Monster
  36. private static final int CATHEROK = 21035;
  37. // Items
  38. private static final int TITAN_LAMP1 = 5875;
  39. private static final int TITAN_LAMP2 = 5876;
  40. private static final int TITAN_LAMP3 = 5877;
  41. private static final int TITAN_LAMP4 = 5878;
  42. private static final int TITAN_LAMP5 = 5879;
  43. private static final int BROKEN_TITAN_LAMP = 5880;
  44. // Misc
  45. private static final int MIN_LEVEL = 37;
  46. // Skill
  47. private static final Skill NPC_THUNDER_STORM = new SkillHolder(4072, 4).getSkill();
  48. public Q00367_ElectrifyingRecharge()
  49. {
  50. super(367, Q00367_ElectrifyingRecharge.class.getSimpleName(), "Electrifying Recharge!");
  51. addStartNpc(LORAIN);
  52. addTalkId(LORAIN);
  53. addAttackId(CATHEROK);
  54. registerQuestItems(TITAN_LAMP1, TITAN_LAMP2, TITAN_LAMP3, TITAN_LAMP4, TITAN_LAMP5, BROKEN_TITAN_LAMP);
  55. }
  56. @Override
  57. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  58. {
  59. final QuestState st = getQuestState(player, false);
  60. if (st == null)
  61. {
  62. return null;
  63. }
  64. String htmltext = null;
  65. switch (event)
  66. {
  67. case "30673-02.htm":
  68. {
  69. st.startQuest();
  70. giveItems(player, TITAN_LAMP1, 1);
  71. htmltext = event;
  72. break;
  73. }
  74. case "30673-05.html":
  75. {
  76. htmltext = event;
  77. break;
  78. }
  79. case "30673-06.html":
  80. {
  81. st.exitQuest(true, true);
  82. htmltext = event;
  83. break;
  84. }
  85. }
  86. return htmltext;
  87. }
  88. @Override
  89. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  90. {
  91. if (npc.isScriptValue(367))
  92. {
  93. return super.onAttack(npc, attacker, damage, isSummon);
  94. }
  95. QuestState qs = getQuestState(attacker, false);
  96. if ((qs == null) || !qs.isStarted())
  97. {
  98. return super.onAttack(npc, attacker, damage, isSummon);
  99. }
  100. npc.setScriptValue(367);
  101. if ((NPC_THUNDER_STORM != null) //
  102. && (NPC_THUNDER_STORM.getMpConsume() < npc.getCurrentMp()) // has enough MP
  103. && (NPC_THUNDER_STORM.getHpConsume() < npc.getCurrentHp()) // has enough HP
  104. && (npc.getSkillRemainingReuseTime(NPC_THUNDER_STORM.getReuseHashCode()) <= 0)) // no reuse delay
  105. {
  106. npc.doCast(NPC_THUNDER_STORM, attacker, null);
  107. }
  108. final L2PcInstance luckyPlayer = getRandomPartyMember(attacker, npc);
  109. if (luckyPlayer == null)
  110. {
  111. return super.onAttack(npc, attacker, damage, isSummon);
  112. }
  113. qs = getQuestState(luckyPlayer, false);
  114. if ((qs != null) && qs.isStarted() && !hasQuestItems(luckyPlayer, TITAN_LAMP5))
  115. {
  116. final int random = getRandom(37);
  117. if (random == 0)
  118. {
  119. if (hasQuestItems(luckyPlayer, TITAN_LAMP1))
  120. {
  121. giveItems(luckyPlayer, TITAN_LAMP2, 1);
  122. takeItems(luckyPlayer, TITAN_LAMP1, -1);
  123. playSound(luckyPlayer, QuestSound.ITEMSOUND_QUEST_MIDDLE);
  124. }
  125. else if (hasQuestItems(luckyPlayer, TITAN_LAMP2))
  126. {
  127. giveItems(luckyPlayer, TITAN_LAMP3, 1);
  128. takeItems(luckyPlayer, TITAN_LAMP2, -1);
  129. playSound(luckyPlayer, QuestSound.ITEMSOUND_QUEST_MIDDLE);
  130. }
  131. else if (hasQuestItems(luckyPlayer, TITAN_LAMP3))
  132. {
  133. giveItems(luckyPlayer, TITAN_LAMP4, 1);
  134. takeItems(luckyPlayer, TITAN_LAMP3, -1);
  135. playSound(luckyPlayer, QuestSound.ITEMSOUND_QUEST_MIDDLE);
  136. }
  137. else if (hasQuestItems(luckyPlayer, TITAN_LAMP4))
  138. {
  139. giveItems(luckyPlayer, TITAN_LAMP5, 1);
  140. takeItems(luckyPlayer, TITAN_LAMP4, -1);
  141. luckyPlayer.getQuestState(getName()).setCond(2, true);
  142. }
  143. }
  144. else if ((random == 1) && !hasQuestItems(luckyPlayer, BROKEN_TITAN_LAMP))
  145. {
  146. giveItems(luckyPlayer, BROKEN_TITAN_LAMP, 1);
  147. takeItems(luckyPlayer, -1, TITAN_LAMP1, TITAN_LAMP2, TITAN_LAMP3, TITAN_LAMP4);
  148. playSound(luckyPlayer, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  149. }
  150. }
  151. return super.onAttack(npc, attacker, damage, isSummon);
  152. }
  153. @Override
  154. public String onTalk(L2Npc npc, L2PcInstance player)
  155. {
  156. final QuestState st = getQuestState(player, true);
  157. String htmltext = getNoQuestMsg(player);
  158. if (st.isCreated())
  159. {
  160. htmltext = (player.getLevel() >= MIN_LEVEL) ? "30673-01.htm" : "30673-03.html";
  161. }
  162. else if (st.isStarted())
  163. {
  164. if (!hasAtLeastOneQuestItem(player, TITAN_LAMP5, BROKEN_TITAN_LAMP))
  165. {
  166. htmltext = "30673-04.html";
  167. }
  168. else if (hasQuestItems(player, BROKEN_TITAN_LAMP))
  169. {
  170. giveItems(player, TITAN_LAMP1, 1);
  171. takeItems(player, BROKEN_TITAN_LAMP, -1);
  172. htmltext = "30673-07.html";
  173. }
  174. else if (hasQuestItems(player, TITAN_LAMP5))
  175. {
  176. final int itemId;
  177. switch (getRandom(14))
  178. {
  179. case 0:
  180. {
  181. itemId = 4553; // Greater Dye of STR <Str+1 Con-1>
  182. break;
  183. }
  184. case 1:
  185. {
  186. itemId = 4554; // Greater Dye of STR <Str+1 Dex-1>
  187. break;
  188. }
  189. case 2:
  190. {
  191. itemId = 4555; // Greater Dye of CON <Con+1 Str-1>
  192. break;
  193. }
  194. case 3:
  195. {
  196. itemId = 4556; // Greater Dye of CON <Con+1 Dex-1>
  197. break;
  198. }
  199. case 4:
  200. {
  201. itemId = 4557; // Greater Dye of DEX <Dex+1 Str-1>
  202. break;
  203. }
  204. case 5:
  205. {
  206. itemId = 4558; // Greater Dye of DEX <Dex+1 Con-1>
  207. break;
  208. }
  209. case 6:
  210. {
  211. itemId = 4559; // Greater Dye of INT <Int+1 Men-1>
  212. break;
  213. }
  214. case 7:
  215. {
  216. itemId = 4560; // Greater Dye of INT <Int+1 Wit-1>
  217. break;
  218. }
  219. case 8:
  220. {
  221. itemId = 4561; // Greater Dye of MEN <Men+1 Int-1>
  222. break;
  223. }
  224. case 9:
  225. {
  226. itemId = 4562; // Greater Dye of MEN <Men+1 Wit-1>
  227. break;
  228. }
  229. case 10:
  230. {
  231. itemId = 4563; // Greater Dye of WIT <Wit+1 Int-1>
  232. break;
  233. }
  234. case 11:
  235. {
  236. itemId = 4564; // Greater Dye of WIT <Wit+1 Men-1>
  237. break;
  238. }
  239. default:
  240. {
  241. itemId = 4445; // Dye of STR <Str+1 Con-3>
  242. break;
  243. }
  244. }
  245. rewardItems(player, itemId, 1);
  246. takeItems(player, TITAN_LAMP5, -1);
  247. giveItems(player, TITAN_LAMP1, 1);
  248. htmltext = "30673-08.html";
  249. }
  250. }
  251. return htmltext;
  252. }
  253. }