FourSepulchersManager.java 51 KB

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