FourSepulchersManager.java 51 KB

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