Q00616_MagicalPowerOfFirePart2.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.Q00616_MagicalPowerOfFirePart2;
  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 Fire - Part 2 (616)
  32. * @author Joxit
  33. */
  34. public class Q00616_MagicalPowerOfFirePart2 extends Quest
  35. {
  36. // NPCs
  37. private static final int UDAN = 31379;
  38. private static final int KETRA_TOTEM = 31558;
  39. // Monster
  40. private static final int NASTRON = 25306;
  41. // Items
  42. private static final int RED_TOTEM = 7243;
  43. private static final int NASTRON_HEART = 7244;
  44. // Misc
  45. private static final int MIN_LEVEL = 75;
  46. public Q00616_MagicalPowerOfFirePart2()
  47. {
  48. super(616, Q00616_MagicalPowerOfFirePart2.class.getSimpleName(), "Magical Power of Fire - Part 2");
  49. addStartNpc(UDAN);
  50. addTalkId(UDAN, KETRA_TOTEM);
  51. addKillId(NASTRON);
  52. registerQuestItems(RED_TOTEM, NASTRON_HEART);
  53. final String test = loadGlobalQuestVar("Q00616_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(KETRA_TOTEM, 142368, -82512, -6487, 58000, 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() == NASTRON)
  71. {
  72. switch (st.getCond())
  73. {
  74. case 1: // take the item and give the heart
  75. st.takeItems(RED_TOTEM, 1);
  76. case 2:
  77. if (!st.hasQuestItems(NASTRON_HEART))
  78. {
  79. st.giveItems(NASTRON_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 "31379-02.html":
  101. st.startQuest();
  102. htmltext = event;
  103. break;
  104. case "give_heart":
  105. if (st.hasQuestItems(NASTRON_HEART))
  106. {
  107. st.addExpAndSp(10000, 0);
  108. st.exitQuest(true, true);
  109. htmltext = "31379-06.html";
  110. }
  111. else
  112. {
  113. htmltext = "31379-07.html";
  114. }
  115. break;
  116. case "spawn_totem":
  117. htmltext = (st.hasQuestItems(RED_TOTEM)) ? spawnNastron(npc, st) : "31558-04.html";
  118. break;
  119. }
  120. }
  121. else
  122. {
  123. if (event.equals("despawn_nastron"))
  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(KETRA_TOTEM, 142368, -82512, -6487, 58000, false, 0, true);
  128. }
  129. else if (event.equals("spawn_npc"))
  130. {
  131. addSpawn(KETRA_TOTEM, 142368, -82512, -6487, 58000, 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_nastron", npc, null);
  143. saveGlobalQuestVar("Q00616_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 UDAN:
  160. switch (st.getState())
  161. {
  162. case State.CREATED:
  163. htmltext = (player.getLevel() >= MIN_LEVEL) ? (st.hasQuestItems(RED_TOTEM)) ? "31379-01.htm" : "31379-00a.html" : "31379-00b.html";
  164. break;
  165. case State.STARTED:
  166. htmltext = (st.isCond(1)) ? "31379-03.html" : (st.hasQuestItems(NASTRON_HEART)) ? "31379-04.html" : "31379-05.html";
  167. break;
  168. }
  169. break;
  170. case KETRA_TOTEM:
  171. if (st.isStarted())
  172. {
  173. switch (st.getCond())
  174. {
  175. case 1:
  176. htmltext = "31558-01.html";
  177. break;
  178. case 2:
  179. htmltext = spawnNastron(npc, st);
  180. break;
  181. case 3:
  182. htmltext = "31558-05.html";
  183. break;
  184. }
  185. }
  186. break;
  187. }
  188. return htmltext;
  189. }
  190. private String spawnNastron(L2Npc npc, QuestState st)
  191. {
  192. if (getQuestTimer("spawn_npc", null, null) != null)
  193. {
  194. return "31558-03.html";
  195. }
  196. if (st.isCond(1))
  197. {
  198. st.takeItems(RED_TOTEM, 1);
  199. st.setCond(2, true);
  200. }
  201. npc.deleteMe();
  202. final L2Npc nastron = addSpawn(NASTRON, 142528, -82528, -6496, 0, false, 0);
  203. nastron.broadcastPacket(new NpcSay(nastron, Say2.NPC_ALL, NpcStringId.THE_MAGICAL_POWER_OF_FIRE_IS_ALSO_THE_POWER_OF_FLAMES_AND_LAVA_IF_YOU_DARE_TO_CONFRONT_IT_ONLY_DEATH_WILL_AWAIT_YOU));
  204. startQuestTimer("despawn_nastron", 1200000, nastron, null);
  205. return "31558-02.html";
  206. }
  207. }