Q00329_CuriosityOfADwarf.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.Q00329_CuriosityOfADwarf;
  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. * Curiosity Of A Dwarf (329)
  33. * @author ivantotov
  34. */
  35. public final class Q00329_CuriosityOfADwarf extends Quest
  36. {
  37. // NPC
  38. private static final int TRADER_ROLENTO = 30437;
  39. // Items
  40. private static final int GOLEM_HEARTSTONE = 1346;
  41. private static final int BROKEN_HEARTSTONE = 1365;
  42. // Misc
  43. private static final int MIN_LEVEL = 33;
  44. // Monsters
  45. private static final Map<Integer, List<ItemHolder>> MONSTER_DROPS = new HashMap<>();
  46. static
  47. {
  48. MONSTER_DROPS.put(20083, Arrays.asList(new ItemHolder(GOLEM_HEARTSTONE, 3), new ItemHolder(BROKEN_HEARTSTONE, 54))); // Granitic Golem
  49. MONSTER_DROPS.put(20085, Arrays.asList(new ItemHolder(GOLEM_HEARTSTONE, 3), new ItemHolder(BROKEN_HEARTSTONE, 58))); // Puncher
  50. }
  51. public Q00329_CuriosityOfADwarf()
  52. {
  53. super(329, Q00329_CuriosityOfADwarf.class.getSimpleName(), "Curiosity Of A Dwarf");
  54. addStartNpc(TRADER_ROLENTO);
  55. addTalkId(TRADER_ROLENTO);
  56. addKillId(MONSTER_DROPS.keySet());
  57. registerQuestItems(GOLEM_HEARTSTONE, BROKEN_HEARTSTONE);
  58. }
  59. @Override
  60. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  61. {
  62. final QuestState st = getQuestState(player, false);
  63. String htmltext = null;
  64. if (st == null)
  65. {
  66. return htmltext;
  67. }
  68. switch (event)
  69. {
  70. case "30437-03.htm":
  71. {
  72. if (st.isCreated())
  73. {
  74. st.startQuest();
  75. htmltext = event;
  76. }
  77. break;
  78. }
  79. case "30437-06.html":
  80. {
  81. st.exitQuest(true, true);
  82. htmltext = event;
  83. break;
  84. }
  85. case "30437-07.html":
  86. {
  87. htmltext = event;
  88. break;
  89. }
  90. }
  91. return htmltext;
  92. }
  93. @Override
  94. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  95. {
  96. final QuestState st = getQuestState(killer, false);
  97. if ((st != null) && Util.checkIfInRange(1500, npc, killer, true))
  98. {
  99. final int rnd = getRandom(100);
  100. for (ItemHolder drop : MONSTER_DROPS.get(npc.getId()))
  101. {
  102. if (rnd < drop.getCount())
  103. {
  104. st.giveItemRandomly(npc, drop.getId(), 1, 0, 1.0, true);
  105. break;
  106. }
  107. }
  108. }
  109. return super.onKill(npc, killer, isSummon);
  110. }
  111. @Override
  112. public String onTalk(L2Npc npc, L2PcInstance player)
  113. {
  114. String htmltext = getNoQuestMsg(player);
  115. final QuestState st = getQuestState(player, true);
  116. if (st == null)
  117. {
  118. return htmltext;
  119. }
  120. switch (st.getState())
  121. {
  122. case State.CREATED:
  123. {
  124. htmltext = player.getLevel() >= MIN_LEVEL ? "30437-02.htm" : "30437-01.htm";
  125. break;
  126. }
  127. case State.STARTED:
  128. {
  129. if (hasAtLeastOneQuestItem(player, getRegisteredItemIds()))
  130. {
  131. final long broken = st.getQuestItemsCount(BROKEN_HEARTSTONE);
  132. final long golem = st.getQuestItemsCount(GOLEM_HEARTSTONE);
  133. st.giveAdena(((broken * 50) + (golem * 1000) + ((broken + golem) >= 10 ? 1183 : 0)), true);
  134. takeItems(player, -1, getRegisteredItemIds());
  135. htmltext = "30437-05.html";
  136. }
  137. else
  138. {
  139. htmltext = "30437-04.html";
  140. }
  141. break;
  142. }
  143. }
  144. return htmltext;
  145. }
  146. }