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