Q00252_ItSmellsDelicious.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.Q00252_ItSmellsDelicious;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.quest.Quest;
  23. import com.l2jserver.gameserver.model.quest.QuestState;
  24. /**
  25. * It Smells Delicious! (252)<br>
  26. * Updated by corbin12, thanks VlLight for help.
  27. * @author Dumpster, jurchiks
  28. */
  29. public class Q00252_ItSmellsDelicious extends Quest
  30. {
  31. // NPC
  32. public static final int STAN = 30200;
  33. // Items
  34. public static final int DIARY = 15500;
  35. public static final int COOKBOOK_PAGE = 15501;
  36. // Monsters
  37. private static final int[] MOBS =
  38. {
  39. 22786,
  40. 22787,
  41. 22788
  42. };
  43. private static final int CHEF = 18908;
  44. // Misc
  45. private static final double DIARY_CHANCE = 0.599;
  46. private static final int DIARY_MAX_COUNT = 10;
  47. private static final double COOKBOOK_PAGE_CHANCE = 0.36;
  48. private static final int COOKBOOK_PAGE_MAX_COUNT = 5;
  49. public Q00252_ItSmellsDelicious()
  50. {
  51. super(252, Q00252_ItSmellsDelicious.class.getSimpleName(), "It Smells Delicious!");
  52. addStartNpc(STAN);
  53. addTalkId(STAN);
  54. addKillId(CHEF);
  55. addKillId(MOBS);
  56. registerQuestItems(DIARY, COOKBOOK_PAGE);
  57. }
  58. @Override
  59. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  60. {
  61. final QuestState qs = getQuestState(player, false);
  62. String htmltext = null;
  63. if (qs == null)
  64. {
  65. return htmltext;
  66. }
  67. switch (event)
  68. {
  69. case "30200-04.htm":
  70. htmltext = event;
  71. break;
  72. case "30200-05.htm":
  73. if (qs.isCreated())
  74. {
  75. qs.startQuest();
  76. htmltext = event;
  77. }
  78. break;
  79. case "30200-08.html":
  80. if (qs.isCond(2))
  81. {
  82. giveAdena(player, 147656, true);
  83. addExpAndSp(player, 716238, 78324);
  84. qs.exitQuest(false, true);
  85. htmltext = event;
  86. }
  87. break;
  88. }
  89. return htmltext;
  90. }
  91. @Override
  92. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  93. {
  94. final QuestState qs;
  95. if (npc.getId() == CHEF) // only the killer gets quest items from the chef
  96. {
  97. qs = getQuestState(killer, false);
  98. if ((qs != null) && qs.isCond(1))
  99. {
  100. if (giveItemRandomly(killer, npc, COOKBOOK_PAGE, 1, COOKBOOK_PAGE_MAX_COUNT, COOKBOOK_PAGE_CHANCE, true))
  101. {
  102. if (hasMaxDiaries(qs))
  103. {
  104. qs.setCond(2, true);
  105. }
  106. }
  107. }
  108. }
  109. else
  110. {
  111. qs = getRandomPartyMemberState(killer, 1, 3, npc);
  112. if (qs != null)
  113. {
  114. if (giveItemRandomly(qs.getPlayer(), npc, DIARY, 1, DIARY_MAX_COUNT, DIARY_CHANCE, true))
  115. {
  116. if (hasMaxCookbookPages(qs))
  117. {
  118. qs.setCond(2, true);
  119. }
  120. }
  121. }
  122. }
  123. return super.onKill(npc, killer, isSummon);
  124. }
  125. @Override
  126. public boolean checkPartyMember(QuestState qs, L2Npc npc)
  127. {
  128. return !hasMaxDiaries(qs);
  129. }
  130. @Override
  131. public String onTalk(L2Npc npc, L2PcInstance player)
  132. {
  133. final QuestState qs = getQuestState(player, true);
  134. String htmltext = getNoQuestMsg(player);
  135. if (qs.isCreated())
  136. {
  137. htmltext = ((player.getLevel() >= 82) ? "30200-01.htm" : "30200-02.htm");
  138. }
  139. else if (qs.isStarted())
  140. {
  141. switch (qs.getCond())
  142. {
  143. case 1:
  144. htmltext = "30200-06.html";
  145. break;
  146. case 2:
  147. if (hasMaxDiaries(qs) && hasMaxCookbookPages(qs))
  148. {
  149. htmltext = "30200-07.html";
  150. }
  151. break;
  152. }
  153. }
  154. else
  155. {
  156. htmltext = "30200-03.html";
  157. }
  158. return htmltext;
  159. }
  160. private static boolean hasMaxDiaries(QuestState qs)
  161. {
  162. return (getQuestItemsCount(qs.getPlayer(), DIARY) >= DIARY_MAX_COUNT);
  163. }
  164. private static boolean hasMaxCookbookPages(QuestState qs)
  165. {
  166. return (getQuestItemsCount(qs.getPlayer(), COOKBOOK_PAGE) >= COOKBOOK_PAGE_MAX_COUNT);
  167. }
  168. }