FourSepulchersManager.java 50 KB

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