Kamaloka.java 28 KB

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