FourSepulchersManager.java 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.instancemanager;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.util.ArrayList;
  24. import java.util.Calendar;
  25. import java.util.HashMap;
  26. import java.util.LinkedList;
  27. import java.util.List;
  28. import java.util.Map;
  29. import java.util.Map.Entry;
  30. import java.util.concurrent.ConcurrentHashMap;
  31. import java.util.concurrent.CopyOnWriteArrayList;
  32. import java.util.concurrent.ScheduledFuture;
  33. import java.util.logging.Level;
  34. import java.util.logging.Logger;
  35. import com.l2jserver.Config;
  36. import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  37. import com.l2jserver.gameserver.ThreadPoolManager;
  38. import com.l2jserver.gameserver.data.xml.impl.DoorData;
  39. import com.l2jserver.gameserver.datatables.SpawnTable;
  40. import com.l2jserver.gameserver.instancemanager.tasks.FourSepulchersChangeAttackTimeTask;
  41. import com.l2jserver.gameserver.instancemanager.tasks.FourSepulchersChangeCoolDownTimeTask;
  42. import com.l2jserver.gameserver.instancemanager.tasks.FourSepulchersChangeEntryTimeTask;
  43. import com.l2jserver.gameserver.instancemanager.tasks.FourSepulchersChangeWarmUpTimeTask;
  44. import com.l2jserver.gameserver.model.L2Spawn;
  45. import com.l2jserver.gameserver.model.actor.L2Npc;
  46. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  47. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  48. import com.l2jserver.gameserver.model.actor.instance.L2SepulcherMonsterInstance;
  49. import com.l2jserver.gameserver.model.actor.instance.L2SepulcherNpcInstance;
  50. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  51. import com.l2jserver.gameserver.model.quest.Quest;
  52. import com.l2jserver.gameserver.model.quest.QuestState;
  53. import com.l2jserver.gameserver.network.NpcStringId;
  54. import com.l2jserver.gameserver.network.SystemMessageId;
  55. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  56. import com.l2jserver.gameserver.util.Util;
  57. import com.l2jserver.util.Rnd;
  58. /**
  59. * Zoey76: TODO: Use Location DTO instead of array of int.
  60. * @author sandman
  61. */
  62. public final class FourSepulchersManager
  63. {
  64. private static final Logger _log = Logger.getLogger(FourSepulchersManager.class.getName());
  65. private static final int QUEST_ID = 620;
  66. private static final int ENTRANCE_PASS = 7075;
  67. private static final int USED_PASS = 7261;
  68. private static final int CHAPEL_KEY = 7260;
  69. private static final int ANTIQUE_BROOCH = 7262;
  70. private boolean _firstTimeRun;
  71. private boolean _inEntryTime = false;
  72. private boolean _inWarmUpTime = false;
  73. private boolean _inAttackTime = false;
  74. private boolean _inCoolDownTime = false;
  75. private ScheduledFuture<?> _changeCoolDownTimeTask = null;
  76. private ScheduledFuture<?> _changeEntryTimeTask = null;
  77. private ScheduledFuture<?> _changeWarmUpTimeTask = null;
  78. private ScheduledFuture<?> _changeAttackTimeTask = null;
  79. // @formatter:off
  80. private final int[][] _startHallSpawn =
  81. {
  82. { 181632, -85587, -7218 },
  83. { 179963, -88978, -7218 },
  84. { 173217, -86132, -7218 },
  85. { 175608, -82296, -7218 }
  86. };
  87. private final int[][][] _shadowSpawnLoc =
  88. {
  89. {
  90. { 25339, 191231, -85574, -7216, 33380 },
  91. { 25349, 189534, -88969, -7216, 32768 },
  92. { 25346, 173195, -76560, -7215, 49277 },
  93. { 25342, 175591, -72744, -7215, 49317 }
  94. },
  95. {
  96. { 25342, 191231, -85574, -7216, 33380 },
  97. { 25339, 189534, -88969, -7216, 32768 },
  98. { 25349, 173195, -76560, -7215, 49277 },
  99. { 25346, 175591, -72744, -7215, 49317 }
  100. },
  101. {
  102. { 25346, 191231, -85574, -7216, 33380 },
  103. { 25342, 189534, -88969, -7216, 32768 },
  104. { 25339, 173195, -76560, -7215, 49277 },
  105. { 25349, 175591, -72744, -7215, 49317 }
  106. },
  107. {
  108. { 25349, 191231, -85574, -7216, 33380 },
  109. { 25346, 189534, -88969, -7216, 32768 },
  110. { 25342, 173195, -76560, -7215, 49277 },
  111. { 25339, 175591, -72744, -7215, 49317 }
  112. },
  113. };
  114. // @formatter:on
  115. protected Map<Integer, Boolean> _archonSpawned = new ConcurrentHashMap<>();
  116. protected Map<Integer, Boolean> _hallInUse = new ConcurrentHashMap<>();
  117. protected Map<Integer, L2PcInstance> _challengers = new ConcurrentHashMap<>();
  118. protected Map<Integer, int[]> _startHallSpawns = new HashMap<>();
  119. protected Map<Integer, Integer> _hallGateKeepers = new HashMap<>();
  120. protected Map<Integer, Integer> _keyBoxNpc = new HashMap<>();
  121. protected Map<Integer, Integer> _victim = new HashMap<>();
  122. protected Map<Integer, L2Spawn> _executionerSpawns = new HashMap<>();
  123. protected Map<Integer, L2Spawn> _keyBoxSpawns = new HashMap<>();
  124. protected Map<Integer, L2Spawn> _mysteriousBoxSpawns = new HashMap<>();
  125. protected Map<Integer, L2Spawn> _shadowSpawns = new HashMap<>();
  126. protected Map<Integer, List<L2Spawn>> _dukeFinalMobs = new HashMap<>();
  127. protected Map<Integer, List<L2SepulcherMonsterInstance>> _dukeMobs = new HashMap<>();
  128. protected Map<Integer, List<L2Spawn>> _emperorsGraveNpcs = new HashMap<>();
  129. protected Map<Integer, List<L2Spawn>> _magicalMonsters = new HashMap<>();
  130. protected Map<Integer, List<L2Spawn>> _physicalMonsters = new HashMap<>();
  131. protected Map<Integer, List<L2SepulcherMonsterInstance>> _viscountMobs = new HashMap<>();
  132. protected List<L2Spawn> _physicalSpawns;
  133. protected List<L2Spawn> _magicalSpawns;
  134. protected List<L2Spawn> _managers;
  135. protected List<L2Spawn> _dukeFinalSpawns;
  136. protected List<L2Spawn> _emperorsGraveSpawns;
  137. protected List<L2Npc> _allMobs = new CopyOnWriteArrayList<>();
  138. private long _attackTimeEnd = 0;
  139. private long _coolDownTimeEnd = 0;
  140. private long _entryTimeEnd = 0;
  141. private long _warmUpTimeEnd = 0;
  142. private final byte _newCycleMin = 55;
  143. public void init()
  144. {
  145. if (_changeCoolDownTimeTask != null)
  146. {
  147. _changeCoolDownTimeTask.cancel(true);
  148. }
  149. if (_changeEntryTimeTask != null)
  150. {
  151. _changeEntryTimeTask.cancel(true);
  152. }
  153. if (_changeWarmUpTimeTask != null)
  154. {
  155. _changeWarmUpTimeTask.cancel(true);
  156. }
  157. if (_changeAttackTimeTask != null)
  158. {
  159. _changeAttackTimeTask.cancel(true);
  160. }
  161. _changeCoolDownTimeTask = null;
  162. _changeEntryTimeTask = null;
  163. _changeWarmUpTimeTask = null;
  164. _changeAttackTimeTask = null;
  165. _inEntryTime = false;
  166. _inWarmUpTime = false;
  167. _inAttackTime = false;
  168. _inCoolDownTime = false;
  169. _firstTimeRun = true;
  170. initFixedInfo();
  171. loadMysteriousBox();
  172. initKeyBoxSpawns();
  173. loadPhysicalMonsters();
  174. loadMagicalMonsters();
  175. initLocationShadowSpawns();
  176. initExecutionerSpawns();
  177. loadDukeMonsters();
  178. loadEmperorsGraveMonsters();
  179. spawnManagers();
  180. timeSelector();
  181. }
  182. // phase select on server launch
  183. protected void timeSelector()
  184. {
  185. timeCalculator();
  186. long currentTime = Calendar.getInstance().getTimeInMillis();
  187. // if current time >= time of entry beginning and if current time < time of entry beginning + time of entry end
  188. if ((currentTime >= _coolDownTimeEnd) && (currentTime < _entryTimeEnd)) // entry time check
  189. {
  190. clean();
  191. _changeEntryTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeEntryTimeTask(), 0);
  192. _log.info(getClass().getSimpleName() + ": Beginning in Entry time");
  193. }
  194. else if ((currentTime >= _entryTimeEnd) && (currentTime < _warmUpTimeEnd)) // warmup time check
  195. {
  196. clean();
  197. _changeWarmUpTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeWarmUpTimeTask(), 0);
  198. _log.info(getClass().getSimpleName() + ": Beginning in WarmUp time");
  199. }
  200. else if ((currentTime >= _warmUpTimeEnd) && (currentTime < _attackTimeEnd)) // attack time check
  201. {
  202. clean();
  203. _changeAttackTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeAttackTimeTask(), 0);
  204. _log.info(getClass().getSimpleName() + ": Beginning in Attack time");
  205. }
  206. else
  207. // else cooldown time and without cleanup because it's already implemented
  208. {
  209. _changeCoolDownTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeCoolDownTimeTask(), 0);
  210. _log.info(getClass().getSimpleName() + ": Beginning in Cooldown time");
  211. }
  212. }
  213. // phase end times calculator
  214. protected void timeCalculator()
  215. {
  216. Calendar tmp = Calendar.getInstance();
  217. if (tmp.get(Calendar.MINUTE) < _newCycleMin)
  218. {
  219. tmp.set(Calendar.HOUR, Calendar.getInstance().get(Calendar.HOUR) - 1);
  220. }
  221. tmp.set(Calendar.MINUTE, _newCycleMin);
  222. _coolDownTimeEnd = tmp.getTimeInMillis();
  223. _entryTimeEnd = _coolDownTimeEnd + (Config.FS_TIME_ENTRY * 60000L);
  224. _warmUpTimeEnd = _entryTimeEnd + (Config.FS_TIME_WARMUP * 60000L);
  225. _attackTimeEnd = _warmUpTimeEnd + (Config.FS_TIME_ATTACK * 60000L);
  226. }
  227. public void clean()
  228. {
  229. for (int i = 31921; i < 31925; i++)
  230. {
  231. int[] Location = _startHallSpawns.get(i);
  232. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).oustAllPlayers();
  233. }
  234. deleteAllMobs();
  235. closeAllDoors();
  236. _hallInUse.clear();
  237. _hallInUse.put(31921, false);
  238. _hallInUse.put(31922, false);
  239. _hallInUse.put(31923, false);
  240. _hallInUse.put(31924, false);
  241. for (int npcId : _archonSpawned.keySet())
  242. {
  243. _archonSpawned.put(npcId, false);
  244. }
  245. }
  246. protected void spawnManagers()
  247. {
  248. _managers = new CopyOnWriteArrayList<>();
  249. for (int npcId = 31921; npcId <= 31924; npcId++)
  250. {
  251. try
  252. {
  253. final L2Spawn spawnDat = new L2Spawn(npcId);
  254. spawnDat.setAmount(1);
  255. spawnDat.setRespawnDelay(60);
  256. switch (npcId)
  257. {
  258. case 31921: // conquerors
  259. spawnDat.setX(181061);
  260. spawnDat.setY(-85595);
  261. spawnDat.setZ(-7200);
  262. spawnDat.setHeading(-32584);
  263. break;
  264. case 31922: // emperors
  265. spawnDat.setX(179292);
  266. spawnDat.setY(-88981);
  267. spawnDat.setZ(-7200);
  268. spawnDat.setHeading(-33272);
  269. break;
  270. case 31923: // sages
  271. spawnDat.setX(173202);
  272. spawnDat.setY(-87004);
  273. spawnDat.setZ(-7200);
  274. spawnDat.setHeading(-16248);
  275. break;
  276. case 31924: // judges
  277. spawnDat.setX(175606);
  278. spawnDat.setY(-82853);
  279. spawnDat.setZ(-7200);
  280. spawnDat.setHeading(-16248);
  281. break;
  282. }
  283. _managers.add(spawnDat);
  284. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  285. spawnDat.doSpawn();
  286. spawnDat.startRespawn();
  287. _log.info(getClass().getSimpleName() + ": spawned " + spawnDat.getTemplate().getName());
  288. }
  289. catch (Exception e)
  290. {
  291. _log.log(Level.WARNING, "Error while spawning managers: " + e.getMessage(), e);
  292. }
  293. }
  294. }
  295. protected void initFixedInfo()
  296. {
  297. _startHallSpawns.put(31921, _startHallSpawn[0]);
  298. _startHallSpawns.put(31922, _startHallSpawn[1]);
  299. _startHallSpawns.put(31923, _startHallSpawn[2]);
  300. _startHallSpawns.put(31924, _startHallSpawn[3]);
  301. _hallInUse.put(31921, false);
  302. _hallInUse.put(31922, false);
  303. _hallInUse.put(31923, false);
  304. _hallInUse.put(31924, false);
  305. _hallGateKeepers.put(31925, 25150012);
  306. _hallGateKeepers.put(31926, 25150013);
  307. _hallGateKeepers.put(31927, 25150014);
  308. _hallGateKeepers.put(31928, 25150015);
  309. _hallGateKeepers.put(31929, 25150016);
  310. _hallGateKeepers.put(31930, 25150002);
  311. _hallGateKeepers.put(31931, 25150003);
  312. _hallGateKeepers.put(31932, 25150004);
  313. _hallGateKeepers.put(31933, 25150005);
  314. _hallGateKeepers.put(31934, 25150006);
  315. _hallGateKeepers.put(31935, 25150032);
  316. _hallGateKeepers.put(31936, 25150033);
  317. _hallGateKeepers.put(31937, 25150034);
  318. _hallGateKeepers.put(31938, 25150035);
  319. _hallGateKeepers.put(31939, 25150036);
  320. _hallGateKeepers.put(31940, 25150022);
  321. _hallGateKeepers.put(31941, 25150023);
  322. _hallGateKeepers.put(31942, 25150024);
  323. _hallGateKeepers.put(31943, 25150025);
  324. _hallGateKeepers.put(31944, 25150026);
  325. _keyBoxNpc.put(18120, 31455);
  326. _keyBoxNpc.put(18121, 31455);
  327. _keyBoxNpc.put(18122, 31455);
  328. _keyBoxNpc.put(18123, 31455);
  329. _keyBoxNpc.put(18124, 31456);
  330. _keyBoxNpc.put(18125, 31456);
  331. _keyBoxNpc.put(18126, 31456);
  332. _keyBoxNpc.put(18127, 31456);
  333. _keyBoxNpc.put(18128, 31457);
  334. _keyBoxNpc.put(18129, 31457);
  335. _keyBoxNpc.put(18130, 31457);
  336. _keyBoxNpc.put(18131, 31457);
  337. _keyBoxNpc.put(18149, 31458);
  338. _keyBoxNpc.put(18150, 31459);
  339. _keyBoxNpc.put(18151, 31459);
  340. _keyBoxNpc.put(18152, 31459);
  341. _keyBoxNpc.put(18153, 31459);
  342. _keyBoxNpc.put(18154, 31460);
  343. _keyBoxNpc.put(18155, 31460);
  344. _keyBoxNpc.put(18156, 31460);
  345. _keyBoxNpc.put(18157, 31460);
  346. _keyBoxNpc.put(18158, 31461);
  347. _keyBoxNpc.put(18159, 31461);
  348. _keyBoxNpc.put(18160, 31461);
  349. _keyBoxNpc.put(18161, 31461);
  350. _keyBoxNpc.put(18162, 31462);
  351. _keyBoxNpc.put(18163, 31462);
  352. _keyBoxNpc.put(18164, 31462);
  353. _keyBoxNpc.put(18165, 31462);
  354. _keyBoxNpc.put(18183, 31463);
  355. _keyBoxNpc.put(18184, 31464);
  356. _keyBoxNpc.put(18212, 31465);
  357. _keyBoxNpc.put(18213, 31465);
  358. _keyBoxNpc.put(18214, 31465);
  359. _keyBoxNpc.put(18215, 31465);
  360. _keyBoxNpc.put(18216, 31466);
  361. _keyBoxNpc.put(18217, 31466);
  362. _keyBoxNpc.put(18218, 31466);
  363. _keyBoxNpc.put(18219, 31466);
  364. _victim.put(18150, 18158);
  365. _victim.put(18151, 18159);
  366. _victim.put(18152, 18160);
  367. _victim.put(18153, 18161);
  368. _victim.put(18154, 18162);
  369. _victim.put(18155, 18163);
  370. _victim.put(18156, 18164);
  371. _victim.put(18157, 18165);
  372. }
  373. private void loadMysteriousBox()
  374. {
  375. _mysteriousBoxSpawns.clear();
  376. try (Connection con = ConnectionFactory.getInstance().getConnection();
  377. PreparedStatement ps = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY id"))
  378. {
  379. ps.setInt(1, 0);
  380. try (ResultSet rs = ps.executeQuery())
  381. {
  382. while (rs.next())
  383. {
  384. final L2Spawn spawnDat = new L2Spawn(rs.getInt("npc_templateid"));
  385. spawnDat.setAmount(rs.getInt("count"));
  386. spawnDat.setX(rs.getInt("locx"));
  387. spawnDat.setY(rs.getInt("locy"));
  388. spawnDat.setZ(rs.getInt("locz"));
  389. spawnDat.setHeading(rs.getInt("heading"));
  390. spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
  391. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  392. int keyNpcId = rs.getInt("key_npc_id");
  393. _mysteriousBoxSpawns.put(keyNpcId, spawnDat);
  394. }
  395. }
  396. _log.info(getClass().getSimpleName() + ": loaded " + _mysteriousBoxSpawns.size() + " Mysterious-Box spawns.");
  397. }
  398. catch (Exception e)
  399. {
  400. // problem with initializing spawn, go to next one
  401. _log.log(Level.WARNING, "FourSepulchersManager.LoadMysteriousBox: Spawn could not be initialized: " + e.getMessage(), e);
  402. }
  403. }
  404. private void initKeyBoxSpawns()
  405. {
  406. for (Entry<Integer, Integer> keyNpc : _keyBoxNpc.entrySet())
  407. {
  408. try
  409. {
  410. final L2Spawn spawnDat = new L2Spawn(keyNpc.getValue());
  411. spawnDat.setAmount(1);
  412. spawnDat.setX(0);
  413. spawnDat.setY(0);
  414. spawnDat.setZ(0);
  415. spawnDat.setHeading(0);
  416. spawnDat.setRespawnDelay(3600);
  417. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  418. _keyBoxSpawns.put(keyNpc.getKey(), spawnDat);
  419. }
  420. catch (Exception e)
  421. {
  422. _log.log(Level.WARNING, "FourSepulchersManager.InitKeyBoxSpawns: Spawn could not be initialized: " + e.getMessage(), e);
  423. }
  424. }
  425. }
  426. private void loadPhysicalMonsters()
  427. {
  428. _physicalMonsters.clear();
  429. int loaded = 0;
  430. try (Connection con = ConnectionFactory.getInstance().getConnection();
  431. PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
  432. {
  433. ps1.setInt(1, 1);
  434. try (ResultSet rs1 = ps1.executeQuery();
  435. PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist Where key_npc_id = ? and spawntype = ? ORDER BY id"))
  436. {
  437. while (rs1.next())
  438. {
  439. int keyNpcId = rs1.getInt("key_npc_id");
  440. ps2.setInt(1, keyNpcId);
  441. ps2.setInt(2, 1);
  442. try (ResultSet rs2 = ps2.executeQuery())
  443. {
  444. _physicalSpawns = new ArrayList<>();
  445. while (rs2.next())
  446. {
  447. final L2Spawn spawnDat = new L2Spawn(rs2.getInt("npc_templateid"));
  448. spawnDat.setAmount(rs2.getInt("count"));
  449. spawnDat.setX(rs2.getInt("locx"));
  450. spawnDat.setY(rs2.getInt("locy"));
  451. spawnDat.setZ(rs2.getInt("locz"));
  452. spawnDat.setHeading(rs2.getInt("heading"));
  453. spawnDat.setRespawnDelay(rs2.getInt("respawn_delay"));
  454. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  455. _physicalSpawns.add(spawnDat);
  456. loaded++;
  457. }
  458. }
  459. ps2.clearParameters();
  460. _physicalMonsters.put(keyNpcId, _physicalSpawns);
  461. }
  462. }
  463. _log.info(getClass().getSimpleName() + ": loaded " + loaded + " Physical type monsters spawns.");
  464. }
  465. catch (Exception e)
  466. {
  467. _log.log(Level.WARNING, "FourSepulchersManager.LoadPhysicalMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  468. }
  469. }
  470. private void loadMagicalMonsters()
  471. {
  472. _magicalMonsters.clear();
  473. int loaded = 0;
  474. try (Connection con = ConnectionFactory.getInstance().getConnection();
  475. PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
  476. {
  477. ps1.setInt(1, 2);
  478. try (ResultSet rs1 = ps1.executeQuery();
  479. PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? AND spawntype = ? ORDER BY id"))
  480. {
  481. while (rs1.next())
  482. {
  483. int keyNpcId = rs1.getInt("key_npc_id");
  484. ps2.setInt(1, keyNpcId);
  485. ps2.setInt(2, 2);
  486. try (ResultSet rset2 = ps2.executeQuery())
  487. {
  488. _magicalSpawns = new ArrayList<>();
  489. while (rset2.next())
  490. {
  491. final L2Spawn spawnDat = new L2Spawn(rset2.getInt("npc_templateid"));
  492. spawnDat.setAmount(rset2.getInt("count"));
  493. spawnDat.setX(rset2.getInt("locx"));
  494. spawnDat.setY(rset2.getInt("locy"));
  495. spawnDat.setZ(rset2.getInt("locz"));
  496. spawnDat.setHeading(rset2.getInt("heading"));
  497. spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
  498. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  499. _magicalSpawns.add(spawnDat);
  500. loaded++;
  501. }
  502. }
  503. ps2.clearParameters();
  504. _magicalMonsters.put(keyNpcId, _magicalSpawns);
  505. }
  506. }
  507. _log.info(getClass().getSimpleName() + ": loaded " + loaded + " Magical type monsters spawns.");
  508. }
  509. catch (Exception e)
  510. {
  511. _log.log(Level.WARNING, "FourSepulchersManager.LoadMagicalMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  512. }
  513. }
  514. private void loadDukeMonsters()
  515. {
  516. _dukeFinalMobs.clear();
  517. _archonSpawned.clear();
  518. int loaded = 0;
  519. try (Connection con = ConnectionFactory.getInstance().getConnection();
  520. PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
  521. {
  522. ps1.setInt(1, 5);
  523. try (ResultSet rs1 = ps1.executeQuery();
  524. PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? AND spawntype = ? ORDER BY id"))
  525. {
  526. while (rs1.next())
  527. {
  528. int keyNpcId = rs1.getInt("key_npc_id");
  529. ps2.setInt(1, keyNpcId);
  530. ps2.setInt(2, 5);
  531. try (ResultSet rset2 = ps2.executeQuery())
  532. {
  533. ps2.clearParameters();
  534. _dukeFinalSpawns = new ArrayList<>();
  535. while (rset2.next())
  536. {
  537. final L2Spawn spawnDat = new L2Spawn(rset2.getInt("npc_templateid"));
  538. spawnDat.setAmount(rset2.getInt("count"));
  539. spawnDat.setX(rset2.getInt("locx"));
  540. spawnDat.setY(rset2.getInt("locy"));
  541. spawnDat.setZ(rset2.getInt("locz"));
  542. spawnDat.setHeading(rset2.getInt("heading"));
  543. spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
  544. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  545. _dukeFinalSpawns.add(spawnDat);
  546. loaded++;
  547. }
  548. }
  549. ps2.clearParameters();
  550. _dukeFinalMobs.put(keyNpcId, _dukeFinalSpawns);
  551. _archonSpawned.put(keyNpcId, false);
  552. }
  553. }
  554. _log.info(getClass().getSimpleName() + ": loaded " + loaded + " Church of duke monsters spawns.");
  555. }
  556. catch (Exception e)
  557. {
  558. _log.log(Level.WARNING, "FourSepulchersManager.LoadDukeMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  559. }
  560. }
  561. private void loadEmperorsGraveMonsters()
  562. {
  563. _emperorsGraveNpcs.clear();
  564. int loaded = 0;
  565. try (Connection con = ConnectionFactory.getInstance().getConnection();
  566. PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
  567. {
  568. ps1.setInt(1, 6);
  569. try (ResultSet rs1 = ps1.executeQuery();
  570. PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? and spawntype = ? ORDER BY id"))
  571. {
  572. while (rs1.next())
  573. {
  574. int keyNpcId = rs1.getInt("key_npc_id");
  575. ps2.setInt(1, keyNpcId);
  576. ps2.setInt(2, 6);
  577. try (ResultSet rs2 = ps2.executeQuery())
  578. {
  579. _emperorsGraveSpawns = new ArrayList<>();
  580. while (rs2.next())
  581. {
  582. final L2Spawn spawnDat = new L2Spawn(rs2.getInt("npc_templateid"));
  583. spawnDat.setAmount(rs2.getInt("count"));
  584. spawnDat.setX(rs2.getInt("locx"));
  585. spawnDat.setY(rs2.getInt("locy"));
  586. spawnDat.setZ(rs2.getInt("locz"));
  587. spawnDat.setHeading(rs2.getInt("heading"));
  588. spawnDat.setRespawnDelay(rs2.getInt("respawn_delay"));
  589. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  590. _emperorsGraveSpawns.add(spawnDat);
  591. loaded++;
  592. }
  593. }
  594. ps2.clearParameters();
  595. _emperorsGraveNpcs.put(keyNpcId, _emperorsGraveSpawns);
  596. }
  597. }
  598. _log.info(getClass().getSimpleName() + ": loaded " + loaded + " Emperor's grave NPC spawns.");
  599. }
  600. catch (Exception e)
  601. {
  602. _log.log(Level.WARNING, "FourSepulchersManager.LoadEmperorsGraveMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  603. }
  604. }
  605. protected void initLocationShadowSpawns()
  606. {
  607. int locNo = Rnd.get(4);
  608. final int[] gateKeeper =
  609. {
  610. 31929,
  611. 31934,
  612. 31939,
  613. 31944
  614. };
  615. _shadowSpawns.clear();
  616. for (int i = 0; i <= 3; i++)
  617. {
  618. try
  619. {
  620. final L2Spawn spawnDat = new L2Spawn(_shadowSpawnLoc[locNo][i][0]);
  621. spawnDat.setAmount(1);
  622. spawnDat.setX(_shadowSpawnLoc[locNo][i][1]);
  623. spawnDat.setY(_shadowSpawnLoc[locNo][i][2]);
  624. spawnDat.setZ(_shadowSpawnLoc[locNo][i][3]);
  625. spawnDat.setHeading(_shadowSpawnLoc[locNo][i][4]);
  626. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  627. _shadowSpawns.put(gateKeeper[i], spawnDat);
  628. }
  629. catch (Exception e)
  630. {
  631. _log.log(Level.SEVERE, "Error on InitLocationShadowSpawns", e);
  632. }
  633. }
  634. }
  635. protected void initExecutionerSpawns()
  636. {
  637. for (int keyNpcId : _victim.keySet())
  638. {
  639. try
  640. {
  641. final L2Spawn spawnDat = new L2Spawn(_victim.get(keyNpcId));
  642. spawnDat.setAmount(1);
  643. spawnDat.setX(0);
  644. spawnDat.setY(0);
  645. spawnDat.setZ(0);
  646. spawnDat.setHeading(0);
  647. spawnDat.setRespawnDelay(3600);
  648. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  649. _executionerSpawns.put(keyNpcId, spawnDat);
  650. }
  651. catch (Exception e)
  652. {
  653. _log.log(Level.WARNING, "FourSepulchersManager.InitExecutionerSpawns: Spawn could not be initialized: " + e.getMessage(), e);
  654. }
  655. }
  656. }
  657. public ScheduledFuture<?> getChangeAttackTimeTask()
  658. {
  659. return _changeAttackTimeTask;
  660. }
  661. public void setChangeAttackTimeTask(ScheduledFuture<?> task)
  662. {
  663. _changeAttackTimeTask = task;
  664. }
  665. public ScheduledFuture<?> getChangeCoolDownTimeTask()
  666. {
  667. return _changeCoolDownTimeTask;
  668. }
  669. public void setChangeCoolDownTimeTask(ScheduledFuture<?> task)
  670. {
  671. _changeCoolDownTimeTask = task;
  672. }
  673. public ScheduledFuture<?> getChangeEntryTimeTask()
  674. {
  675. return _changeEntryTimeTask;
  676. }
  677. public void setChangeEntryTimeTask(ScheduledFuture<?> task)
  678. {
  679. _changeEntryTimeTask = task;
  680. }
  681. public ScheduledFuture<?> getChangeWarmUpTimeTask()
  682. {
  683. return _changeWarmUpTimeTask;
  684. }
  685. public void setChangeWarmUpTimeTask(ScheduledFuture<?> task)
  686. {
  687. _changeWarmUpTimeTask = task;
  688. }
  689. public long getAttackTimeEnd()
  690. {
  691. return _attackTimeEnd;
  692. }
  693. public void setAttackTimeEnd(long attackTimeEnd)
  694. {
  695. _attackTimeEnd = attackTimeEnd;
  696. }
  697. public byte getCycleMin()
  698. {
  699. return _newCycleMin;
  700. }
  701. public long getEntrytTimeEnd()
  702. {
  703. return _entryTimeEnd;
  704. }
  705. public void setEntryTimeEnd(long entryTimeEnd)
  706. {
  707. _entryTimeEnd = entryTimeEnd;
  708. }
  709. public long getWarmUpTimeEnd()
  710. {
  711. return _warmUpTimeEnd;
  712. }
  713. public void setWarmUpTimeEnd(long warmUpTimeEnd)
  714. {
  715. _warmUpTimeEnd = warmUpTimeEnd;
  716. }
  717. public boolean isAttackTime()
  718. {
  719. return _inAttackTime;
  720. }
  721. public void setIsAttackTime(boolean attackTime)
  722. {
  723. _inAttackTime = attackTime;
  724. }
  725. public boolean isCoolDownTime()
  726. {
  727. return _inCoolDownTime;
  728. }
  729. public void setIsCoolDownTime(boolean isCoolDownTime)
  730. {
  731. _inCoolDownTime = isCoolDownTime;
  732. }
  733. public boolean isEntryTime()
  734. {
  735. return _inEntryTime;
  736. }
  737. public void setIsEntryTime(boolean entryTime)
  738. {
  739. _inEntryTime = entryTime;
  740. }
  741. public boolean isFirstTimeRun()
  742. {
  743. return _firstTimeRun;
  744. }
  745. public void setIsFirstTimeRun(boolean isFirstTimeRun)
  746. {
  747. _firstTimeRun = isFirstTimeRun;
  748. }
  749. public boolean isWarmUpTime()
  750. {
  751. return _inWarmUpTime;
  752. }
  753. public void setIsWarmUpTime(boolean isWarmUpTime)
  754. {
  755. _inWarmUpTime = isWarmUpTime;
  756. }
  757. public synchronized void tryEntry(L2Npc npc, L2PcInstance player)
  758. {
  759. Quest hostQuest = QuestManager.getInstance().getQuest(QUEST_ID);
  760. if (hostQuest == null)
  761. {
  762. _log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't find quest: " + QUEST_ID);
  763. return;
  764. }
  765. int npcId = npc.getId();
  766. switch (npcId)
  767. {
  768. // ID ok
  769. case 31921:
  770. case 31922:
  771. case 31923:
  772. case 31924:
  773. break;
  774. // ID not ok
  775. default:
  776. if (!player.isGM())
  777. {
  778. _log.warning("Player " + player.getName() + "(" + player.getObjectId() + ") tried to cheat in four sepulchers.");
  779. Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " tried to enter four sepulchers with invalid npc id.", Config.DEFAULT_PUNISH);
  780. }
  781. return;
  782. }
  783. if (_hallInUse.get(npcId).booleanValue())
  784. {
  785. showHtmlFile(player, npcId + "-FULL.htm", npc, null);
  786. return;
  787. }
  788. if (Config.FS_PARTY_MEMBER_COUNT > 1)
  789. {
  790. if (!player.isInParty() || (player.getParty().getMemberCount() < Config.FS_PARTY_MEMBER_COUNT))
  791. {
  792. showHtmlFile(player, npcId + "-SP.htm", npc, null);
  793. return;
  794. }
  795. if (!player.getParty().isLeader(player))
  796. {
  797. showHtmlFile(player, npcId + "-NL.htm", npc, null);
  798. return;
  799. }
  800. for (L2PcInstance mem : player.getParty().getMembers())
  801. {
  802. QuestState qs = mem.getQuestState(hostQuest.getName());
  803. if ((qs == null) || (!qs.isStarted() && !qs.isCompleted()))
  804. {
  805. showHtmlFile(player, npcId + "-NS.htm", npc, mem);
  806. return;
  807. }
  808. if (mem.getInventory().getItemByItemId(ENTRANCE_PASS) == null)
  809. {
  810. showHtmlFile(player, npcId + "-SE.htm", npc, mem);
  811. return;
  812. }
  813. if (player.getWeightPenalty() >= 3)
  814. {
  815. mem.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  816. return;
  817. }
  818. }
  819. }
  820. else if ((Config.FS_PARTY_MEMBER_COUNT <= 1) && player.isInParty())
  821. {
  822. if (!player.getParty().isLeader(player))
  823. {
  824. showHtmlFile(player, npcId + "-NL.htm", npc, null);
  825. return;
  826. }
  827. for (L2PcInstance mem : player.getParty().getMembers())
  828. {
  829. QuestState qs = mem.getQuestState(hostQuest.getName());
  830. if ((qs == null) || (!qs.isStarted() && !qs.isCompleted()))
  831. {
  832. showHtmlFile(player, npcId + "-NS.htm", npc, mem);
  833. return;
  834. }
  835. if (mem.getInventory().getItemByItemId(ENTRANCE_PASS) == null)
  836. {
  837. showHtmlFile(player, npcId + "-SE.htm", npc, mem);
  838. return;
  839. }
  840. if (player.getWeightPenalty() >= 3)
  841. {
  842. mem.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  843. return;
  844. }
  845. }
  846. }
  847. else
  848. {
  849. QuestState qs = player.getQuestState(hostQuest.getName());
  850. if ((qs == null) || (!qs.isStarted() && !qs.isCompleted()))
  851. {
  852. showHtmlFile(player, npcId + "-NS.htm", npc, player);
  853. return;
  854. }
  855. if (player.getInventory().getItemByItemId(ENTRANCE_PASS) == null)
  856. {
  857. showHtmlFile(player, npcId + "-SE.htm", npc, player);
  858. return;
  859. }
  860. if (player.getWeightPenalty() >= 3)
  861. {
  862. player.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  863. return;
  864. }
  865. }
  866. if (!isEntryTime())
  867. {
  868. showHtmlFile(player, npcId + "-NE.htm", npc, null);
  869. return;
  870. }
  871. showHtmlFile(player, npcId + "-OK.htm", npc, null);
  872. entry(npcId, player);
  873. }
  874. private void entry(int npcId, L2PcInstance player)
  875. {
  876. int[] Location = _startHallSpawns.get(npcId);
  877. int driftx;
  878. int drifty;
  879. if (Config.FS_PARTY_MEMBER_COUNT > 1)
  880. {
  881. final List<L2PcInstance> members = new LinkedList<>();
  882. for (L2PcInstance mem : player.getParty().getMembers())
  883. {
  884. if (!mem.isDead() && Util.checkIfInRange(700, player, mem, true))
  885. {
  886. members.add(mem);
  887. }
  888. }
  889. for (L2PcInstance mem : members)
  890. {
  891. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).allowPlayerEntry(mem, 30);
  892. driftx = Rnd.get(-80, 80);
  893. drifty = Rnd.get(-80, 80);
  894. mem.teleToLocation(Location[0] + driftx, Location[1] + drifty, Location[2]);
  895. mem.destroyItemByItemId("Quest", ENTRANCE_PASS, 1, mem, true);
  896. if (mem.getInventory().getItemByItemId(ANTIQUE_BROOCH) == null)
  897. {
  898. mem.addItem("Quest", USED_PASS, 1, mem, true);
  899. }
  900. L2ItemInstance hallsKey = mem.getInventory().getItemByItemId(CHAPEL_KEY);
  901. if (hallsKey != null)
  902. {
  903. mem.destroyItemByItemId("Quest", CHAPEL_KEY, hallsKey.getCount(), mem, true);
  904. }
  905. }
  906. _challengers.put(npcId, player);
  907. _hallInUse.put(npcId, true);
  908. }
  909. if ((Config.FS_PARTY_MEMBER_COUNT <= 1) && player.isInParty())
  910. {
  911. final List<L2PcInstance> members = new LinkedList<>();
  912. for (L2PcInstance mem : player.getParty().getMembers())
  913. {
  914. if (!mem.isDead() && Util.checkIfInRange(700, player, mem, true))
  915. {
  916. members.add(mem);
  917. }
  918. }
  919. for (L2PcInstance mem : members)
  920. {
  921. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).allowPlayerEntry(mem, 30);
  922. driftx = Rnd.get(-80, 80);
  923. drifty = Rnd.get(-80, 80);
  924. mem.teleToLocation(Location[0] + driftx, Location[1] + drifty, Location[2]);
  925. mem.destroyItemByItemId("Quest", ENTRANCE_PASS, 1, mem, true);
  926. if (mem.getInventory().getItemByItemId(ANTIQUE_BROOCH) == null)
  927. {
  928. mem.addItem("Quest", USED_PASS, 1, mem, true);
  929. }
  930. L2ItemInstance hallsKey = mem.getInventory().getItemByItemId(CHAPEL_KEY);
  931. if (hallsKey != null)
  932. {
  933. mem.destroyItemByItemId("Quest", CHAPEL_KEY, hallsKey.getCount(), mem, true);
  934. }
  935. }
  936. _challengers.put(npcId, player);
  937. _hallInUse.put(npcId, true);
  938. }
  939. else
  940. {
  941. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).allowPlayerEntry(player, 30);
  942. driftx = Rnd.get(-80, 80);
  943. drifty = Rnd.get(-80, 80);
  944. player.teleToLocation(Location[0] + driftx, Location[1] + drifty, Location[2]);
  945. player.destroyItemByItemId("Quest", ENTRANCE_PASS, 1, player, true);
  946. if (player.getInventory().getItemByItemId(ANTIQUE_BROOCH) == null)
  947. {
  948. player.addItem("Quest", USED_PASS, 1, player, true);
  949. }
  950. L2ItemInstance hallsKey = player.getInventory().getItemByItemId(CHAPEL_KEY);
  951. if (hallsKey != null)
  952. {
  953. player.destroyItemByItemId("Quest", CHAPEL_KEY, hallsKey.getCount(), player, true);
  954. }
  955. _challengers.put(npcId, player);
  956. _hallInUse.put(npcId, true);
  957. }
  958. }
  959. public void spawnMysteriousBox(int npcId)
  960. {
  961. if (!isAttackTime())
  962. {
  963. return;
  964. }
  965. L2Spawn spawnDat = _mysteriousBoxSpawns.get(npcId);
  966. if (spawnDat != null)
  967. {
  968. _allMobs.add(spawnDat.doSpawn());
  969. spawnDat.stopRespawn();
  970. }
  971. }
  972. public void spawnMonster(int npcId)
  973. {
  974. if (!isAttackTime())
  975. {
  976. return;
  977. }
  978. final List<L2SepulcherMonsterInstance> mobs = new CopyOnWriteArrayList<>();
  979. final List<L2Spawn> monsterList;
  980. if (Rnd.get(2) == 0)
  981. {
  982. monsterList = _physicalMonsters.get(npcId);
  983. }
  984. else
  985. {
  986. monsterList = _magicalMonsters.get(npcId);
  987. }
  988. if (monsterList != null)
  989. {
  990. boolean spawnKeyBoxMob = false;
  991. boolean spawnedKeyBoxMob = false;
  992. for (L2Spawn spawnDat : monsterList)
  993. {
  994. if (spawnedKeyBoxMob)
  995. {
  996. spawnKeyBoxMob = false;
  997. }
  998. else
  999. {
  1000. switch (npcId)
  1001. {
  1002. case 31469:
  1003. case 31474:
  1004. case 31479:
  1005. case 31484:
  1006. if (Rnd.get(48) == 0)
  1007. {
  1008. spawnKeyBoxMob = true;
  1009. }
  1010. break;
  1011. default:
  1012. spawnKeyBoxMob = false;
  1013. }
  1014. }
  1015. L2SepulcherMonsterInstance mob = null;
  1016. if (spawnKeyBoxMob)
  1017. {
  1018. try
  1019. {
  1020. final L2Spawn keyBoxMobSpawn = new L2Spawn(18149);
  1021. keyBoxMobSpawn.setAmount(1);
  1022. keyBoxMobSpawn.setLocation(spawnDat.getLocation());
  1023. keyBoxMobSpawn.setRespawnDelay(3600);
  1024. SpawnTable.getInstance().addNewSpawn(keyBoxMobSpawn, false);
  1025. mob = (L2SepulcherMonsterInstance) keyBoxMobSpawn.doSpawn();
  1026. keyBoxMobSpawn.stopRespawn();
  1027. }
  1028. catch (Exception e)
  1029. {
  1030. _log.log(Level.WARNING, "FourSepulchersManager.SpawnMonster: Spawn could not be initialized: " + e.getMessage(), e);
  1031. }
  1032. spawnedKeyBoxMob = true;
  1033. }
  1034. else
  1035. {
  1036. mob = (L2SepulcherMonsterInstance) spawnDat.doSpawn();
  1037. spawnDat.stopRespawn();
  1038. }
  1039. if (mob != null)
  1040. {
  1041. mob.mysteriousBoxId = npcId;
  1042. switch (npcId)
  1043. {
  1044. case 31469:
  1045. case 31474:
  1046. case 31479:
  1047. case 31484:
  1048. case 31472:
  1049. case 31477:
  1050. case 31482:
  1051. case 31487:
  1052. mobs.add(mob);
  1053. }
  1054. _allMobs.add(mob);
  1055. }
  1056. }
  1057. switch (npcId)
  1058. {
  1059. case 31469:
  1060. case 31474:
  1061. case 31479:
  1062. case 31484:
  1063. _viscountMobs.put(npcId, mobs);
  1064. break;
  1065. case 31472:
  1066. case 31477:
  1067. case 31482:
  1068. case 31487:
  1069. _dukeMobs.put(npcId, mobs);
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. public synchronized boolean isViscountMobsAnnihilated(int npcId)
  1075. {
  1076. List<L2SepulcherMonsterInstance> mobs = _viscountMobs.get(npcId);
  1077. if (mobs == null)
  1078. {
  1079. return true;
  1080. }
  1081. for (L2SepulcherMonsterInstance mob : mobs)
  1082. {
  1083. if (!mob.isDead())
  1084. {
  1085. return false;
  1086. }
  1087. }
  1088. return true;
  1089. }
  1090. public synchronized boolean isDukeMobsAnnihilated(int npcId)
  1091. {
  1092. List<L2SepulcherMonsterInstance> mobs = _dukeMobs.get(npcId);
  1093. if (mobs == null)
  1094. {
  1095. return true;
  1096. }
  1097. for (L2SepulcherMonsterInstance mob : mobs)
  1098. {
  1099. if (!mob.isDead())
  1100. {
  1101. return false;
  1102. }
  1103. }
  1104. return true;
  1105. }
  1106. public void spawnKeyBox(L2Npc activeChar)
  1107. {
  1108. if (!isAttackTime())
  1109. {
  1110. return;
  1111. }
  1112. L2Spawn spawnDat = _keyBoxSpawns.get(activeChar.getId());
  1113. if (spawnDat != null)
  1114. {
  1115. spawnDat.setAmount(1);
  1116. spawnDat.setX(activeChar.getX());
  1117. spawnDat.setY(activeChar.getY());
  1118. spawnDat.setZ(activeChar.getZ());
  1119. spawnDat.setHeading(activeChar.getHeading());
  1120. spawnDat.setRespawnDelay(3600);
  1121. _allMobs.add(spawnDat.doSpawn());
  1122. spawnDat.stopRespawn();
  1123. }
  1124. }
  1125. public void spawnExecutionerOfHalisha(L2Npc activeChar)
  1126. {
  1127. if (!isAttackTime())
  1128. {
  1129. return;
  1130. }
  1131. L2Spawn spawnDat = _executionerSpawns.get(activeChar.getId());
  1132. if (spawnDat != null)
  1133. {
  1134. spawnDat.setAmount(1);
  1135. spawnDat.setX(activeChar.getX());
  1136. spawnDat.setY(activeChar.getY());
  1137. spawnDat.setZ(activeChar.getZ());
  1138. spawnDat.setHeading(activeChar.getHeading());
  1139. spawnDat.setRespawnDelay(3600);
  1140. _allMobs.add(spawnDat.doSpawn());
  1141. spawnDat.stopRespawn();
  1142. }
  1143. }
  1144. public void spawnArchonOfHalisha(int npcId)
  1145. {
  1146. if (!isAttackTime())
  1147. {
  1148. return;
  1149. }
  1150. if (_archonSpawned.get(npcId))
  1151. {
  1152. return;
  1153. }
  1154. List<L2Spawn> monsterList = _dukeFinalMobs.get(npcId);
  1155. if (monsterList != null)
  1156. {
  1157. for (L2Spawn spawnDat : monsterList)
  1158. {
  1159. L2SepulcherMonsterInstance mob = (L2SepulcherMonsterInstance) spawnDat.doSpawn();
  1160. spawnDat.stopRespawn();
  1161. if (mob != null)
  1162. {
  1163. mob.mysteriousBoxId = npcId;
  1164. _allMobs.add(mob);
  1165. }
  1166. }
  1167. _archonSpawned.put(npcId, true);
  1168. }
  1169. }
  1170. public void spawnEmperorsGraveNpc(int npcId)
  1171. {
  1172. if (!isAttackTime())
  1173. {
  1174. return;
  1175. }
  1176. List<L2Spawn> monsterList = _emperorsGraveNpcs.get(npcId);
  1177. if (monsterList != null)
  1178. {
  1179. for (L2Spawn spawnDat : monsterList)
  1180. {
  1181. _allMobs.add(spawnDat.doSpawn());
  1182. spawnDat.stopRespawn();
  1183. }
  1184. }
  1185. }
  1186. public void locationShadowSpawns()
  1187. {
  1188. int locNo = Rnd.get(4);
  1189. final int[] gateKeeper =
  1190. {
  1191. 31929,
  1192. 31934,
  1193. 31939,
  1194. 31944
  1195. };
  1196. for (int i = 0; i <= 3; i++)
  1197. {
  1198. int keyNpcId = gateKeeper[i];
  1199. L2Spawn spawnDat = _shadowSpawns.get(keyNpcId);
  1200. spawnDat.setX(_shadowSpawnLoc[locNo][i][1]);
  1201. spawnDat.setY(_shadowSpawnLoc[locNo][i][2]);
  1202. spawnDat.setZ(_shadowSpawnLoc[locNo][i][3]);
  1203. spawnDat.setHeading(_shadowSpawnLoc[locNo][i][4]);
  1204. _shadowSpawns.put(keyNpcId, spawnDat);
  1205. }
  1206. }
  1207. public void spawnShadow(int npcId)
  1208. {
  1209. if (!isAttackTime())
  1210. {
  1211. return;
  1212. }
  1213. L2Spawn spawnDat = _shadowSpawns.get(npcId);
  1214. if (spawnDat != null)
  1215. {
  1216. L2SepulcherMonsterInstance mob = (L2SepulcherMonsterInstance) spawnDat.doSpawn();
  1217. spawnDat.stopRespawn();
  1218. if (mob != null)
  1219. {
  1220. mob.mysteriousBoxId = npcId;
  1221. _allMobs.add(mob);
  1222. }
  1223. }
  1224. }
  1225. public void deleteAllMobs()
  1226. {
  1227. for (L2Npc mob : _allMobs)
  1228. {
  1229. try
  1230. {
  1231. if (mob.getSpawn() != null)
  1232. {
  1233. mob.getSpawn().stopRespawn();
  1234. }
  1235. mob.deleteMe();
  1236. }
  1237. catch (Exception e)
  1238. {
  1239. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed deleting mob.", e);
  1240. }
  1241. }
  1242. _allMobs.clear();
  1243. }
  1244. protected void closeAllDoors()
  1245. {
  1246. for (int doorId : _hallGateKeepers.values())
  1247. {
  1248. try
  1249. {
  1250. L2DoorInstance door = DoorData.getInstance().getDoor(doorId);
  1251. if (door != null)
  1252. {
  1253. door.closeMe();
  1254. }
  1255. else
  1256. {
  1257. _log.warning(getClass().getSimpleName() + ": Attempted to close undefined door. doorId: " + doorId);
  1258. }
  1259. }
  1260. catch (Exception e)
  1261. {
  1262. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed closing door", e);
  1263. }
  1264. }
  1265. }
  1266. protected byte minuteSelect(byte min)
  1267. {
  1268. if (((double) min % 5) != 0)// if doesn't divides on 5 fully
  1269. {
  1270. // mad table for selecting proper minutes...
  1271. // may be there is a better way to do this
  1272. switch (min)
  1273. {
  1274. case 6:
  1275. case 7:
  1276. min = 5;
  1277. break;
  1278. case 8:
  1279. case 9:
  1280. case 11:
  1281. case 12:
  1282. min = 10;
  1283. break;
  1284. case 13:
  1285. case 14:
  1286. case 16:
  1287. case 17:
  1288. min = 15;
  1289. break;
  1290. case 18:
  1291. case 19:
  1292. case 21:
  1293. case 22:
  1294. min = 20;
  1295. break;
  1296. case 23:
  1297. case 24:
  1298. case 26:
  1299. case 27:
  1300. min = 25;
  1301. break;
  1302. case 28:
  1303. case 29:
  1304. case 31:
  1305. case 32:
  1306. min = 30;
  1307. break;
  1308. case 33:
  1309. case 34:
  1310. case 36:
  1311. case 37:
  1312. min = 35;
  1313. break;
  1314. case 38:
  1315. case 39:
  1316. case 41:
  1317. case 42:
  1318. min = 40;
  1319. break;
  1320. case 43:
  1321. case 44:
  1322. case 46:
  1323. case 47:
  1324. min = 45;
  1325. break;
  1326. case 48:
  1327. case 49:
  1328. case 51:
  1329. case 52:
  1330. min = 50;
  1331. break;
  1332. case 53:
  1333. case 54:
  1334. case 56:
  1335. case 57:
  1336. min = 55;
  1337. break;
  1338. }
  1339. }
  1340. return min;
  1341. }
  1342. public void managerSay(byte min)
  1343. {
  1344. // for attack phase, sending message every 5 minutes
  1345. if (_inAttackTime)
  1346. {
  1347. if (min < 5)
  1348. {
  1349. return; // do not shout when < 5 minutes
  1350. }
  1351. min = minuteSelect(min);
  1352. NpcStringId msg = NpcStringId.MINUTES_HAVE_PASSED;
  1353. if (min == 90)
  1354. {
  1355. msg = NpcStringId.GAME_OVER_THE_TELEPORT_WILL_APPEAR_MOMENTARILY;
  1356. }
  1357. for (L2Spawn temp : _managers)
  1358. {
  1359. if (temp == null)
  1360. {
  1361. _log.warning(getClass().getSimpleName() + ": managerSay(): manager is null");
  1362. continue;
  1363. }
  1364. if (!(temp.getLastSpawn() instanceof L2SepulcherNpcInstance))
  1365. {
  1366. _log.warning(getClass().getSimpleName() + ": managerSay(): manager is not Sepulcher instance");
  1367. continue;
  1368. }
  1369. // hall not used right now, so its manager will not tell you anything :)
  1370. // if you don't need this - delete next two lines.
  1371. if (!_hallInUse.get(temp.getId()).booleanValue())
  1372. {
  1373. continue;
  1374. }
  1375. ((L2SepulcherNpcInstance) temp.getLastSpawn()).sayInShout(msg);
  1376. }
  1377. }
  1378. else if (_inEntryTime)
  1379. {
  1380. NpcStringId msg1 = NpcStringId.YOU_MAY_NOW_ENTER_THE_SEPULCHER;
  1381. NpcStringId msg2 = NpcStringId.IF_YOU_PLACE_YOUR_HAND_ON_THE_STONE_STATUE_IN_FRONT_OF_EACH_SEPULCHER_YOU_WILL_BE_ABLE_TO_ENTER;
  1382. for (L2Spawn temp : _managers)
  1383. {
  1384. if (temp == null)
  1385. {
  1386. _log.warning(getClass().getSimpleName() + ": Something goes wrong in managerSay()...");
  1387. continue;
  1388. }
  1389. if (!(temp.getLastSpawn() instanceof L2SepulcherNpcInstance))
  1390. {
  1391. _log.warning(getClass().getSimpleName() + ": Something goes wrong in managerSay()...");
  1392. continue;
  1393. }
  1394. ((L2SepulcherNpcInstance) temp.getLastSpawn()).sayInShout(msg1);
  1395. ((L2SepulcherNpcInstance) temp.getLastSpawn()).sayInShout(msg2);
  1396. }
  1397. }
  1398. }
  1399. public Map<Integer, Integer> getHallGateKeepers()
  1400. {
  1401. return _hallGateKeepers;
  1402. }
  1403. public void showHtmlFile(L2PcInstance player, String file, L2Npc npc, L2PcInstance member)
  1404. {
  1405. final NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  1406. html.setFile(player.getHtmlPrefix(), "data/html/SepulcherNpc/" + file);
  1407. if (member != null)
  1408. {
  1409. html.replace("%member%", member.getName());
  1410. }
  1411. player.sendPacket(html);
  1412. }
  1413. public static final FourSepulchersManager getInstance()
  1414. {
  1415. return SingletonHolder._instance;
  1416. }
  1417. private static class SingletonHolder
  1418. {
  1419. protected static final FourSepulchersManager _instance = new FourSepulchersManager();
  1420. }
  1421. }