criss28282

Untitled

May 10th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.80 KB | None | 0 0
  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.Kamaloka;
  20.  
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.Calendar;
  24. import java.util.List;
  25. import java.util.Map;
  26.  
  27. import l2r.gameserver.data.xml.impl.SkillData;
  28. import l2r.gameserver.instancemanager.InstanceManager;
  29. import l2r.gameserver.model.L2Party;
  30. import l2r.gameserver.model.L2Spawn;
  31. import l2r.gameserver.model.L2World;
  32. import l2r.gameserver.model.Location;
  33. import l2r.gameserver.model.actor.L2Character;
  34. import l2r.gameserver.model.actor.L2Npc;
  35. import l2r.gameserver.model.actor.instance.L2PcInstance;
  36. import l2r.gameserver.model.effects.L2Effect;
  37. import l2r.gameserver.model.entity.Instance;
  38. import l2r.gameserver.model.instancezone.InstanceWorld;
  39. import l2r.gameserver.model.skills.L2Skill;
  40. import l2r.gameserver.network.SystemMessageId;
  41. import l2r.gameserver.network.serverpackets.SystemMessage;
  42.  
  43. import instances.AbstractInstance;
  44.  
  45. public final class Kamaloka extends AbstractInstance
  46. {
  47. /*
  48. * Reset time for all kamaloka Default: 6:30AM on server time
  49. */
  50. private static final int RESET_HOUR = 6;
  51. private static final int RESET_MIN = 30;
  52.  
  53. /*
  54. * Time after which instance without players will be destroyed Default: 5 minutes
  55. */
  56. private static final int EMPTY_DESTROY_TIME = 5;
  57.  
  58. /*
  59. * Time to destroy instance (and eject players away) after boss defeat Default: 5 minutes
  60. */
  61. private static final int EXIT_TIME = 5;
  62.  
  63. /*
  64. * Maximum level difference between players level and kamaloka level Default: 5
  65. */
  66. private static final int MAX_LEVEL_DIFFERENCE = 5;
  67.  
  68. /*
  69. * If true shaman in the first room will have same npcId as other mobs, making radar useless Default: true (but not retail like)
  70. */
  71. private static final boolean STEALTH_SHAMAN = true;
  72. // Template IDs for Kamaloka
  73. // @formatter:off
  74. private static final int[] TEMPLATE_IDS =
  75. {
  76. 57, 58, 73, 60, 61, 74, 63, 64, 75, 66, 67, 76, 69, 70, 77, 72, 78, 79, 134
  77. };
  78. // Level of the Kamaloka
  79. private static final int[] LEVEL =
  80. {
  81. 23, 26, 29, 33, 36, 39, 43, 46, 49, 53, 56, 59, 63, 66, 69, 73, 78, 81, 83
  82. };
  83. // Duration of the instance, minutes
  84. private static final int[] DURATION =
  85. {
  86. 30, 30, 45, 30, 30, 45, 30, 30, 45, 30, 30, 45, 30, 30, 45, 30, 45, 45, 45
  87. };
  88. // Maximum party size for the instance
  89. private static final int[] MAX_PARTY_SIZE =
  90. {
  91. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9
  92. };
  93.  
  94. /**
  95. * List of buffs NOT removed on enter from player and pet<br>
  96. * On retail only newbie guide buffs not removed<br>
  97. * CAUTION: array must be sorted in ascension order!
  98. */
  99. protected static final int[] BUFFS_WHITELIST =
  100. {
  101. 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 5632, 5637, 5950
  102. };
  103. // @formatter:on
  104. // Teleport points into instances x, y, z
  105. private static final Location[] TELEPORTS =
  106. {
  107. new Location(-88429, -220629, -7903),
  108. new Location(-82464, -219532, -7899),
  109. new Location(-10700, -174882, -10936), // -76280, -185540, -10936
  110. new Location(-89683, -213573, -8106),
  111. new Location(-81413, -213568, -8104),
  112. new Location(-10700, -174882, -10936), // -76280, -174905, -10936
  113. new Location(-89759, -206143, -8120),
  114. new Location(-81415, -206078, -8107),
  115. new Location(-10700, -174882, -10936),
  116. new Location(-56999, -219856, -8117),
  117. new Location(-48794, -220261, -8075),
  118. new Location(-10700, -174882, -10936),
  119. new Location(-56940, -212939, -8072),
  120. new Location(-55566, -206139, -8120),
  121. new Location(-10700, -174882, -10936),
  122. new Location(-49805, -206139, -8117),
  123. new Location(-10700, -174882, -10936),
  124. new Location(-10700, -174882, -10936),
  125. new Location(22003, -174886, -10900),
  126. };
  127.  
  128. // Respawn delay for the mobs in the first room, seconds Default: 25
  129. private static final int FIRST_ROOM_RESPAWN_DELAY = 25;
  130.  
  131. //@formatter:off
  132.  
  133. /*
  134. * First room information, null if room not spawned
  135. * Skill is casted on the boss when shaman is defeated and mobs respawn stopped
  136. * Default: 5699 (decrease pdef)
  137. *
  138. * shaman npcId, minions npcId, skillId, skillLvl
  139. */
  140. private static final int[][] FIRST_ROOM =
  141. {
  142. null, null,
  143. { 22485, 22486, 5699, 1 },
  144. null, null,
  145. { 22488, 22489, 5699, 2 },
  146. null, null,
  147. { 22491, 22492, 5699, 3 },
  148. null, null,
  149. { 22494, 22495, 5699, 4 },
  150. null, null,
  151. { 22497, 22498, 5699, 5 },
  152. null,
  153. { 22500, 22501, 5699, 6 },
  154. { 22503, 22504, 5699, 7 },
  155. { 25706, 25707, 5699, 7 }
  156. };
  157.  
  158. /*
  159. * First room spawns, null if room not spawned
  160. *
  161. * x, y, z
  162. */
  163. private static final int[][][] FIRST_ROOM_SPAWNS =
  164. {
  165. null, null,
  166. {
  167. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  168. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  169. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  170. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  171. { -12233, -174954, -10953 }
  172. },
  173. null, null,
  174. {
  175. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  176. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  177. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  178. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  179. { -12233, -174954, -10953 }
  180. },
  181. null, null,
  182. {
  183. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  184. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  185. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  186. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  187. { -12233, -174954, -10953 }
  188. },
  189. null, null,
  190. {
  191. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  192. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  193. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  194. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  195. { -12233, -174954, -10953 }
  196. },
  197. null, null,
  198. {
  199. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  200. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  201. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  202. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  203. { -12233, -174954, -10953 }
  204. },
  205. null,
  206. {
  207. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  208. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  209. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  210. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  211. { -12233, -174954, -10953 }
  212. },
  213. {
  214. { -12381, -174973, -10955 }, { -12413, -174905, -10955 },
  215. { -12377, -174838, -10953 }, { -12316, -174903, -10953 },
  216. { -12326, -174786, -10953 }, { -12330, -175024, -10953 },
  217. { -12211, -174900, -10955 }, { -12238, -174849, -10953 },
  218. { -12233, -174954, -10953 }
  219. },
  220. {
  221. { 20409, -174827, -10912 }, { 20409, -174947, -10912 },
  222. { 20494, -174887, -10912 }, { 20494, -174767, -10912 },
  223. { 20614, -174887, -10912 }, { 20579, -174827, -10912 },
  224. { 20579, -174947, -10912 }, { 20494, -175007, -10912 },
  225. { 20374, -174887, -10912 }
  226. }
  227. };
  228.  
  229. /*
  230. * Second room information, null if room not spawned
  231. * Skill is casted on the boss when all mobs are defeated
  232. * Default: 5700 (decrease mdef)
  233. *
  234. * npcId, skillId, skillLvl
  235. */
  236. private static final int[][] SECOND_ROOM =
  237. {
  238. null, null,
  239. { 22487, 5700, 1 },
  240. null, null,
  241. { 22490, 5700, 2 },
  242. null, null,
  243. { 22493, 5700, 3 },
  244. null, null,
  245. { 22496, 5700, 4 },
  246. null, null,
  247. { 22499, 5700, 5 },
  248. null,
  249. { 22502, 5700, 6 },
  250. { 22505, 5700, 7 },
  251. { 25708, 5700, 7 }
  252.  
  253. };
  254.  
  255. /*
  256. * Spawns for second room, null if room not spawned
  257. *
  258. * x, y, z
  259. */
  260. private static final int[][][] SECOND_ROOM_SPAWNS =
  261. {
  262. null, null,
  263. {
  264. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  265. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  266. { -14410, -174904, -10690 }
  267. },
  268. null, null,
  269. {
  270. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  271. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  272. { -14410, -174904, -10690 }
  273. },
  274. null, null,
  275. {
  276. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  277. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  278. { -14410, -174904, -10690 }
  279. },
  280. null, null,
  281. {
  282. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  283. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  284. { -14410, -174904, -10690 }
  285. },
  286. null, null,
  287. {
  288. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  289. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  290. { -14410, -174904, -10690 }
  291. },
  292. null,
  293. {
  294. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  295. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  296. { -14410, -174904, -10690 }
  297. },
  298. {
  299. { -14547, -174901, -10690 }, { -14543, -175030, -10690 },
  300. { -14668, -174900, -10690 }, { -14538, -174774, -10690 },
  301. { -14410, -174904, -10690 }
  302. },
  303. {
  304. { 18175, -174991, -10653 }, { 18070, -174890, -10655 },
  305. { 18157, -174886, -10655 }, { 18249, -174885, -10653 },
  306. { 18144, -174821, -10648 }
  307. }
  308. };
  309.  
  310. // miniboss info
  311. // skill is casted on the boss when miniboss is defeated
  312. // npcId, x, y, z, skill id, skill level
  313. /*
  314. * Miniboss information, null if miniboss not spawned
  315. * Skill is casted on the boss when miniboss is defeated
  316. * Default: 5701 (decrease patk)
  317. *
  318. * npcId, x, y, z, skillId, skillLvl
  319. */
  320. private static final int[][] MINIBOSS =
  321. {
  322. null, null,
  323. { 25616, -16874, -174900, -10427, 5701, 1 },
  324. null, null,
  325. { 25617, -16874, -174900, -10427, 5701, 2 },
  326. null, null,
  327. { 25618, -16874, -174900, -10427, 5701, 3 },
  328. null, null,
  329. { 25619, -16874, -174900, -10427, 5701, 4 },
  330. null, null,
  331. { 25620, -16874, -174900, -10427, 5701, 5 },
  332. null,
  333. { 25621, -16874, -174900, -10427, 5701, 6 },
  334. { 25622, -16874, -174900, -10427, 5701, 7 },
  335. { 25709, 15828, -174885, -10384, 5701, 7 }
  336. };
  337.  
  338. /*
  339. * Bosses of the kamaloka
  340. * Instance ends when boss is defeated
  341. *
  342. * npcId, x, y, z
  343. */
  344. private static final int[][] BOSS =
  345. {
  346. { 18554, -88998, -220077, -7892 },
  347. { 18555, -81891, -220078, -7893 },
  348. { 29129, -20659, -174903, -9983 },
  349. { 18558, -89183, -213564, -8100 },
  350. { 18559, -81937, -213566, -8100 },
  351. { 29132, -20659, -174903, -9983 },
  352. { 18562, -89054, -206144, -8115 },
  353. { 18564, -81937, -206077, -8100 },
  354. { 29135, -20659, -174903, -9983 },
  355. { 18566, -56281, -219859, -8115 },
  356. { 18568, -49336, -220260, -8068 },
  357. { 29138, -20659, -174903, -9983 },
  358. { 18571, -56415, -212939, -8068 },
  359. { 18573, -56281, -206140, -8115 },
  360. { 29141, -20659, -174903, -9983 },
  361. { 18577, -49084, -206140, -8115 },
  362. { 29144, -20659, -174903, -9983 },
  363. { 29147, -20659, -174903, -9983 },
  364. { 25710, 12047, -174887, -9944 }
  365. };
  366.  
  367. /*
  368. * Escape telepoters spawns, null if not spawned
  369. *
  370. * x, y, z
  371. */
  372. private static final int[][] TELEPORTERS =
  373. {
  374. null, null,
  375. { -10865, -174905, -10944 },
  376. null, null,
  377. { -10865, -174905, -10944 },
  378. null, null,
  379. { -10865, -174905, -10944 },
  380. null, null,
  381. { -10865, -174905, -10944 },
  382. null, null,
  383. { -10865, -174905, -10944 },
  384. null,
  385. { -10865, -174905, -10944 },
  386. { -10865, -174905, -10944 },
  387. { 21837, -174885, -10904 }
  388. };
  389.  
  390. /*
  391. * Escape teleporter npcId
  392. */
  393. private static final int TELEPORTER = 32496;
  394.  
  395. /*
  396. * Kamaloka captains (start npc's) npcIds.
  397. */
  398. private static final int[] CAPTAINS =
  399. { 30332, 30071, 30916, 30196, 31981, 31340 };
  400.  
  401. //@formatter:on
  402.  
  403. protected class KamaWorld extends InstanceWorld
  404. {
  405. public int index; // 0-18 index of the kama type in arrays
  406. public int shaman = 0; // objectId of the shaman
  407. public List<L2Spawn> firstRoom; // list of the spawns in the first room (excluding shaman)
  408. public List<Integer> secondRoom;// list of objectIds mobs in the second room
  409. public int miniBoss = 0; // objectId of the miniboss
  410. public L2Npc boss = null; // boss
  411. }
  412.  
  413. public Kamaloka()
  414. {
  415. super(Kamaloka.class.getSimpleName());
  416. addFirstTalkId(TELEPORTER);
  417. addTalkId(TELEPORTER);
  418. addStartNpc(CAPTAINS);
  419. addTalkId(CAPTAINS);
  420.  
  421. for (int[] mob : FIRST_ROOM)
  422. {
  423. if (mob != null)
  424. {
  425. if (STEALTH_SHAMAN)
  426. {
  427. addKillId(mob[1]);
  428. }
  429. else
  430. {
  431. addKillId(mob[0]);
  432. }
  433. }
  434. }
  435. for (int[] mob : SECOND_ROOM)
  436. {
  437. if (mob != null)
  438. {
  439. addKillId(mob[0]);
  440. }
  441. }
  442. for (int[] mob : MINIBOSS)
  443. {
  444. if (mob != null)
  445. {
  446. addKillId(mob[0]);
  447. }
  448. }
  449. for (int[] mob : BOSS)
  450. {
  451. addKillId(mob[0]);
  452. }
  453. }
  454.  
  455. /**
  456. * Check if party with player as leader allowed to enter
  457. * @param player party leader
  458. * @param index (0-18) index of the kamaloka in arrays
  459. * @return true if party allowed to enter
  460. */
  461. private static final boolean checkPartyConditions(L2PcInstance player, int index)
  462. {
  463. if (player.isGM())
  464. {
  465. return true;
  466. }
  467.  
  468. final L2Party party = player.getParty();
  469. // player must be in party
  470. if (party == null)
  471. {
  472. player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
  473. return false;
  474. }
  475. // ...and be party leader
  476. if (party.getLeader() != player)
  477. {
  478. player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
  479. return false;
  480. }
  481. // party must not exceed max size for selected instance
  482. if (party.getMemberCount() > MAX_PARTY_SIZE[index])
  483. {
  484. player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
  485. return false;
  486. }
  487.  
  488. // get level of the instance
  489. final int level = LEVEL[index];
  490. // and client name
  491. final String instanceName = InstanceManager.getInstance().getInstanceIdName(TEMPLATE_IDS[index]);
  492.  
  493. Map<Integer, Long> instanceTimes;
  494. // for each party member
  495. for (L2PcInstance partyMember : party.getMembers())
  496. {
  497. // player level must be in range
  498. if (Math.abs(partyMember.getLevel() - level) > MAX_LEVEL_DIFFERENCE)
  499. {
  500. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_S_LEVEL_REQUIREMENT_IS_NOT_SUFFICIENT_AND_CANNOT_BE_ENTERED);
  501. sm.addPcName(partyMember);
  502. player.sendPacket(sm);
  503. return false;
  504. }
  505. // player must be near party leader
  506. if (!partyMember.isInsideRadius(player, 1000, true, true))
  507. {
  508. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_LOCATION_WHICH_CANNOT_BE_ENTERED_THEREFORE_IT_CANNOT_BE_PROCESSED);
  509. sm.addPcName(partyMember);
  510. player.sendPacket(sm);
  511. return false;
  512. }
  513. // get instances reenter times for player
  514. instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(partyMember.getObjectId());
  515. if (instanceTimes != null)
  516. {
  517. for (int id : instanceTimes.keySet())
  518. {
  519. // find instance with same name (kamaloka or labyrinth)
  520. // TODO: Zoey76: Don't use instance name, use other system.
  521. if (!instanceName.equals(InstanceManager.getInstance().getInstanceIdName(id)))
  522. {
  523. continue;
  524. }
  525. // if found instance still can't be reentered - exit
  526. if (System.currentTimeMillis() < instanceTimes.get(id))
  527. {
  528. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_RE_ENTER_YET);
  529. sm.addPcName(partyMember);
  530. player.sendPacket(sm);
  531. return false;
  532. }
  533. }
  534. }
  535. }
  536. return true;
  537. }
  538.  
  539. /**
  540. * Removing all buffs from player and pet except BUFFS_WHITELIST
  541. * @param ch player
  542. */
  543. private static final void removeBuffs(L2Character ch)
  544. {
  545. for (L2Effect e : ch.getEffectList().getEffects())
  546. {
  547. if (e == null)
  548. {
  549. continue;
  550. }
  551. L2Skill skill = e.getSkill();
  552. if (skill.isDebuff() || skill.isStayAfterDeath())
  553. {
  554. continue;
  555. }
  556. if (Arrays.binarySearch(BUFFS_WHITELIST, skill.getId()) >= 0)
  557. {
  558. continue;
  559. }
  560. e.exit();
  561. }
  562. if (ch.getSummon() != null)
  563. {
  564. for (L2Effect e : ch.getSummon().getEffectList().getEffects())
  565. {
  566. if (e == null)
  567. {
  568. continue;
  569. }
  570. L2Skill skill = e.getSkill();
  571. if (skill.isDebuff() || skill.isStayAfterDeath())
  572. {
  573. continue;
  574. }
  575. if (Arrays.binarySearch(BUFFS_WHITELIST, skill.getId()) >= 0)
  576. {
  577. continue;
  578. }
  579. e.exit();
  580. }
  581. }
  582. }
  583.  
  584. /**
  585. * Handling enter of the players into kamaloka
  586. * @param player party leader
  587. * @param index (0-18) kamaloka index in arrays
  588. */
  589. private final synchronized void enterInstance(L2PcInstance player, int index)
  590. {
  591. int templateId = TEMPLATE_IDS[index];
  592. // check for existing instances for this player
  593. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  594. // player already in the instance
  595. if (world != null)
  596. {
  597. // but not in kamaloka
  598. if (!(world instanceof KamaWorld) || (world.getTemplateId() != templateId))
  599. {
  600. player.sendPacket(SystemMessageId.YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON);
  601. return;
  602. }
  603. // check for level difference again on reenter
  604. if (Math.abs(player.getLevel() - LEVEL[((KamaWorld) world).index]) > MAX_LEVEL_DIFFERENCE)
  605. {
  606. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_S_LEVEL_REQUIREMENT_IS_NOT_SUFFICIENT_AND_CANNOT_BE_ENTERED);
  607. sm.addPcName(player);
  608. player.sendPacket(sm);
  609. return;
  610. }
  611. // check what instance still exist
  612. Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  613. if (inst != null)
  614. {
  615. removeBuffs(player);
  616. teleportPlayer(player, TELEPORTS[index], world.getInstanceId());
  617. }
  618. return;
  619. }
  620. // Creating new kamaloka instance
  621. if (!checkPartyConditions(player, index))
  622. {
  623. return;
  624. }
  625.  
  626. // Creating dynamic instance without template
  627. final int instanceId = InstanceManager.getInstance().createDynamicInstance(null);
  628. final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
  629. // set name for the kamaloka
  630. inst.setName(InstanceManager.getInstance().getInstanceIdName(templateId));
  631. // set return location
  632. inst.setExitLoc(new Location(player));
  633. // disable summon friend into instance
  634. inst.setAllowSummon(false);
  635. // set duration and empty destroy time
  636. inst.setDuration(DURATION[index] * 60000);
  637. inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000);
  638.  
  639. // Creating new instanceWorld, using our instanceId and templateId
  640. world = new KamaWorld();
  641. world.setInstanceId(instanceId);
  642. world.setTemplateId(templateId);
  643. // set index for easy access to the arrays
  644. ((KamaWorld) world).index = index;
  645. InstanceManager.getInstance().addWorld(world);
  646. world.setStatus(0);
  647. // spawn npcs
  648. spawnKama((KamaWorld) world);
  649.  
  650. if (player.isGM())
  651. {
  652. world.addAllowed(player.getObjectId());
  653. removeBuffs(player);
  654. teleportPlayer(player, TELEPORTS[index], instanceId);
  655. }
  656. else
  657. {
  658. // and finally teleport party into instance
  659. final L2Party party = player.getParty();
  660. for (L2PcInstance partyMember : party.getMembers())
  661. {
  662. world.addAllowed(partyMember.getObjectId());
  663. removeBuffs(partyMember);
  664. teleportPlayer(partyMember, TELEPORTS[index], instanceId);
  665. }
  666. }
  667. return;
  668. }
  669.  
  670. /**
  671. * Called on instance finish and handles reenter time for instance
  672. * @param world instanceWorld
  673. */
  674. @Override
  675. protected final void finishInstance(InstanceWorld world)
  676. {
  677. if (world instanceof KamaWorld)
  678. {
  679. Calendar reenter = Calendar.getInstance();
  680. reenter.set(Calendar.MINUTE, RESET_MIN);
  681. // if time is >= RESET_HOUR - roll to the next day
  682. if (reenter.get(Calendar.HOUR_OF_DAY) >= RESET_HOUR)
  683. {
  684. reenter.add(Calendar.DATE, 1);
  685. }
  686. reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
  687.  
  688. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_FROM_HERE_S1_S_ENTRY_HAS_BEEN_RESTRICTED);
  689. sm.addInstanceName(world.getTemplateId());
  690.  
  691. // set instance reenter time for all allowed players
  692. for (int objectId : world.getAllowed())
  693. {
  694. L2PcInstance obj = L2World.getInstance().getPlayer(objectId);
  695. if ((obj != null) && obj.isOnline())
  696. {
  697. InstanceManager.getInstance().setInstanceTime(objectId, world.getTemplateId(), reenter.getTimeInMillis());
  698. obj.sendPacket(sm);
  699. }
  700. }
  701.  
  702. // destroy instance after EXIT_TIME
  703. Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  704. inst.setDuration(EXIT_TIME * 60000);
  705. inst.setEmptyDestroyTime(0);
  706. }
  707. }
  708.  
  709. /**
  710. * Spawn all NPCs in kamaloka
  711. * @param world instanceWorld
  712. */
  713. private final void spawnKama(KamaWorld world)
  714. {
  715. int[] npcs;
  716. int[][] spawns;
  717. L2Npc npc;
  718. final int index = world.index;
  719.  
  720. // first room
  721. npcs = FIRST_ROOM[index];
  722. spawns = FIRST_ROOM_SPAWNS[index];
  723. if (npcs != null)
  724. {
  725. world.firstRoom = new ArrayList<>(spawns.length - 1);
  726. int shaman = getRandom(spawns.length); // random position for shaman
  727.  
  728. for (int i = 0; i < spawns.length; i++)
  729. {
  730. if (i == shaman)
  731. {
  732. // stealth shaman use same npcId as other mobs
  733. npc = addSpawn(STEALTH_SHAMAN ? npcs[1] : npcs[0], spawns[i][0], spawns[i][1], spawns[i][2], 0, false, 0, false, world.getInstanceId());
  734. world.shaman = npc.getObjectId();
  735. }
  736. else
  737. {
  738. npc = addSpawn(npcs[1], spawns[i][0], spawns[i][1], spawns[i][2], 0, false, 0, false, world.getInstanceId());
  739. L2Spawn spawn = npc.getSpawn();
  740. spawn.setRespawnDelay(FIRST_ROOM_RESPAWN_DELAY);
  741. spawn.setAmount(1);
  742. spawn.startRespawn();
  743. world.firstRoom.add(spawn); // store mobs spawns
  744. }
  745. npc.setIsNoRndWalk(true);
  746. }
  747. }
  748.  
  749. // second room
  750. npcs = SECOND_ROOM[index];
  751. spawns = SECOND_ROOM_SPAWNS[index];
  752. if (npcs != null)
  753. {
  754. world.secondRoom = new ArrayList<>(spawns.length);
  755.  
  756. for (int[] spawn : spawns)
  757. {
  758. npc = addSpawn(npcs[0], spawn[0], spawn[1], spawn[2], 0, false, 0, false, world.getInstanceId());
  759. npc.setIsNoRndWalk(true);
  760. world.secondRoom.add(npc.getObjectId());
  761. }
  762. }
  763.  
  764. // miniboss
  765. if (MINIBOSS[index] != null)
  766. {
  767. npc = addSpawn(MINIBOSS[index][0], MINIBOSS[index][1], MINIBOSS[index][2], MINIBOSS[index][3], 0, false, 0, false, world.getInstanceId());
  768. npc.setIsNoRndWalk(true);
  769. world.miniBoss = npc.getObjectId();
  770. }
  771.  
  772. // escape teleporter
  773. if (TELEPORTERS[index] != null)
  774. {
  775. addSpawn(TELEPORTER, TELEPORTERS[index][0], TELEPORTERS[index][1], TELEPORTERS[index][2], 0, false, 0, false, world.getInstanceId());
  776. }
  777.  
  778. // boss
  779. world.boss = addSpawn(BOSS[index][0], BOSS[index][1], BOSS[index][2], BOSS[index][3], 0, false, 0, false, world.getInstanceId());
  780. }
  781.  
  782. /**
  783. * Handles only player's enter, single parameter - integer kamaloka index
  784. */
  785. @Override
  786. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  787. {
  788. enterInstance(player, Integer.parseInt(event));
  789. return "";
  790. }
  791.  
  792. /**
  793. * Talk with captains and using of the escape teleporter
  794. */
  795. @Override
  796. public final String onTalk(L2Npc npc, L2PcInstance player)
  797. {
  798. final int npcId = npc.getId();
  799. if (npcId == TELEPORTER)
  800. {
  801. final L2Party party = player.getParty();
  802. // only party leader can talk with escape teleporter
  803. if ((party != null) && party.isLeader(player))
  804. {
  805. final InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  806. if (world instanceof KamaWorld)
  807. {
  808. // party members must be in the instance
  809. if (world.isAllowed(player.getObjectId()))
  810. {
  811. Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  812.  
  813. // teleports entire party away
  814. for (L2PcInstance partyMember : party.getMembers())
  815. {
  816. if ((partyMember != null) && (partyMember.getInstanceId() == world.getInstanceId()))
  817. {
  818. teleportPlayer(partyMember, inst.getExitLoc(), 0);
  819. }
  820. }
  821. }
  822. }
  823. }
  824. }
  825. else
  826. {
  827. return npcId + ".htm";
  828. }
  829.  
  830. return "";
  831. }
  832.  
  833. /**
  834. * Only escape teleporters first talk handled
  835. */
  836. @Override
  837. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  838. {
  839. if (npc.getId() == TELEPORTER)
  840. {
  841. if (player.isGM())
  842. {
  843. return "32496.htm";
  844. }
  845.  
  846. if (player.isInParty() && player.getParty().isLeader(player))
  847. {
  848. return "32496.htm";
  849. }
  850. return "32496-no.htm";
  851. }
  852. return "";
  853. }
  854.  
  855. @Override
  856. public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  857. {
  858. final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  859. if (tmpWorld instanceof KamaWorld)
  860. {
  861. final KamaWorld world = (KamaWorld) tmpWorld;
  862. final int objectId = npc.getObjectId();
  863.  
  864. // first room was spawned ?
  865. if (world.firstRoom != null)
  866. {
  867. // is shaman killed ?
  868. if ((world.shaman != 0) && (world.shaman == objectId))
  869. {
  870. world.shaman = 0;
  871. // stop respawn of the minions
  872. for (L2Spawn spawn : world.firstRoom)
  873. {
  874. if (spawn != null)
  875. {
  876. spawn.stopRespawn();
  877. }
  878. }
  879. world.firstRoom.clear();
  880. world.firstRoom = null;
  881.  
  882. if (world.boss != null)
  883. {
  884. final int skillId = FIRST_ROOM[world.index][2];
  885. final int skillLvl = FIRST_ROOM[world.index][3];
  886. if ((skillId != 0) && (skillLvl != 0))
  887. {
  888. final L2Skill skill = SkillData.getInstance().getInfo(skillId, skillLvl);
  889. if (skill != null)
  890. {
  891. skill.getEffects(world.boss, world.boss);
  892. }
  893. }
  894. }
  895.  
  896. return super.onKill(npc, player, isSummon);
  897. }
  898. }
  899.  
  900. // second room was spawned ?
  901. if (world.secondRoom != null)
  902. {
  903. boolean all = true;
  904. // check for all mobs in the second room
  905. for (int i = 0; i < world.secondRoom.size(); i++)
  906. {
  907. // found killed now mob
  908. if (world.secondRoom.get(i) == objectId)
  909. {
  910. world.secondRoom.set(i, 0);
  911. }
  912. else if (world.secondRoom.get(i) != 0)
  913. {
  914. all = false;
  915. }
  916. }
  917. // all mobs killed ?
  918. if (all)
  919. {
  920. world.secondRoom.clear();
  921. world.secondRoom = null;
  922.  
  923. if (world.boss != null)
  924. {
  925. final int skillId = SECOND_ROOM[world.index][1];
  926. final int skillLvl = SECOND_ROOM[world.index][2];
  927. if ((skillId != 0) && (skillLvl != 0))
  928. {
  929. final L2Skill skill = SkillData.getInstance().getInfo(skillId, skillLvl);
  930. if (skill != null)
  931. {
  932. skill.getEffects(world.boss, world.boss);
  933. }
  934. }
  935. }
  936.  
  937. return super.onKill(npc, player, isSummon);
  938. }
  939. }
  940.  
  941. // miniboss spawned ?
  942. if ((world.miniBoss != 0) && (world.miniBoss == objectId))
  943. {
  944. world.miniBoss = 0;
  945.  
  946. if (world.boss != null)
  947. {
  948. final int skillId = MINIBOSS[world.index][4];
  949. final int skillLvl = MINIBOSS[world.index][5];
  950. if ((skillId != 0) && (skillLvl != 0))
  951. {
  952. final L2Skill skill = SkillData.getInstance().getInfo(skillId, skillLvl);
  953. if (skill != null)
  954. {
  955. skill.getEffects(world.boss, world.boss);
  956. }
  957. }
  958. }
  959.  
  960. return super.onKill(npc, player, isSummon);
  961. }
  962.  
  963. // boss was killed, finish instance
  964. if ((world.boss != null) && (world.boss == npc))
  965. {
  966. world.boss = null;
  967. finishInstance(world);
  968. }
  969. }
  970. return super.onKill(npc, player, isSummon);
  971. }
  972.  
  973. @Override
  974. public void onEnterInstance(L2PcInstance player, InstanceWorld world, boolean firstEntrance)
  975. {
  976.  
  977. }
  978. }
Add Comment
Please, Sign In to add comment