2
0

FourSepulchersManager.java 52 KB

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