FourSepulchersManager.java 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  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. Connection con = null;
  377. _mysteriousBoxSpawns.clear();
  378. try
  379. {
  380. con = L2DatabaseFactory.getInstance().getConnection();
  381. 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");
  382. statement.setInt(1, 0);
  383. ResultSet rset = statement.executeQuery();
  384. L2Spawn spawnDat;
  385. L2NpcTemplate template1;
  386. while (rset.next())
  387. {
  388. template1 = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
  389. if (template1 != null)
  390. {
  391. spawnDat = new L2Spawn(template1);
  392. spawnDat.setAmount(rset.getInt("count"));
  393. spawnDat.setLocx(rset.getInt("locx"));
  394. spawnDat.setLocy(rset.getInt("locy"));
  395. spawnDat.setLocz(rset.getInt("locz"));
  396. spawnDat.setHeading(rset.getInt("heading"));
  397. spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));
  398. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  399. int keyNpcId = rset.getInt("key_npc_id");
  400. _mysteriousBoxSpawns.put(keyNpcId, spawnDat);
  401. }
  402. else
  403. {
  404. _log.warning("FourSepulchersManager.LoadMysteriousBox: Data missing in NPC table for ID: "
  405. + rset.getInt("npc_templateid") + ".");
  406. }
  407. }
  408. rset.close();
  409. statement.close();
  410. _log.info("FourSepulchersManager: loaded " + _mysteriousBoxSpawns.size() + " Mysterious-Box spawns.");
  411. }
  412. catch (Exception e)
  413. {
  414. // problem with initializing spawn, go to next one
  415. _log.log(Level.WARNING, "FourSepulchersManager.LoadMysteriousBox: Spawn could not be initialized: " + e.getMessage(), e);
  416. }
  417. finally
  418. {
  419. L2DatabaseFactory.close(con);
  420. }
  421. }
  422. private void initKeyBoxSpawns()
  423. {
  424. L2Spawn spawnDat;
  425. L2NpcTemplate template;
  426. for (int keyNpcId : _keyBoxNpc.keys())
  427. {
  428. try
  429. {
  430. template = NpcTable.getInstance().getTemplate(_keyBoxNpc.get(keyNpcId));
  431. if (template != null)
  432. {
  433. spawnDat = new L2Spawn(template);
  434. spawnDat.setAmount(1);
  435. spawnDat.setLocx(0);
  436. spawnDat.setLocy(0);
  437. spawnDat.setLocz(0);
  438. spawnDat.setHeading(0);
  439. spawnDat.setRespawnDelay(3600);
  440. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  441. _keyBoxSpawns.put(keyNpcId, spawnDat);
  442. }
  443. else
  444. {
  445. _log.warning("FourSepulchersManager.InitKeyBoxSpawns: Data missing in NPC table for ID: " + _keyBoxNpc.get(keyNpcId)
  446. + ".");
  447. }
  448. }
  449. catch (Exception e)
  450. {
  451. _log.log(Level.WARNING, "FourSepulchersManager.InitKeyBoxSpawns: Spawn could not be initialized: " + e.getMessage(), e);
  452. }
  453. }
  454. }
  455. private void loadPhysicalMonsters()
  456. {
  457. _physicalMonsters.clear();
  458. int loaded = 0;
  459. Connection con = null;
  460. try
  461. {
  462. con = L2DatabaseFactory.getInstance().getConnection();
  463. PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
  464. statement1.setInt(1, 1);
  465. ResultSet rset1 = statement1.executeQuery();
  466. 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");
  467. while (rset1.next())
  468. {
  469. int keyNpcId = rset1.getInt("key_npc_id");
  470. statement2.setInt(1, keyNpcId);
  471. statement2.setInt(2, 1);
  472. ResultSet rset2 = statement2.executeQuery();
  473. statement2.clearParameters();
  474. L2Spawn spawnDat;
  475. L2NpcTemplate template1;
  476. _physicalSpawns = new FastList<>();
  477. while (rset2.next())
  478. {
  479. template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
  480. if (template1 != null)
  481. {
  482. spawnDat = new L2Spawn(template1);
  483. spawnDat.setAmount(rset2.getInt("count"));
  484. spawnDat.setLocx(rset2.getInt("locx"));
  485. spawnDat.setLocy(rset2.getInt("locy"));
  486. spawnDat.setLocz(rset2.getInt("locz"));
  487. spawnDat.setHeading(rset2.getInt("heading"));
  488. spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
  489. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  490. _physicalSpawns.add(spawnDat);
  491. loaded++;
  492. }
  493. else
  494. {
  495. _log.warning("FourSepulchersManager.LoadPhysicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
  496. }
  497. }
  498. rset2.close();
  499. _physicalMonsters.put(keyNpcId, _physicalSpawns);
  500. }
  501. rset1.close();
  502. statement1.close();
  503. statement2.close();
  504. _log.info("FourSepulchersManager: loaded " + loaded + " Physical type monsters spawns.");
  505. }
  506. catch (Exception e)
  507. {
  508. // problem with initializing spawn, go to next one
  509. _log.log(Level.WARNING, "FourSepulchersManager.LoadPhysicalMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  510. }
  511. finally
  512. {
  513. L2DatabaseFactory.close(con);
  514. }
  515. }
  516. private void loadMagicalMonsters()
  517. {
  518. _magicalMonsters.clear();
  519. int loaded = 0;
  520. Connection con = null;
  521. try
  522. {
  523. con = L2DatabaseFactory.getInstance().getConnection();
  524. PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
  525. statement1.setInt(1, 2);
  526. ResultSet rset1 = statement1.executeQuery();
  527. 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");
  528. while (rset1.next())
  529. {
  530. int keyNpcId = rset1.getInt("key_npc_id");
  531. statement2.setInt(1, keyNpcId);
  532. statement2.setInt(2, 2);
  533. ResultSet rset2 = statement2.executeQuery();
  534. statement2.clearParameters();
  535. L2Spawn spawnDat;
  536. L2NpcTemplate template1;
  537. _magicalSpawns = new FastList<>();
  538. while (rset2.next())
  539. {
  540. template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
  541. if (template1 != null)
  542. {
  543. spawnDat = new L2Spawn(template1);
  544. spawnDat.setAmount(rset2.getInt("count"));
  545. spawnDat.setLocx(rset2.getInt("locx"));
  546. spawnDat.setLocy(rset2.getInt("locy"));
  547. spawnDat.setLocz(rset2.getInt("locz"));
  548. spawnDat.setHeading(rset2.getInt("heading"));
  549. spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
  550. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  551. _magicalSpawns.add(spawnDat);
  552. loaded++;
  553. }
  554. else
  555. {
  556. _log.warning("FourSepulchersManager.LoadMagicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
  557. }
  558. }
  559. rset2.close();
  560. _magicalMonsters.put(keyNpcId, _magicalSpawns);
  561. }
  562. rset1.close();
  563. statement1.close();
  564. statement2.close();
  565. _log.info("FourSepulchersManager: loaded " + loaded + " Magical type monsters spawns.");
  566. }
  567. catch (Exception e)
  568. {
  569. // problem with initializing spawn, go to next one
  570. _log.log(Level.WARNING, "FourSepulchersManager.LoadMagicalMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  571. }
  572. finally
  573. {
  574. L2DatabaseFactory.close(con);
  575. }
  576. }
  577. private void loadDukeMonsters()
  578. {
  579. _dukeFinalMobs.clear();
  580. _archonSpawned.clear();
  581. int loaded = 0;
  582. Connection con = null;
  583. try
  584. {
  585. con = L2DatabaseFactory.getInstance().getConnection();
  586. PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
  587. statement1.setInt(1, 5);
  588. ResultSet rset1 = statement1.executeQuery();
  589. 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");
  590. while (rset1.next())
  591. {
  592. int keyNpcId = rset1.getInt("key_npc_id");
  593. statement2.setInt(1, keyNpcId);
  594. statement2.setInt(2, 5);
  595. ResultSet rset2 = statement2.executeQuery();
  596. statement2.clearParameters();
  597. L2Spawn spawnDat;
  598. L2NpcTemplate template1;
  599. _dukeFinalSpawns = new FastList<>();
  600. while (rset2.next())
  601. {
  602. template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
  603. if (template1 != null)
  604. {
  605. spawnDat = new L2Spawn(template1);
  606. spawnDat.setAmount(rset2.getInt("count"));
  607. spawnDat.setLocx(rset2.getInt("locx"));
  608. spawnDat.setLocy(rset2.getInt("locy"));
  609. spawnDat.setLocz(rset2.getInt("locz"));
  610. spawnDat.setHeading(rset2.getInt("heading"));
  611. spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
  612. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  613. _dukeFinalSpawns.add(spawnDat);
  614. loaded++;
  615. }
  616. else
  617. {
  618. _log.warning("FourSepulchersManager.LoadDukeMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
  619. }
  620. }
  621. rset2.close();
  622. _dukeFinalMobs.put(keyNpcId, _dukeFinalSpawns);
  623. _archonSpawned.put(keyNpcId, false);
  624. }
  625. rset1.close();
  626. statement1.close();
  627. statement2.close();
  628. _log.info("FourSepulchersManager: loaded " + loaded + " Church of duke monsters spawns.");
  629. }
  630. catch (Exception e)
  631. {
  632. // problem with initializing spawn, go to next one
  633. _log.log(Level.WARNING, "FourSepulchersManager.LoadDukeMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  634. }
  635. finally
  636. {
  637. L2DatabaseFactory.close(con);
  638. }
  639. }
  640. private void loadEmperorsGraveMonsters()
  641. {
  642. _emperorsGraveNpcs.clear();
  643. int loaded = 0;
  644. Connection con = null;
  645. try
  646. {
  647. con = L2DatabaseFactory.getInstance().getConnection();
  648. PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
  649. statement1.setInt(1, 6);
  650. ResultSet rset1 = statement1.executeQuery();
  651. 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");
  652. while (rset1.next())
  653. {
  654. int keyNpcId = rset1.getInt("key_npc_id");
  655. statement2.setInt(1, keyNpcId);
  656. statement2.setInt(2, 6);
  657. ResultSet rset2 = statement2.executeQuery();
  658. statement2.clearParameters();
  659. L2Spawn spawnDat;
  660. L2NpcTemplate template1;
  661. _emperorsGraveSpawns = new FastList<>();
  662. while (rset2.next())
  663. {
  664. template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
  665. if (template1 != null)
  666. {
  667. spawnDat = new L2Spawn(template1);
  668. spawnDat.setAmount(rset2.getInt("count"));
  669. spawnDat.setLocx(rset2.getInt("locx"));
  670. spawnDat.setLocy(rset2.getInt("locy"));
  671. spawnDat.setLocz(rset2.getInt("locz"));
  672. spawnDat.setHeading(rset2.getInt("heading"));
  673. spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
  674. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  675. _emperorsGraveSpawns.add(spawnDat);
  676. loaded++;
  677. }
  678. else
  679. {
  680. _log.warning("FourSepulchersManager.LoadEmperorsGraveMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
  681. }
  682. }
  683. rset2.close();
  684. _emperorsGraveNpcs.put(keyNpcId, _emperorsGraveSpawns);
  685. }
  686. rset1.close();
  687. statement1.close();
  688. statement2.close();
  689. _log.info("FourSepulchersManager: loaded " + loaded + " Emperor's grave NPC spawns.");
  690. }
  691. catch (Exception e)
  692. {
  693. // problem with initializing spawn, go to next one
  694. _log.log(Level.WARNING, "FourSepulchersManager.LoadEmperorsGraveMonsters: Spawn could not be initialized: " + e.getMessage(), e);
  695. }
  696. finally
  697. {
  698. L2DatabaseFactory.close(con);
  699. }
  700. }
  701. protected void initLocationShadowSpawns()
  702. {
  703. int locNo = Rnd.get(4);
  704. final int[] gateKeeper = { 31929, 31934, 31939, 31944 };
  705. L2Spawn spawnDat;
  706. L2NpcTemplate template;
  707. _shadowSpawns.clear();
  708. for (int i = 0; i <= 3; i++)
  709. {
  710. template = NpcTable.getInstance().getTemplate(_shadowSpawnLoc[locNo][i][0]);
  711. if (template != null)
  712. {
  713. try
  714. {
  715. spawnDat = new L2Spawn(template);
  716. spawnDat.setAmount(1);
  717. spawnDat.setLocx(_shadowSpawnLoc[locNo][i][1]);
  718. spawnDat.setLocy(_shadowSpawnLoc[locNo][i][2]);
  719. spawnDat.setLocz(_shadowSpawnLoc[locNo][i][3]);
  720. spawnDat.setHeading(_shadowSpawnLoc[locNo][i][4]);
  721. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  722. int keyNpcId = gateKeeper[i];
  723. _shadowSpawns.put(keyNpcId, spawnDat);
  724. }
  725. catch (Exception e)
  726. {
  727. _log.log(Level.SEVERE, "Error on InitLocationShadowSpawns", e);
  728. }
  729. }
  730. else
  731. {
  732. _log.warning("FourSepulchersManager.InitLocationShadowSpawns: Data missing in NPC table for ID: "
  733. + _shadowSpawnLoc[locNo][i][0] + ".");
  734. }
  735. }
  736. }
  737. protected void initExecutionerSpawns()
  738. {
  739. L2Spawn spawnDat;
  740. L2NpcTemplate template;
  741. for (int keyNpcId : _victim.keys())
  742. {
  743. try
  744. {
  745. template = NpcTable.getInstance().getTemplate(_victim.get(keyNpcId));
  746. if (template != null)
  747. {
  748. spawnDat = new L2Spawn(template);
  749. spawnDat.setAmount(1);
  750. spawnDat.setLocx(0);
  751. spawnDat.setLocy(0);
  752. spawnDat.setLocz(0);
  753. spawnDat.setHeading(0);
  754. spawnDat.setRespawnDelay(3600);
  755. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  756. _executionerSpawns.put(keyNpcId, spawnDat);
  757. }
  758. else
  759. {
  760. _log.warning("FourSepulchersManager.InitExecutionerSpawns: Data missing in NPC table for ID: " + _victim.get(keyNpcId)
  761. + ".");
  762. }
  763. }
  764. catch (Exception e)
  765. {
  766. _log.log(Level.WARNING, "FourSepulchersManager.InitExecutionerSpawns: Spawn could not be initialized: " + e.getMessage(), e);
  767. }
  768. }
  769. }
  770. public boolean isEntryTime()
  771. {
  772. return _inEntryTime;
  773. }
  774. public boolean isAttackTime()
  775. {
  776. return _inAttackTime;
  777. }
  778. public synchronized void tryEntry(L2Npc npc, L2PcInstance player)
  779. {
  780. int npcId = npc.getNpcId();
  781. switch (npcId)
  782. {
  783. // ID ok
  784. case 31921:
  785. case 31922:
  786. case 31923:
  787. case 31924:
  788. break;
  789. // ID not ok
  790. default:
  791. if (!player.isGM())
  792. {
  793. _log.warning("Player " + player.getName() + "(" + player.getObjectId() + ") tried to cheat in four sepulchers.");
  794. Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName()
  795. + " tried to enter four sepulchers with invalid npc id.", Config.DEFAULT_PUNISH);
  796. }
  797. return;
  798. }
  799. if (_hallInUse.get(npcId).booleanValue())
  800. {
  801. showHtmlFile(player, npcId + "-FULL.htm", npc, null);
  802. return;
  803. }
  804. if (Config.FS_PARTY_MEMBER_COUNT > 1)
  805. {
  806. if (!player.isInParty() || player.getParty().getMemberCount() < Config.FS_PARTY_MEMBER_COUNT)
  807. {
  808. showHtmlFile(player, npcId + "-SP.htm", npc, null);
  809. return;
  810. }
  811. if (!player.getParty().isLeader(player))
  812. {
  813. showHtmlFile(player, npcId + "-NL.htm", npc, null);
  814. return;
  815. }
  816. for (L2PcInstance mem : player.getParty().getMembers())
  817. {
  818. QuestState qs = mem.getQuestState(QUEST_ID);
  819. if (qs == null || (!qs.isStarted() && !qs.isCompleted()))
  820. {
  821. showHtmlFile(player, npcId + "-NS.htm", npc, mem);
  822. return;
  823. }
  824. if (mem.getInventory().getItemByItemId(ENTRANCE_PASS) == null)
  825. {
  826. showHtmlFile(player, npcId + "-SE.htm", npc, mem);
  827. return;
  828. }
  829. if (player.getWeightPenalty() >= 3)
  830. {
  831. mem.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  832. return;
  833. }
  834. }
  835. }
  836. else if (Config.FS_PARTY_MEMBER_COUNT <= 1 && player.isInParty())
  837. {
  838. if (!player.getParty().isLeader(player))
  839. {
  840. showHtmlFile(player, npcId + "-NL.htm", npc, null);
  841. return;
  842. }
  843. for (L2PcInstance mem : player.getParty().getMembers())
  844. {
  845. QuestState qs = mem.getQuestState(QUEST_ID);
  846. if (qs == null || (!qs.isStarted() && !qs.isCompleted()))
  847. {
  848. showHtmlFile(player, npcId + "-NS.htm", npc, mem);
  849. return;
  850. }
  851. if (mem.getInventory().getItemByItemId(ENTRANCE_PASS) == null)
  852. {
  853. showHtmlFile(player, npcId + "-SE.htm", npc, mem);
  854. return;
  855. }
  856. if (player.getWeightPenalty() >= 3)
  857. {
  858. mem.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  859. return;
  860. }
  861. }
  862. }
  863. else
  864. {
  865. QuestState qs = player.getQuestState(QUEST_ID);
  866. if (qs == null || (!qs.isStarted() && !qs.isCompleted()))
  867. {
  868. showHtmlFile(player, npcId + "-NS.htm", npc, player);
  869. return;
  870. }
  871. if (player.getInventory().getItemByItemId(ENTRANCE_PASS) == null)
  872. {
  873. showHtmlFile(player, npcId + "-SE.htm", npc, player);
  874. return;
  875. }
  876. if (player.getWeightPenalty() >= 3)
  877. {
  878. player.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  879. return;
  880. }
  881. }
  882. if (!isEntryTime())
  883. {
  884. showHtmlFile(player, npcId + "-NE.htm", npc, null);
  885. return;
  886. }
  887. showHtmlFile(player, npcId + "-OK.htm", npc, null);
  888. entry(npcId, player);
  889. }
  890. private void entry(int npcId, L2PcInstance player)
  891. {
  892. int[] Location = _startHallSpawns.get(npcId);
  893. int driftx;
  894. int drifty;
  895. if (Config.FS_PARTY_MEMBER_COUNT > 1)
  896. {
  897. List<L2PcInstance> members = new FastList<>();
  898. for (L2PcInstance mem : player.getParty().getMembers())
  899. {
  900. if (!mem.isDead() && Util.checkIfInRange(700, player, mem, true))
  901. {
  902. members.add(mem);
  903. }
  904. }
  905. for (L2PcInstance mem : members)
  906. {
  907. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).allowPlayerEntry(mem, 30);
  908. driftx = Rnd.get(-80, 80);
  909. drifty = Rnd.get(-80, 80);
  910. mem.teleToLocation(Location[0] + driftx, Location[1] + drifty, Location[2]);
  911. mem.destroyItemByItemId("Quest", ENTRANCE_PASS, 1, mem, true);
  912. if (mem.getInventory().getItemByItemId(ANTIQUE_BROOCH) == null)
  913. {
  914. mem.addItem("Quest", USED_PASS, 1, mem, true);
  915. }
  916. L2ItemInstance hallsKey = mem.getInventory().getItemByItemId(CHAPEL_KEY);
  917. if (hallsKey != null)
  918. {
  919. mem.destroyItemByItemId("Quest", CHAPEL_KEY, hallsKey.getCount(), mem, true);
  920. }
  921. }
  922. _challengers.remove(npcId);
  923. _challengers.put(npcId, player);
  924. _hallInUse.remove(npcId);
  925. _hallInUse.put(npcId, true);
  926. }
  927. if (Config.FS_PARTY_MEMBER_COUNT <= 1 && player.isInParty())
  928. {
  929. List<L2PcInstance> members = new FastList<>();
  930. for (L2PcInstance mem : player.getParty().getMembers())
  931. {
  932. if (!mem.isDead() && Util.checkIfInRange(700, player, mem, true))
  933. {
  934. members.add(mem);
  935. }
  936. }
  937. for (L2PcInstance mem : members)
  938. {
  939. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).allowPlayerEntry(mem, 30);
  940. driftx = Rnd.get(-80, 80);
  941. drifty = Rnd.get(-80, 80);
  942. mem.teleToLocation(Location[0] + driftx, Location[1] + drifty, Location[2]);
  943. mem.destroyItemByItemId("Quest", ENTRANCE_PASS, 1, mem, true);
  944. if (mem.getInventory().getItemByItemId(ANTIQUE_BROOCH) == null)
  945. {
  946. mem.addItem("Quest", USED_PASS, 1, mem, true);
  947. }
  948. L2ItemInstance hallsKey = mem.getInventory().getItemByItemId(CHAPEL_KEY);
  949. if (hallsKey != null)
  950. {
  951. mem.destroyItemByItemId("Quest", CHAPEL_KEY, hallsKey.getCount(), mem, true);
  952. }
  953. }
  954. _challengers.remove(npcId);
  955. _challengers.put(npcId, player);
  956. _hallInUse.remove(npcId);
  957. _hallInUse.put(npcId, true);
  958. }
  959. else
  960. {
  961. GrandBossManager.getInstance().getZone(Location[0], Location[1], Location[2]).allowPlayerEntry(player, 30);
  962. driftx = Rnd.get(-80, 80);
  963. drifty = Rnd.get(-80, 80);
  964. player.teleToLocation(Location[0] + driftx, Location[1] + drifty, Location[2]);
  965. player.destroyItemByItemId("Quest", ENTRANCE_PASS, 1, player, true);
  966. if (player.getInventory().getItemByItemId(ANTIQUE_BROOCH) == null)
  967. {
  968. player.addItem("Quest", USED_PASS, 1, player, true);
  969. }
  970. L2ItemInstance hallsKey = player.getInventory().getItemByItemId(CHAPEL_KEY);
  971. if (hallsKey != null)
  972. {
  973. player.destroyItemByItemId("Quest", CHAPEL_KEY, hallsKey.getCount(), player, true);
  974. }
  975. _challengers.remove(npcId);
  976. _challengers.put(npcId, player);
  977. _hallInUse.remove(npcId);
  978. _hallInUse.put(npcId, true);
  979. }
  980. }
  981. public void spawnMysteriousBox(int npcId)
  982. {
  983. if (!isAttackTime())
  984. return;
  985. L2Spawn spawnDat = _mysteriousBoxSpawns.get(npcId);
  986. if (spawnDat != null)
  987. {
  988. _allMobs.add(spawnDat.doSpawn());
  989. spawnDat.stopRespawn();
  990. }
  991. }
  992. public void spawnMonster(int npcId)
  993. {
  994. if (!isAttackTime())
  995. return;
  996. FastList<L2Spawn> monsterList;
  997. FastList<L2SepulcherMonsterInstance> mobs = new FastList<>();
  998. L2Spawn keyBoxMobSpawn;
  999. if (Rnd.get(2) == 0)
  1000. {
  1001. monsterList = _physicalMonsters.get(npcId);
  1002. }
  1003. else
  1004. {
  1005. monsterList = _magicalMonsters.get(npcId);
  1006. }
  1007. if (monsterList != null)
  1008. {
  1009. boolean spawnKeyBoxMob = false;
  1010. boolean spawnedKeyBoxMob = false;
  1011. for (L2Spawn spawnDat : monsterList)
  1012. {
  1013. if (spawnedKeyBoxMob)
  1014. {
  1015. spawnKeyBoxMob = false;
  1016. }
  1017. else
  1018. {
  1019. switch (npcId)
  1020. {
  1021. case 31469:
  1022. case 31474:
  1023. case 31479:
  1024. case 31484:
  1025. if (Rnd.get(48) == 0)
  1026. {
  1027. spawnKeyBoxMob = true;
  1028. // _log.info("FourSepulchersManager.SpawnMonster:
  1029. // Set to spawn Church of Viscount Key Mob.");
  1030. }
  1031. break;
  1032. default:
  1033. spawnKeyBoxMob = false;
  1034. }
  1035. }
  1036. L2SepulcherMonsterInstance mob = null;
  1037. if (spawnKeyBoxMob)
  1038. {
  1039. try
  1040. {
  1041. L2NpcTemplate template = NpcTable.getInstance().getTemplate(18149);
  1042. if (template != null)
  1043. {
  1044. keyBoxMobSpawn = new L2Spawn(template);
  1045. keyBoxMobSpawn.setAmount(1);
  1046. keyBoxMobSpawn.setLocx(spawnDat.getLocx());
  1047. keyBoxMobSpawn.setLocy(spawnDat.getLocy());
  1048. keyBoxMobSpawn.setLocz(spawnDat.getLocz());
  1049. keyBoxMobSpawn.setHeading(spawnDat.getHeading());
  1050. keyBoxMobSpawn.setRespawnDelay(3600);
  1051. SpawnTable.getInstance().addNewSpawn(keyBoxMobSpawn, false);
  1052. mob = (L2SepulcherMonsterInstance) keyBoxMobSpawn.doSpawn();
  1053. keyBoxMobSpawn.stopRespawn();
  1054. }
  1055. else
  1056. {
  1057. _log.warning("FourSepulchersManager.SpawnMonster: Data missing in NPC table for ID: 18149");
  1058. }
  1059. }
  1060. catch (Exception e)
  1061. {
  1062. _log.log(Level.WARNING, "FourSepulchersManager.SpawnMonster: Spawn could not be initialized: " + e.getMessage(), e);
  1063. }
  1064. spawnedKeyBoxMob = true;
  1065. }
  1066. else
  1067. {
  1068. mob = (L2SepulcherMonsterInstance) spawnDat.doSpawn();
  1069. spawnDat.stopRespawn();
  1070. }
  1071. if (mob != null)
  1072. {
  1073. mob.mysteriousBoxId = npcId;
  1074. switch (npcId)
  1075. {
  1076. case 31469:
  1077. case 31474:
  1078. case 31479:
  1079. case 31484:
  1080. case 31472:
  1081. case 31477:
  1082. case 31482:
  1083. case 31487:
  1084. mobs.add(mob);
  1085. }
  1086. _allMobs.add(mob);
  1087. }
  1088. }
  1089. switch (npcId)
  1090. {
  1091. case 31469:
  1092. case 31474:
  1093. case 31479:
  1094. case 31484:
  1095. _viscountMobs.put(npcId, mobs);
  1096. break;
  1097. case 31472:
  1098. case 31477:
  1099. case 31482:
  1100. case 31487:
  1101. _dukeMobs.put(npcId, mobs);
  1102. break;
  1103. }
  1104. }
  1105. }
  1106. public synchronized boolean isViscountMobsAnnihilated(int npcId)
  1107. {
  1108. FastList<L2SepulcherMonsterInstance> mobs = _viscountMobs.get(npcId);
  1109. if (mobs == null)
  1110. return true;
  1111. for (L2SepulcherMonsterInstance mob : mobs)
  1112. {
  1113. if (!mob.isDead())
  1114. return false;
  1115. }
  1116. return true;
  1117. }
  1118. public synchronized boolean isDukeMobsAnnihilated(int npcId)
  1119. {
  1120. FastList<L2SepulcherMonsterInstance> mobs = _dukeMobs.get(npcId);
  1121. if (mobs == null)
  1122. return true;
  1123. for (L2SepulcherMonsterInstance mob : mobs)
  1124. {
  1125. if (!mob.isDead())
  1126. return false;
  1127. }
  1128. return true;
  1129. }
  1130. public void spawnKeyBox(L2Npc activeChar)
  1131. {
  1132. if (!isAttackTime())
  1133. return;
  1134. L2Spawn spawnDat = _keyBoxSpawns.get(activeChar.getNpcId());
  1135. if (spawnDat != null)
  1136. {
  1137. spawnDat.setAmount(1);
  1138. spawnDat.setLocx(activeChar.getX());
  1139. spawnDat.setLocy(activeChar.getY());
  1140. spawnDat.setLocz(activeChar.getZ());
  1141. spawnDat.setHeading(activeChar.getHeading());
  1142. spawnDat.setRespawnDelay(3600);
  1143. _allMobs.add(spawnDat.doSpawn());
  1144. spawnDat.stopRespawn();
  1145. }
  1146. }
  1147. public void spawnExecutionerOfHalisha(L2Npc activeChar)
  1148. {
  1149. if (!isAttackTime())
  1150. return;
  1151. L2Spawn spawnDat = _executionerSpawns.get(activeChar.getNpcId());
  1152. if (spawnDat != null)
  1153. {
  1154. spawnDat.setAmount(1);
  1155. spawnDat.setLocx(activeChar.getX());
  1156. spawnDat.setLocy(activeChar.getY());
  1157. spawnDat.setLocz(activeChar.getZ());
  1158. spawnDat.setHeading(activeChar.getHeading());
  1159. spawnDat.setRespawnDelay(3600);
  1160. _allMobs.add(spawnDat.doSpawn());
  1161. spawnDat.stopRespawn();
  1162. }
  1163. }
  1164. public void spawnArchonOfHalisha(int npcId)
  1165. {
  1166. if (!isAttackTime())
  1167. return;
  1168. if (_archonSpawned.get(npcId))
  1169. return;
  1170. FastList<L2Spawn> monsterList = _dukeFinalMobs.get(npcId);
  1171. if (monsterList != null)
  1172. {
  1173. for (L2Spawn spawnDat : monsterList)
  1174. {
  1175. L2SepulcherMonsterInstance mob = (L2SepulcherMonsterInstance) spawnDat.doSpawn();
  1176. spawnDat.stopRespawn();
  1177. if (mob != null)
  1178. {
  1179. mob.mysteriousBoxId = npcId;
  1180. _allMobs.add(mob);
  1181. }
  1182. }
  1183. _archonSpawned.put(npcId, true);
  1184. }
  1185. }
  1186. public void spawnEmperorsGraveNpc(int npcId)
  1187. {
  1188. if (!isAttackTime())
  1189. return;
  1190. FastList<L2Spawn> monsterList = _emperorsGraveNpcs.get(npcId);
  1191. if (monsterList != null)
  1192. {
  1193. for (L2Spawn spawnDat : monsterList)
  1194. {
  1195. _allMobs.add(spawnDat.doSpawn());
  1196. spawnDat.stopRespawn();
  1197. }
  1198. }
  1199. }
  1200. protected void locationShadowSpawns()
  1201. {
  1202. int locNo = Rnd.get(4);
  1203. // _log.info("FourSepulchersManager.LocationShadowSpawns: Location index
  1204. // is " + locNo + ".");
  1205. final int[] gateKeeper = { 31929, 31934, 31939, 31944 };
  1206. L2Spawn spawnDat;
  1207. for (int i = 0; i <= 3; i++)
  1208. {
  1209. int keyNpcId = gateKeeper[i];
  1210. spawnDat = _shadowSpawns.get(keyNpcId);
  1211. spawnDat.setLocx(_shadowSpawnLoc[locNo][i][1]);
  1212. spawnDat.setLocy(_shadowSpawnLoc[locNo][i][2]);
  1213. spawnDat.setLocz(_shadowSpawnLoc[locNo][i][3]);
  1214. spawnDat.setHeading(_shadowSpawnLoc[locNo][i][4]);
  1215. _shadowSpawns.put(keyNpcId, spawnDat);
  1216. }
  1217. }
  1218. public void spawnShadow(int npcId)
  1219. {
  1220. if (!isAttackTime())
  1221. return;
  1222. L2Spawn spawnDat = _shadowSpawns.get(npcId);
  1223. if (spawnDat != null)
  1224. {
  1225. L2SepulcherMonsterInstance mob = (L2SepulcherMonsterInstance) spawnDat.doSpawn();
  1226. spawnDat.stopRespawn();
  1227. if (mob != null)
  1228. {
  1229. mob.mysteriousBoxId = npcId;
  1230. _allMobs.add(mob);
  1231. }
  1232. }
  1233. }
  1234. public void deleteAllMobs()
  1235. {
  1236. for (L2Npc mob : _allMobs)
  1237. {
  1238. if (mob == null)
  1239. continue;
  1240. try
  1241. {
  1242. if (mob.getSpawn() != null)
  1243. mob.getSpawn().stopRespawn();
  1244. mob.deleteMe();
  1245. }
  1246. catch (Exception e)
  1247. {
  1248. _log.log(Level.SEVERE, "FourSepulchersManager: Failed deleting mob.", e);
  1249. }
  1250. }
  1251. _allMobs.clear();
  1252. }
  1253. protected void closeAllDoors()
  1254. {
  1255. for (int doorId : _hallGateKeepers.values())
  1256. {
  1257. try
  1258. {
  1259. L2DoorInstance door = DoorTable.getInstance().getDoor(doorId);
  1260. if (door != null)
  1261. {
  1262. door.closeMe();
  1263. }
  1264. else
  1265. {
  1266. _log.warning("FourSepulchersManager: Attempted to close undefined door. doorId: " + doorId);
  1267. }
  1268. }
  1269. catch (Exception e)
  1270. {
  1271. _log.log(Level.SEVERE, "FourSepulchersManager: Failed closing door", e);
  1272. }
  1273. }
  1274. }
  1275. protected byte minuteSelect(byte min)
  1276. {
  1277. if ((double) min % 5 != 0)// if doesn't divides on 5 fully
  1278. {
  1279. // mad table for selecting proper minutes...
  1280. // may be there is a better way to do this
  1281. switch (min)
  1282. {
  1283. case 6:
  1284. case 7:
  1285. min = 5;
  1286. break;
  1287. case 8:
  1288. case 9:
  1289. case 11:
  1290. case 12:
  1291. min = 10;
  1292. break;
  1293. case 13:
  1294. case 14:
  1295. case 16:
  1296. case 17:
  1297. min = 15;
  1298. break;
  1299. case 18:
  1300. case 19:
  1301. case 21:
  1302. case 22:
  1303. min = 20;
  1304. break;
  1305. case 23:
  1306. case 24:
  1307. case 26:
  1308. case 27:
  1309. min = 25;
  1310. break;
  1311. case 28:
  1312. case 29:
  1313. case 31:
  1314. case 32:
  1315. min = 30;
  1316. break;
  1317. case 33:
  1318. case 34:
  1319. case 36:
  1320. case 37:
  1321. min = 35;
  1322. break;
  1323. case 38:
  1324. case 39:
  1325. case 41:
  1326. case 42:
  1327. min = 40;
  1328. break;
  1329. case 43:
  1330. case 44:
  1331. case 46:
  1332. case 47:
  1333. min = 45;
  1334. break;
  1335. case 48:
  1336. case 49:
  1337. case 51:
  1338. case 52:
  1339. min = 50;
  1340. break;
  1341. case 53:
  1342. case 54:
  1343. case 56:
  1344. case 57:
  1345. min = 55;
  1346. break;
  1347. }
  1348. }
  1349. return min;
  1350. }
  1351. public void managerSay(byte min)
  1352. {
  1353. // for attack phase, sending message every 5 minutes
  1354. if (_inAttackTime)
  1355. {
  1356. if (min < 5)
  1357. return; // do not shout when < 5 minutes
  1358. min = minuteSelect(min);
  1359. NpcStringId msg = NpcStringId.MINUTES_HAVE_PASSED;
  1360. if (min == 90)
  1361. msg = NpcStringId.GAME_OVER_THE_TELEPORT_WILL_APPEAR_MOMENTARILY;
  1362. for (L2Spawn temp : _managers)
  1363. {
  1364. if (temp == null)
  1365. {
  1366. _log.warning("FourSepulchersManager: managerSay(): manager is null");
  1367. continue;
  1368. }
  1369. if (!(temp.getLastSpawn() instanceof L2SepulcherNpcInstance))
  1370. {
  1371. _log.warning("FourSepulchersManager: managerSay(): manager is not Sepulcher instance");
  1372. continue;
  1373. }
  1374. // hall not used right now, so its manager will not tell you
  1375. // anything :)
  1376. // if you don't need this - delete next two lines.
  1377. if (!_hallInUse.get(temp.getNpcid()).booleanValue())
  1378. continue;
  1379. ((L2SepulcherNpcInstance) temp.getLastSpawn()).sayInShout(msg);
  1380. }
  1381. }
  1382. else if (_inEntryTime)
  1383. {
  1384. NpcStringId msg1 = NpcStringId.YOU_MAY_NOW_ENTER_THE_SEPULCHER;
  1385. NpcStringId msg2 = NpcStringId.IF_YOU_PLACE_YOUR_HAND_ON_THE_STONE_STATUE_IN_FRONT_OF_EACH_SEPULCHER_YOU_WILL_BE_ABLE_TO_ENTER;
  1386. for (L2Spawn temp : _managers)
  1387. {
  1388. if (temp == null)
  1389. {
  1390. _log.warning("FourSepulchersManager: Something goes wrong in managerSay()...");
  1391. continue;
  1392. }
  1393. if (!(temp.getLastSpawn() instanceof L2SepulcherNpcInstance))
  1394. {
  1395. _log.warning("FourSepulchersManager: Something goes wrong in managerSay()...");
  1396. continue;
  1397. }
  1398. ((L2SepulcherNpcInstance) temp.getLastSpawn()).sayInShout(msg1);
  1399. ((L2SepulcherNpcInstance) temp.getLastSpawn()).sayInShout(msg2);
  1400. }
  1401. }
  1402. }
  1403. protected class ManagerSay implements Runnable
  1404. {
  1405. @Override
  1406. public void run()
  1407. {
  1408. if (_inAttackTime)
  1409. {
  1410. Calendar tmp = Calendar.getInstance();
  1411. tmp.setTimeInMillis(Calendar.getInstance().getTimeInMillis() - _warmUpTimeEnd);
  1412. if (tmp.get(Calendar.MINUTE) + 5 < Config.FS_TIME_ATTACK)
  1413. {
  1414. managerSay((byte) tmp.get(Calendar.MINUTE)); // byte
  1415. // because
  1416. // minute
  1417. // cannot be
  1418. // more than
  1419. // 59
  1420. ThreadPoolManager.getInstance().scheduleGeneral(new ManagerSay(), 5 * 60000);
  1421. }
  1422. // attack time ending chat
  1423. else if (tmp.get(Calendar.MINUTE) + 5 >= Config.FS_TIME_ATTACK)
  1424. {
  1425. managerSay((byte) 90); // sending a unique id :D
  1426. }
  1427. }
  1428. else if (_inEntryTime)
  1429. managerSay((byte) 0);
  1430. }
  1431. }
  1432. protected class ChangeEntryTime implements Runnable
  1433. {
  1434. @Override
  1435. public void run()
  1436. {
  1437. // _log.info("FourSepulchersManager:In Entry Time");
  1438. _inEntryTime = true;
  1439. _inWarmUpTime = false;
  1440. _inAttackTime = false;
  1441. _inCoolDownTime = false;
  1442. long interval = 0;
  1443. // if this is first launch - search time when entry time will be
  1444. // ended:
  1445. // counting difference between time when entry time ends and current
  1446. // time
  1447. // and then launching change time task
  1448. if (_firstTimeRun)
  1449. interval = _entryTimeEnd - Calendar.getInstance().getTimeInMillis();
  1450. else
  1451. interval = Config.FS_TIME_ENTRY * 60000L; // else use stupid
  1452. // method
  1453. // launching saying process...
  1454. ThreadPoolManager.getInstance().scheduleGeneral(new ManagerSay(), 0);
  1455. _changeWarmUpTimeTask = ThreadPoolManager.getInstance().scheduleEffect(new ChangeWarmUpTime(), interval);
  1456. if (_changeEntryTimeTask != null)
  1457. {
  1458. _changeEntryTimeTask.cancel(true);
  1459. _changeEntryTimeTask = null;
  1460. }
  1461. }
  1462. }
  1463. protected class ChangeWarmUpTime implements Runnable
  1464. {
  1465. @Override
  1466. public void run()
  1467. {
  1468. // _log.info("FourSepulchersManager:In Warm-Up Time");
  1469. _inEntryTime = true;
  1470. _inWarmUpTime = false;
  1471. _inAttackTime = false;
  1472. _inCoolDownTime = false;
  1473. long interval = 0;
  1474. // searching time when warmup time will be ended:
  1475. // counting difference between time when warmup time ends and
  1476. // current time
  1477. // and then launching change time task
  1478. if (_firstTimeRun)
  1479. interval = _warmUpTimeEnd - Calendar.getInstance().getTimeInMillis();
  1480. else
  1481. interval = Config.FS_TIME_WARMUP * 60000L;
  1482. _changeAttackTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChangeAttackTime(), interval);
  1483. if (_changeWarmUpTimeTask != null)
  1484. {
  1485. _changeWarmUpTimeTask.cancel(true);
  1486. _changeWarmUpTimeTask = null;
  1487. }
  1488. }
  1489. }
  1490. protected class ChangeAttackTime implements Runnable
  1491. {
  1492. @Override
  1493. public void run()
  1494. {
  1495. // _log.info("FourSepulchersManager:In Attack Time");
  1496. _inEntryTime = false;
  1497. _inWarmUpTime = false;
  1498. _inAttackTime = true;
  1499. _inCoolDownTime = false;
  1500. locationShadowSpawns();
  1501. spawnMysteriousBox(31921);
  1502. spawnMysteriousBox(31922);
  1503. spawnMysteriousBox(31923);
  1504. spawnMysteriousBox(31924);
  1505. if (!_firstTimeRun)
  1506. {
  1507. _warmUpTimeEnd = Calendar.getInstance().getTimeInMillis();
  1508. }
  1509. long interval = 0;
  1510. // say task
  1511. if (_firstTimeRun)
  1512. {
  1513. for (double min = Calendar.getInstance().get(Calendar.MINUTE); min < _newCycleMin; min++)
  1514. {
  1515. // looking for next shout time....
  1516. if (min % 5 == 0)// check if min can be divided by 5
  1517. {
  1518. _log.info(Calendar.getInstance().getTime() + " Atk announce scheduled to " + min + " minute of this hour.");
  1519. Calendar inter = Calendar.getInstance();
  1520. inter.set(Calendar.MINUTE, (int) min);
  1521. ThreadPoolManager.getInstance().scheduleGeneral(new ManagerSay(), inter.getTimeInMillis()
  1522. - Calendar.getInstance().getTimeInMillis());
  1523. break;
  1524. }
  1525. }
  1526. }
  1527. else
  1528. ThreadPoolManager.getInstance().scheduleGeneral(new ManagerSay(), 5 * 60400);
  1529. // searching time when attack time will be ended:
  1530. // counting difference between time when attack time ends and
  1531. // current time
  1532. // and then launching change time task
  1533. if (_firstTimeRun)
  1534. interval = _attackTimeEnd - Calendar.getInstance().getTimeInMillis();
  1535. else
  1536. interval = Config.FS_TIME_ATTACK * 60000L;
  1537. _changeCoolDownTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChangeCoolDownTime(), interval);
  1538. if (_changeAttackTimeTask != null)
  1539. {
  1540. _changeAttackTimeTask.cancel(true);
  1541. _changeAttackTimeTask = null;
  1542. }
  1543. }
  1544. }
  1545. protected class ChangeCoolDownTime implements Runnable
  1546. {
  1547. @Override
  1548. public void run()
  1549. {
  1550. // _log.info("FourSepulchersManager:In Cool-Down Time");
  1551. _inEntryTime = false;
  1552. _inWarmUpTime = false;
  1553. _inAttackTime = false;
  1554. _inCoolDownTime = true;
  1555. clean();
  1556. Calendar time = Calendar.getInstance();
  1557. // one hour = 55th min to 55 min of next hour, so we check for this,
  1558. // also check for first launch
  1559. if (Calendar.getInstance().get(Calendar.MINUTE) > _newCycleMin && !_firstTimeRun)
  1560. time.set(Calendar.HOUR, Calendar.getInstance().get(Calendar.HOUR) + 1);
  1561. time.set(Calendar.MINUTE, _newCycleMin);
  1562. _log.info("FourSepulchersManager: Entry time: " + time.getTime());
  1563. if (_firstTimeRun)
  1564. _firstTimeRun = false; // cooldown phase ends event hour, so it
  1565. // will be not first run
  1566. long interval = time.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
  1567. _changeEntryTimeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChangeEntryTime(), interval);
  1568. if (_changeCoolDownTimeTask != null)
  1569. {
  1570. _changeCoolDownTimeTask.cancel(true);
  1571. _changeCoolDownTimeTask = null;
  1572. }
  1573. }
  1574. }
  1575. public TIntIntHashMap getHallGateKeepers()
  1576. {
  1577. return _hallGateKeepers;
  1578. }
  1579. public void showHtmlFile(L2PcInstance player, String file, L2Npc npc, L2PcInstance member)
  1580. {
  1581. NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  1582. html.setFile(player.getHtmlPrefix(), "data/html/SepulcherNpc/" + file);
  1583. if (member != null)
  1584. html.replace("%member%", member.getName());
  1585. player.sendPacket(html);
  1586. }
  1587. private static class SingletonHolder
  1588. {
  1589. protected static final FourSepulchersManager _instance = new FourSepulchersManager();
  1590. }
  1591. }