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