FourSepulchersManager.java 47 KB

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