FourSepulchersManager.java 51 KB

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