FinalEmperialTomb.java 52 KB

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