FourSepulchersManager.java 51 KB

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