Q250_WatchWhatYouEat.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package quests.Q250_WatchWhatYouEat;
  16. import com.l2jserver.gameserver.instancemanager.QuestManager;
  17. import com.l2jserver.gameserver.model.actor.L2Npc;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.quest.Quest;
  20. import com.l2jserver.gameserver.model.quest.QuestState;
  21. import com.l2jserver.gameserver.model.quest.State;
  22. /**
  23. ** @author Gnacik
  24. **
  25. ** 2010-08-05 Based on Freya PTS
  26. */
  27. public class Q250_WatchWhatYouEat extends Quest
  28. {
  29. private static final String qn = "250_WatchWhatYouEat";
  30. // NPCs
  31. private static final int _sally = 32743;
  32. // Mobs - Items
  33. private static final int[][] _mobs = {
  34. { 18864, 15493 },
  35. { 18865, 15494 },
  36. { 18868, 15495 }
  37. };
  38. @Override
  39. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  40. {
  41. String htmltext = event;
  42. QuestState st = player.getQuestState(qn);
  43. if (st == null)
  44. return htmltext;
  45. if (npc.getNpcId() == _sally)
  46. {
  47. if (event.equalsIgnoreCase("32743-03.htm"))
  48. {
  49. st.setState(State.STARTED);
  50. st.set("cond", "1");
  51. st.playSound("ItemSound.quest_accept");
  52. }
  53. else if (event.equalsIgnoreCase("32743-end.htm"))
  54. {
  55. st.unset("cond");
  56. st.rewardItems(57,135661);
  57. st.addExpAndSp(698334,76369);
  58. st.playSound("ItemSound.quest_finish");
  59. st.exitQuest(false);
  60. }
  61. else if (event.equalsIgnoreCase("32743-22.html") && st.getState() == State.COMPLETED)
  62. {
  63. htmltext = "32743-23.html";
  64. }
  65. }
  66. return htmltext;
  67. }
  68. @Override
  69. public String onTalk(L2Npc npc, L2PcInstance player)
  70. {
  71. String htmltext = getNoQuestMsg(player);
  72. QuestState st = player.getQuestState(qn);
  73. if (st == null)
  74. return htmltext;
  75. if (npc.getNpcId() == _sally)
  76. {
  77. switch(st.getState())
  78. {
  79. case State.CREATED :
  80. if (player.getLevel() >= 82)
  81. htmltext = "32743-01.htm";
  82. else
  83. htmltext = "32743-00.htm";
  84. break;
  85. case State.STARTED :
  86. if (st.getInt("cond") == 1)
  87. {
  88. htmltext = "32743-04.htm";
  89. }
  90. else if (st.getInt("cond") == 2)
  91. {
  92. if(st.hasQuestItems(_mobs[0][1]) && st.hasQuestItems(_mobs[1][1]) && st.hasQuestItems(_mobs[2][1]))
  93. {
  94. htmltext = "32743-05.htm";
  95. for(int items[] : _mobs)
  96. st.takeItems(items[1], -1);
  97. }
  98. else
  99. htmltext = "32743-06.htm";
  100. }
  101. break;
  102. case State.COMPLETED :
  103. htmltext = "32743-done.htm";
  104. break;
  105. }
  106. }
  107. return htmltext;
  108. }
  109. @Override
  110. public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  111. {
  112. QuestState st = player.getQuestState(qn);
  113. if (st == null)
  114. return null;
  115. if (st.getState() == State.STARTED && st.getInt("cond") == 1)
  116. {
  117. for(int mob[] : _mobs)
  118. {
  119. if (npc.getNpcId() == mob[0])
  120. {
  121. if (!st.hasQuestItems(mob[1]))
  122. {
  123. st.giveItems(mob[1], 1);
  124. st.playSound("ItemSound.quest_itemget");
  125. }
  126. }
  127. }
  128. if(st.hasQuestItems(_mobs[0][1]) && st.hasQuestItems(_mobs[1][1]) && st.hasQuestItems(_mobs[2][1]))
  129. {
  130. st.set("cond", "2");
  131. st.playSound("ItemSound.quest_middle");
  132. }
  133. }
  134. return null;
  135. }
  136. @Override
  137. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  138. {
  139. QuestState st = player.getQuestState(qn);
  140. if (st == null)
  141. {
  142. Quest q = QuestManager.getInstance().getQuest(qn);
  143. st = q.newQuestState(player);
  144. }
  145. if (npc.getNpcId() == _sally)
  146. return "32743-20.html";
  147. return null;
  148. }
  149. public Q250_WatchWhatYouEat(int questId, String name, String descr)
  150. {
  151. super(questId, name, descr);
  152. questItemIds = new int[]{15493,15494,15495};
  153. addStartNpc(_sally);
  154. addFirstTalkId(_sally);
  155. addTalkId(_sally);
  156. for(int i[] : _mobs)
  157. addKillId(i[0]);
  158. }
  159. public static void main(String[] args)
  160. {
  161. new Q250_WatchWhatYouEat(250, qn, "Watch What You Eat");
  162. }
  163. }