Kamaloka.java 28 KB

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