TowerOfNaia.java 26 KB

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