Q00159_ProtectTheWaterSource.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.Q00159_ProtectTheWaterSource;
  20. import com.l2jserver.gameserver.enums.QuestSound;
  21. import com.l2jserver.gameserver.enums.Race;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.QuestState;
  26. import com.l2jserver.gameserver.model.quest.State;
  27. /**
  28. * Protect the Water Source (159)
  29. * @author xban1x
  30. */
  31. public class Q00159_ProtectTheWaterSource extends Quest
  32. {
  33. // NPC
  34. private static final int ASTERIOS = 30154;
  35. // Monster
  36. private static final int PLAGUE_ZOMBIE = 27017;
  37. // Items
  38. private static final int PLAGUE_DUST = 1035;
  39. private static final int HYACINTH_CHARM = 1071;
  40. private static final int HYACINTH_CHARM2 = 1072;
  41. // Misc
  42. private static final int MIN_LVL = 12;
  43. public Q00159_ProtectTheWaterSource()
  44. {
  45. super(159, Q00159_ProtectTheWaterSource.class.getSimpleName(), "Protect the Water Source");
  46. addStartNpc(ASTERIOS);
  47. addTalkId(ASTERIOS);
  48. addKillId(PLAGUE_ZOMBIE);
  49. registerQuestItems(PLAGUE_DUST, HYACINTH_CHARM, HYACINTH_CHARM2);
  50. }
  51. @Override
  52. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  53. {
  54. final QuestState st = getQuestState(player, false);
  55. if ((st != null) && event.equals("30154-04.htm"))
  56. {
  57. st.startQuest();
  58. st.giveItems(HYACINTH_CHARM, 1);
  59. return event;
  60. }
  61. return null;
  62. }
  63. @Override
  64. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  65. {
  66. final QuestState st = getQuestState(killer, false);
  67. if ((st != null))
  68. {
  69. switch (st.getCond())
  70. {
  71. case 1:
  72. {
  73. if ((getRandom(100) < 40) && st.hasQuestItems(HYACINTH_CHARM) && !st.hasQuestItems(PLAGUE_DUST))
  74. {
  75. st.giveItems(PLAGUE_DUST, 1);
  76. st.setCond(2, true);
  77. }
  78. break;
  79. }
  80. case 3:
  81. {
  82. long dust = st.getQuestItemsCount(PLAGUE_DUST);
  83. if ((getRandom(100) < 40) && (dust < 5) && st.hasQuestItems(HYACINTH_CHARM2))
  84. {
  85. st.giveItems(PLAGUE_DUST, 1);
  86. if ((++dust) >= 5)
  87. {
  88. st.setCond(4, true);
  89. }
  90. else
  91. {
  92. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  93. }
  94. }
  95. break;
  96. }
  97. }
  98. }
  99. return super.onKill(npc, killer, isSummon);
  100. }
  101. @Override
  102. public String onTalk(L2Npc npc, L2PcInstance player)
  103. {
  104. final QuestState st = getQuestState(player, true);
  105. String htmltext = getNoQuestMsg(player);
  106. if (st != null)
  107. {
  108. switch (st.getState())
  109. {
  110. case State.CREATED:
  111. {
  112. htmltext = (player.getRace() == Race.ELF) ? (player.getLevel() >= MIN_LVL ? "30154-03.htm" : "30154-02.htm") : "30154-01.htm";
  113. break;
  114. }
  115. case State.STARTED:
  116. {
  117. switch (st.getCond())
  118. {
  119. case 1:
  120. {
  121. if (st.hasQuestItems(HYACINTH_CHARM) && !st.hasQuestItems(PLAGUE_DUST))
  122. {
  123. htmltext = "30154-05.html";
  124. }
  125. break;
  126. }
  127. case 2:
  128. {
  129. if (st.hasQuestItems(HYACINTH_CHARM, PLAGUE_DUST))
  130. {
  131. st.takeItems(HYACINTH_CHARM, -1);
  132. st.takeItems(PLAGUE_DUST, -1);
  133. st.giveItems(HYACINTH_CHARM2, 1);
  134. st.setCond(3, true);
  135. htmltext = "30154-06.html";
  136. }
  137. break;
  138. }
  139. case 3:
  140. {
  141. if (st.hasQuestItems(HYACINTH_CHARM2))
  142. {
  143. htmltext = "30154-07.html";
  144. }
  145. break;
  146. }
  147. case 4:
  148. {
  149. if (st.hasQuestItems(HYACINTH_CHARM2) && (st.getQuestItemsCount(PLAGUE_DUST) >= 5))
  150. {
  151. st.giveAdena(18250, true);
  152. st.exitQuest(false, true);
  153. htmltext = "30154-08.html";
  154. }
  155. break;
  156. }
  157. }
  158. break;
  159. }
  160. case State.COMPLETED:
  161. {
  162. htmltext = getAlreadyCompletedMsg(player);
  163. break;
  164. }
  165. }
  166. }
  167. return htmltext;
  168. }
  169. }