FinalEmperialTomb.java 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package instances.FinalEmperialTomb;
  20. import java.io.File;
  21. import java.util.Calendar;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.concurrent.ScheduledFuture;
  26. import java.util.concurrent.locks.Lock;
  27. import java.util.concurrent.locks.ReentrantLock;
  28. import java.util.logging.Level;
  29. import javax.xml.parsers.DocumentBuilderFactory;
  30. import javolution.util.FastList;
  31. import javolution.util.FastMap;
  32. import org.w3c.dom.Document;
  33. import org.w3c.dom.NamedNodeMap;
  34. import org.w3c.dom.Node;
  35. import com.l2jserver.Config;
  36. import com.l2jserver.gameserver.GeoData;
  37. import com.l2jserver.gameserver.ThreadPoolManager;
  38. import com.l2jserver.gameserver.ai.CtrlIntention;
  39. import com.l2jserver.gameserver.enums.InstanceType;
  40. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  41. import com.l2jserver.gameserver.model.L2CommandChannel;
  42. import com.l2jserver.gameserver.model.L2Party;
  43. import com.l2jserver.gameserver.model.L2Territory;
  44. import com.l2jserver.gameserver.model.L2World;
  45. import com.l2jserver.gameserver.model.Location;
  46. import com.l2jserver.gameserver.model.PcCondOverride;
  47. import com.l2jserver.gameserver.model.actor.L2Attackable;
  48. import com.l2jserver.gameserver.model.actor.L2Character;
  49. import com.l2jserver.gameserver.model.actor.L2Npc;
  50. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  51. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  52. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  53. import com.l2jserver.gameserver.model.effects.L2EffectType;
  54. import com.l2jserver.gameserver.model.holders.SkillHolder;
  55. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  56. import com.l2jserver.gameserver.model.quest.Quest;
  57. import com.l2jserver.gameserver.model.quest.QuestState;
  58. import com.l2jserver.gameserver.model.skills.L2Skill;
  59. import com.l2jserver.gameserver.model.skills.L2SkillType;
  60. import com.l2jserver.gameserver.network.NpcStringId;
  61. import com.l2jserver.gameserver.network.SystemMessageId;
  62. import com.l2jserver.gameserver.network.serverpackets.AbstractNpcInfo.NpcInfo;
  63. import com.l2jserver.gameserver.network.serverpackets.Earthquake;
  64. import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  65. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  66. import com.l2jserver.gameserver.network.serverpackets.MagicSkillCanceld;
  67. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  68. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  69. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  70. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  71. import com.l2jserver.gameserver.util.Util;
  72. /**
  73. * Final Emperial Tomb instance zone. TODO:<br>
  74. * Test when Frintezza song use 5008 effect skill.<br>
  75. * Test deeply Scarlet van Halisha's AI.<br>
  76. * Use proper zone spawn system.
  77. * @author Gigiikun
  78. */
  79. public class FinalEmperialTomb extends Quest
  80. {
  81. private class FETWorld extends InstanceWorld
  82. {
  83. public Lock lock = new ReentrantLock();
  84. public FastList<L2Npc> npcList = new FastList<>();
  85. public int darkChoirPlayerCount = 0;
  86. public FrintezzaSong OnSong = null;
  87. public ScheduledFuture<?> songTask = null;
  88. public ScheduledFuture<?> songEffectTask = null;
  89. public boolean isVideo = false;
  90. public L2Npc frintezzaDummy = null;
  91. public L2Npc overheadDummy = null;
  92. public L2Npc portraitDummy1 = null;
  93. public L2Npc portraitDummy3 = null;
  94. public L2Npc scarletDummy = null;
  95. public L2GrandBossInstance frintezza = null;
  96. public L2GrandBossInstance activeScarlet = null;
  97. public List<L2MonsterInstance> demons = new FastList<>();
  98. public Map<L2MonsterInstance, Integer> portraits = new FastMap<>();
  99. public int scarlet_x = 0;
  100. public int scarlet_y = 0;
  101. public int scarlet_z = 0;
  102. public int scarlet_h = 0;
  103. public int scarlet_a = 0;
  104. protected FETWorld()
  105. {
  106. npcList.shared();
  107. }
  108. }
  109. protected static class FETSpawn
  110. {
  111. public boolean isZone = false;
  112. public boolean isNeededNextFlag = false;
  113. public int npcId;
  114. public int x = 0;
  115. public int y = 0;
  116. public int z = 0;
  117. public int h = 0;
  118. public int zone = 0;
  119. public int count = 0;
  120. }
  121. private static class FrintezzaSong
  122. {
  123. public SkillHolder skill;
  124. public SkillHolder effectSkill;
  125. public NpcStringId songName;
  126. public int chance;
  127. public FrintezzaSong(SkillHolder sk, SkillHolder esk, NpcStringId sn, int ch)
  128. {
  129. skill = sk;
  130. effectSkill = esk;
  131. songName = sn;
  132. chance = ch;
  133. }
  134. }
  135. private static final int INSTANCEID = 136; // this is the client number
  136. private static final int MIN_PLAYERS = 36;
  137. private static final int MAX_PLAYERS = 45;
  138. private static final boolean debug = false;
  139. private final Map<Integer, L2Territory> _spawnZoneList = new HashMap<>();
  140. private final Map<Integer, List<FETSpawn>> _spawnList = new HashMap<>();
  141. private final List<Integer> _mustKillMobsId = new FastList<>();
  142. // Teleports
  143. private static final Location ENTER_TELEPORT = new Location(-88015, -141153, -9168);
  144. // NPCs
  145. private static final int GUIDE = 32011;
  146. private static final int CUBE = 29061;
  147. // Item
  148. private static final int DEWDROP_OF_DESTRUCTION_ITEM_ID = 8556;
  149. // mobs
  150. private static final int SCARLET1 = 29046;
  151. private static final int SCARLET2 = 29047;
  152. private static final int FRINTEZZA = 29045;
  153. private static final int[] PORTRAITS =
  154. {
  155. 29048,
  156. 29049
  157. };
  158. private static final int[] DEMONS =
  159. {
  160. 29050,
  161. 29051
  162. };
  163. private static final int HALL_ALARM = 18328;
  164. private static final int HALL_KEEPER_CAPTAIN = 18329;
  165. private static final int HALL_KEEPER_SUICIDAL_SOLDIER = 18333;
  166. private static final int DARK_CHOIR_PLAYER = 18339;
  167. private static final int[] AI_DISABLED_MOBS =
  168. {
  169. 18328
  170. };
  171. private static final int FIRST_SCARLET_WEAPON = 8204;
  172. private static final int SECOND_SCARLET_WEAPON = 7903;
  173. protected static final SkillHolder INTRO_SKILL = new SkillHolder(5004, 1);
  174. private static final SkillHolder FIRST_MORPH_SKILL = new SkillHolder(5017, 1);
  175. protected static final FrintezzaSong[] FRINTEZZASONGLIST =
  176. {
  177. new FrintezzaSong(new SkillHolder(5007, 1), new SkillHolder(5008, 1), NpcStringId.REQUIEM_OF_HATRED, 5),
  178. new FrintezzaSong(new SkillHolder(5007, 2), new SkillHolder(5008, 2), NpcStringId.RONDO_OF_SOLITUDE, 50),
  179. new FrintezzaSong(new SkillHolder(5007, 3), new SkillHolder(5008, 3), NpcStringId.FRENETIC_TOCCATA, 70),
  180. new FrintezzaSong(new SkillHolder(5007, 4), new SkillHolder(5008, 4), NpcStringId.FUGUE_OF_JUBILATION, 90),
  181. new FrintezzaSong(new SkillHolder(5007, 5), new SkillHolder(5008, 5), NpcStringId.HYPNOTIC_MAZURKA, 100),
  182. };
  183. // Skills
  184. private static final int DEWDROP_OF_DESTRUCTION_SKILL_ID = 2276;
  185. private static final int SOUL_BREAKING_ARROW_SKILL_ID = 2234;
  186. // Doors/Walls/Zones
  187. protected static final int[] FIRST_ROOM_DOORS =
  188. {
  189. 17130051,
  190. 17130052,
  191. 17130053,
  192. 17130054,
  193. 17130055,
  194. 17130056,
  195. 17130057,
  196. 17130058
  197. };
  198. protected static final int[] SECOND_ROOM_DOORS =
  199. {
  200. 17130061,
  201. 17130062,
  202. 17130063,
  203. 17130064,
  204. 17130065,
  205. 17130066,
  206. 17130067,
  207. 17130068,
  208. 17130069,
  209. 17130070
  210. };
  211. protected static final int[] FIRST_ROUTE_DOORS =
  212. {
  213. 17130042,
  214. 17130043
  215. };
  216. protected static final int[] SECOND_ROUTE_DOORS =
  217. {
  218. 17130045,
  219. 17130046
  220. };
  221. protected static final Location MOVE_TO_CENTER = new Location(-87904, -141296, -9168, 0);
  222. // spawns
  223. private static final int TIME_BETWEEN_DEMON_SPAWNS = 20000;
  224. private static final int MAX_DEMONS = 24;
  225. protected static final int[][] PORTRAIT_SPAWNS =
  226. {
  227. {
  228. 29048,
  229. -89381,
  230. -153981,
  231. -9168,
  232. 3368,
  233. -89378,
  234. -153968,
  235. -9168,
  236. 3368
  237. },
  238. {
  239. 29048,
  240. -86234,
  241. -152467,
  242. -9168,
  243. 37656,
  244. -86261,
  245. -152492,
  246. -9168,
  247. 37656
  248. },
  249. {
  250. 29049,
  251. -89342,
  252. -152479,
  253. -9168,
  254. -5152,
  255. -89311,
  256. -152491,
  257. -9168,
  258. -5152
  259. },
  260. {
  261. 29049,
  262. -86189,
  263. -153968,
  264. -9168,
  265. 29456,
  266. -86217,
  267. -153956,
  268. -9168,
  269. 29456
  270. }
  271. };
  272. // Initialization at 6:30 am on Wednesday and Saturday
  273. private static final int RESET_HOUR = 6;
  274. private static final int RESET_MIN = 30;
  275. private static final int RESET_DAY_1 = 4;
  276. private static final int RESET_DAY_2 = 7;
  277. @SuppressWarnings("unused")
  278. private void load()
  279. {
  280. int spawnCount = 0;
  281. try
  282. {
  283. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  284. factory.setValidating(false);
  285. factory.setIgnoringComments(true);
  286. File file = new File(Config.DATAPACK_ROOT + "/data/spawnZones/final_emperial_tomb.xml");
  287. if (!file.exists())
  288. {
  289. _log.severe("[Final Emperial Tomb] Missing final_emperial_tomb.xml. The quest wont work without it!");
  290. return;
  291. }
  292. Document doc = factory.newDocumentBuilder().parse(file);
  293. Node first = doc.getFirstChild();
  294. if ((first != null) && "list".equalsIgnoreCase(first.getNodeName()))
  295. {
  296. for (Node n = first.getFirstChild(); n != null; n = n.getNextSibling())
  297. {
  298. if ("npc".equalsIgnoreCase(n.getNodeName()))
  299. {
  300. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  301. {
  302. if ("spawn".equalsIgnoreCase(d.getNodeName()))
  303. {
  304. NamedNodeMap attrs = d.getAttributes();
  305. Node att = attrs.getNamedItem("npcId");
  306. if (att == null)
  307. {
  308. _log.severe("[Final Emperial Tomb] Missing npcId in npc List, skipping");
  309. continue;
  310. }
  311. int npcId = Integer.parseInt(attrs.getNamedItem("npcId").getNodeValue());
  312. att = attrs.getNamedItem("flag");
  313. if (att == null)
  314. {
  315. _log.severe("[Final Emperial Tomb] Missing flag in npc List npcId: " + npcId + ", skipping");
  316. continue;
  317. }
  318. int flag = Integer.parseInt(attrs.getNamedItem("flag").getNodeValue());
  319. if (!_spawnList.containsKey(flag))
  320. {
  321. _spawnList.put(flag, new FastList<FETSpawn>());
  322. }
  323. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  324. {
  325. if ("loc".equalsIgnoreCase(cd.getNodeName()))
  326. {
  327. attrs = cd.getAttributes();
  328. FETSpawn spw = new FETSpawn();
  329. spw.npcId = npcId;
  330. att = attrs.getNamedItem("x");
  331. if (att != null)
  332. {
  333. spw.x = Integer.parseInt(att.getNodeValue());
  334. }
  335. else
  336. {
  337. continue;
  338. }
  339. att = attrs.getNamedItem("y");
  340. if (att != null)
  341. {
  342. spw.y = Integer.parseInt(att.getNodeValue());
  343. }
  344. else
  345. {
  346. continue;
  347. }
  348. att = attrs.getNamedItem("z");
  349. if (att != null)
  350. {
  351. spw.z = Integer.parseInt(att.getNodeValue());
  352. }
  353. else
  354. {
  355. continue;
  356. }
  357. att = attrs.getNamedItem("heading");
  358. if (att != null)
  359. {
  360. spw.h = Integer.parseInt(att.getNodeValue());
  361. }
  362. else
  363. {
  364. continue;
  365. }
  366. att = attrs.getNamedItem("mustKill");
  367. if (att != null)
  368. {
  369. spw.isNeededNextFlag = Boolean.parseBoolean(att.getNodeValue());
  370. }
  371. if (spw.isNeededNextFlag)
  372. {
  373. _mustKillMobsId.add(npcId);
  374. }
  375. _spawnList.get(flag).add(spw);
  376. spawnCount++;
  377. }
  378. else if ("zone".equalsIgnoreCase(cd.getNodeName()))
  379. {
  380. attrs = cd.getAttributes();
  381. FETSpawn spw = new FETSpawn();
  382. spw.npcId = npcId;
  383. spw.isZone = true;
  384. att = attrs.getNamedItem("id");
  385. if (att != null)
  386. {
  387. spw.zone = Integer.parseInt(att.getNodeValue());
  388. }
  389. else
  390. {
  391. continue;
  392. }
  393. att = attrs.getNamedItem("count");
  394. if (att != null)
  395. {
  396. spw.count = Integer.parseInt(att.getNodeValue());
  397. }
  398. else
  399. {
  400. continue;
  401. }
  402. att = attrs.getNamedItem("mustKill");
  403. if (att != null)
  404. {
  405. spw.isNeededNextFlag = Boolean.parseBoolean(att.getNodeValue());
  406. }
  407. if (spw.isNeededNextFlag)
  408. {
  409. _mustKillMobsId.add(npcId);
  410. }
  411. _spawnList.get(flag).add(spw);
  412. spawnCount++;
  413. }
  414. }
  415. }
  416. }
  417. }
  418. else if ("spawnZones".equalsIgnoreCase(n.getNodeName()))
  419. {
  420. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  421. {
  422. if ("zone".equalsIgnoreCase(d.getNodeName()))
  423. {
  424. NamedNodeMap attrs = d.getAttributes();
  425. Node att = attrs.getNamedItem("id");
  426. if (att == null)
  427. {
  428. _log.severe("[Final Emperial Tomb] Missing id in spawnZones List, skipping");
  429. continue;
  430. }
  431. int id = Integer.parseInt(att.getNodeValue());
  432. att = attrs.getNamedItem("minZ");
  433. if (att == null)
  434. {
  435. _log.severe("[Final Emperial Tomb] Missing minZ in spawnZones List id: " + id + ", skipping");
  436. continue;
  437. }
  438. int minz = Integer.parseInt(att.getNodeValue());
  439. att = attrs.getNamedItem("maxZ");
  440. if (att == null)
  441. {
  442. _log.severe("[Final Emperial Tomb] Missing maxZ in spawnZones List id: " + id + ", skipping");
  443. continue;
  444. }
  445. int maxz = Integer.parseInt(att.getNodeValue());
  446. L2Territory ter = new L2Territory(id);
  447. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  448. {
  449. if ("point".equalsIgnoreCase(cd.getNodeName()))
  450. {
  451. attrs = cd.getAttributes();
  452. int x, y;
  453. att = attrs.getNamedItem("x");
  454. if (att != null)
  455. {
  456. x = Integer.parseInt(att.getNodeValue());
  457. }
  458. else
  459. {
  460. continue;
  461. }
  462. att = attrs.getNamedItem("y");
  463. if (att != null)
  464. {
  465. y = Integer.parseInt(att.getNodeValue());
  466. }
  467. else
  468. {
  469. continue;
  470. }
  471. ter.add(x, y, minz, maxz, 0);
  472. }
  473. }
  474. _spawnZoneList.put(id, ter);
  475. }
  476. }
  477. }
  478. }
  479. }
  480. }
  481. catch (Exception e)
  482. {
  483. _log.log(Level.WARNING, "[Final Emperial Tomb] Could not parse final_emperial_tomb.xml file: " + e.getMessage(), e);
  484. }
  485. if (debug)
  486. {
  487. _log.info("[Final Emperial Tomb] Loaded " + _spawnZoneList.size() + " spawn zones data.");
  488. _log.info("[Final Emperial Tomb] Loaded " + spawnCount + " spawns data.");
  489. }
  490. }
  491. private boolean checkConditions(L2PcInstance player)
  492. {
  493. if (debug || player.canOverrideCond(PcCondOverride.INSTANCE_CONDITIONS))
  494. {
  495. return true;
  496. }
  497. L2Party party = player.getParty();
  498. if (party == null)
  499. {
  500. player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
  501. return false;
  502. }
  503. L2CommandChannel channel = player.getParty().getCommandChannel();
  504. if (channel == null)
  505. {
  506. player.sendPacket(SystemMessageId.NOT_IN_COMMAND_CHANNEL_CANT_ENTER);
  507. return false;
  508. }
  509. else if (channel.getLeader() != player)
  510. {
  511. player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
  512. return false;
  513. }
  514. else if (player.getInventory().getItemByItemId(8073) == null)
  515. {
  516. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  517. sm.addPcName(player);
  518. player.sendPacket(sm);
  519. return false;
  520. }
  521. else if ((channel.getMemberCount() < MIN_PLAYERS) || (channel.getMemberCount() > MAX_PLAYERS))
  522. {
  523. player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
  524. return false;
  525. }
  526. for (L2PcInstance channelMember : channel.getMembers())
  527. {
  528. if (channelMember.getLevel() < 80)
  529. {
  530. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  531. sm.addPcName(channelMember);
  532. party.broadcastPacket(sm);
  533. return false;
  534. }
  535. if (!Util.checkIfInRange(1000, player, channelMember, true))
  536. {
  537. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  538. sm.addPcName(channelMember);
  539. party.broadcastPacket(sm);
  540. return false;
  541. }
  542. Long reentertime = InstanceManager.getInstance().getInstanceTime(channelMember.getObjectId(), INSTANCEID);
  543. if (System.currentTimeMillis() < reentertime)
  544. {
  545. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
  546. sm.addPcName(channelMember);
  547. party.broadcastPacket(sm);
  548. return false;
  549. }
  550. }
  551. return true;
  552. }
  553. protected int enterInstance(L2PcInstance player, String template, Location loc)
  554. {
  555. int instanceId = 0;
  556. // check for existing instances for this player
  557. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  558. // existing instance
  559. if (world != null)
  560. {
  561. if (!(world instanceof FETWorld))
  562. {
  563. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  564. return 0;
  565. }
  566. teleportPlayer(player, loc, world.getInstanceId(), false);
  567. return world.getInstanceId();
  568. }
  569. // New instance
  570. if (!checkConditions(player))
  571. {
  572. return 0;
  573. }
  574. if (!player.canOverrideCond(PcCondOverride.INSTANCE_CONDITIONS) && !player.destroyItemByItemId("QUEST", 8073, 1, player, true))
  575. {
  576. return 0;
  577. }
  578. instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  579. // Instance ins = InstanceManager.getInstance().getInstance(instanceId);
  580. // ins.setSpawnLoc(new int[]{player.getX(),player.getY(),player.getZ()});
  581. world = new FETWorld();
  582. world.setTemplateId(INSTANCEID);
  583. world.setInstanceId(instanceId);
  584. world.setStatus(0);
  585. InstanceManager.getInstance().addWorld(world);
  586. controlStatus((FETWorld) world);
  587. _log.info("Final Emperial Tomb started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  588. // teleport players
  589. if ((player.getParty() == null) || (player.getParty().getCommandChannel() == null))
  590. {
  591. player.destroyItemByItemId(getName(), DEWDROP_OF_DESTRUCTION_ITEM_ID, player.getInventory().getInventoryItemCount(DEWDROP_OF_DESTRUCTION_ITEM_ID, -1), null, true);
  592. world.addAllowed(player.getObjectId());
  593. teleportPlayer(player, loc, instanceId, false);
  594. }
  595. else
  596. {
  597. for (L2PcInstance channelMember : player.getParty().getCommandChannel().getMembers())
  598. {
  599. channelMember.destroyItemByItemId(getName(), DEWDROP_OF_DESTRUCTION_ITEM_ID, channelMember.getInventory().getInventoryItemCount(DEWDROP_OF_DESTRUCTION_ITEM_ID, -1), null, true);
  600. world.addAllowed(channelMember.getObjectId());
  601. teleportPlayer(channelMember, loc, instanceId, false);
  602. }
  603. }
  604. return instanceId;
  605. }
  606. protected boolean checkKillProgress(L2Npc mob, FETWorld world)
  607. {
  608. if (world.npcList.contains(mob))
  609. {
  610. world.npcList.remove(mob);
  611. }
  612. return world.npcList.isEmpty();
  613. }
  614. private void spawnFlaggedNPCs(FETWorld world, int flag)
  615. {
  616. if (world.lock.tryLock())
  617. {
  618. try
  619. {
  620. for (FETSpawn spw : _spawnList.get(flag))
  621. {
  622. if (spw.isZone)
  623. {
  624. for (int i = 0; i < spw.count; i++)
  625. {
  626. if (_spawnZoneList.containsKey(spw.zone))
  627. {
  628. int[] point = _spawnZoneList.get(spw.zone).getRandomPoint();
  629. spawn(world, spw.npcId, point[0], point[1], GeoData.getInstance().getSpawnHeight(point[0], point[1], point[2], point[3], null), getRandom(65535), spw.isNeededNextFlag);
  630. }
  631. else
  632. {
  633. _log.info("[Final Emperial Tomb] Missing zone: " + spw.zone);
  634. }
  635. }
  636. }
  637. else
  638. {
  639. spawn(world, spw.npcId, spw.x, spw.y, spw.z, spw.h, spw.isNeededNextFlag);
  640. }
  641. }
  642. }
  643. finally
  644. {
  645. world.lock.unlock();
  646. }
  647. }
  648. }
  649. protected boolean controlStatus(FETWorld world)
  650. {
  651. if (world.lock.tryLock())
  652. {
  653. try
  654. {
  655. if (debug)
  656. {
  657. _log.info("[Final Emperial Tomb] Starting " + world.getStatus() + ". status.");
  658. }
  659. world.npcList.clear();
  660. switch (world.getStatus())
  661. {
  662. case 0:
  663. spawnFlaggedNPCs(world, 0);
  664. break;
  665. case 1:
  666. for (int doorId : FIRST_ROUTE_DOORS)
  667. {
  668. openDoor(doorId, world.getInstanceId());
  669. }
  670. spawnFlaggedNPCs(world, world.getStatus());
  671. break;
  672. case 2:
  673. for (int doorId : SECOND_ROUTE_DOORS)
  674. {
  675. openDoor(doorId, world.getInstanceId());
  676. }
  677. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 0), 600000);
  678. break;
  679. case 3: // first morph
  680. if (world.songEffectTask != null)
  681. {
  682. world.songEffectTask.cancel(false);
  683. }
  684. world.songEffectTask = null;
  685. world.activeScarlet.setIsInvul(true);
  686. if (world.activeScarlet.isCastingNow())
  687. {
  688. world.activeScarlet.abortCast();
  689. }
  690. setInstanceTimeRestrictions(world);
  691. world.activeScarlet.doCast(FIRST_MORPH_SKILL.getSkill());
  692. ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(world, 2), 1500);
  693. break;
  694. case 4: // second morph
  695. world.isVideo = true;
  696. broadCastPacket(world, new MagicSkillCanceld(world.frintezza.getObjectId()));
  697. if (world.songEffectTask != null)
  698. {
  699. world.songEffectTask.cancel(false);
  700. }
  701. world.songEffectTask = null;
  702. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 23), 2000);
  703. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 24), 2100);
  704. break;
  705. case 5: // raid success
  706. world.isVideo = true;
  707. broadCastPacket(world, new MagicSkillCanceld(world.frintezza.getObjectId()));
  708. if (world.songTask != null)
  709. {
  710. world.songTask.cancel(true);
  711. }
  712. if (world.songEffectTask != null)
  713. {
  714. world.songEffectTask.cancel(false);
  715. }
  716. world.songTask = null;
  717. world.songEffectTask = null;
  718. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 33), 500);
  719. break;
  720. case 6: // open doors
  721. InstanceManager.getInstance().getInstance(world.getInstanceId()).setDuration(300000);
  722. for (int doorId : FIRST_ROOM_DOORS)
  723. {
  724. openDoor(doorId, world.getInstanceId());
  725. }
  726. for (int doorId : FIRST_ROUTE_DOORS)
  727. {
  728. openDoor(doorId, world.getInstanceId());
  729. }
  730. for (int doorId : SECOND_ROUTE_DOORS)
  731. {
  732. openDoor(doorId, world.getInstanceId());
  733. }
  734. for (int doorId : SECOND_ROOM_DOORS)
  735. {
  736. closeDoor(doorId, world.getInstanceId());
  737. }
  738. break;
  739. }
  740. world.incStatus();
  741. return true;
  742. }
  743. finally
  744. {
  745. world.lock.unlock();
  746. }
  747. }
  748. return false;
  749. }
  750. protected void spawn(FETWorld world, int npcId, int x, int y, int z, int h, boolean addToKillTable)
  751. {
  752. L2Npc npc = addSpawn(npcId, x, y, z, h, false, 0, false, world.getInstanceId());
  753. if (addToKillTable)
  754. {
  755. world.npcList.add(npc);
  756. }
  757. npc.setIsNoRndWalk(true);
  758. if (npc.isInstanceType(InstanceType.L2Attackable))
  759. {
  760. ((L2Attackable) npc).setSeeThroughSilentMove(true);
  761. }
  762. if (Util.contains(AI_DISABLED_MOBS, npcId))
  763. {
  764. npc.disableCoreAI(true);
  765. }
  766. if (npcId == DARK_CHOIR_PLAYER)
  767. {
  768. world.darkChoirPlayerCount++;
  769. }
  770. }
  771. private class DemonSpawnTask implements Runnable
  772. {
  773. private final FETWorld _world;
  774. DemonSpawnTask(FETWorld world)
  775. {
  776. _world = world;
  777. }
  778. @Override
  779. public void run()
  780. {
  781. if ((InstanceManager.getInstance().getWorld(_world.getInstanceId()) != _world) || _world.portraits.isEmpty())
  782. {
  783. if (debug)
  784. {
  785. _log.info("[Final Emperial Tomb] Instance is deleted or all Portraits is killed.");
  786. }
  787. return;
  788. }
  789. for (int i : _world.portraits.values())
  790. {
  791. if (_world.demons.size() > MAX_DEMONS)
  792. {
  793. break;
  794. }
  795. L2MonsterInstance demon = (L2MonsterInstance) addSpawn(PORTRAIT_SPAWNS[i][0] + 2, PORTRAIT_SPAWNS[i][5], PORTRAIT_SPAWNS[i][6], PORTRAIT_SPAWNS[i][7], PORTRAIT_SPAWNS[i][8], false, 0, false, _world.getInstanceId());
  796. updateKnownList(_world, demon);
  797. _world.demons.add(demon);
  798. }
  799. ThreadPoolManager.getInstance().scheduleGeneral(new DemonSpawnTask(_world), TIME_BETWEEN_DEMON_SPAWNS);
  800. }
  801. }
  802. private class SoulBreakingArrow implements Runnable
  803. {
  804. private final L2Npc _npc;
  805. protected SoulBreakingArrow(L2Npc npc)
  806. {
  807. _npc = npc;
  808. }
  809. @Override
  810. public void run()
  811. {
  812. _npc.setScriptValue(0);
  813. }
  814. }
  815. private class SongTask implements Runnable
  816. {
  817. private final FETWorld _world;
  818. private final int _status;
  819. SongTask(FETWorld world, int status)
  820. {
  821. _world = world;
  822. _status = status;
  823. }
  824. @Override
  825. public void run()
  826. {
  827. if (InstanceManager.getInstance().getWorld(_world.getInstanceId()) != _world)
  828. {
  829. return;
  830. }
  831. switch (_status)
  832. {
  833. case 0: // new song play
  834. if (_world.isVideo)
  835. {
  836. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), 1000);
  837. }
  838. else if ((_world.frintezza != null) && !_world.frintezza.isDead())
  839. {
  840. if (_world.frintezza.getScriptValue() != 1)
  841. {
  842. int rnd = getRandom(100);
  843. for (FrintezzaSong element : FRINTEZZASONGLIST)
  844. {
  845. if (rnd < element.chance)
  846. {
  847. _world.OnSong = element;
  848. broadCastPacket(_world, new ExShowScreenMessage(2, -1, 2, 0, 0, 0, 0, true, 4000, false, null, element.songName, null));
  849. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, element.skill.getSkillId(), element.skill.getSkillLvl(), element.skill.getSkill().getHitTime(), 0));
  850. _world.songEffectTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 1), element.skill.getSkill().getHitTime() - 10000);
  851. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), element.skill.getSkill().getHitTime());
  852. break;
  853. }
  854. }
  855. }
  856. else
  857. {
  858. ThreadPoolManager.getInstance().scheduleGeneral(new SoulBreakingArrow(_world.frintezza), 35000);
  859. }
  860. }
  861. break;
  862. case 1: // Frintezza song effect
  863. _world.songEffectTask = null;
  864. L2Skill skill = _world.OnSong.effectSkill.getSkill();
  865. if (skill == null)
  866. {
  867. return;
  868. }
  869. if ((_world.frintezza != null) && !_world.frintezza.isDead() && (_world.activeScarlet != null) && !_world.activeScarlet.isDead())
  870. {
  871. List<L2Character> targetList = new FastList<>();
  872. if (skill.hasEffectType(L2EffectType.STUN) || (skill.getSkillType() == L2SkillType.DEBUFF))
  873. {
  874. for (int objId : _world.getAllowed())
  875. {
  876. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  877. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  878. {
  879. if (!player.isDead())
  880. {
  881. targetList.add(player);
  882. }
  883. if (player.hasSummon() && !player.getSummon().isDead())
  884. {
  885. targetList.add(player.getSummon());
  886. }
  887. }
  888. }
  889. }
  890. else
  891. {
  892. targetList.add(_world.activeScarlet);
  893. }
  894. if (targetList.size() > 0)
  895. {
  896. _world.frintezza.doCast(skill, targetList.get(0), targetList.toArray(new L2Character[targetList.size()]));
  897. }
  898. }
  899. break;
  900. case 2: // finish morph
  901. _world.activeScarlet.setRHandId(SECOND_SCARLET_WEAPON);
  902. _world.activeScarlet.setIsInvul(false);
  903. break;
  904. }
  905. }
  906. }
  907. private class IntroTask implements Runnable
  908. {
  909. private final FETWorld _world;
  910. private final int _status;
  911. IntroTask(FETWorld world, int status)
  912. {
  913. _world = world;
  914. _status = status;
  915. }
  916. @Override
  917. public void run()
  918. {
  919. switch (_status)
  920. {
  921. case 0:
  922. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 1), 27000);
  923. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 2), 30000);
  924. broadCastPacket(_world, new Earthquake(-87784, -155083, -9087, 45, 27));
  925. break;
  926. case 1:
  927. for (int doorId : FIRST_ROOM_DOORS)
  928. {
  929. closeDoor(doorId, _world.getInstanceId());
  930. }
  931. for (int doorId : FIRST_ROUTE_DOORS)
  932. {
  933. closeDoor(doorId, _world.getInstanceId());
  934. }
  935. for (int doorId : SECOND_ROOM_DOORS)
  936. {
  937. closeDoor(doorId, _world.getInstanceId());
  938. }
  939. for (int doorId : SECOND_ROUTE_DOORS)
  940. {
  941. closeDoor(doorId, _world.getInstanceId());
  942. }
  943. addSpawn(29061, -87904, -141296, -9168, 0, false, 0, false, _world.getInstanceId());
  944. break;
  945. case 2:
  946. _world.frintezzaDummy = addSpawn(29052, -87784, -155083, -9087, 16048, false, 0, false, _world.getInstanceId());
  947. _world.frintezzaDummy.setIsInvul(true);
  948. _world.frintezzaDummy.setIsImmobilized(true);
  949. _world.overheadDummy = addSpawn(29052, -87784, -153298, -9175, 16384, false, 0, false, _world.getInstanceId());
  950. _world.overheadDummy.setIsInvul(true);
  951. _world.overheadDummy.setIsImmobilized(true);
  952. _world.overheadDummy.setCollisionHeight(600);
  953. broadCastPacket(_world, new NpcInfo(_world.overheadDummy, null));
  954. _world.portraitDummy1 = addSpawn(29052, -89566, -153168, -9165, 16048, false, 0, false, _world.getInstanceId());
  955. _world.portraitDummy1.setIsImmobilized(true);
  956. _world.portraitDummy1.setIsInvul(true);
  957. _world.portraitDummy3 = addSpawn(29052, -86004, -153168, -9165, 16048, false, 0, false, _world.getInstanceId());
  958. _world.portraitDummy3.setIsImmobilized(true);
  959. _world.portraitDummy3.setIsInvul(true);
  960. _world.scarletDummy = addSpawn(29053, -87784, -153298, -9175, 16384, false, 0, false, _world.getInstanceId());
  961. _world.scarletDummy.setIsInvul(true);
  962. _world.scarletDummy.setIsImmobilized(true);
  963. stopPc();
  964. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 3), 1000);
  965. break;
  966. case 3:
  967. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 0, 75, -89, 0, 100, 0, 0, 1, 0));
  968. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 0, 75, -89, 0, 100, 0, 0, 1, 0));
  969. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 300, 90, -10, 6500, 7000, 0, 0, 1, 0));
  970. _world.frintezza = (L2GrandBossInstance) addSpawn(FRINTEZZA, -87780, -155086, -9080, 16384, false, 0, false, _world.getInstanceId());
  971. _world.frintezza.setIsImmobilized(true);
  972. _world.frintezza.setIsInvul(true);
  973. _world.frintezza.disableAllSkills();
  974. updateKnownList(_world, _world.frintezza);
  975. for (int[] element : PORTRAIT_SPAWNS)
  976. {
  977. L2MonsterInstance demon = (L2MonsterInstance) addSpawn(element[0] + 2, element[5], element[6], element[7], element[8], false, 0, false, _world.getInstanceId());
  978. demon.setIsImmobilized(true);
  979. demon.disableAllSkills();
  980. updateKnownList(_world, demon);
  981. _world.demons.add(demon);
  982. }
  983. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 4), 6500);
  984. break;
  985. case 4:
  986. broadCastPacket(_world, new SpecialCamera(_world.frintezzaDummy.getObjectId(), 1800, 90, 8, 6500, 7000, 0, 0, 1, 0));
  987. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 5), 900);
  988. break;
  989. case 5:
  990. broadCastPacket(_world, new SpecialCamera(_world.frintezzaDummy.getObjectId(), 140, 90, 10, 2500, 4500, 0, 0, 1, 0));
  991. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 6), 4000);
  992. break;
  993. case 6:
  994. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 40, 75, -10, 0, 1000, 0, 0, 1, 0));
  995. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 40, 75, -10, 0, 12000, 0, 0, 1, 0));
  996. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 7), 1350);
  997. break;
  998. case 7:
  999. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 2));
  1000. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 8), 7000);
  1001. break;
  1002. case 8:
  1003. _world.frintezzaDummy.deleteMe();
  1004. _world.frintezzaDummy = null;
  1005. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 9), 1000);
  1006. break;
  1007. case 9:
  1008. broadCastPacket(_world, new SocialAction(_world.demons.get(1).getObjectId(), 1));
  1009. broadCastPacket(_world, new SocialAction(_world.demons.get(2).getObjectId(), 1));
  1010. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 10), 400);
  1011. break;
  1012. case 10:
  1013. broadCastPacket(_world, new SocialAction(_world.demons.get(0).getObjectId(), 1));
  1014. broadCastPacket(_world, new SocialAction(_world.demons.get(3).getObjectId(), 1));
  1015. sendPacketX(new SpecialCamera(_world.portraitDummy1.getObjectId(), 1000, 118, 0, 0, 1000, 0, 0, 1, 0), new SpecialCamera(_world.portraitDummy3.getObjectId(), 1000, 62, 0, 0, 1000, 0, 0, 1, 0), -87784);
  1016. sendPacketX(new SpecialCamera(_world.portraitDummy1.getObjectId(), 1000, 118, 0, 0, 10000, 0, 0, 1, 0), new SpecialCamera(_world.portraitDummy3.getObjectId(), 1000, 62, 0, 0, 10000, 0, 0, 1, 0), -87784);
  1017. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 11), 2000);
  1018. break;
  1019. case 11:
  1020. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 240, 90, 0, 0, 1000, 0, 0, 1, 0));
  1021. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 240, 90, 25, 5500, 10000, 0, 0, 1, 0));
  1022. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 3));
  1023. _world.portraitDummy1.deleteMe();
  1024. _world.portraitDummy3.deleteMe();
  1025. _world.portraitDummy1 = null;
  1026. _world.portraitDummy3 = null;
  1027. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 12), 4500);
  1028. break;
  1029. case 12:
  1030. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 195, 35, 0, 10000, 0, 0, 1, 0));
  1031. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 13), 700);
  1032. break;
  1033. case 13:
  1034. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 195, 35, 0, 10000, 0, 0, 1, 0));
  1035. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 14), 1300);
  1036. break;
  1037. case 14:
  1038. broadCastPacket(_world, new ExShowScreenMessage(NpcStringId.MOURNFUL_CHORALE_PRELUDE, 2, 5000));
  1039. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 120, 180, 45, 1500, 10000, 0, 0, 1, 0));
  1040. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, 5006, 1, 34000, 0));
  1041. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 15), 1500);
  1042. break;
  1043. case 15:
  1044. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 520, 135, 45, 8000, 10000, 0, 0, 1, 0));
  1045. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 16), 7500);
  1046. break;
  1047. case 16:
  1048. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 1500, 110, 25, 10000, 13000, 0, 0, 1, 0));
  1049. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 17), 9500);
  1050. break;
  1051. case 17:
  1052. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 930, 160, -20, 0, 1000, 0, 0, 1, 0));
  1053. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 600, 180, -25, 0, 10000, 0, 0, 1, 0));
  1054. broadCastPacket(_world, new MagicSkillUse(_world.scarletDummy, _world.overheadDummy, 5004, 1, 5800, 0));
  1055. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 18), 5000);
  1056. break;
  1057. case 18:
  1058. _world.activeScarlet = (L2GrandBossInstance) addSpawn(29046, -87789, -153295, -9176, 16384, false, 0, false, _world.getInstanceId());
  1059. _world.activeScarlet.setRHandId(FIRST_SCARLET_WEAPON);
  1060. _world.activeScarlet.setIsInvul(true);
  1061. _world.activeScarlet.setIsImmobilized(true);
  1062. _world.activeScarlet.disableAllSkills();
  1063. updateKnownList(_world, _world.activeScarlet);
  1064. broadCastPacket(_world, new SocialAction(_world.activeScarlet.getObjectId(), 3));
  1065. broadCastPacket(_world, new SpecialCamera(_world.scarletDummy.getObjectId(), 800, 180, 10, 1000, 10000, 0, 0, 1, 0));
  1066. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 19), 2100);
  1067. break;
  1068. case 19:
  1069. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 300, 60, 8, 0, 10000, 0, 0, 1, 0));
  1070. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 20), 2000);
  1071. break;
  1072. case 20:
  1073. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 500, 90, 10, 3000, 5000, 0, 0, 1, 0));
  1074. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), 100);
  1075. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 21), 3000);
  1076. break;
  1077. case 21:
  1078. for (int i = 0; i < PORTRAIT_SPAWNS.length; i++)
  1079. {
  1080. L2MonsterInstance portrait = (L2MonsterInstance) addSpawn(PORTRAIT_SPAWNS[i][0], PORTRAIT_SPAWNS[i][1], PORTRAIT_SPAWNS[i][2], PORTRAIT_SPAWNS[i][3], PORTRAIT_SPAWNS[i][4], false, 0, false, _world.getInstanceId());
  1081. updateKnownList(_world, portrait);
  1082. _world.portraits.put(portrait, i);
  1083. }
  1084. _world.overheadDummy.deleteMe();
  1085. _world.scarletDummy.deleteMe();
  1086. _world.overheadDummy = null;
  1087. _world.scarletDummy = null;
  1088. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 22), 2000);
  1089. break;
  1090. case 22:
  1091. for (L2MonsterInstance demon : _world.demons)
  1092. {
  1093. demon.setIsImmobilized(false);
  1094. demon.enableAllSkills();
  1095. }
  1096. _world.activeScarlet.setIsInvul(false);
  1097. _world.activeScarlet.setIsImmobilized(false);
  1098. _world.activeScarlet.enableAllSkills();
  1099. _world.activeScarlet.setRunning();
  1100. _world.activeScarlet.doCast(INTRO_SKILL.getSkill());
  1101. _world.frintezza.enableAllSkills();
  1102. _world.frintezza.disableCoreAI(true);
  1103. _world.frintezza.setIsMortal(false);
  1104. startPc();
  1105. ThreadPoolManager.getInstance().scheduleGeneral(new DemonSpawnTask(_world), TIME_BETWEEN_DEMON_SPAWNS);
  1106. break;
  1107. case 23:
  1108. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 4));
  1109. break;
  1110. case 24:
  1111. stopPc();
  1112. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 250, 120, 15, 0, 1000, 0, 0, 1, 0));
  1113. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 250, 120, 15, 0, 10000, 0, 0, 1, 0));
  1114. _world.activeScarlet.abortAttack();
  1115. _world.activeScarlet.abortCast();
  1116. _world.activeScarlet.setIsInvul(true);
  1117. _world.activeScarlet.setIsImmobilized(true);
  1118. _world.activeScarlet.disableAllSkills();
  1119. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 25), 7000);
  1120. break;
  1121. case 25:
  1122. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, 5006, 1, 34000, 0));
  1123. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 500, 70, 15, 3000, 10000, 0, 0, 1, 0));
  1124. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 26), 3000);
  1125. break;
  1126. case 26:
  1127. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 2500, 90, 12, 6000, 10000, 0, 0, 1, 0));
  1128. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 27), 3000);
  1129. break;
  1130. case 27:
  1131. _world.scarlet_x = _world.activeScarlet.getX();
  1132. _world.scarlet_y = _world.activeScarlet.getY();
  1133. _world.scarlet_z = _world.activeScarlet.getZ();
  1134. _world.scarlet_h = _world.activeScarlet.getHeading();
  1135. if (_world.scarlet_h < 32768)
  1136. {
  1137. _world.scarlet_a = Math.abs(180 - (int) (_world.scarlet_h / 182.044444444));
  1138. }
  1139. else
  1140. {
  1141. _world.scarlet_a = Math.abs(540 - (int) (_world.scarlet_h / 182.044444444));
  1142. }
  1143. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 250, _world.scarlet_a, 12, 0, 1000, 0, 0, 1, 0));
  1144. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 250, _world.scarlet_a, 12, 0, 10000, 0, 0, 1, 0));
  1145. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 28), 500);
  1146. break;
  1147. case 28:
  1148. _world.activeScarlet.doDie(_world.activeScarlet);
  1149. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 450, _world.scarlet_a, 14, 8000, 8000, 0, 0, 1, 0));
  1150. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 29), 6250);
  1151. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 30), 7200);
  1152. break;
  1153. case 29:
  1154. _world.activeScarlet.deleteMe();
  1155. _world.activeScarlet = null;
  1156. break;
  1157. case 30:
  1158. _world.activeScarlet = (L2GrandBossInstance) addSpawn(SCARLET2, _world.scarlet_x, _world.scarlet_y, _world.scarlet_z, _world.scarlet_h, false, 0, false, _world.getInstanceId());
  1159. _world.activeScarlet.setIsInvul(true);
  1160. _world.activeScarlet.setIsImmobilized(true);
  1161. _world.activeScarlet.disableAllSkills();
  1162. updateKnownList(_world, _world.activeScarlet);
  1163. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 450, _world.scarlet_a, 12, 500, 14000, 0, 0, 1, 0));
  1164. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 31), 8100);
  1165. break;
  1166. case 31:
  1167. broadCastPacket(_world, new SocialAction(_world.activeScarlet.getObjectId(), 2));
  1168. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 32), 9000);
  1169. break;
  1170. case 32:
  1171. startPc();
  1172. _world.activeScarlet.setIsInvul(false);
  1173. _world.activeScarlet.setIsImmobilized(false);
  1174. _world.activeScarlet.enableAllSkills();
  1175. _world.isVideo = false;
  1176. break;
  1177. case 33:
  1178. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 300, _world.scarlet_a - 180, 5, 0, 7000, 0, 0, 1, 0));
  1179. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 200, _world.scarlet_a, 85, 4000, 10000, 0, 0, 1, 0));
  1180. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 34), 7400);
  1181. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 35), 7500);
  1182. break;
  1183. case 34:
  1184. _world.frintezza.doDie(_world.frintezza);
  1185. break;
  1186. case 35:
  1187. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 120, 5, 0, 7000, 0, 0, 1, 0));
  1188. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 90, 5, 5000, 15000, 0, 0, 1, 0));
  1189. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 36), 7000);
  1190. break;
  1191. case 36:
  1192. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 900, 90, 25, 7000, 10000, 0, 0, 1, 0));
  1193. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 37), 9000);
  1194. break;
  1195. case 37:
  1196. controlStatus(_world);
  1197. _world.isVideo = false;
  1198. startPc();
  1199. break;
  1200. }
  1201. }
  1202. private void stopPc()
  1203. {
  1204. for (int objId : _world.getAllowed())
  1205. {
  1206. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1207. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  1208. {
  1209. player.abortAttack();
  1210. player.abortCast();
  1211. player.disableAllSkills();
  1212. player.setTarget(null);
  1213. player.stopMove(null);
  1214. player.setIsImmobilized(true);
  1215. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1216. }
  1217. }
  1218. }
  1219. private void startPc()
  1220. {
  1221. for (int objId : _world.getAllowed())
  1222. {
  1223. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1224. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  1225. {
  1226. player.enableAllSkills();
  1227. player.setIsImmobilized(false);
  1228. }
  1229. }
  1230. }
  1231. private void sendPacketX(L2GameServerPacket packet1, L2GameServerPacket packet2, int x)
  1232. {
  1233. for (int objId : _world.getAllowed())
  1234. {
  1235. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1236. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  1237. {
  1238. if (player.getX() < x)
  1239. {
  1240. player.sendPacket(packet1);
  1241. }
  1242. else
  1243. {
  1244. player.sendPacket(packet2);
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. private class StatusTask implements Runnable
  1251. {
  1252. private final FETWorld _world;
  1253. private final int _status;
  1254. StatusTask(FETWorld world, int status)
  1255. {
  1256. _world = world;
  1257. _status = status;
  1258. }
  1259. @Override
  1260. public void run()
  1261. {
  1262. if (InstanceManager.getInstance().getWorld(_world.getInstanceId()) != _world)
  1263. {
  1264. return;
  1265. }
  1266. switch (_status)
  1267. {
  1268. case 0:
  1269. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(_world, 1), 2000);
  1270. for (int doorId : FIRST_ROOM_DOORS)
  1271. {
  1272. openDoor(doorId, _world.getInstanceId());
  1273. }
  1274. break;
  1275. case 1:
  1276. addAggroToMobs();
  1277. break;
  1278. case 2:
  1279. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(_world, 3), 100);
  1280. for (int doorId : SECOND_ROOM_DOORS)
  1281. {
  1282. openDoor(doorId, _world.getInstanceId());
  1283. }
  1284. break;
  1285. case 3:
  1286. addAggroToMobs();
  1287. break;
  1288. case 4:
  1289. controlStatus(_world);
  1290. break;
  1291. }
  1292. }
  1293. private void addAggroToMobs()
  1294. {
  1295. L2PcInstance target = L2World.getInstance().getPlayer(_world.getAllowed().get(getRandom(_world.getAllowed().size())));
  1296. if ((target == null) || (target.getInstanceId() != _world.getInstanceId()) || target.isDead() || target.isFakeDeath())
  1297. {
  1298. for (int objId : _world.getAllowed())
  1299. {
  1300. target = L2World.getInstance().getPlayer(objId);
  1301. if ((target != null) && (target.getInstanceId() == _world.getInstanceId()) && !target.isDead() && !target.isFakeDeath())
  1302. {
  1303. break;
  1304. }
  1305. target = null;
  1306. }
  1307. }
  1308. for (L2Npc mob : _world.npcList)
  1309. {
  1310. mob.setRunning();
  1311. if (target != null)
  1312. {
  1313. ((L2MonsterInstance) mob).addDamageHate(target, 0, 500);
  1314. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  1315. }
  1316. else
  1317. {
  1318. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, MOVE_TO_CENTER);
  1319. }
  1320. }
  1321. }
  1322. }
  1323. protected void setInstanceTimeRestrictions(FETWorld world)
  1324. {
  1325. Calendar reenter = Calendar.getInstance();
  1326. reenter.set(Calendar.MINUTE, RESET_MIN);
  1327. reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
  1328. // if time is >= RESET_HOUR - roll to the next day
  1329. if (reenter.getTimeInMillis() <= System.currentTimeMillis())
  1330. {
  1331. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1332. }
  1333. if (reenter.get(Calendar.DAY_OF_WEEK) <= RESET_DAY_1)
  1334. {
  1335. while (reenter.get(Calendar.DAY_OF_WEEK) != RESET_DAY_1)
  1336. {
  1337. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1338. }
  1339. }
  1340. else
  1341. {
  1342. while (reenter.get(Calendar.DAY_OF_WEEK) != RESET_DAY_2)
  1343. {
  1344. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1345. }
  1346. }
  1347. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
  1348. sm.addInstanceName(INSTANCEID);
  1349. // set instance reenter time for all allowed players
  1350. for (int objectId : world.getAllowed())
  1351. {
  1352. L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  1353. InstanceManager.getInstance().setInstanceTime(objectId, INSTANCEID, reenter.getTimeInMillis());
  1354. if ((player != null) && player.isOnline())
  1355. {
  1356. player.sendPacket(sm);
  1357. }
  1358. }
  1359. }
  1360. protected void broadCastPacket(FETWorld world, L2GameServerPacket packet)
  1361. {
  1362. for (int objId : world.getAllowed())
  1363. {
  1364. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1365. if ((player != null) && player.isOnline() && (player.getInstanceId() == world.getInstanceId()))
  1366. {
  1367. player.sendPacket(packet);
  1368. }
  1369. }
  1370. }
  1371. protected void updateKnownList(FETWorld world, L2Npc npc)
  1372. {
  1373. Map<Integer, L2PcInstance> npcKnownPlayers = npc.getKnownList().getKnownPlayers();
  1374. for (int objId : world.getAllowed())
  1375. {
  1376. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1377. if ((player != null) && player.isOnline() && (player.getInstanceId() == world.getInstanceId()))
  1378. {
  1379. npcKnownPlayers.put(player.getObjectId(), player);
  1380. }
  1381. }
  1382. }
  1383. @Override
  1384. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, L2Skill skill)
  1385. {
  1386. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1387. if (tmpworld instanceof FETWorld)
  1388. {
  1389. final FETWorld world = (FETWorld) tmpworld;
  1390. if ((npc.getId() == SCARLET1) && (world.getStatus() == 3) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.80)))
  1391. {
  1392. controlStatus(world);
  1393. }
  1394. else if ((npc.getId() == SCARLET1) && (world.getStatus() == 4) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.20)))
  1395. {
  1396. controlStatus(world);
  1397. }
  1398. if (skill != null)
  1399. {
  1400. // When Dewdrop of Destruction is used on Portraits they suicide.
  1401. if (Util.contains(PORTRAITS, npc.getId()) && (skill.getId() == DEWDROP_OF_DESTRUCTION_SKILL_ID))
  1402. {
  1403. npc.doDie(attacker);
  1404. }
  1405. else if ((npc.getId() == FRINTEZZA) && (skill.getId() == SOUL_BREAKING_ARROW_SKILL_ID))
  1406. {
  1407. npc.setScriptValue(1);
  1408. npc.setTarget(null);
  1409. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1410. }
  1411. }
  1412. }
  1413. return null;
  1414. }
  1415. @Override
  1416. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  1417. {
  1418. if (skill.isSuicideAttack())
  1419. {
  1420. return onKill(npc, null, false);
  1421. }
  1422. return super.onSpellFinished(npc, player, skill);
  1423. }
  1424. @Override
  1425. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  1426. {
  1427. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1428. if (tmpworld instanceof FETWorld)
  1429. {
  1430. FETWorld world = (FETWorld) tmpworld;
  1431. if (npc.getId() == HALL_ALARM)
  1432. {
  1433. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(world, 0), 2000);
  1434. if (debug)
  1435. {
  1436. _log.info("[Final Emperial Tomb] Hall alarm is disabled, doors will open!");
  1437. }
  1438. }
  1439. else if (npc.getId() == DARK_CHOIR_PLAYER)
  1440. {
  1441. world.darkChoirPlayerCount--;
  1442. if (world.darkChoirPlayerCount < 1)
  1443. {
  1444. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(world, 2), 2000);
  1445. if (debug)
  1446. {
  1447. _log.info("[Final Emperial Tomb] All Dark Choir Players are killed, doors will open!");
  1448. }
  1449. }
  1450. }
  1451. else if (npc.getId() == SCARLET2)
  1452. {
  1453. controlStatus(world);
  1454. }
  1455. else if (world.getStatus() <= 2)
  1456. {
  1457. if (npc.getId() == HALL_KEEPER_CAPTAIN)
  1458. {
  1459. if (getRandom(100) < 5)
  1460. {
  1461. ((L2MonsterInstance) npc).dropItem(player, DEWDROP_OF_DESTRUCTION_ITEM_ID, 1);
  1462. }
  1463. }
  1464. if (checkKillProgress(npc, world))
  1465. {
  1466. controlStatus(world);
  1467. }
  1468. }
  1469. else if (world.demons.contains(npc))
  1470. {
  1471. world.demons.remove(npc);
  1472. }
  1473. else if (world.portraits.containsKey(npc))
  1474. {
  1475. world.portraits.remove(npc);
  1476. }
  1477. }
  1478. return "";
  1479. }
  1480. @Override
  1481. public String onTalk(L2Npc npc, L2PcInstance player)
  1482. {
  1483. int npcId = npc.getId();
  1484. QuestState st = player.getQuestState(getName());
  1485. if (st == null)
  1486. {
  1487. st = newQuestState(player);
  1488. }
  1489. if (npcId == GUIDE)
  1490. {
  1491. enterInstance(player, "FinalEmperialTomb.xml", ENTER_TELEPORT);
  1492. }
  1493. else if (npc.getId() == CUBE)
  1494. {
  1495. int x = -87534 + getRandom(500);
  1496. int y = -153048 + getRandom(500);
  1497. player.teleToLocation(x, y, -9165);
  1498. return null;
  1499. }
  1500. return "";
  1501. }
  1502. public FinalEmperialTomb(int questId, String name, String descr)
  1503. {
  1504. super(questId, name, descr);
  1505. load();
  1506. addAttackId(SCARLET1, FRINTEZZA);
  1507. addAttackId(PORTRAITS);
  1508. addStartNpc(GUIDE, CUBE);
  1509. addTalkId(GUIDE, CUBE);
  1510. addKillId(HALL_ALARM, HALL_KEEPER_CAPTAIN, DARK_CHOIR_PLAYER, SCARLET2);
  1511. addKillId(PORTRAITS);
  1512. addKillId(DEMONS);
  1513. addKillId(_mustKillMobsId);
  1514. addSpellFinishedId(HALL_KEEPER_SUICIDAL_SOLDIER);
  1515. }
  1516. public static void main(String[] args)
  1517. {
  1518. new FinalEmperialTomb(-1, FinalEmperialTomb.class.getSimpleName(), "instances");
  1519. }
  1520. }