Q00406_PathOfTheElvenKnight.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.Q00406_PathOfTheElvenKnight;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.enums.QuestSound;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.base.ClassId;
  26. import com.l2jserver.gameserver.model.holders.ItemChanceHolder;
  27. import com.l2jserver.gameserver.model.quest.Quest;
  28. import com.l2jserver.gameserver.model.quest.QuestState;
  29. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  30. import com.l2jserver.gameserver.util.Util;
  31. /**
  32. * Path Of The Elven Knight (406)
  33. * @author ivantotov
  34. */
  35. public final class Q00406_PathOfTheElvenKnight extends Quest
  36. {
  37. // NPCs
  38. private static final int BLACKSMITH_KLUTO = 30317;
  39. private static final int MASTER_SORIUS = 30327;
  40. // Items
  41. private static final int SORIUS_LETTER = 1202;
  42. private static final int KLUTO_BOX = 1203;
  43. private static final int TOPAZ_PIECE = 1205;
  44. private static final int EMERALD_PIECE = 1206;
  45. private static final int KLUTO_MEMO = 1276;
  46. // Reward
  47. private static final int ELVEN_KNIGHT_BROOCH = 1204;
  48. // Misc
  49. private static final int MIN_LEVEL = 18;
  50. // Mobs
  51. private static final int OL_MAHUM_NOVICE = 20782;
  52. private static final Map<Integer, ItemChanceHolder> MONSTER_DROPS = new HashMap<>();
  53. static
  54. {
  55. MONSTER_DROPS.put(20035, new ItemChanceHolder(TOPAZ_PIECE, 70)); // Tracker Skeleton
  56. MONSTER_DROPS.put(20042, new ItemChanceHolder(TOPAZ_PIECE, 70)); // Tracker Skeleton Leader
  57. MONSTER_DROPS.put(20045, new ItemChanceHolder(TOPAZ_PIECE, 70)); // Skeleton Scout
  58. MONSTER_DROPS.put(20051, new ItemChanceHolder(TOPAZ_PIECE, 70)); // Skeleton Bowman
  59. MONSTER_DROPS.put(20054, new ItemChanceHolder(TOPAZ_PIECE, 70)); // Ruin Spartoi
  60. MONSTER_DROPS.put(20060, new ItemChanceHolder(TOPAZ_PIECE, 70)); // Salamander Noble
  61. MONSTER_DROPS.put(OL_MAHUM_NOVICE, new ItemChanceHolder(EMERALD_PIECE, 50)); // Ol Mahum Novice
  62. }
  63. public Q00406_PathOfTheElvenKnight()
  64. {
  65. super(406, Q00406_PathOfTheElvenKnight.class.getSimpleName(), "Path Of The Elven Knight");
  66. addStartNpc(MASTER_SORIUS);
  67. addTalkId(MASTER_SORIUS, BLACKSMITH_KLUTO);
  68. addKillId(MONSTER_DROPS.keySet());
  69. registerQuestItems(SORIUS_LETTER, KLUTO_BOX, TOPAZ_PIECE, EMERALD_PIECE, KLUTO_MEMO);
  70. }
  71. @Override
  72. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  73. {
  74. final QuestState qs = getQuestState(player, false);
  75. if (qs == null)
  76. {
  77. return null;
  78. }
  79. String htmltext = null;
  80. switch (event)
  81. {
  82. case "ACCEPT":
  83. {
  84. if (player.getClassId() != ClassId.elvenFighter)
  85. {
  86. if (player.getClassId() == ClassId.elvenKnight)
  87. {
  88. htmltext = "30327-02a.htm";
  89. }
  90. else
  91. {
  92. htmltext = "30327-02.htm";
  93. }
  94. }
  95. else if (player.getLevel() < MIN_LEVEL)
  96. {
  97. htmltext = "30327-03.htm";
  98. }
  99. else if (hasQuestItems(player, ELVEN_KNIGHT_BROOCH))
  100. {
  101. htmltext = "30327-04.htm";
  102. }
  103. else
  104. {
  105. htmltext = "30327-05.htm";
  106. }
  107. break;
  108. }
  109. case "30327-06.htm":
  110. {
  111. qs.startQuest();
  112. htmltext = event;
  113. break;
  114. }
  115. case "30317-02.html":
  116. {
  117. takeItems(player, SORIUS_LETTER, 1);
  118. if (!hasQuestItems(player, KLUTO_MEMO))
  119. {
  120. giveItems(player, KLUTO_MEMO, 1);
  121. }
  122. qs.setCond(4, true);
  123. htmltext = event;
  124. break;
  125. }
  126. }
  127. return htmltext;
  128. }
  129. @Override
  130. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  131. {
  132. final QuestState qs = getQuestState(killer, false);
  133. final ItemChanceHolder reward = MONSTER_DROPS.get(npc.getId());
  134. int requiredItemId = KLUTO_BOX;
  135. int cond = 2;
  136. boolean check = !hasQuestItems(killer, requiredItemId);
  137. if (npc.getId() == OL_MAHUM_NOVICE)
  138. {
  139. requiredItemId = KLUTO_MEMO;
  140. cond = 5;
  141. check = hasQuestItems(killer, requiredItemId);
  142. }
  143. if ((qs != null) && qs.isStarted() && Util.checkIfInRange(1500, npc, killer, false))
  144. {
  145. if (check && (getQuestItemsCount(killer, reward.getId()) < 20) && (getRandom(100) < reward.getChance()))
  146. {
  147. giveItems(killer, reward);
  148. if (getQuestItemsCount(killer, reward.getId()) == 20)
  149. {
  150. qs.setCond(cond, true);
  151. }
  152. else
  153. {
  154. playSound(killer, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  155. }
  156. }
  157. }
  158. return super.onKill(npc, killer, isSummon);
  159. }
  160. @Override
  161. public String onTalk(L2Npc npc, L2PcInstance player)
  162. {
  163. final QuestState qs = getQuestState(player, true);
  164. String htmltext = getNoQuestMsg(player);
  165. if (qs.isCreated() || qs.isCompleted())
  166. {
  167. if (npc.getId() == MASTER_SORIUS)
  168. {
  169. htmltext = "30327-01.htm";
  170. }
  171. }
  172. else if (qs.isStarted())
  173. {
  174. switch (npc.getId())
  175. {
  176. case MASTER_SORIUS:
  177. {
  178. if (!hasQuestItems(player, KLUTO_BOX))
  179. {
  180. if (!hasQuestItems(player, TOPAZ_PIECE))
  181. {
  182. htmltext = "30327-07.html";
  183. }
  184. else if (hasQuestItems(player, TOPAZ_PIECE) && (getQuestItemsCount(player, TOPAZ_PIECE) < 20))
  185. {
  186. htmltext = "30327-08.html";
  187. }
  188. else if (!hasAtLeastOneQuestItem(player, KLUTO_MEMO, SORIUS_LETTER) && (getQuestItemsCount(player, TOPAZ_PIECE) >= 20))
  189. {
  190. if (!hasQuestItems(player, SORIUS_LETTER))
  191. {
  192. giveItems(player, SORIUS_LETTER, 1);
  193. }
  194. qs.setCond(3, true);
  195. htmltext = "30327-09.html";
  196. }
  197. else if ((getQuestItemsCount(player, TOPAZ_PIECE) >= 20) && hasAtLeastOneQuestItem(player, SORIUS_LETTER, KLUTO_MEMO))
  198. {
  199. htmltext = "30327-11.html";
  200. }
  201. }
  202. else
  203. {
  204. giveAdena(player, 163800, true);
  205. if (!hasQuestItems(player, ELVEN_KNIGHT_BROOCH))
  206. {
  207. giveItems(player, ELVEN_KNIGHT_BROOCH, 1);
  208. }
  209. final int level = player.getLevel();
  210. if (level >= 20)
  211. {
  212. addExpAndSp(player, 320534, 23152);
  213. }
  214. else if (level == 19)
  215. {
  216. addExpAndSp(player, 456128, 29850);
  217. }
  218. else
  219. {
  220. addExpAndSp(player, 591724, 33328);
  221. }
  222. qs.exitQuest(false, true);
  223. player.sendPacket(new SocialAction(player.getObjectId(), 3));
  224. qs.saveGlobalQuestVar("1ClassQuestFinished", "1");
  225. htmltext = "30327-10.html";
  226. }
  227. break;
  228. }
  229. case BLACKSMITH_KLUTO:
  230. {
  231. if (!hasQuestItems(player, KLUTO_BOX))
  232. {
  233. if (hasQuestItems(player, SORIUS_LETTER) && (getQuestItemsCount(player, TOPAZ_PIECE) >= 20))
  234. {
  235. htmltext = "30317-01.html";
  236. }
  237. else if (!hasQuestItems(player, EMERALD_PIECE) && hasQuestItems(player, KLUTO_MEMO) && (getQuestItemsCount(player, TOPAZ_PIECE) >= 20))
  238. {
  239. htmltext = "30317-03.html";
  240. }
  241. else if (hasQuestItems(player, KLUTO_MEMO, EMERALD_PIECE) && (getQuestItemsCount(player, TOPAZ_PIECE) >= 20) && (getQuestItemsCount(player, EMERALD_PIECE) < 20))
  242. {
  243. htmltext = "30317-04.html";
  244. }
  245. else if (hasQuestItems(player, KLUTO_MEMO) && (getQuestItemsCount(player, TOPAZ_PIECE) >= 20) && (getQuestItemsCount(player, EMERALD_PIECE) >= 20))
  246. {
  247. if (!hasQuestItems(player, KLUTO_BOX))
  248. {
  249. giveItems(player, KLUTO_BOX, 1);
  250. }
  251. takeItems(player, TOPAZ_PIECE, -1);
  252. takeItems(player, EMERALD_PIECE, -1);
  253. takeItems(player, KLUTO_MEMO, 1);
  254. qs.setCond(6, true);
  255. htmltext = "30317-05.html";
  256. }
  257. }
  258. else if (hasQuestItems(player, KLUTO_BOX))
  259. {
  260. htmltext = "30317-06.html";
  261. }
  262. break;
  263. }
  264. }
  265. }
  266. return htmltext;
  267. }
  268. }