TowerOfNaia.java 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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 hellbound.TowerOfNaia;
  16. import java.util.Arrays;
  17. import java.util.HashMap;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import java.util.Map;
  21. import javolution.util.FastList;
  22. import javolution.util.FastMap;
  23. import com.l2jserver.gameserver.ThreadPoolManager;
  24. import com.l2jserver.gameserver.ai.CtrlIntention;
  25. import com.l2jserver.gameserver.datatables.DoorTable;
  26. import com.l2jserver.gameserver.datatables.SkillTable;
  27. import com.l2jserver.gameserver.instancemanager.GlobalVariablesManager;
  28. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  29. import com.l2jserver.gameserver.model.L2CharPosition;
  30. import com.l2jserver.gameserver.model.L2Party;
  31. import com.l2jserver.gameserver.model.L2Skill;
  32. import com.l2jserver.gameserver.model.actor.L2Character;
  33. import com.l2jserver.gameserver.model.actor.L2Npc;
  34. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.quest.Quest;
  37. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  38. import com.l2jserver.gameserver.model.zone.type.L2EffectZone;
  39. import com.l2jserver.gameserver.network.NpcStringId;
  40. import com.l2jserver.gameserver.network.SystemMessageId;
  41. import com.l2jserver.gameserver.network.clientpackets.Say2;
  42. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  43. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  44. import com.l2jserver.gameserver.util.MinionList;
  45. import com.l2jserver.gameserver.util.Util;
  46. import com.l2jserver.util.Rnd;
  47. /**
  48. * @author GKR
  49. */
  50. public class TowerOfNaia extends Quest
  51. {
  52. // Challenge states
  53. private static final int STATE_SPORE_CHALLENGE_IN_PROGRESS = 1;
  54. private static final int STATE_SPORE_CHALLENGE_SUCCESSFULL = 2;
  55. private static final int STATE_SPORE_IDLE_TOO_LONG = 3;
  56. // Some constants
  57. private static final int SELF_DESPAWN_LIMIT = 600; // Challenge discontinues after 600 self-despawns by timer
  58. private static final int ELEMENT_INDEX_LIMIT = 120; // Epidos spawns when index reaches 120 points
  59. private static final int LOCK = 18491;
  60. private static final int CONTROLLER = 18492;
  61. private static final int ROOM_MANAGER_FIRST = 18494;
  62. private static final int ROOM_MANAGER_LAST = 18505;
  63. private static final int MUTATED_ELPY = 25604;
  64. private static final int SPORE_BASIC = 25613;
  65. private static final int SPORE_FIRE = 25605;
  66. private static final int SPORE_WATER = 25606;
  67. private static final int SPORE_WIND = 25607;
  68. private static final int SPORE_EARTH = 25608;
  69. private static final int DWARVEN_GHOST = 32370;
  70. private static final int[] EPIDOSES =
  71. {
  72. 25610, 25609, 25612, 25611
  73. }; // Order is important!
  74. private static final int[] TOWER_MONSTERS =
  75. {
  76. 18490, 22393, 22394, 22395, 22411, 22412, 22413, 22439, 22440, 22441, 22442
  77. };
  78. private static final int[] ELEMENTS =
  79. {
  80. 25605, 25606, 25607, 25608
  81. };
  82. private static final int[] OPPOSITE_ELEMENTS =
  83. {
  84. 25606, 25605, 25608, 25607
  85. };
  86. private static final String[] ELEMENTS_NAME =
  87. {
  88. "Fire", "Water", "Wind", "Earth"
  89. };
  90. private static final int[][] SPORES_MOVE_POINTS =
  91. {
  92. {
  93. -46080, 246368, -14183
  94. },
  95. {
  96. -44816, 246368, -14183
  97. },
  98. {
  99. -44224, 247440, -14184
  100. },
  101. {
  102. -44896, 248464, -14183
  103. },
  104. {
  105. -46064, 248544, -14183
  106. },
  107. {
  108. -46720, 247424, -14183
  109. }
  110. };
  111. private static final int[][] SPORES_MERGE_POSITION =
  112. {
  113. {
  114. -45488, 246768, -14183
  115. },
  116. {
  117. -44767, 247419, -14183
  118. },
  119. {
  120. -46207, 247417, -14183
  121. },
  122. {
  123. -45462, 248174, -14183
  124. }
  125. };
  126. private static final NpcStringId[] SPORES_NPCSTRING_ID =
  127. {
  128. NpcStringId.ITS_S1, NpcStringId.S1_IS_STRONG, NpcStringId.ITS_ALWAYS_S1, NpcStringId.S1_WONT_DO
  129. };
  130. private static Map<Integer, int[]> DOORS = new HashMap<Integer, int[]>();
  131. private static Map<Integer, Integer> ZONES = new HashMap<Integer, Integer>();
  132. private static Map<Integer, int[][]> SPAWNS = new HashMap<Integer, int[][]>();
  133. private L2MonsterInstance _lock;
  134. private final L2Npc _controller;
  135. private int _counter;
  136. private int _despawnedSporesCount;
  137. private final int[] _indexCount =
  138. {
  139. 0, 0
  140. };
  141. private int _challengeState;
  142. private int _winIndex;
  143. private final Map<Integer, Boolean> _activeRooms = new FastMap<Integer, Boolean>();
  144. private final Map<Integer, List<L2Npc>> _spawns = new FastMap<Integer, List<L2Npc>>();
  145. private final FastList<L2Npc> _sporeSpawn = new FastList<L2Npc>().shared();
  146. static
  147. {
  148. // Format: entrance_door, exit_door
  149. DOORS.put(18494, new int[]
  150. {
  151. 18250001, 18250002
  152. });
  153. DOORS.put(18495, new int[]
  154. {
  155. 18250003, 18250004
  156. });
  157. DOORS.put(18496, new int[]
  158. {
  159. 18250005, 18250006
  160. });
  161. DOORS.put(18497, new int[]
  162. {
  163. 18250007, 18250008
  164. });
  165. DOORS.put(18498, new int[]
  166. {
  167. 18250009, 18250010
  168. });
  169. DOORS.put(18499, new int[]
  170. {
  171. 18250011, 18250101
  172. });
  173. DOORS.put(18500, new int[]
  174. {
  175. 18250013, 18250014
  176. });
  177. DOORS.put(18501, new int[]
  178. {
  179. 18250015, 18250102
  180. });
  181. DOORS.put(18502, new int[]
  182. {
  183. 18250017, 18250018
  184. });
  185. DOORS.put(18503, new int[]
  186. {
  187. 18250019, 18250103
  188. });
  189. DOORS.put(18504, new int[]
  190. {
  191. 18250021, 18250022
  192. });
  193. DOORS.put(18505, new int[]
  194. {
  195. 18250023, 18250024
  196. });
  197. ZONES.put(18494, 200020);
  198. ZONES.put(18495, 200021);
  199. ZONES.put(18496, 200022);
  200. ZONES.put(18497, 200023);
  201. ZONES.put(18498, 200024);
  202. ZONES.put(18499, 200025);
  203. ZONES.put(18500, 200026);
  204. ZONES.put(18501, 200027);
  205. ZONES.put(18502, 200028);
  206. ZONES.put(18503, 200029);
  207. ZONES.put(18504, 200030);
  208. ZONES.put(18505, 200031);
  209. SPAWNS.put(18494, new int[][]
  210. {
  211. {
  212. 22393, -46371, 246400, -9120, 0
  213. },
  214. {
  215. 22394, -46435, 245830, -9120, 0
  216. },
  217. {
  218. 22394, -46536, 246275, -9120, 0
  219. },
  220. {
  221. 22393, -46239, 245996, -9120, 0
  222. },
  223. {
  224. 22394, -46229, 246347, -9120, 0
  225. },
  226. {
  227. 22394, -46019, 246198, -9120, 0
  228. }
  229. });
  230. SPAWNS.put(18495, new int[][]
  231. {
  232. {
  233. 22439, -48146, 249597, -9124, -16280
  234. },
  235. {
  236. 22439, -48144, 248711, -9124, 16368
  237. },
  238. {
  239. 22439, -48704, 249597, -9104, -16380
  240. },
  241. {
  242. 22439, -49219, 249596, -9104, -16400
  243. },
  244. {
  245. 22439, -49715, 249601, -9104, -16360
  246. },
  247. {
  248. 22439, -49714, 248696, -9104, 15932
  249. },
  250. {
  251. 22439, -49225, 248710, -9104, 16512
  252. },
  253. {
  254. 22439, -48705, 248708, -9104, 16576
  255. }
  256. });
  257. SPAWNS.put(18496, new int[][]
  258. {
  259. {
  260. 22441, -51176, 246055, -9984, 0
  261. },
  262. {
  263. 22441, -51699, 246190, -9984, 0
  264. },
  265. {
  266. 22442, -52060, 245956, -9984, 0
  267. },
  268. {
  269. 22442, -51565, 246433, -9984, 0
  270. }
  271. });
  272. SPAWNS.put(18497, new int[][]
  273. {
  274. {
  275. 22440, -49754, 243866, -9968, -16328
  276. },
  277. {
  278. 22440, -49754, 242940, -9968, 16336
  279. },
  280. {
  281. 22440, -48733, 243858, -9968, -16208
  282. },
  283. {
  284. 22440, -48745, 242936, -9968, 16320
  285. },
  286. {
  287. 22440, -49264, 242946, -9968, 16312
  288. },
  289. {
  290. 22440, -49268, 243869, -9968, -16448
  291. },
  292. {
  293. 22440, -48186, 242934, -9968, 16576
  294. },
  295. {
  296. 22440, -48185, 243855, -9968, -16448
  297. }
  298. });
  299. SPAWNS.put(18498, new int[][]
  300. {
  301. {
  302. 22411, -46355, 246375, -9984, 0
  303. },
  304. {
  305. 22411, -46167, 246160, -9984, 0
  306. },
  307. {
  308. 22393, -45952, 245748, -9984, 0
  309. },
  310. {
  311. 22394, -46428, 246254, -9984, 0
  312. },
  313. {
  314. 22393, -46490, 245871, -9984, 0
  315. },
  316. {
  317. 22394, -45877, 246309, -9984, 0
  318. }
  319. });
  320. SPAWNS.put(18499, new int[][]
  321. {
  322. {
  323. 22395, -48730, 248067, -9984, 0
  324. },
  325. {
  326. 22395, -49112, 248250, -9984, 0
  327. }
  328. });
  329. SPAWNS.put(18500, new int[][]
  330. {
  331. {
  332. 22393, -51954, 246475, -10848, 0
  333. },
  334. {
  335. 22394, -51421, 246512, -10848, 0
  336. },
  337. {
  338. 22394, -51404, 245951, -10848, 0
  339. },
  340. {
  341. 22393, -51913, 246206, -10848, 0
  342. },
  343. {
  344. 22394, -51663, 245979, -10848, 0
  345. },
  346. {
  347. 22394, -51969, 245809, -10848, 0
  348. },
  349. {
  350. 22412, -51259, 246357, -10848, 0
  351. }
  352. });
  353. SPAWNS.put(18501, new int[][]
  354. {
  355. {
  356. 22395, -48856, 243949, -10848, 0
  357. },
  358. {
  359. 22395, -49144, 244190, -10848, 0
  360. }
  361. });
  362. SPAWNS.put(18502, new int[][]
  363. {
  364. {
  365. 22441, -46471, 246135, -11704, 0
  366. },
  367. {
  368. 22441, -46449, 245997, -11704, 0
  369. },
  370. {
  371. 22441, -46235, 246187, -11704, 0
  372. },
  373. {
  374. 22441, -46513, 246326, -11704, 0
  375. },
  376. {
  377. 22441, -45889, 246313, -11704, 0
  378. }
  379. });
  380. SPAWNS.put(18503, new int[][]
  381. {
  382. {
  383. 22395, -49067, 248050, -11712, 0
  384. },
  385. {
  386. 22395, -48957, 248223, -11712, 0
  387. }
  388. });
  389. SPAWNS.put(18504, new int[][]
  390. {
  391. {
  392. 22413, -51748, 246138, -12568, 0
  393. },
  394. {
  395. 22413, -51279, 246200, -12568, 0
  396. },
  397. {
  398. 22413, -51787, 246594, -12568, 0
  399. },
  400. {
  401. 22413, -51892, 246544, -12568, 0
  402. },
  403. {
  404. 22413, -51500, 245781, -12568, 0
  405. },
  406. {
  407. 22413, -51941, 246045, -12568, 0
  408. }
  409. });
  410. SPAWNS.put(18505, new int[][]
  411. {
  412. {
  413. 18490, -48238, 243347, -13376, 0
  414. },
  415. {
  416. 18490, -48462, 244022, -13376, 0
  417. },
  418. {
  419. 18490, -48050, 244045, -13376, 0
  420. },
  421. {
  422. 18490, -48229, 243823, -13376, 0
  423. },
  424. {
  425. 18490, -47871, 243208, -13376, 0
  426. },
  427. {
  428. 18490, -48255, 243528, -13376, 0
  429. },
  430. {
  431. 18490, -48461, 243780, -13376, 0
  432. },
  433. {
  434. 18490, -47983, 243197, -13376, 0
  435. },
  436. {
  437. 18490, -47841, 243819, -13376, 0
  438. },
  439. {
  440. 18490, -48646, 243764, -13376, 0
  441. },
  442. {
  443. 18490, -47806, 243850, -13376, 0
  444. },
  445. {
  446. 18490, -48456, 243447, -13376, 0
  447. }
  448. });
  449. }
  450. public TowerOfNaia(int questId, String name, String descr)
  451. {
  452. super(questId, name, descr);
  453. addFirstTalkId(CONTROLLER);
  454. addStartNpc(CONTROLLER);
  455. addStartNpc(DWARVEN_GHOST);
  456. addTalkId(CONTROLLER);
  457. addTalkId(DWARVEN_GHOST);
  458. addAttackId(LOCK);
  459. addKillId(LOCK);
  460. addKillId(MUTATED_ELPY);
  461. addSpawnId(MUTATED_ELPY);
  462. addKillId(SPORE_BASIC);
  463. addSpawnId(SPORE_BASIC);
  464. for (int npcId = SPORE_FIRE; npcId <= SPORE_EARTH; npcId++)
  465. {
  466. addKillId(npcId);
  467. addSpawnId(npcId);
  468. }
  469. for (int npcId = ROOM_MANAGER_FIRST; npcId <= ROOM_MANAGER_LAST; npcId++)
  470. {
  471. addFirstTalkId(npcId);
  472. addTalkId(npcId);
  473. addStartNpc(npcId);
  474. initRoom(npcId);
  475. }
  476. for (int npcId : TOWER_MONSTERS)
  477. {
  478. addKillId(npcId);
  479. }
  480. _lock = (L2MonsterInstance) addSpawn(LOCK, 16409, 244438, 11620, -1048, false, 0, false);
  481. _controller = addSpawn(CONTROLLER, 16608, 244420, 11620, 31264, false, 0, false);
  482. _counter = 90;
  483. _despawnedSporesCount = 0;
  484. _challengeState = 0;
  485. _winIndex = -1;
  486. initSporeChallenge();
  487. spawnElpy();
  488. }
  489. @Override
  490. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  491. {
  492. int npcId = npc.getNpcId();
  493. if (npcId == CONTROLLER)
  494. {
  495. if (_lock == null)
  496. {
  497. return "18492-02.htm";
  498. }
  499. else
  500. {
  501. return "18492-01.htm";
  502. }
  503. }
  504. else if ((npcId >= ROOM_MANAGER_FIRST) && (npcId <= ROOM_MANAGER_LAST))
  505. {
  506. if (_activeRooms.containsKey(npcId) && !_activeRooms.get(npcId))
  507. {
  508. if (player.getParty() == null)
  509. {
  510. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CAN_OPERATE_MACHINE_WHEN_IN_PARTY));
  511. return null;
  512. }
  513. return "manager.htm";
  514. }
  515. }
  516. return null;
  517. }
  518. @Override
  519. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  520. {
  521. String htmltext = event;
  522. // Timer. Spawns Naia Lock
  523. if (event.equalsIgnoreCase("spawn_lock"))
  524. {
  525. htmltext = null;
  526. _lock = (L2MonsterInstance) addSpawn(LOCK, 16409, 244438, 11620, -1048, false, 0, false);
  527. _counter = 90;
  528. }
  529. // Timer. Depending of _challengeState despans all spawned spores, or spores, reached assembly point
  530. else if (event.equalsIgnoreCase("despawn_total"))
  531. {
  532. // Spores is not attacked too long - despawn them all, reinit values
  533. if (_challengeState == STATE_SPORE_IDLE_TOO_LONG)
  534. {
  535. for (L2Npc spore : _sporeSpawn)
  536. {
  537. if ((spore != null) && !spore.isDead())
  538. {
  539. spore.deleteMe();
  540. }
  541. }
  542. _sporeSpawn.clear();
  543. initSporeChallenge();
  544. }
  545. // Spores are moving to assembly point. Despawn all reached, check for reached spores count.
  546. else if ((_challengeState == STATE_SPORE_CHALLENGE_SUCCESSFULL) && (_winIndex >= 0))
  547. {
  548. // Requirements are met, despawn all spores, spawn Epidos
  549. if ((_despawnedSporesCount >= 10) || _sporeSpawn.isEmpty())
  550. {
  551. if (!_sporeSpawn.isEmpty())
  552. {
  553. for (L2Npc spore : _sporeSpawn)
  554. {
  555. if ((spore != null) && !spore.isDead())
  556. {
  557. spore.deleteMe();
  558. }
  559. }
  560. }
  561. _sporeSpawn.clear();
  562. _despawnedSporesCount = 0;
  563. int[] coords = SPORES_MERGE_POSITION[_winIndex];
  564. addSpawn(EPIDOSES[_winIndex], coords[0], coords[1], coords[2], 0, false, 0, false);
  565. initSporeChallenge();
  566. }
  567. // Requirements aren't met, despawn reached spores
  568. else
  569. {
  570. Iterator<L2Npc> it = _sporeSpawn.iterator();
  571. while (it.hasNext())
  572. {
  573. L2Npc spore = it.next();
  574. if ((spore != null) && !spore.isDead() && (spore.getX() == spore.getSpawn().getLocx()) && (spore.getY() == spore.getSpawn().getLocy()))
  575. {
  576. spore.deleteMe();
  577. it.remove();
  578. _despawnedSporesCount++;
  579. }
  580. }
  581. startQuestTimer("despawn_total", 3000, null, null);
  582. }
  583. }
  584. }
  585. if (npc == null)
  586. {
  587. return null;
  588. }
  589. int npcId = npc.getNpcId();
  590. if (event.equalsIgnoreCase("despawn_spore") && !npc.isDead() && (_challengeState == STATE_SPORE_CHALLENGE_IN_PROGRESS))
  591. {
  592. htmltext = null;
  593. _sporeSpawn.remove(npc);
  594. npc.deleteMe();
  595. if (npcId == SPORE_BASIC)
  596. {
  597. spawnRandomSpore();
  598. spawnRandomSpore();
  599. }
  600. else if ((npcId >= SPORE_FIRE) && (npcId <= SPORE_EARTH))
  601. {
  602. _despawnedSporesCount++;
  603. /*
  604. * if (_despawnedSporesCount % 20 == 0) { Announcements.getInstance().announceToAll("Despawned " + Integer.toString(_despawnedSporesCount) + " creatures"); }
  605. */
  606. if (_despawnedSporesCount < SELF_DESPAWN_LIMIT)
  607. {
  608. spawnOppositeSpore(npcId);
  609. }
  610. else
  611. {
  612. _challengeState = STATE_SPORE_IDLE_TOO_LONG;
  613. startQuestTimer("despawn_total", 60000, null, null);
  614. }
  615. }
  616. }
  617. else if (event.equalsIgnoreCase("18492-05.htm"))
  618. {
  619. if ((_lock == null) || (_lock.getCurrentHp() > (_lock.getMaxHp() / 10)))
  620. {
  621. htmltext = null;
  622. _lock.deleteMe();
  623. _lock = null;
  624. cancelQuestTimers("spawn_lock");
  625. startQuestTimer("spawn_lock", 300000, null, null);
  626. npc.setTarget(player);
  627. npc.doCast(SkillTable.getInstance().getInfo(5527, 1));
  628. }
  629. }
  630. else if (event.equalsIgnoreCase("teleport") && (_lock != null))
  631. {
  632. htmltext = null;
  633. L2Party party = player.getParty();
  634. if (party != null)
  635. {
  636. if (Util.checkIfInRange(3000, party.getLeader(), npc, true))
  637. {
  638. for (L2PcInstance partyMember : party.getPartyMembers())
  639. {
  640. if (Util.checkIfInRange(2000, partyMember, npc, true))
  641. {
  642. partyMember.teleToLocation(-47271, 246098, -9120, true);
  643. }
  644. }
  645. _lock.deleteMe();
  646. _lock = null;
  647. cancelQuestTimers("spawn_lock");
  648. startQuestTimer("spawn_lock", 1200000, null, null);
  649. }
  650. else
  651. {
  652. npc.setTarget(player);
  653. npc.doCast(SkillTable.getInstance().getInfo(5527, 1));
  654. }
  655. }
  656. else
  657. {
  658. player.teleToLocation(-47271, 246098, -9120);
  659. _lock.deleteMe();
  660. _lock = null;
  661. cancelQuestTimers("spawn_lock");
  662. startQuestTimer("spawn_lock", 1200000, null, null);
  663. }
  664. }
  665. else if (event.equalsIgnoreCase("go") && _activeRooms.containsKey(npcId) && !_activeRooms.get(npcId))
  666. {
  667. htmltext = null;
  668. L2Party party = player.getParty();
  669. if (party != null)
  670. {
  671. removeForeigners(npcId, party);
  672. startRoom(npcId);
  673. ThreadPoolManager.getInstance().scheduleGeneral(new StopRoomTask(npcId), 300000);
  674. }
  675. else
  676. {
  677. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CAN_OPERATE_MACHINE_WHEN_IN_PARTY));
  678. }
  679. }
  680. return htmltext;
  681. }
  682. @Override
  683. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  684. {
  685. if ((_lock != null) && (npc.getObjectId() == _lock.getObjectId()))
  686. {
  687. int remaindedHpPercent = (int) ((npc.getCurrentHp() * 100) / npc.getMaxHp());
  688. if ((remaindedHpPercent <= _counter) && (_controller != null))
  689. {
  690. if (_counter == 50)
  691. {
  692. MinionList.spawnMinion(_lock, 18493);
  693. }
  694. else if (_counter == 10)
  695. {
  696. MinionList.spawnMinion(_lock, 18493);
  697. MinionList.spawnMinion(_lock, 18493);
  698. }
  699. _controller.broadcastPacket(new NpcSay(_controller.getObjectId(), Say2.ALL, _controller.getNpcId(), NpcStringId.EMERGENCY_EMERGENCY_THE_OUTER_WALL_IS_WEAKENING_RAPIDLY));
  700. _counter -= 10;
  701. }
  702. }
  703. return super.onAttack(npc, attacker, damage, isPet, skill);
  704. }
  705. @Override
  706. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  707. {
  708. int npcId = npc.getNpcId();
  709. if (npcId == LOCK)
  710. {
  711. _lock = null;
  712. cancelQuestTimers("spawn_lock");
  713. startQuestTimer("spawn_lock", 300000, null, null);
  714. }
  715. else if (Arrays.binarySearch(TOWER_MONSTERS, npcId) >= 0)
  716. {
  717. int managerId = 0;
  718. for (L2ZoneType zone : ZoneManager.getInstance().getZones(npc.getX(), npc.getY(), npc.getZ()))
  719. {
  720. if (ZONES.containsValue(zone.getId()))
  721. {
  722. for (int i : ZONES.keySet())
  723. {
  724. if (ZONES.get(i) == zone.getId())
  725. {
  726. managerId = i;
  727. break;
  728. }
  729. }
  730. }
  731. }
  732. if ((managerId > 0) && _spawns.containsKey(managerId))
  733. {
  734. List<L2Npc> spawned = _spawns.get(managerId);
  735. spawned.remove(npc);
  736. if (spawned.isEmpty() && DOORS.containsKey(managerId))
  737. {
  738. int[] doorList = DOORS.get(managerId);
  739. DoorTable.getInstance().getDoor(doorList[1]).openMe();
  740. _spawns.remove(managerId);
  741. }
  742. }
  743. }
  744. else if (npcId == MUTATED_ELPY)
  745. {
  746. _challengeState = STATE_SPORE_CHALLENGE_IN_PROGRESS;
  747. markElpyRespawn();
  748. DoorTable.getInstance().getDoor(18250025).closeMe();
  749. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200100)).setZoneEnabled(true);
  750. for (int i = 0; i < 10; i++)
  751. {
  752. addSpawn(SPORE_BASIC, -45474, 247450, -13994, 49152, false, 0, false);
  753. }
  754. }
  755. else if ((npcId == SPORE_BASIC) && (_challengeState == STATE_SPORE_CHALLENGE_IN_PROGRESS))
  756. {
  757. _sporeSpawn.remove(npc);
  758. spawnRandomSpore();
  759. spawnRandomSpore();
  760. }
  761. else if ((npcId >= SPORE_FIRE) && (npcId <= SPORE_EARTH) && ((_challengeState == STATE_SPORE_CHALLENGE_IN_PROGRESS) || (_challengeState == STATE_SPORE_CHALLENGE_SUCCESSFULL)))
  762. {
  763. _sporeSpawn.remove(npc);
  764. if (_challengeState == STATE_SPORE_CHALLENGE_IN_PROGRESS)
  765. {
  766. _despawnedSporesCount--;
  767. int sporeGroup = getSporeGroup(npcId);
  768. if (sporeGroup >= 0)
  769. {
  770. if ((npcId == SPORE_FIRE) || (npcId == SPORE_WIND))
  771. {
  772. _indexCount[sporeGroup] += 2;
  773. }
  774. else
  775. {
  776. _indexCount[sporeGroup] -= 2;
  777. }
  778. if (_indexCount[Math.abs(sporeGroup - 1)] > 0)
  779. {
  780. _indexCount[Math.abs(sporeGroup - 1)]--;
  781. }
  782. else if (_indexCount[Math.abs(sporeGroup - 1)] < 0)
  783. {
  784. _indexCount[Math.abs(sporeGroup - 1)]++;
  785. }
  786. if ((Math.abs(_indexCount[sporeGroup]) < ELEMENT_INDEX_LIMIT) && (Math.abs(_indexCount[sporeGroup]) > 0) && ((_indexCount[sporeGroup] % 20) == 0) && (Rnd.get(100) < 50))
  787. {
  788. String el = ELEMENTS_NAME[Arrays.binarySearch(ELEMENTS, npcId)];
  789. for (L2Npc spore : _sporeSpawn)
  790. {
  791. if ((spore != null) && !spore.isDead() && (spore.getNpcId() == npcId))
  792. {
  793. NpcSay ns = new NpcSay(spore.getObjectId(), Say2.ALL, spore.getNpcId(), SPORES_NPCSTRING_ID[Rnd.get(4)]);
  794. ns.addStringParameter(el);
  795. spore.broadcastPacket(ns);
  796. }
  797. }
  798. }
  799. if (Math.abs(_indexCount[sporeGroup]) < ELEMENT_INDEX_LIMIT)
  800. {
  801. if ((((_indexCount[sporeGroup] > 0) && ((npcId == SPORE_FIRE) || (npcId == SPORE_WIND))) || ((_indexCount[sporeGroup] <= 0) && ((npcId == SPORE_WATER) || (npcId == SPORE_EARTH)))) && (Rnd.get(1000) > 200))
  802. {
  803. spawnOppositeSpore(npcId);
  804. }
  805. else
  806. {
  807. spawnRandomSpore();
  808. }
  809. }
  810. else
  811. // index value was reached
  812. {
  813. _challengeState = STATE_SPORE_CHALLENGE_SUCCESSFULL;
  814. _despawnedSporesCount = 0;
  815. _winIndex = Arrays.binarySearch(ELEMENTS, npcId);
  816. int[] coord = SPORES_MERGE_POSITION[_winIndex];
  817. for (L2Npc spore : _sporeSpawn)
  818. {
  819. if ((spore != null) && !spore.isDead())
  820. {
  821. moveTo(spore, coord);
  822. }
  823. }
  824. startQuestTimer("despawn_total", 3000, null, null);
  825. }
  826. }
  827. }
  828. }
  829. return super.onKill(npc, killer, isPet);
  830. }
  831. @Override
  832. public final String onSpawn(L2Npc npc)
  833. {
  834. int npcId = npc.getNpcId();
  835. if ((npcId == MUTATED_ELPY) && !npc.isTeleporting())
  836. {
  837. DoorTable.getInstance().getDoor(18250025).openMe();
  838. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200100)).setZoneEnabled(false);
  839. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200101)).setZoneEnabled(true);
  840. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200101)).setZoneEnabled(false);
  841. }
  842. else if (((npcId == SPORE_BASIC) || ((npcId >= SPORE_FIRE) && (npcId <= SPORE_EARTH))) && (_challengeState == STATE_SPORE_CHALLENGE_IN_PROGRESS))
  843. {
  844. _sporeSpawn.add(npc);
  845. npc.setIsRunning(false);
  846. int[] coord = SPORES_MOVE_POINTS[Rnd.get(SPORES_MOVE_POINTS.length)];
  847. npc.getSpawn().setLocx(coord[0]);
  848. npc.getSpawn().setLocy(coord[1]);
  849. npc.getSpawn().setLocz(coord[2]);
  850. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(coord[0], coord[1], coord[2], 0));
  851. startQuestTimer("despawn_spore", 60000, npc, null);
  852. }
  853. return super.onSpawn(npc);
  854. }
  855. private int getSporeGroup(int sporeId)
  856. {
  857. int ret;
  858. switch (sporeId)
  859. {
  860. case SPORE_FIRE:
  861. case SPORE_WATER:
  862. ret = 0;
  863. break;
  864. case SPORE_WIND:
  865. case SPORE_EARTH:
  866. ret = 1;
  867. break;
  868. default:
  869. ret = -1;
  870. }
  871. return ret;
  872. }
  873. private void initRoom(int managerId)
  874. {
  875. removeAllPlayers(managerId);
  876. _activeRooms.put(managerId, false);
  877. if (DOORS.containsKey(managerId))
  878. {
  879. int[] doorList = DOORS.get(managerId);
  880. DoorTable.getInstance().getDoor(doorList[0]).openMe();
  881. DoorTable.getInstance().getDoor(doorList[1]).closeMe();
  882. }
  883. if (_spawns.containsKey(managerId) && (_spawns.get(managerId) != null))
  884. {
  885. for (L2Npc npc : _spawns.get(managerId))
  886. {
  887. if ((npc != null) && !npc.isDead())
  888. {
  889. npc.deleteMe();
  890. }
  891. }
  892. _spawns.get(managerId).clear();
  893. _spawns.remove(managerId);
  894. }
  895. }
  896. private void initSporeChallenge()
  897. {
  898. _despawnedSporesCount = 0;
  899. _challengeState = 0;
  900. _winIndex = -1;
  901. _indexCount[0] = 0;
  902. _indexCount[1] = 0;
  903. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200100)).setZoneEnabled(false);
  904. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200101)).setZoneEnabled(false);
  905. ((L2EffectZone) ZoneManager.getInstance().getZoneById(200101)).setZoneEnabled(true);
  906. }
  907. private void markElpyRespawn()
  908. {
  909. long respawnTime = (Rnd.get(43200, 216000) * 1000);
  910. GlobalVariablesManager.getInstance().storeVariable("elpy_respawn_time", Long.toString(respawnTime + System.currentTimeMillis()));
  911. }
  912. private int moveTo(L2Npc npc, int[] coords)
  913. {
  914. int time = 0;
  915. if (npc != null)
  916. {
  917. double distance = Util.calculateDistance(coords[0], coords[1], coords[2], npc.getX(), npc.getY(), npc.getZ(), true);
  918. int heading = Util.calculateHeadingFrom(npc.getX(), npc.getY(), coords[0], coords[1]);
  919. time = (int) ((distance / npc.getWalkSpeed()) * 1000);
  920. npc.setIsRunning(false);
  921. npc.disableCoreAI(true);
  922. npc.setIsNoRndWalk(true);
  923. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(coords[0], coords[1], coords[2], heading));
  924. npc.getSpawn().setLocx(coords[0]);
  925. npc.getSpawn().setLocy(coords[1]);
  926. npc.getSpawn().setLocz(coords[2]);
  927. }
  928. return time == 0 ? 100 : time;
  929. }
  930. private void spawnElpy()
  931. {
  932. String tmp = GlobalVariablesManager.getInstance().getStoredVariable("elpy_respawn_time");
  933. long respawnTime = tmp == null ? 0 : Long.parseLong(tmp) * 1000;
  934. if (respawnTime <= System.currentTimeMillis())
  935. {
  936. addSpawn(MUTATED_ELPY, 45474, 247450, -13994, 49152, false, 0, false);
  937. }
  938. else
  939. {
  940. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  941. {
  942. @Override
  943. public void run()
  944. {
  945. addSpawn(MUTATED_ELPY, 45474, 247450, -13994, 49152, false, 0, false);
  946. }
  947. }, respawnTime - System.currentTimeMillis());
  948. }
  949. }
  950. private L2Npc spawnRandomSpore()
  951. {
  952. return addSpawn(Rnd.get(SPORE_FIRE, SPORE_EARTH), -45474, 247450, -13994, 49152, false, 0, false);
  953. }
  954. private L2Npc spawnOppositeSpore(int srcSporeId)
  955. {
  956. int idx = Arrays.binarySearch(ELEMENTS, srcSporeId);
  957. return idx >= 0 ? addSpawn(OPPOSITE_ELEMENTS[idx], -45474, 247450, -13994, 49152, false, 0, false) : null;
  958. }
  959. private void startRoom(int managerId)
  960. {
  961. _activeRooms.put(managerId, true);
  962. if (DOORS.containsKey(managerId))
  963. {
  964. int[] doorList = DOORS.get(managerId);
  965. DoorTable.getInstance().getDoor(doorList[0]).closeMe();
  966. }
  967. if (SPAWNS.containsKey(managerId))
  968. {
  969. int[][] spawnList = SPAWNS.get(managerId);
  970. List<L2Npc> spawned = new FastList<L2Npc>();
  971. for (int[] spawn : spawnList)
  972. {
  973. L2Npc spawnedNpc = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false, 0, false);
  974. spawned.add(spawnedNpc);
  975. }
  976. if (!spawned.isEmpty())
  977. {
  978. _spawns.put(managerId, spawned);
  979. }
  980. }
  981. }
  982. private void removeForeigners(int managerId, L2Party party)
  983. {
  984. if ((party != null) && ZONES.containsKey(managerId) && (ZoneManager.getInstance().getZoneById(ZONES.get(managerId)) != null))
  985. {
  986. L2ZoneType zone = ZoneManager.getInstance().getZoneById(ZONES.get(managerId));
  987. for (L2Character ch : zone.getCharactersInsideArray())
  988. {
  989. if (ch instanceof L2PcInstance)
  990. {
  991. L2Party charParty = ((L2PcInstance) ch).getParty();
  992. if ((charParty == null) || (charParty.getPartyLeaderOID() != party.getPartyLeaderOID()))
  993. {
  994. ch.teleToLocation(16110, 243841, 11616);
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. private void removeAllPlayers(int managerId)
  1001. {
  1002. if (ZONES.containsKey(managerId) && (ZoneManager.getInstance().getZoneById(ZONES.get(managerId)) != null))
  1003. {
  1004. L2ZoneType zone = ZoneManager.getInstance().getZoneById(ZONES.get(managerId));
  1005. for (L2Character ch : zone.getCharactersInsideArray())
  1006. {
  1007. if (ch instanceof L2PcInstance)
  1008. {
  1009. ch.teleToLocation(16110, 243841, 11616);
  1010. }
  1011. }
  1012. }
  1013. }
  1014. private class StopRoomTask implements Runnable
  1015. {
  1016. private final int _managerId;
  1017. public StopRoomTask(int managerId)
  1018. {
  1019. _managerId = managerId;
  1020. }
  1021. @Override
  1022. public void run()
  1023. {
  1024. initRoom(_managerId);
  1025. }
  1026. }
  1027. public static void main(String[] args)
  1028. {
  1029. new TowerOfNaia(-1, "TowerOfNaia", "hellbound");
  1030. }
  1031. }