Kamaloka.java 28 KB

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