FourSepulchersManager.java 51 KB

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