FourSepulchersManager.java 46 KB

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