Q00280_TheFoodChain.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.Q00280_TheFoodChain;
  20. import java.util.Arrays;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.holders.ItemHolder;
  27. import com.l2jserver.gameserver.model.quest.Quest;
  28. import com.l2jserver.gameserver.model.quest.QuestState;
  29. import com.l2jserver.gameserver.model.quest.State;
  30. import com.l2jserver.gameserver.util.Util;
  31. /**
  32. * The Food Chain (280)
  33. * @author xban1x
  34. */
  35. public final class Q00280_TheFoodChain extends Quest
  36. {
  37. // Npc
  38. private static final int BIXON = 32175;
  39. // Items
  40. private static final int GREY_KELTIR_TOOTH = 9809;
  41. private static final int BLACK_WOLF_TOOTH = 9810;
  42. // Monsters
  43. private static final Map<Integer, Integer> MONSTER_ITEM = new HashMap<>();
  44. private static final Map<Integer, List<ItemHolder>> MONSTER_CHANCE = new HashMap<>();
  45. static
  46. {
  47. MONSTER_ITEM.put(22229, GREY_KELTIR_TOOTH);
  48. MONSTER_ITEM.put(22230, GREY_KELTIR_TOOTH);
  49. MONSTER_ITEM.put(22231, GREY_KELTIR_TOOTH);
  50. MONSTER_ITEM.put(22232, BLACK_WOLF_TOOTH);
  51. MONSTER_ITEM.put(22233, BLACK_WOLF_TOOTH);
  52. MONSTER_CHANCE.put(22229, Arrays.asList(new ItemHolder(1000, 1)));
  53. MONSTER_CHANCE.put(22230, Arrays.asList(new ItemHolder(500, 1), new ItemHolder(1000, 2)));
  54. MONSTER_CHANCE.put(22231, Arrays.asList(new ItemHolder(1000, 2)));
  55. MONSTER_CHANCE.put(22232, Arrays.asList(new ItemHolder(1000, 3)));
  56. MONSTER_CHANCE.put(22233, Arrays.asList(new ItemHolder(500, 3), new ItemHolder(1000, 4)));
  57. }
  58. // Rewards
  59. private static final int[] REWARDS = new int[]
  60. {
  61. 28,
  62. 35,
  63. 41,
  64. 48,
  65. 116,
  66. };
  67. // Misc
  68. private static final int MIN_LVL = 3;
  69. private static final int TEETH_COUNT = 25;
  70. public Q00280_TheFoodChain()
  71. {
  72. super(280, Q00280_TheFoodChain.class.getSimpleName(), "The Food Chain");
  73. addStartNpc(BIXON);
  74. addTalkId(BIXON);
  75. addKillId(MONSTER_ITEM.keySet());
  76. registerQuestItems(GREY_KELTIR_TOOTH, BLACK_WOLF_TOOTH);
  77. }
  78. @Override
  79. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  80. {
  81. final QuestState st = getQuestState(player, false);
  82. String htmltext = null;
  83. if (st == null)
  84. {
  85. return htmltext;
  86. }
  87. switch (event)
  88. {
  89. case "32175-03.htm":
  90. {
  91. st.startQuest();
  92. htmltext = event;
  93. break;
  94. }
  95. case "32175-06.html":
  96. {
  97. if (hasAtLeastOneQuestItem(player, getRegisteredItemIds()))
  98. {
  99. final long greyTeeth = st.getQuestItemsCount(GREY_KELTIR_TOOTH);
  100. final long blackTeeth = st.getQuestItemsCount(BLACK_WOLF_TOOTH);
  101. st.giveAdena(2 * (greyTeeth + blackTeeth), true);
  102. takeItems(player, -1, GREY_KELTIR_TOOTH, BLACK_WOLF_TOOTH);
  103. htmltext = event;
  104. }
  105. else
  106. {
  107. htmltext = "32175-07.html";
  108. }
  109. }
  110. case "32175-08.html":
  111. {
  112. htmltext = event;
  113. break;
  114. }
  115. case "32175-09.html":
  116. {
  117. st.exitQuest(true, true);
  118. htmltext = event;
  119. break;
  120. }
  121. case "32175-11.html":
  122. {
  123. final long greyTeeth = st.getQuestItemsCount(GREY_KELTIR_TOOTH);
  124. final long blackTeeth = st.getQuestItemsCount(BLACK_WOLF_TOOTH);
  125. if ((greyTeeth + blackTeeth) >= TEETH_COUNT)
  126. {
  127. if (greyTeeth >= TEETH_COUNT)
  128. {
  129. st.takeItems(GREY_KELTIR_TOOTH, TEETH_COUNT);
  130. }
  131. else
  132. {
  133. st.takeItems(GREY_KELTIR_TOOTH, greyTeeth);
  134. st.takeItems(BLACK_WOLF_TOOTH, TEETH_COUNT - greyTeeth);
  135. }
  136. st.rewardItems(REWARDS[getRandom(5)], 1);
  137. htmltext = event;
  138. }
  139. else
  140. {
  141. htmltext = "32175-10.html";
  142. }
  143. break;
  144. }
  145. }
  146. return htmltext;
  147. }
  148. @Override
  149. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  150. {
  151. final QuestState st = getQuestState(killer, false);
  152. if ((st != null) && Util.checkIfInRange(1500, npc, killer, true))
  153. {
  154. final int chance = getRandom(1000);
  155. for (ItemHolder dropChance : MONSTER_CHANCE.get(npc.getId()))
  156. {
  157. if (chance < dropChance.getId())
  158. {
  159. st.giveItemRandomly(MONSTER_ITEM.get(npc.getId()), dropChance.getCount(), 0, 1, true);
  160. break;
  161. }
  162. }
  163. }
  164. return super.onKill(npc, killer, isSummon);
  165. }
  166. @Override
  167. public String onTalk(L2Npc npc, L2PcInstance talker)
  168. {
  169. final QuestState st = getQuestState(talker, true);
  170. String htmltext = getNoQuestMsg(talker);
  171. if (st == null)
  172. {
  173. return htmltext;
  174. }
  175. switch (st.getState())
  176. {
  177. case State.CREATED:
  178. {
  179. htmltext = (talker.getLevel() >= MIN_LVL) ? "32175-01.htm" : "32175-02.htm";
  180. break;
  181. }
  182. case State.STARTED:
  183. {
  184. if (hasAtLeastOneQuestItem(talker, getRegisteredItemIds()))
  185. {
  186. htmltext = "32175-05.html";
  187. }
  188. else
  189. {
  190. htmltext = "32175-04.html";
  191. }
  192. break;
  193. }
  194. }
  195. return htmltext;
  196. }
  197. }