FourSepulchersManager.java 51 KB

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