FourSepulchersManager.java 43 KB

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