Q00370_AnElderSowsSeeds.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.Q00370_AnElderSowsSeeds;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.QuestState;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * An Elder Sows Seeds (370)
  29. * @author Adry_85
  30. */
  31. public final class Q00370_AnElderSowsSeeds extends Quest
  32. {
  33. // NPC
  34. private static final int CASIAN = 30612;
  35. // Items
  36. private static final int SPELLBOOK_PAGE = 5916;
  37. private static final int CHAPTER_OF_FIRE = 5917;
  38. private static final int CHAPTER_OF_WATER = 5918;
  39. private static final int CHAPTER_OF_WIND = 5919;
  40. private static final int CHAPTER_OF_EARTH = 5920;
  41. // Misc
  42. private static final int MIN_LEVEL = 28;
  43. // Mobs
  44. private static final Map<Integer, Integer> MOBS1 = new HashMap<>();
  45. private static final Map<Integer, Double> MOBS2 = new HashMap<>();
  46. static
  47. {
  48. MOBS1.put(20082, 9); // ant_recruit
  49. MOBS1.put(20086, 9); // ant_guard
  50. MOBS1.put(20090, 22); // noble_ant_leader
  51. MOBS2.put(20084, 0.101); // ant_patrol
  52. MOBS2.put(20089, 0.100); // noble_ant
  53. }
  54. public Q00370_AnElderSowsSeeds()
  55. {
  56. super(370, Q00370_AnElderSowsSeeds.class.getSimpleName(), "An Elder Sows Seeds");
  57. addStartNpc(CASIAN);
  58. addTalkId(CASIAN);
  59. addKillId(MOBS1.keySet());
  60. addKillId(MOBS2.keySet());
  61. }
  62. @Override
  63. public boolean checkPartyMember(L2PcInstance member, L2Npc npc)
  64. {
  65. final QuestState st = getQuestState(member, false);
  66. return ((st != null) && st.isStarted());
  67. }
  68. @Override
  69. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  70. {
  71. final QuestState st = getQuestState(player, false);
  72. if (st == null)
  73. {
  74. return null;
  75. }
  76. String htmltext = null;
  77. switch (event)
  78. {
  79. case "30612-02.htm":
  80. case "30612-03.htm":
  81. case "30612-06.html":
  82. case "30612-07.html":
  83. case "30612-09.html":
  84. {
  85. htmltext = event;
  86. break;
  87. }
  88. case "30612-04.htm":
  89. {
  90. st.startQuest();
  91. htmltext = event;
  92. break;
  93. }
  94. case "REWARD":
  95. {
  96. if (st.isStarted())
  97. {
  98. if (exchangeChapters(player, false))
  99. {
  100. htmltext = "30612-08.html";
  101. }
  102. else
  103. {
  104. htmltext = "30612-11.html";
  105. }
  106. }
  107. break;
  108. }
  109. case "30612-10.html":
  110. {
  111. if (st.isStarted())
  112. {
  113. exchangeChapters(player, true);
  114. st.exitQuest(true, true);
  115. htmltext = event;
  116. }
  117. break;
  118. }
  119. }
  120. return htmltext;
  121. }
  122. @Override
  123. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  124. {
  125. int npcId = npc.getId();
  126. if (MOBS1.containsKey(npcId))
  127. {
  128. if (getRandom(100) < MOBS1.get(npcId))
  129. {
  130. L2PcInstance luckyPlayer = getRandomPartyMember(player, npc);
  131. if (luckyPlayer != null)
  132. {
  133. giveItemRandomly(luckyPlayer, npc, SPELLBOOK_PAGE, 1, 0, 1.0, true);
  134. }
  135. }
  136. }
  137. else
  138. {
  139. final QuestState st = getRandomPartyMemberState(player, -1, 3, npc);
  140. if (st != null)
  141. {
  142. giveItemRandomly(st.getPlayer(), npc, SPELLBOOK_PAGE, 1, 0, MOBS2.get(npcId), true);
  143. }
  144. }
  145. return super.onKill(npc, player, isSummon);
  146. }
  147. @Override
  148. public String onTalk(L2Npc npc, L2PcInstance player)
  149. {
  150. final QuestState st = getQuestState(player, true);
  151. String htmltext = getNoQuestMsg(player);
  152. if (st.isCreated())
  153. {
  154. htmltext = (player.getLevel() >= MIN_LEVEL) ? "30612-01.htm" : "30612-05.html";
  155. }
  156. else if (st.isStarted())
  157. {
  158. htmltext = "30612-06.html";
  159. }
  160. return htmltext;
  161. }
  162. private final boolean exchangeChapters(L2PcInstance player, boolean takeAllItems)
  163. {
  164. final long waterChapters = getQuestItemsCount(player, CHAPTER_OF_WATER);
  165. final long earthChapters = getQuestItemsCount(player, CHAPTER_OF_EARTH);
  166. final long windChapters = getQuestItemsCount(player, CHAPTER_OF_WIND);
  167. final long fireChapters = getQuestItemsCount(player, CHAPTER_OF_FIRE);
  168. final long minCount = Util.min(waterChapters, earthChapters, windChapters, fireChapters);
  169. if (minCount > 0)
  170. {
  171. giveAdena(player, minCount * 3600, true);
  172. }
  173. final long countToTake = (takeAllItems ? -1 : minCount);
  174. takeItems(player, (int) countToTake, CHAPTER_OF_WATER, CHAPTER_OF_EARTH, CHAPTER_OF_WIND, CHAPTER_OF_FIRE);
  175. return (minCount > 0);
  176. }
  177. }