FourSepulchersManager.java 51 KB

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