Q00610_MagicalPowerOfWaterPart2.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.Q00610_MagicalPowerOfWaterPart2;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.quest.Quest;
  24. import com.l2jserver.gameserver.model.quest.QuestState;
  25. import com.l2jserver.gameserver.model.quest.State;
  26. import com.l2jserver.gameserver.network.NpcStringId;
  27. import com.l2jserver.gameserver.network.clientpackets.Say2;
  28. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  29. import com.l2jserver.gameserver.util.Util;
  30. /**
  31. * Magical Power of Water - Part 2 (610)
  32. * @author Joxit
  33. */
  34. public class Q00610_MagicalPowerOfWaterPart2 extends Quest
  35. {
  36. // NPCs
  37. private static final int ASEFA = 31372;
  38. private static final int VARKA_TOTEM = 31560;
  39. // Monster
  40. private static final int ASHUTAR = 25316;
  41. // Items
  42. private static final int GREEN_TOTEM = 7238;
  43. private static final int ASHUTAR_HEART = 7239;
  44. // Misc
  45. private static final int MIN_LEVEL = 75;
  46. public Q00610_MagicalPowerOfWaterPart2()
  47. {
  48. super(610, Q00610_MagicalPowerOfWaterPart2.class.getSimpleName(), "Magical Power of Water - Part 2");
  49. addStartNpc(ASEFA);
  50. addTalkId(ASEFA, VARKA_TOTEM);
  51. addKillId(ASHUTAR);
  52. registerQuestItems(GREEN_TOTEM, ASHUTAR_HEART);
  53. final String test = loadGlobalQuestVar("Q00610_respawn");
  54. final long remain = (!test.isEmpty()) ? (Long.parseLong(test) - System.currentTimeMillis()) : 0;
  55. if (remain > 0)
  56. {
  57. startQuestTimer("spawn_npc", remain, null, null);
  58. }
  59. else
  60. {
  61. addSpawn(VARKA_TOTEM, 105452, -36775, -1050, 34000, false, 0, true);
  62. }
  63. }
  64. @Override
  65. public void actionForEachPlayer(L2PcInstance player, L2Npc npc, boolean isSummon)
  66. {
  67. final QuestState st = getQuestState(player, false);
  68. if ((st != null) && Util.checkIfInRange(1500, npc, player, false))
  69. {
  70. if (npc.getId() == ASHUTAR)
  71. {
  72. switch (st.getCond())
  73. {
  74. case 1: // take the item and give the heart
  75. st.takeItems(GREEN_TOTEM, 1);
  76. case 2:
  77. if (!st.hasQuestItems(ASHUTAR_HEART))
  78. {
  79. st.giveItems(ASHUTAR_HEART, 1);
  80. }
  81. st.setCond(3, true);
  82. break;
  83. }
  84. }
  85. }
  86. }
  87. @Override
  88. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  89. {
  90. String htmltext = null;
  91. if (player != null)
  92. {
  93. final QuestState st = getQuestState(player, false);
  94. if (st == null)
  95. {
  96. return null;
  97. }
  98. switch (event)
  99. {
  100. case "31372-02.html":
  101. st.startQuest();
  102. htmltext = event;
  103. break;
  104. case "give_heart":
  105. if (st.hasQuestItems(ASHUTAR_HEART))
  106. {
  107. st.addExpAndSp(10000, 0);
  108. st.exitQuest(true, true);
  109. htmltext = "31372-06.html";
  110. }
  111. else
  112. {
  113. htmltext = "31372-07.html";
  114. }
  115. break;
  116. case "spawn_totem":
  117. htmltext = (st.hasQuestItems(GREEN_TOTEM)) ? spawnAshutar(npc, st) : "31560-04.html";
  118. break;
  119. }
  120. }
  121. else
  122. {
  123. if (event.equals("despawn_ashutar"))
  124. {
  125. npc.broadcastPacket(new NpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_POWER_OF_CONSTRAINT_IS_GETTING_WEAKER_YOUR_RITUAL_HAS_FAILED));
  126. npc.deleteMe();
  127. addSpawn(VARKA_TOTEM, 105452, -36775, -1050, 34000, false, 0, true);
  128. }
  129. else if (event.equals("spawn_npc"))
  130. {
  131. addSpawn(VARKA_TOTEM, 105452, -36775, -1050, 34000, false, 0, true);
  132. }
  133. }
  134. return htmltext;
  135. }
  136. @Override
  137. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  138. {
  139. final int respawnMinDelay = (int) (43200000 * Config.RAID_MIN_RESPAWN_MULTIPLIER);
  140. final int respawnMaxDelay = (int) (129600000 * Config.RAID_MAX_RESPAWN_MULTIPLIER);
  141. final int respawnDelay = getRandom(respawnMinDelay, respawnMaxDelay);
  142. cancelQuestTimer("despawn_ashutar", npc, null);
  143. saveGlobalQuestVar("Q00610_respawn", String.valueOf(System.currentTimeMillis() + respawnDelay));
  144. startQuestTimer("spawn_npc", respawnDelay, null, null);
  145. executeForEachPlayer(killer, npc, isSummon, true, false);
  146. return super.onKill(npc, killer, isSummon);
  147. }
  148. @Override
  149. public String onTalk(L2Npc npc, L2PcInstance player)
  150. {
  151. String htmltext = getNoQuestMsg(player);
  152. final QuestState st = getQuestState(player, true);
  153. if (st == null)
  154. {
  155. return htmltext;
  156. }
  157. switch (npc.getId())
  158. {
  159. case ASEFA:
  160. switch (st.getState())
  161. {
  162. case State.CREATED:
  163. htmltext = (player.getLevel() >= MIN_LEVEL) ? (st.hasQuestItems(GREEN_TOTEM)) ? "31372-01.htm" : "31372-00a.html" : "31372-00b.html";
  164. break;
  165. case State.STARTED:
  166. htmltext = (st.isCond(1)) ? "31372-03.html" : (st.hasQuestItems(ASHUTAR_HEART)) ? "31372-04.html" : "31372-05.html";
  167. break;
  168. }
  169. break;
  170. case VARKA_TOTEM:
  171. if (st.isStarted())
  172. {
  173. switch (st.getCond())
  174. {
  175. case 1:
  176. htmltext = "31560-01.html";
  177. break;
  178. case 2:
  179. htmltext = spawnAshutar(npc, st);
  180. break;
  181. case 3:
  182. htmltext = "31560-05.html";
  183. break;
  184. }
  185. }
  186. break;
  187. }
  188. return htmltext;
  189. }
  190. private String spawnAshutar(L2Npc npc, QuestState st)
  191. {
  192. if (getQuestTimer("spawn_npc", null, null) != null)
  193. {
  194. return "31560-03.html";
  195. }
  196. if (st.isCond(1))
  197. {
  198. st.takeItems(GREEN_TOTEM, 1);
  199. st.setCond(2, true);
  200. }
  201. npc.deleteMe();
  202. final L2Npc ashutar = addSpawn(ASHUTAR, 104825, -36926, -1136, 0, false, 0);
  203. ashutar.broadcastPacket(new NpcSay(ashutar, Say2.NPC_ALL, NpcStringId.THE_MAGICAL_POWER_OF_WATER_COMES_FROM_THE_POWER_OF_STORM_AND_HAIL_IF_YOU_DARE_TO_CONFRONT_IT_ONLY_DEATH_WILL_AWAIT_YOU));
  204. startQuestTimer("despawn_ashutar", 1200000, ashutar, null);
  205. return "31560-02.html";
  206. }
  207. }