Q00456_DontKnowDontCare.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.Q00456_DontKnowDontCare;
  20. import java.util.HashMap;
  21. import java.util.HashSet;
  22. import java.util.Map;
  23. import java.util.Set;
  24. import com.l2jserver.gameserver.datatables.ItemTable;
  25. import com.l2jserver.gameserver.enums.QuestSound;
  26. import com.l2jserver.gameserver.enums.QuestType;
  27. import com.l2jserver.gameserver.model.AggroInfo;
  28. import com.l2jserver.gameserver.model.L2CommandChannel;
  29. import com.l2jserver.gameserver.model.actor.L2Attackable;
  30. import com.l2jserver.gameserver.model.actor.L2Npc;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.items.L2Item;
  33. import com.l2jserver.gameserver.model.quest.Quest;
  34. import com.l2jserver.gameserver.model.quest.QuestState;
  35. import com.l2jserver.gameserver.model.quest.State;
  36. import com.l2jserver.gameserver.network.NpcStringId;
  37. import com.l2jserver.gameserver.network.clientpackets.Say2;
  38. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  39. import com.l2jserver.gameserver.util.Util;
  40. /**
  41. * Don't Know, Don't Care (456)
  42. * @author lion, ivantotov, jurchiks
  43. */
  44. public final class Q00456_DontKnowDontCare extends Quest
  45. {
  46. // NPCs
  47. // @formatter:off
  48. private static final int[] SEPARATED_SOUL =
  49. {
  50. 32864, 32865, 32866, 32867, 32868, 32869, 32870, 32891
  51. };
  52. // @formatter:on
  53. private static final int DRAKE_LORD_CORPSE = 32884;
  54. private static final int BEHEMOTH_LEADER_CORPSE = 32885;
  55. private static final int DRAGON_BEAST_CORPSE = 32886;
  56. // Items
  57. private static final int DRAKE_LORD_ESSENCE = 17251;
  58. private static final int BEHEMOTH_LEADER_ESSENCE = 17252;
  59. private static final int DRAGON_BEAST_ESSENCE = 17253;
  60. // Misc
  61. private static final int MIN_PLAYERS = 18;
  62. private static final int MIN_LEVEL = 80;
  63. private static final Map<Integer, Integer> MONSTER_NPCS = new HashMap<>();
  64. private static final Map<Integer, Integer> MONSTER_ESSENCES = new HashMap<>();
  65. static
  66. {
  67. MONSTER_NPCS.put(25725, DRAKE_LORD_CORPSE);
  68. MONSTER_NPCS.put(25726, BEHEMOTH_LEADER_CORPSE);
  69. MONSTER_NPCS.put(25727, DRAGON_BEAST_CORPSE);
  70. MONSTER_ESSENCES.put(DRAKE_LORD_CORPSE, DRAKE_LORD_ESSENCE);
  71. MONSTER_ESSENCES.put(BEHEMOTH_LEADER_CORPSE, BEHEMOTH_LEADER_ESSENCE);
  72. MONSTER_ESSENCES.put(DRAGON_BEAST_CORPSE, DRAGON_BEAST_ESSENCE);
  73. }
  74. // Rewards
  75. private static final int[] WEAPONS =
  76. {
  77. 15558, // Periel Sword
  78. 15559, // Skull Edge
  79. 15560, // Vigwik Axe
  80. 15561, // Devilish Maul
  81. 15562, // Feather Eye Blade
  82. 15563, // Octo Claw
  83. 15564, // Doubletop Spear
  84. 15565, // Rising Star
  85. 15566, // Black Visage
  86. 15567, // Veniplant Sword
  87. 15568, // Skull Carnium Bow
  88. 15569, // Gemtail Rapier
  89. 15570, // Finale Blade
  90. 15571, // Dominion Crossbow
  91. };
  92. private static final int[] ARMOR =
  93. {
  94. 15743, // Sealed Vorpal Helmet
  95. 15746, // Sealed Vorpal Breastplate
  96. 15749, // Sealed Vorpal Gaiters
  97. 15752, // Sealed Vorpal Gauntlets
  98. 15755, // Sealed Vorpal Boots
  99. 15758, // Sealed Vorpal Shield
  100. 15744, // Sealed Vorpal Leather Helmet
  101. 15747, // Sealed Vorpal Leather Breastplate
  102. 15750, // Sealed Vorpal Leather Leggings
  103. 15753, // Sealed Vorpal Leather Gloves
  104. 15756, // Sealed Vorpal Leather Boots
  105. 15745, // Sealed Vorpal Circlet
  106. 15748, // Sealed Vorpal Tunic
  107. 15751, // Sealed Vorpal Stockings
  108. 15754, // Sealed Vorpal Gloves
  109. 15757, // Sealed Vorpal Shoes
  110. 15759, // Sealed Vorpal Sigil
  111. };
  112. private static final int[] ACCESSORIES =
  113. {
  114. 15763, // Sealed Vorpal Ring
  115. 15764, // Sealed Vorpal Earring
  116. 15765, // Sealed Vorpal Necklace
  117. };
  118. private static final int[] ATTRIBUTE_CRYSTALS =
  119. {
  120. 9552, // Fire Crystal
  121. 9553, // Water Crystal
  122. 9554, // Earth Crystal
  123. 9555, // Wind Crystal
  124. 9556, // Dark Crystal
  125. 9557, // Holy Crystal
  126. };
  127. private static final int BLESSED_SCROLL_ENCHANT_WEAPON_S = 6577;
  128. private static final int BLESSED_SCROLL_ENCHANT_ARMOR_S = 6578;
  129. private static final int SCROLL_ENCHANT_WEAPON_S = 959;
  130. private static final int GEMSTONE_S = 2134;
  131. private final Map<Integer, Set<Integer>> allowedPlayerMap = new HashMap<>();
  132. public Q00456_DontKnowDontCare()
  133. {
  134. super(456, Q00456_DontKnowDontCare.class.getSimpleName(), "Don't Know, Don't Care");
  135. addStartNpc(SEPARATED_SOUL);
  136. addTalkId(SEPARATED_SOUL);
  137. addFirstTalkId(DRAKE_LORD_CORPSE, BEHEMOTH_LEADER_CORPSE, DRAGON_BEAST_CORPSE);
  138. addTalkId(DRAKE_LORD_CORPSE, BEHEMOTH_LEADER_CORPSE, DRAGON_BEAST_CORPSE);
  139. addKillId(MONSTER_NPCS.keySet());
  140. registerQuestItems(DRAKE_LORD_ESSENCE, BEHEMOTH_LEADER_ESSENCE, DRAGON_BEAST_ESSENCE);
  141. }
  142. @Override
  143. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  144. {
  145. final QuestState qs = getQuestState(player, false);
  146. final Set<Integer> allowedPlayers = allowedPlayerMap.get(npc.getObjectId());
  147. if ((qs == null) || !qs.isCond(1) || (allowedPlayers == null) || !allowedPlayers.contains(player.getObjectId()))
  148. {
  149. return npc.getId() + "-02.html";
  150. }
  151. final int essence = MONSTER_ESSENCES.get(npc.getId());
  152. final String htmltext;
  153. if (hasQuestItems(player, essence))
  154. {
  155. htmltext = npc.getId() + "-03.html";
  156. }
  157. else
  158. {
  159. giveItems(player, essence, 1);
  160. htmltext = npc.getId() + "-01.html";
  161. if (hasQuestItems(player, getRegisteredItemIds()))
  162. {
  163. qs.setCond(2, true);
  164. }
  165. else
  166. {
  167. playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
  168. }
  169. }
  170. return htmltext;
  171. }
  172. @Override
  173. public String onTalk(L2Npc npc, L2PcInstance player)
  174. {
  175. final QuestState qs = getQuestState(player, true);
  176. String htmltext = getNoQuestMsg(player);
  177. if (qs == null)
  178. {
  179. return htmltext;
  180. }
  181. if (Util.contains(SEPARATED_SOUL, npc.getId()))
  182. {
  183. switch (qs.getState())
  184. {
  185. case State.COMPLETED:
  186. if (!qs.isNowAvailable())
  187. {
  188. htmltext = "32864-02.html";
  189. break;
  190. }
  191. qs.setState(State.CREATED);
  192. // intentional fall-through
  193. case State.CREATED:
  194. htmltext = ((player.getLevel() >= MIN_LEVEL) ? "32864-01.htm" : "32864-03.html");
  195. break;
  196. case State.STARTED:
  197. switch (qs.getCond())
  198. {
  199. case 1:
  200. {
  201. htmltext = (hasAtLeastOneQuestItem(player, getRegisteredItemIds()) ? "32864-09.html" : "32864-08.html");
  202. break;
  203. }
  204. case 2:
  205. {
  206. if (hasQuestItems(player, getRegisteredItemIds()))
  207. {
  208. rewardPlayer(player, npc);
  209. qs.exitQuest(QuestType.DAILY, true);
  210. htmltext = "32864-10.html";
  211. }
  212. break;
  213. }
  214. }
  215. break;
  216. }
  217. }
  218. return htmltext;
  219. }
  220. @Override
  221. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  222. {
  223. final QuestState qs = getQuestState(player, false);
  224. String htmltext = null;
  225. switch (event)
  226. {
  227. case "32864-04.htm":
  228. case "32864-05.htm":
  229. case "32864-06.htm":
  230. if ((qs != null) && qs.isCreated())
  231. {
  232. htmltext = event;
  233. }
  234. break;
  235. case "32864-07.htm":
  236. if ((qs != null) && qs.isCreated())
  237. {
  238. qs.startQuest();
  239. htmltext = event;
  240. }
  241. break;
  242. case "unspawnRaidCorpse":
  243. allowedPlayerMap.remove(npc.getObjectId());
  244. npc.deleteMe();
  245. break;
  246. }
  247. return htmltext;
  248. }
  249. @Override
  250. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  251. {
  252. if (!killer.isInParty() || !killer.getParty().isInCommandChannel())
  253. {
  254. // only the killing cc gets the quest
  255. return super.onKill(npc, killer, isSummon);
  256. }
  257. final L2CommandChannel cc = killer.getParty().getCommandChannel();
  258. if (cc.getMemberCount() < MIN_PLAYERS)
  259. {
  260. return super.onKill(npc, killer, isSummon);
  261. }
  262. Set<Integer> allowedPlayers = new HashSet<>();
  263. for (AggroInfo aggro : ((L2Attackable) npc).getAggroList().values())
  264. {
  265. if ((aggro.getAttacker() == null) || !aggro.getAttacker().isPlayer())
  266. {
  267. continue;
  268. }
  269. L2PcInstance attacker = aggro.getAttacker().getActingPlayer();
  270. if (attacker.isInParty() //
  271. && attacker.getParty().isInCommandChannel() //
  272. && attacker.getParty().getCommandChannel().equals(cc) // only players from the same cc are allowed
  273. && Util.checkIfInRange(1500, npc, attacker, true))
  274. {
  275. allowedPlayers.add(attacker.getObjectId());
  276. }
  277. }
  278. if (!allowedPlayers.isEmpty())
  279. {
  280. // This depends on the boss respawn delay being at least 5 minutes.
  281. final L2Npc spawned = addSpawn(MONSTER_NPCS.get(npc.getId()), npc, true, 0);
  282. allowedPlayerMap.put(spawned.getObjectId(), allowedPlayers);
  283. startQuestTimer("unspawnRaidCorpse", 300000, npc, null);
  284. }
  285. return super.onKill(npc, killer, isSummon);
  286. }
  287. private static void rewardPlayer(L2PcInstance player, L2Npc npc)
  288. {
  289. int chance = getRandom(10000);
  290. final int reward;
  291. int count = 1;
  292. if (chance < 170)
  293. {
  294. reward = ARMOR[getRandom(ARMOR.length)];
  295. }
  296. else if (chance < 200)
  297. {
  298. reward = ACCESSORIES[getRandom(ACCESSORIES.length)];
  299. }
  300. else if (chance < 270)
  301. {
  302. reward = WEAPONS[getRandom(WEAPONS.length)];
  303. }
  304. else if (chance < 325)
  305. {
  306. reward = BLESSED_SCROLL_ENCHANT_WEAPON_S;
  307. }
  308. else if (chance < 425)
  309. {
  310. reward = BLESSED_SCROLL_ENCHANT_ARMOR_S;
  311. }
  312. else if (chance < 925)
  313. {
  314. reward = ATTRIBUTE_CRYSTALS[getRandom(ATTRIBUTE_CRYSTALS.length)];
  315. }
  316. else if (chance < 1100)
  317. {
  318. reward = SCROLL_ENCHANT_WEAPON_S;
  319. }
  320. else
  321. {
  322. reward = GEMSTONE_S;
  323. count = 3;
  324. }
  325. giveItems(player, reward, count);
  326. L2Item item = ItemTable.getInstance().getTemplate(reward);
  327. NpcSay packet = new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.S1_RECEIVED_A_S2_ITEM_AS_A_REWARD_FROM_THE_SEPARATED_SOUL);
  328. packet.addStringParameter(player.getName());
  329. packet.addStringParameter(item.getName());
  330. npc.broadcastPacket(packet);
  331. }
  332. }