Q00691_MatrasSuspiciousRequest.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.Q00691_MatrasSuspiciousRequest;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.enums.QuestSound;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.quest.Quest;
  27. import com.l2jserver.gameserver.model.quest.QuestState;
  28. import com.l2jserver.gameserver.model.quest.State;
  29. /**
  30. * Matras' Suspicious Request (691)
  31. * @author GKR
  32. */
  33. public final class Q00691_MatrasSuspiciousRequest extends Quest
  34. {
  35. // NPC
  36. private static final int MATRAS = 32245;
  37. // Items
  38. private static final int RED_GEM = 10372;
  39. private static final int DYNASTY_SOUL_II = 10413;
  40. // Reward
  41. private static final Map<Integer, Integer> REWARD_CHANCES = new HashMap<>();
  42. static
  43. {
  44. REWARD_CHANCES.put(22363, 890);
  45. REWARD_CHANCES.put(22364, 261);
  46. REWARD_CHANCES.put(22365, 560);
  47. REWARD_CHANCES.put(22366, 560);
  48. REWARD_CHANCES.put(22367, 190);
  49. REWARD_CHANCES.put(22368, 129);
  50. REWARD_CHANCES.put(22369, 210);
  51. REWARD_CHANCES.put(22370, 787);
  52. REWARD_CHANCES.put(22371, 257);
  53. REWARD_CHANCES.put(22372, 656);
  54. }
  55. // Misc
  56. private static final int MIN_LEVEL = 76;
  57. public Q00691_MatrasSuspiciousRequest()
  58. {
  59. super(691, Q00691_MatrasSuspiciousRequest.class.getSimpleName(), "Matras' Suspicious Request");
  60. addStartNpc(MATRAS);
  61. addTalkId(MATRAS);
  62. addKillId(REWARD_CHANCES.keySet());
  63. }
  64. @Override
  65. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  66. {
  67. final QuestState st = getQuestState(player, false);
  68. if (st == null)
  69. {
  70. return null;
  71. }
  72. String htmltext = null;
  73. switch (event)
  74. {
  75. case "32245-02.htm":
  76. case "32245-11.html":
  77. htmltext = event;
  78. break;
  79. case "32245-04.htm":
  80. st.startQuest();
  81. htmltext = event;
  82. break;
  83. case "take_reward":
  84. if (st.isStarted())
  85. {
  86. final int gemsCount = st.getInt("submitted_gems");
  87. if (gemsCount >= 744)
  88. {
  89. st.set("submitted_gems", Integer.toString(gemsCount - 744));
  90. st.giveItems(DYNASTY_SOUL_II, 1);
  91. htmltext = "32245-09.html";
  92. }
  93. else
  94. {
  95. htmltext = getHtm(player.getHtmlPrefix(), "32245-10.html").replace("%itemcount%", st.get("submitted_gems"));
  96. }
  97. }
  98. break;
  99. case "32245-08.html":
  100. if (st.isStarted())
  101. {
  102. final int submittedCount = st.getInt("submitted_gems");
  103. final int broughtCount = (int) st.getQuestItemsCount(RED_GEM);
  104. final int finalCount = submittedCount + broughtCount;
  105. st.takeItems(RED_GEM, broughtCount);
  106. st.set("submitted_gems", Integer.toString(finalCount));
  107. htmltext = getHtm(player.getHtmlPrefix(), "32245-08.html").replace("%itemcount%", Integer.toString(finalCount));
  108. }
  109. break;
  110. case "32245-12.html":
  111. if (st.isStarted())
  112. {
  113. st.giveAdena((st.getInt("submitted_gems") * 10000), true);
  114. st.exitQuest(true, true);
  115. htmltext = event;
  116. }
  117. break;
  118. }
  119. return htmltext;
  120. }
  121. @Override
  122. public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  123. {
  124. final L2PcInstance pl = getRandomPartyMember(player, 1);
  125. if (pl == null)
  126. {
  127. return super.onKill(npc, player, isSummon);
  128. }
  129. final QuestState st = getQuestState(pl, false);
  130. int chance = (int) (Config.RATE_QUEST_DROP * REWARD_CHANCES.get(npc.getId()));
  131. int numItems = Math.max((chance / 1000), 1);
  132. chance = chance % 1000;
  133. if (getRandom(1000) <= chance)
  134. {
  135. st.giveItems(RED_GEM, numItems);
  136. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  137. }
  138. return super.onKill(npc, player, isSummon);
  139. }
  140. @Override
  141. public final String onTalk(L2Npc npc, L2PcInstance player)
  142. {
  143. String htmltext = getNoQuestMsg(player);
  144. final QuestState st = getQuestState(player, true);
  145. if (st == null)
  146. {
  147. return htmltext;
  148. }
  149. switch (st.getState())
  150. {
  151. case State.CREATED:
  152. htmltext = (player.getLevel() >= MIN_LEVEL) ? "32245-01.htm" : "32245-03.html";
  153. break;
  154. case State.STARTED:
  155. if (st.hasQuestItems(RED_GEM))
  156. {
  157. htmltext = "32245-05.html";
  158. }
  159. else if (st.getInt("submitted_gems") > 0)
  160. {
  161. htmltext = getHtm(player.getHtmlPrefix(), "32245-07.html").replace("%itemcount%", st.get("submitted_gems"));
  162. }
  163. else
  164. {
  165. htmltext = "32245-06.html";
  166. }
  167. break;
  168. }
  169. return htmltext;
  170. }
  171. }