CavernOfThePirateCaptain.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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 instances.CavernOfThePirateCaptain;
  20. import instances.AbstractInstance;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  24. import com.l2jserver.gameserver.model.L2Party;
  25. import com.l2jserver.gameserver.model.Location;
  26. import com.l2jserver.gameserver.model.PcCondOverride;
  27. import com.l2jserver.gameserver.model.actor.L2Attackable;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  31. import com.l2jserver.gameserver.network.NpcStringId;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  34. /**
  35. * Cavern Of The Pirate Captain (Day Dream) instance Zone.
  36. * @author St3eT
  37. */
  38. public final class CavernOfThePirateCaptain extends AbstractInstance
  39. {
  40. protected class CavernOfThePirateCaptainWorld extends InstanceWorld
  41. {
  42. protected List<L2PcInstance> playersInside = new ArrayList<>();
  43. protected L2Attackable _zaken;
  44. protected long storeTime = 0;
  45. protected boolean _is83;
  46. protected int _zakenRoom;
  47. protected int _blueFounded;
  48. }
  49. // NPCs
  50. private static final int PATHFINDER = 32713; // Pathfinder Worker
  51. private static final int ZAKEN_60 = 29176; // Zaken
  52. private static final int ZAKEN_83 = 29181; // Zaken
  53. private static final int CANDLE = 32705; // Zaken's Candle
  54. private static final int DOLL_BLADER_60 = 29023; // Doll Blader
  55. private static final int DOLL_BLADER_83 = 29182; // Doll Blader
  56. private static final int VALE_MASTER_60 = 29024; // Veil Master
  57. private static final int VALE_MASTER_83 = 29183; // Veil Master
  58. private static final int PIRATES_ZOMBIE_60 = 29027; // Pirate Zombie
  59. private static final int PIRATES_ZOMBIE_83 = 29185; // Pirate Zombie
  60. private static final int PIRATES_ZOMBIE_CAPTAIN_60 = 29026; // Pirate Zombie Captain
  61. private static final int PIRATES_ZOMBIE_CAPTAIN_83 = 29184; // Pirate Zombie Captain
  62. // Items
  63. private static final int VORPAL_RING = 15763; // Sealed Vorpal Ring
  64. private static final int VORPAL_EARRING = 15764; // Sealed Vorpal Earring
  65. private static final int FIRE = 15280; // Transparent 1HS (for NPC)
  66. private static final int RED = 15281; // Transparent 1HS (for NPC)
  67. private static final int BLUE = 15302; // Transparent Bow (for NPC)
  68. // Locations
  69. private static final Location[] ENTER_LOC =
  70. {
  71. new Location(52684, 219989, -3496),
  72. new Location(52669, 219120, -3224),
  73. new Location(52672, 219439, -3312),
  74. };
  75. private static final Location[] CANDLE_LOC =
  76. {
  77. // Floor 1
  78. new Location(53313, 220133, -3498),
  79. new Location(53313, 218079, -3498),
  80. new Location(54240, 221045, -3498),
  81. new Location(54325, 219095, -3498),
  82. new Location(54240, 217155, -3498),
  83. new Location(55257, 220028, -3498),
  84. new Location(55257, 218172, -3498),
  85. new Location(56280, 221045, -3498),
  86. new Location(56195, 219095, -3498),
  87. new Location(56280, 217155, -3498),
  88. new Location(57215, 220133, -3498),
  89. new Location(57215, 218079, -3498),
  90. // Floor 2
  91. new Location(53313, 220133, -3226),
  92. new Location(53313, 218079, -3226),
  93. new Location(54240, 221045, -3226),
  94. new Location(54325, 219095, -3226),
  95. new Location(54240, 217155, -3226),
  96. new Location(55257, 220028, -3226),
  97. new Location(55257, 218172, -3226),
  98. new Location(56280, 221045, -3226),
  99. new Location(56195, 219095, -3226),
  100. new Location(56280, 217155, -3226),
  101. new Location(57215, 220133, -3226),
  102. new Location(57215, 218079, -3226),
  103. // Floor 3
  104. new Location(53313, 220133, -2954),
  105. new Location(53313, 218079, -2954),
  106. new Location(54240, 221045, -2954),
  107. new Location(54325, 219095, -2954),
  108. new Location(54240, 217155, -2954),
  109. new Location(55257, 220028, -2954),
  110. new Location(55257, 218172, -2954),
  111. new Location(56280, 221045, -2954),
  112. new Location(56195, 219095, -2954),
  113. new Location(56280, 217155, -2954),
  114. new Location(57215, 220133, -2954),
  115. new Location(57215, 218079, -2954),
  116. };
  117. // Misc
  118. private static final int MIN_LV_60 = 55;
  119. private static final int MIN_LV_83 = 78;
  120. private static final int PLAYERS_60_MIN = 9;
  121. private static final int PLAYERS_60_MAX = 27;
  122. private static final int PLAYERS_83_MIN = 9;
  123. private static final int PLAYERS_83_MAX = 27;
  124. private static final int TEMPLATE_ID_60 = 133;
  125. private static final int TEMPLATE_ID_83 = 135;
  126. //@formatter:off
  127. private static final int[][] ROOM_DATA =
  128. {
  129. // Floor 1
  130. {54240, 220133, -3498, 1, 3, 4, 6},
  131. {54240, 218073, -3498, 2, 5, 4, 7},
  132. {55265, 219095, -3498, 4, 9, 6, 7},
  133. {56289, 220133, -3498, 8, 11, 6, 9},
  134. {56289, 218073, -3498, 10, 12, 7, 9},
  135. // Floor 2
  136. {54240, 220133, -3226, 13, 15, 16, 18},
  137. {54240, 218073, -3226, 14, 17, 16, 19},
  138. {55265, 219095, -3226, 21, 16, 19, 18},
  139. {56289, 220133, -3226, 20, 23, 21, 18},
  140. {56289, 218073, -3226, 22, 24, 19, 21},
  141. // Floor 3
  142. {54240, 220133, -2954, 25, 27, 28, 30},
  143. {54240, 218073, -2954, 26, 29, 28, 31},
  144. {55265, 219095, -2954, 33, 28, 31, 30},
  145. {56289, 220133, -2954, 32, 35, 30, 33},
  146. {56289, 218073, -2954, 34, 36, 31, 33}
  147. };
  148. //@formatter:on
  149. public CavernOfThePirateCaptain()
  150. {
  151. super(CavernOfThePirateCaptain.class.getSimpleName());
  152. addStartNpc(PATHFINDER);
  153. addTalkId(PATHFINDER);
  154. addKillId(ZAKEN_60, ZAKEN_83);
  155. addFirstTalkId(CANDLE);
  156. }
  157. @Override
  158. public void onEnterInstance(L2PcInstance player, InstanceWorld world, boolean firstEntrance)
  159. {
  160. if (firstEntrance)
  161. {
  162. final CavernOfThePirateCaptainWorld curworld = (CavernOfThePirateCaptainWorld) world;
  163. curworld._is83 = curworld.getTemplateId() == TEMPLATE_ID_83;
  164. curworld.storeTime = System.currentTimeMillis();
  165. if (!player.isInParty())
  166. {
  167. managePlayerEnter(player, curworld);
  168. }
  169. else if (player.getParty().isInCommandChannel())
  170. {
  171. for (L2PcInstance players : player.getParty().getCommandChannel().getMembers())
  172. {
  173. managePlayerEnter(players, curworld);
  174. }
  175. }
  176. else
  177. {
  178. for (L2PcInstance players : player.getParty().getMembers())
  179. {
  180. managePlayerEnter(players, curworld);
  181. }
  182. }
  183. manageNpcSpawn(curworld);
  184. }
  185. else
  186. {
  187. teleportPlayer(player, ENTER_LOC[getRandom(ENTER_LOC.length)], world.getInstanceId(), false);
  188. }
  189. }
  190. private void managePlayerEnter(L2PcInstance player, CavernOfThePirateCaptainWorld world)
  191. {
  192. world.playersInside.add(player);
  193. world.addAllowed(player.getObjectId());
  194. teleportPlayer(player, ENTER_LOC[getRandom(ENTER_LOC.length)], world.getInstanceId(), false);
  195. }
  196. @Override
  197. protected boolean checkConditions(L2PcInstance player)
  198. {
  199. if (player.canOverrideCond(PcCondOverride.INSTANCE_CONDITIONS))
  200. {
  201. return true;
  202. }
  203. if (!player.isInParty())
  204. {
  205. broadcastSystemMessage(player, null, SystemMessageId.NOT_IN_PARTY_CANT_ENTER, false);
  206. return false;
  207. }
  208. final boolean is83 = InstanceManager.getInstance().getPlayerWorld(player).getTemplateId() == TEMPLATE_ID_83 ? true : false;
  209. final L2Party party = player.getParty();
  210. final boolean isInCC = party.isInCommandChannel();
  211. final List<L2PcInstance> members = (isInCC) ? party.getCommandChannel().getMembers() : party.getMembers();
  212. final boolean isPartyLeader = (isInCC) ? party.getCommandChannel().isLeader(player) : party.isLeader(player);
  213. if (!isPartyLeader)
  214. {
  215. broadcastSystemMessage(player, null, SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER, false);
  216. return false;
  217. }
  218. if ((members.size() < (is83 ? PLAYERS_83_MIN : PLAYERS_60_MIN)) || (members.size() > (is83 ? PLAYERS_83_MAX : PLAYERS_60_MAX)))
  219. {
  220. broadcastSystemMessage(player, null, SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER, false);
  221. return false;
  222. }
  223. for (L2PcInstance groupMembers : members)
  224. {
  225. if (groupMembers.getLevel() < (is83 ? MIN_LV_83 : MIN_LV_60))
  226. {
  227. broadcastSystemMessage(player, groupMembers, SystemMessageId.C1_S_LEVEL_REQUIREMENT_IS_NOT_SUFFICIENT_AND_CANNOT_BE_ENTERED, true);
  228. return false;
  229. }
  230. if (!player.isInsideRadius(groupMembers, 1000, true, true))
  231. {
  232. broadcastSystemMessage(player, groupMembers, SystemMessageId.C1_IS_IN_A_LOCATION_WHICH_CANNOT_BE_ENTERED_THEREFORE_IT_CANNOT_BE_PROCESSED, true);
  233. return false;
  234. }
  235. final Long reentertime = InstanceManager.getInstance().getInstanceTime(groupMembers.getObjectId(), (is83 ? TEMPLATE_ID_83 : TEMPLATE_ID_60));
  236. if (System.currentTimeMillis() < reentertime)
  237. {
  238. broadcastSystemMessage(player, groupMembers, SystemMessageId.C1_MAY_NOT_RE_ENTER_YET, true);
  239. return false;
  240. }
  241. }
  242. return true;
  243. }
  244. private void broadcastSystemMessage(L2PcInstance player, L2PcInstance member, SystemMessageId msgId, boolean toGroup)
  245. {
  246. final SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  247. if (toGroup)
  248. {
  249. sm.addPcName(member);
  250. if (player.getParty().isInCommandChannel())
  251. {
  252. player.getParty().getCommandChannel().broadcastPacket(sm);
  253. }
  254. else
  255. {
  256. player.getParty().broadcastPacket(sm);
  257. }
  258. }
  259. else
  260. {
  261. player.broadcastPacket(sm);
  262. }
  263. }
  264. @Override
  265. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  266. {
  267. if (event.equals("enter60"))
  268. {
  269. enterInstance(player, new CavernOfThePirateCaptainWorld(), "CavernOfThePirateCaptainWorldDay60.xml", TEMPLATE_ID_60);
  270. }
  271. else if (event.equals("enter83"))
  272. {
  273. enterInstance(player, new CavernOfThePirateCaptainWorld(), "CavernOfThePirateCaptainWorldDay83.xml", TEMPLATE_ID_83);
  274. }
  275. else
  276. {
  277. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  278. if ((tmpworld != null) && (tmpworld instanceof CavernOfThePirateCaptainWorld))
  279. {
  280. final CavernOfThePirateCaptainWorld world = (CavernOfThePirateCaptainWorld) tmpworld;
  281. switch (event)
  282. {
  283. case "BURN_BLUE":
  284. {
  285. if (npc.getRightHandItem() == 0)
  286. {
  287. npc.setRHandId(FIRE);
  288. startQuestTimer("BURN_BLUE2", 3000, npc, player);
  289. if (world._blueFounded == 4)
  290. {
  291. startQuestTimer("SHOW_ZAKEN", 5000, npc, player);
  292. }
  293. }
  294. break;
  295. }
  296. case "BURN_BLUE2":
  297. {
  298. if (npc.getRightHandItem() == FIRE)
  299. {
  300. npc.setRHandId(BLUE);
  301. }
  302. break;
  303. }
  304. case "BURN_RED":
  305. {
  306. if (npc.getRightHandItem() == 0)
  307. {
  308. npc.setRHandId(FIRE);
  309. startQuestTimer("BURN_RED2", 3000, npc, player);
  310. }
  311. break;
  312. }
  313. case "BURN_RED2":
  314. {
  315. if (npc.getRightHandItem() == FIRE)
  316. {
  317. final int room = getRoomByCandle(npc);
  318. npc.setRHandId(RED);
  319. manageScreenMsg(world, NpcStringId.THE_CANDLES_CAN_LEAD_YOU_TO_ZAKEN_DESTROY_HIM);
  320. spawnNpc(world._is83 ? DOLL_BLADER_83 : DOLL_BLADER_60, room, player, world);
  321. spawnNpc(world._is83 ? VALE_MASTER_83 : VALE_MASTER_60, room, player, world);
  322. spawnNpc(world._is83 ? PIRATES_ZOMBIE_83 : PIRATES_ZOMBIE_60, room, player, world);
  323. spawnNpc(world._is83 ? PIRATES_ZOMBIE_CAPTAIN_83 : PIRATES_ZOMBIE_CAPTAIN_60, room, player, world);
  324. }
  325. break;
  326. }
  327. case "SHOW_ZAKEN":
  328. {
  329. if (world._is83)
  330. {
  331. manageScreenMsg(world, NpcStringId.WHO_DARES_AWKAWEN_THE_MIGHTY_ZAKEN);
  332. }
  333. world._zaken.setInvisible(false);
  334. world._zaken.setIsParalyzed(false);
  335. spawnNpc(world._is83 ? DOLL_BLADER_83 : DOLL_BLADER_60, world._zakenRoom, player, world);
  336. spawnNpc(world._is83 ? PIRATES_ZOMBIE_83 : PIRATES_ZOMBIE_60, world._zakenRoom, player, world);
  337. spawnNpc(world._is83 ? PIRATES_ZOMBIE_CAPTAIN_83 : PIRATES_ZOMBIE_CAPTAIN_60, world._zakenRoom, player, world);
  338. break;
  339. }
  340. }
  341. }
  342. }
  343. return super.onAdvEvent(event, npc, player);
  344. }
  345. @Override
  346. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  347. {
  348. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  349. if ((tmpworld != null) && (tmpworld instanceof CavernOfThePirateCaptainWorld))
  350. {
  351. final CavernOfThePirateCaptainWorld world = (CavernOfThePirateCaptainWorld) tmpworld;
  352. if (npc.getId() == ZAKEN_83)
  353. {
  354. for (L2PcInstance playersInside : world.playersInside)
  355. {
  356. if ((playersInside != null) && ((playersInside.getInstanceId() == world.getInstanceId()) && playersInside.isInsideRadius(npc, 1500, true, true)))
  357. {
  358. final long time = System.currentTimeMillis() - world.storeTime;
  359. if (time <= 300000) // 5 minutes
  360. {
  361. if (getRandomBoolean())
  362. {
  363. giveItems(playersInside, VORPAL_RING, 1);
  364. }
  365. }
  366. else if (time <= 600000) // 10 minutes
  367. {
  368. if (getRandom(100) < 30)
  369. {
  370. giveItems(playersInside, VORPAL_EARRING, 1);
  371. }
  372. }
  373. else if (time <= 900000) // 15 minutes
  374. {
  375. if (getRandom(100) < 25)
  376. {
  377. giveItems(playersInside, VORPAL_RING, 1);
  378. }
  379. }
  380. }
  381. }
  382. }
  383. finishInstance(world);
  384. }
  385. return super.onKill(npc, killer, isSummon);
  386. }
  387. @Override
  388. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  389. {
  390. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  391. if ((tmpworld != null) && (tmpworld instanceof CavernOfThePirateCaptainWorld))
  392. {
  393. final CavernOfThePirateCaptainWorld world = (CavernOfThePirateCaptainWorld) tmpworld;
  394. final boolean isBlue = npc.getVariables().getInt("isBlue", 0) == 1;
  395. if (npc.isScriptValue(0))
  396. {
  397. if (isBlue)
  398. {
  399. world._blueFounded++;
  400. startQuestTimer("BURN_BLUE", 500, npc, player);
  401. }
  402. else
  403. {
  404. startQuestTimer("BURN_RED", 500, npc, player);
  405. }
  406. npc.setScriptValue(1);
  407. }
  408. }
  409. return null;
  410. }
  411. private int getRoomByCandle(L2Npc npc)
  412. {
  413. final int candleId = npc.getVariables().getInt("candleId", 0);
  414. for (int i = 0; i < 15; i++)
  415. {
  416. if ((ROOM_DATA[i][3] == candleId) || (ROOM_DATA[i][4] == candleId))
  417. {
  418. return i + 1;
  419. }
  420. }
  421. if ((candleId == 6) || (candleId == 7))
  422. {
  423. return 3;
  424. }
  425. else if ((candleId == 18) || (candleId == 19))
  426. {
  427. return 8;
  428. }
  429. else if ((candleId == 30) || (candleId == 31))
  430. {
  431. return 13;
  432. }
  433. return 0;
  434. }
  435. private void manageScreenMsg(CavernOfThePirateCaptainWorld world, NpcStringId stringId)
  436. {
  437. for (L2PcInstance players : world.playersInside)
  438. {
  439. if ((players != null) && (players.getInstanceId() == world.getInstanceId()))
  440. {
  441. showOnScreenMsg(players, stringId, 2, 6000);
  442. }
  443. }
  444. }
  445. private L2Attackable spawnNpc(int npcId, int roomId, L2PcInstance player, CavernOfThePirateCaptainWorld world)
  446. {
  447. if ((player != null) && (npcId != ZAKEN_60) && (npcId != ZAKEN_83))
  448. {
  449. final L2Attackable mob = (L2Attackable) addSpawn(npcId, ROOM_DATA[roomId - 1][0] + getRandom(350), ROOM_DATA[roomId - 1][1] + getRandom(350), ROOM_DATA[roomId - 1][2], 0, false, 0, false, world.getInstanceId());
  450. addAttackPlayerDesire(mob, player);
  451. return mob;
  452. }
  453. return (L2Attackable) addSpawn(npcId, ROOM_DATA[roomId - 1][0], ROOM_DATA[roomId - 1][1], ROOM_DATA[roomId - 1][2], 0, false, 0, false, world.getInstanceId());
  454. }
  455. private void manageNpcSpawn(CavernOfThePirateCaptainWorld world)
  456. {
  457. final List<L2Npc> candles = new ArrayList<>();
  458. world._zakenRoom = getRandom(1, 15);
  459. for (int i = 0; i < 36; i++)
  460. {
  461. final L2Npc candle = addSpawn(CANDLE, CANDLE_LOC[i], false, 0, false, world.getInstanceId());
  462. candle.getVariables().set("candleId", i + 1);
  463. candles.add(candle);
  464. }
  465. for (int i = 3; i < 7; i++)
  466. {
  467. candles.get(ROOM_DATA[world._zakenRoom - 1][i] - 1).getVariables().set("isBlue", 1);
  468. }
  469. world._zaken = spawnNpc(world._is83 ? ZAKEN_83 : ZAKEN_60, world._zakenRoom, null, world);
  470. world._zaken.setInvisible(true);
  471. world._zaken.setIsParalyzed(true);
  472. }
  473. }