Q00650_ABrokenDream.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.Q00650_ABrokenDream;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import quests.Q00117_TheOceanOfDistantStars.Q00117_TheOceanOfDistantStars;
  25. import com.l2jserver.gameserver.enums.QuestSound;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.quest.Quest;
  29. import com.l2jserver.gameserver.model.quest.QuestState;
  30. import com.l2jserver.gameserver.model.quest.State;
  31. import com.l2jserver.gameserver.util.Util;
  32. /**
  33. * A Broken Dream (650)
  34. * @author netvirus
  35. */
  36. public final class Q00650_ABrokenDream extends Quest
  37. {
  38. // Npc
  39. private static final int GHOST_OF_A_RAILROAD_ENGINEER = 32054;
  40. // Item
  41. private static final int REMNANTS_OF_OLD_DWARVES_DREAMS = 8514;
  42. // Misc
  43. private static final int MIN_LVL = 39;
  44. // Monsters
  45. private static final Map<Integer, Integer> MONSTER_DROP_CHANCES = new HashMap<>();
  46. static
  47. {
  48. MONSTER_DROP_CHANCES.put(22027, 575); // Forgotten Crewman
  49. MONSTER_DROP_CHANCES.put(22028, 515); // Vagabond of the Ruins
  50. }
  51. public Q00650_ABrokenDream()
  52. {
  53. super(650, Q00650_ABrokenDream.class.getSimpleName(), "A Broken Dream");
  54. addStartNpc(GHOST_OF_A_RAILROAD_ENGINEER);
  55. addTalkId(GHOST_OF_A_RAILROAD_ENGINEER);
  56. addKillId(MONSTER_DROP_CHANCES.keySet());
  57. registerQuestItems(REMNANTS_OF_OLD_DWARVES_DREAMS);
  58. }
  59. @Override
  60. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  61. {
  62. final QuestState st = getQuestState(player, false);
  63. String htmltext = null;
  64. if (st == null)
  65. {
  66. return htmltext;
  67. }
  68. switch (event)
  69. {
  70. case "32054-03.htm":
  71. {
  72. if (st.isCreated())
  73. {
  74. st.startQuest();
  75. htmltext = event;
  76. }
  77. break;
  78. }
  79. case "32054-07.html":
  80. case "32054-08.html":
  81. {
  82. if (st.isStarted())
  83. {
  84. htmltext = event;
  85. }
  86. break;
  87. }
  88. case "32054-09.html":
  89. {
  90. if (st.isStarted())
  91. {
  92. st.exitQuest(true, true);
  93. htmltext = event;
  94. }
  95. break;
  96. }
  97. }
  98. return htmltext;
  99. }
  100. @Override
  101. public String onTalk(L2Npc npc, L2PcInstance player)
  102. {
  103. final QuestState st = getQuestState(player, true);
  104. String htmltext = getNoQuestMsg(player);
  105. if (st == null)
  106. {
  107. return htmltext;
  108. }
  109. switch (st.getState())
  110. {
  111. case State.CREATED:
  112. {
  113. if (player.getLevel() < MIN_LVL)
  114. {
  115. htmltext = "32054-02.htm";
  116. }
  117. else
  118. {
  119. final QuestState q117 = player.getQuestState(Q00117_TheOceanOfDistantStars.class.getSimpleName());
  120. htmltext = (q117 != null) && q117.isCompleted() ? "32054-01.htm" : "32054-04.htm";
  121. }
  122. break;
  123. }
  124. case State.STARTED:
  125. {
  126. htmltext = st.hasQuestItems(REMNANTS_OF_OLD_DWARVES_DREAMS) ? "32054-05.html" : "32054-06.html";
  127. break;
  128. }
  129. }
  130. return htmltext;
  131. }
  132. @Override
  133. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  134. {
  135. final List<L2PcInstance> randomList = new ArrayList<>();
  136. final QuestState st = getQuestState(killer, false);
  137. if ((st != null) && st.isStarted())
  138. {
  139. randomList.add(killer);
  140. randomList.add(killer);
  141. }
  142. final int monsterChance = MONSTER_DROP_CHANCES.get(npc.getId());
  143. if (killer.isInParty())
  144. {
  145. for (L2PcInstance member : killer.getParty().getMembers())
  146. {
  147. final QuestState qs = getQuestState(member, false);
  148. if ((qs != null) && qs.isStarted())
  149. {
  150. randomList.add(member);
  151. }
  152. }
  153. }
  154. if (!randomList.isEmpty())
  155. {
  156. final L2PcInstance player = randomList.get(getRandom(randomList.size()));
  157. if ((getRandom(1000) < monsterChance) && Util.checkIfInRange(1500, npc, player, true))
  158. {
  159. giveItems(player, REMNANTS_OF_OLD_DWARVES_DREAMS, 1);
  160. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  161. }
  162. }
  163. return super.onKill(npc, killer, isSummon);
  164. }
  165. }