Q00276_TotemOfTheHestui.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.Q00276_TotemOfTheHestui;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import quests.Q00261_CollectorsDream.Q00261_CollectorsDream;
  23. import com.l2jserver.gameserver.enums.Race;
  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. * Totem of the Hestui (276)
  33. * @author xban1x
  34. */
  35. public final class Q00276_TotemOfTheHestui extends Quest
  36. {
  37. // Npc
  38. private static final int TANAPI = 30571;
  39. // Items
  40. private static final int KASHA_PARASITE = 1480;
  41. private static final int KASHA_CRYSTAL = 1481;
  42. // Monsters
  43. private static final int KASHA_BEAR = 20479;
  44. private static final int KASHA_BEAR_TOTEM = 27044;
  45. // Rewards
  46. private static final int[] REWARDS = new int[]
  47. {
  48. 29,
  49. 1500,
  50. };
  51. // Misc
  52. private static final List<ItemHolder> SPAWN_CHANCES = new ArrayList<>();
  53. private static final int MIN_LVL = 15;
  54. static
  55. {
  56. SPAWN_CHANCES.add(new ItemHolder(79, 100));
  57. SPAWN_CHANCES.add(new ItemHolder(69, 20));
  58. SPAWN_CHANCES.add(new ItemHolder(59, 15));
  59. SPAWN_CHANCES.add(new ItemHolder(49, 10));
  60. SPAWN_CHANCES.add(new ItemHolder(39, 2));
  61. }
  62. public Q00276_TotemOfTheHestui()
  63. {
  64. super(276, Q00276_TotemOfTheHestui.class.getSimpleName(), "Totem of the Hestui");
  65. addStartNpc(TANAPI);
  66. addTalkId(TANAPI);
  67. addKillId(KASHA_BEAR, KASHA_BEAR_TOTEM);
  68. registerQuestItems(KASHA_PARASITE, KASHA_CRYSTAL);
  69. }
  70. @Override
  71. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  72. {
  73. final QuestState st = getQuestState(player, false);
  74. if ((st != null) && event.equals("30571-03.htm"))
  75. {
  76. st.startQuest();
  77. return event;
  78. }
  79. return null;
  80. }
  81. @Override
  82. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  83. {
  84. final QuestState st = getQuestState(killer, false);
  85. if ((st != null) && st.isCond(1) && Util.checkIfInRange(1500, killer, npc, true))
  86. {
  87. switch (npc.getId())
  88. {
  89. case KASHA_BEAR:
  90. {
  91. final long chance1 = st.getQuestItemsCount(KASHA_PARASITE);
  92. final int chance2 = getRandom(100);
  93. boolean chance3 = true;
  94. for (ItemHolder spawnChance : SPAWN_CHANCES)
  95. {
  96. if ((chance1 >= spawnChance.getId()) && (chance2 <= spawnChance.getCount()))
  97. {
  98. st.addSpawn(KASHA_BEAR_TOTEM);
  99. st.takeItems(KASHA_PARASITE, -1);
  100. chance3 = false;
  101. break;
  102. }
  103. }
  104. if (chance3)
  105. {
  106. st.giveItemRandomly(KASHA_PARASITE, 1, 0, 1, true);
  107. }
  108. break;
  109. }
  110. case KASHA_BEAR_TOTEM:
  111. {
  112. if (st.giveItemRandomly(KASHA_CRYSTAL, 1, 1, 1, true))
  113. {
  114. st.setCond(2);
  115. }
  116. break;
  117. }
  118. }
  119. }
  120. return super.onKill(npc, killer, isSummon);
  121. }
  122. @Override
  123. public String onTalk(L2Npc npc, L2PcInstance player)
  124. {
  125. final QuestState st = getQuestState(player, true);
  126. String htmltext = getNoQuestMsg(player);
  127. if (st == null)
  128. {
  129. return htmltext;
  130. }
  131. switch (st.getState())
  132. {
  133. case State.CREATED:
  134. {
  135. htmltext = (player.getRace() == Race.ORC) ? (player.getLevel() >= MIN_LVL) ? "30571-02.htm" : "30571-01.htm" : "30571-00.htm";
  136. break;
  137. }
  138. case State.STARTED:
  139. {
  140. switch (st.getCond())
  141. {
  142. case 1:
  143. {
  144. htmltext = "30571-04.html";
  145. break;
  146. }
  147. case 2:
  148. {
  149. if (st.hasQuestItems(KASHA_CRYSTAL))
  150. {
  151. Q00261_CollectorsDream.giveNewbieReward(player);
  152. for (int reward : REWARDS)
  153. {
  154. st.rewardItems(reward, 1);
  155. }
  156. st.exitQuest(true, true);
  157. htmltext = "30571-05.html";
  158. }
  159. break;
  160. }
  161. }
  162. break;
  163. }
  164. }
  165. return htmltext;
  166. }
  167. }