FourSepulchersManager.java 51 KB

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