FinalEmperialTomb.java 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  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.L2Skill;
  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 INSTANCEID = 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(), INSTANCEID);
  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. int instanceId = 0;
  569. // check for existing instances for this player
  570. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  571. // existing instance
  572. if (world != null)
  573. {
  574. if (!(world instanceof FETWorld))
  575. {
  576. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  577. return 0;
  578. }
  579. teleportPlayer(player, loc, world.getInstanceId(), false);
  580. return world.getInstanceId();
  581. }
  582. // New instance
  583. if (!checkConditions(player))
  584. {
  585. return 0;
  586. }
  587. if (!player.canOverrideCond(PcCondOverride.INSTANCE_CONDITIONS) && !player.destroyItemByItemId("QUEST", 8073, 1, player, true))
  588. {
  589. return 0;
  590. }
  591. instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  592. // Instance ins = InstanceManager.getInstance().getInstance(instanceId);
  593. // ins.setSpawnLoc(new int[]{player.getX(),player.getY(),player.getZ()});
  594. world = new FETWorld();
  595. world.setTemplateId(INSTANCEID);
  596. world.setInstanceId(instanceId);
  597. world.setStatus(0);
  598. InstanceManager.getInstance().addWorld(world);
  599. controlStatus((FETWorld) world);
  600. _log.info("Final Emperial Tomb started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  601. // teleport players
  602. if ((player.getParty() == null) || (player.getParty().getCommandChannel() == null))
  603. {
  604. player.destroyItemByItemId(getName(), DEWDROP_OF_DESTRUCTION_ITEM_ID, player.getInventory().getInventoryItemCount(DEWDROP_OF_DESTRUCTION_ITEM_ID, -1), null, true);
  605. world.addAllowed(player.getObjectId());
  606. teleportPlayer(player, loc, instanceId, false);
  607. }
  608. else
  609. {
  610. for (L2PcInstance channelMember : player.getParty().getCommandChannel().getMembers())
  611. {
  612. channelMember.destroyItemByItemId(getName(), DEWDROP_OF_DESTRUCTION_ITEM_ID, channelMember.getInventory().getInventoryItemCount(DEWDROP_OF_DESTRUCTION_ITEM_ID, -1), null, true);
  613. world.addAllowed(channelMember.getObjectId());
  614. teleportPlayer(channelMember, loc, instanceId, false);
  615. }
  616. }
  617. return instanceId;
  618. }
  619. protected boolean checkKillProgress(L2Npc mob, FETWorld world)
  620. {
  621. if (world.npcList.contains(mob))
  622. {
  623. world.npcList.remove(mob);
  624. }
  625. return world.npcList.isEmpty();
  626. }
  627. private void spawnFlaggedNPCs(FETWorld world, int flag)
  628. {
  629. if (world.lock.tryLock())
  630. {
  631. try
  632. {
  633. for (FETSpawn spw : _spawnList.get(flag))
  634. {
  635. if (spw.isZone)
  636. {
  637. for (int i = 0; i < spw.count; i++)
  638. {
  639. if (_spawnZoneList.containsKey(spw.zone))
  640. {
  641. int[] point = _spawnZoneList.get(spw.zone).getRandomPoint();
  642. spawn(world, spw.npcId, point[0], point[1], GeoData.getInstance().getSpawnHeight(point[0], point[1], point[2], point[3]), getRandom(65535), spw.isNeededNextFlag);
  643. }
  644. else
  645. {
  646. _log.info("[Final Emperial Tomb] Missing zone: " + spw.zone);
  647. }
  648. }
  649. }
  650. else
  651. {
  652. spawn(world, spw.npcId, spw.x, spw.y, spw.z, spw.h, spw.isNeededNextFlag);
  653. }
  654. }
  655. }
  656. finally
  657. {
  658. world.lock.unlock();
  659. }
  660. }
  661. }
  662. protected boolean controlStatus(FETWorld world)
  663. {
  664. if (world.lock.tryLock())
  665. {
  666. try
  667. {
  668. if (debug)
  669. {
  670. _log.info("[Final Emperial Tomb] Starting " + world.getStatus() + ". status.");
  671. }
  672. world.npcList.clear();
  673. switch (world.getStatus())
  674. {
  675. case 0:
  676. spawnFlaggedNPCs(world, 0);
  677. break;
  678. case 1:
  679. for (int doorId : FIRST_ROUTE_DOORS)
  680. {
  681. openDoor(doorId, world.getInstanceId());
  682. }
  683. spawnFlaggedNPCs(world, world.getStatus());
  684. break;
  685. case 2:
  686. for (int doorId : SECOND_ROUTE_DOORS)
  687. {
  688. openDoor(doorId, world.getInstanceId());
  689. }
  690. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 0), 600000);
  691. break;
  692. case 3: // first morph
  693. if (world.songEffectTask != null)
  694. {
  695. world.songEffectTask.cancel(false);
  696. }
  697. world.songEffectTask = null;
  698. world.activeScarlet.setIsInvul(true);
  699. if (world.activeScarlet.isCastingNow())
  700. {
  701. world.activeScarlet.abortCast();
  702. }
  703. setInstanceTimeRestrictions(world);
  704. world.activeScarlet.doCast(FIRST_MORPH_SKILL.getSkill());
  705. ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(world, 2), 1500);
  706. break;
  707. case 4: // second morph
  708. world.isVideo = true;
  709. broadCastPacket(world, new MagicSkillCanceld(world.frintezza.getObjectId()));
  710. if (world.songEffectTask != null)
  711. {
  712. world.songEffectTask.cancel(false);
  713. }
  714. world.songEffectTask = null;
  715. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 23), 2000);
  716. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 24), 2100);
  717. break;
  718. case 5: // raid success
  719. world.isVideo = true;
  720. broadCastPacket(world, new MagicSkillCanceld(world.frintezza.getObjectId()));
  721. if (world.songTask != null)
  722. {
  723. world.songTask.cancel(true);
  724. }
  725. if (world.songEffectTask != null)
  726. {
  727. world.songEffectTask.cancel(false);
  728. }
  729. world.songTask = null;
  730. world.songEffectTask = null;
  731. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 33), 500);
  732. break;
  733. case 6: // open doors
  734. InstanceManager.getInstance().getInstance(world.getInstanceId()).setDuration(300000);
  735. for (int doorId : FIRST_ROOM_DOORS)
  736. {
  737. openDoor(doorId, world.getInstanceId());
  738. }
  739. for (int doorId : FIRST_ROUTE_DOORS)
  740. {
  741. openDoor(doorId, world.getInstanceId());
  742. }
  743. for (int doorId : SECOND_ROUTE_DOORS)
  744. {
  745. openDoor(doorId, world.getInstanceId());
  746. }
  747. for (int doorId : SECOND_ROOM_DOORS)
  748. {
  749. closeDoor(doorId, world.getInstanceId());
  750. }
  751. break;
  752. }
  753. world.incStatus();
  754. return true;
  755. }
  756. finally
  757. {
  758. world.lock.unlock();
  759. }
  760. }
  761. return false;
  762. }
  763. protected void spawn(FETWorld world, int npcId, int x, int y, int z, int h, boolean addToKillTable)
  764. {
  765. L2Npc npc = addSpawn(npcId, x, y, z, h, false, 0, false, world.getInstanceId());
  766. if (addToKillTable)
  767. {
  768. world.npcList.add(npc);
  769. }
  770. npc.setIsNoRndWalk(true);
  771. if (npc.isInstanceTypes(InstanceType.L2Attackable))
  772. {
  773. ((L2Attackable) npc).setSeeThroughSilentMove(true);
  774. }
  775. if (Util.contains(AI_DISABLED_MOBS, npcId))
  776. {
  777. npc.disableCoreAI(true);
  778. }
  779. if (npcId == DARK_CHOIR_PLAYER)
  780. {
  781. world.darkChoirPlayerCount++;
  782. }
  783. }
  784. private class DemonSpawnTask implements Runnable
  785. {
  786. private final FETWorld _world;
  787. DemonSpawnTask(FETWorld world)
  788. {
  789. _world = world;
  790. }
  791. @Override
  792. public void run()
  793. {
  794. if ((InstanceManager.getInstance().getWorld(_world.getInstanceId()) != _world) || _world.portraits.isEmpty())
  795. {
  796. if (debug)
  797. {
  798. _log.info("[Final Emperial Tomb] Instance is deleted or all Portraits is killed.");
  799. }
  800. return;
  801. }
  802. for (int i : _world.portraits.values())
  803. {
  804. if (_world.demons.size() > MAX_DEMONS)
  805. {
  806. break;
  807. }
  808. 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());
  809. updateKnownList(_world, demon);
  810. _world.demons.add(demon);
  811. }
  812. ThreadPoolManager.getInstance().scheduleGeneral(new DemonSpawnTask(_world), TIME_BETWEEN_DEMON_SPAWNS);
  813. }
  814. }
  815. private class SoulBreakingArrow implements Runnable
  816. {
  817. private final L2Npc _npc;
  818. protected SoulBreakingArrow(L2Npc npc)
  819. {
  820. _npc = npc;
  821. }
  822. @Override
  823. public void run()
  824. {
  825. _npc.setScriptValue(0);
  826. }
  827. }
  828. private class SongTask implements Runnable
  829. {
  830. private final FETWorld _world;
  831. private final int _status;
  832. SongTask(FETWorld world, int status)
  833. {
  834. _world = world;
  835. _status = status;
  836. }
  837. @Override
  838. public void run()
  839. {
  840. if (InstanceManager.getInstance().getWorld(_world.getInstanceId()) != _world)
  841. {
  842. return;
  843. }
  844. switch (_status)
  845. {
  846. case 0: // new song play
  847. if (_world.isVideo)
  848. {
  849. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), 1000);
  850. }
  851. else if ((_world.frintezza != null) && !_world.frintezza.isDead())
  852. {
  853. if (_world.frintezza.getScriptValue() != 1)
  854. {
  855. int rnd = getRandom(100);
  856. for (FrintezzaSong element : FRINTEZZASONGLIST)
  857. {
  858. if (rnd < element.chance)
  859. {
  860. _world.OnSong = element;
  861. broadCastPacket(_world, new ExShowScreenMessage(2, -1, 2, 0, 0, 0, 0, true, 4000, false, null, element.songName, null));
  862. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, element.skill.getSkillId(), element.skill.getSkillLvl(), element.skill.getSkill().getHitTime(), 0));
  863. _world.songEffectTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 1), element.skill.getSkill().getHitTime() - 10000);
  864. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), element.skill.getSkill().getHitTime());
  865. break;
  866. }
  867. }
  868. }
  869. else
  870. {
  871. ThreadPoolManager.getInstance().scheduleGeneral(new SoulBreakingArrow(_world.frintezza), 35000);
  872. }
  873. }
  874. break;
  875. case 1: // Frintezza song effect
  876. _world.songEffectTask = null;
  877. L2Skill skill = _world.OnSong.effectSkill.getSkill();
  878. if (skill == null)
  879. {
  880. return;
  881. }
  882. if ((_world.frintezza != null) && !_world.frintezza.isDead() && (_world.activeScarlet != null) && !_world.activeScarlet.isDead())
  883. {
  884. List<L2Character> targetList = new FastList<>();
  885. if (skill.hasEffectType(L2EffectType.STUN) || skill.isDebuff())
  886. {
  887. for (int objId : _world.getAllowed())
  888. {
  889. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  890. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  891. {
  892. if (!player.isDead())
  893. {
  894. targetList.add(player);
  895. }
  896. if (player.hasSummon() && !player.getSummon().isDead())
  897. {
  898. targetList.add(player.getSummon());
  899. }
  900. }
  901. }
  902. }
  903. else
  904. {
  905. targetList.add(_world.activeScarlet);
  906. }
  907. if (targetList.size() > 0)
  908. {
  909. _world.frintezza.doCast(skill, targetList.get(0), targetList.toArray(new L2Character[targetList.size()]));
  910. }
  911. }
  912. break;
  913. case 2: // finish morph
  914. _world.activeScarlet.setRHandId(SECOND_SCARLET_WEAPON);
  915. _world.activeScarlet.setIsInvul(false);
  916. break;
  917. }
  918. }
  919. }
  920. private class IntroTask implements Runnable
  921. {
  922. private final FETWorld _world;
  923. private final int _status;
  924. IntroTask(FETWorld world, int status)
  925. {
  926. _world = world;
  927. _status = status;
  928. }
  929. @Override
  930. public void run()
  931. {
  932. switch (_status)
  933. {
  934. case 0:
  935. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 1), 27000);
  936. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 2), 30000);
  937. broadCastPacket(_world, new Earthquake(-87784, -155083, -9087, 45, 27));
  938. break;
  939. case 1:
  940. for (int doorId : FIRST_ROOM_DOORS)
  941. {
  942. closeDoor(doorId, _world.getInstanceId());
  943. }
  944. for (int doorId : FIRST_ROUTE_DOORS)
  945. {
  946. closeDoor(doorId, _world.getInstanceId());
  947. }
  948. for (int doorId : SECOND_ROOM_DOORS)
  949. {
  950. closeDoor(doorId, _world.getInstanceId());
  951. }
  952. for (int doorId : SECOND_ROUTE_DOORS)
  953. {
  954. closeDoor(doorId, _world.getInstanceId());
  955. }
  956. addSpawn(29061, -87904, -141296, -9168, 0, false, 0, false, _world.getInstanceId());
  957. break;
  958. case 2:
  959. _world.frintezzaDummy = addSpawn(29052, -87784, -155083, -9087, 16048, false, 0, false, _world.getInstanceId());
  960. _world.frintezzaDummy.setIsInvul(true);
  961. _world.frintezzaDummy.setIsImmobilized(true);
  962. _world.overheadDummy = addSpawn(29052, -87784, -153298, -9175, 16384, false, 0, false, _world.getInstanceId());
  963. _world.overheadDummy.setIsInvul(true);
  964. _world.overheadDummy.setIsImmobilized(true);
  965. _world.overheadDummy.setCollisionHeight(600);
  966. broadCastPacket(_world, new NpcInfo(_world.overheadDummy, null));
  967. _world.portraitDummy1 = addSpawn(29052, -89566, -153168, -9165, 16048, false, 0, false, _world.getInstanceId());
  968. _world.portraitDummy1.setIsImmobilized(true);
  969. _world.portraitDummy1.setIsInvul(true);
  970. _world.portraitDummy3 = addSpawn(29052, -86004, -153168, -9165, 16048, false, 0, false, _world.getInstanceId());
  971. _world.portraitDummy3.setIsImmobilized(true);
  972. _world.portraitDummy3.setIsInvul(true);
  973. _world.scarletDummy = addSpawn(29053, -87784, -153298, -9175, 16384, false, 0, false, _world.getInstanceId());
  974. _world.scarletDummy.setIsInvul(true);
  975. _world.scarletDummy.setIsImmobilized(true);
  976. stopPc();
  977. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 3), 1000);
  978. break;
  979. case 3:
  980. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy, 0, 75, -89, 0, 100, 0, 0, 1, 0, 0));
  981. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy, 0, 75, -89, 0, 100, 0, 0, 1, 0, 0));
  982. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy, 300, 90, -10, 6500, 7000, 0, 0, 1, 0, 0));
  983. _world.frintezza = (L2GrandBossInstance) addSpawn(FRINTEZZA, -87780, -155086, -9080, 16384, false, 0, false, _world.getInstanceId());
  984. _world.frintezza.setIsImmobilized(true);
  985. _world.frintezza.setIsInvul(true);
  986. _world.frintezza.disableAllSkills();
  987. updateKnownList(_world, _world.frintezza);
  988. for (int[] element : PORTRAIT_SPAWNS)
  989. {
  990. L2MonsterInstance demon = (L2MonsterInstance) addSpawn(element[0] + 2, element[5], element[6], element[7], element[8], false, 0, false, _world.getInstanceId());
  991. demon.setIsImmobilized(true);
  992. demon.disableAllSkills();
  993. updateKnownList(_world, demon);
  994. _world.demons.add(demon);
  995. }
  996. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 4), 6500);
  997. break;
  998. case 4:
  999. broadCastPacket(_world, new SpecialCamera(_world.frintezzaDummy, 1800, 90, 8, 6500, 7000, 0, 0, 1, 0, 0));
  1000. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 5), 900);
  1001. break;
  1002. case 5:
  1003. broadCastPacket(_world, new SpecialCamera(_world.frintezzaDummy, 140, 90, 10, 2500, 4500, 0, 0, 1, 0, 0));
  1004. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 6), 4000);
  1005. break;
  1006. case 6:
  1007. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 40, 75, -10, 0, 1000, 0, 0, 1, 0, 0));
  1008. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 40, 75, -10, 0, 12000, 0, 0, 1, 0, 0));
  1009. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 7), 1350);
  1010. break;
  1011. case 7:
  1012. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 2));
  1013. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 8), 7000);
  1014. break;
  1015. case 8:
  1016. _world.frintezzaDummy.deleteMe();
  1017. _world.frintezzaDummy = null;
  1018. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 9), 1000);
  1019. break;
  1020. case 9:
  1021. broadCastPacket(_world, new SocialAction(_world.demons.get(1).getObjectId(), 1));
  1022. broadCastPacket(_world, new SocialAction(_world.demons.get(2).getObjectId(), 1));
  1023. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 10), 400);
  1024. break;
  1025. case 10:
  1026. broadCastPacket(_world, new SocialAction(_world.demons.get(0).getObjectId(), 1));
  1027. broadCastPacket(_world, new SocialAction(_world.demons.get(3).getObjectId(), 1));
  1028. 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);
  1029. 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);
  1030. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 11), 2000);
  1031. break;
  1032. case 11:
  1033. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 240, 90, 0, 0, 1000, 0, 0, 1, 0, 0));
  1034. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 240, 90, 25, 5500, 10000, 0, 0, 1, 0, 0));
  1035. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 3));
  1036. _world.portraitDummy1.deleteMe();
  1037. _world.portraitDummy3.deleteMe();
  1038. _world.portraitDummy1 = null;
  1039. _world.portraitDummy3 = null;
  1040. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 12), 4500);
  1041. break;
  1042. case 12:
  1043. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 100, 195, 35, 0, 10000, 0, 0, 1, 0, 0));
  1044. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 13), 700);
  1045. break;
  1046. case 13:
  1047. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 100, 195, 35, 0, 10000, 0, 0, 1, 0, 0));
  1048. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 14), 1300);
  1049. break;
  1050. case 14:
  1051. broadCastPacket(_world, new ExShowScreenMessage(NpcStringId.MOURNFUL_CHORALE_PRELUDE, 2, 5000));
  1052. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 120, 180, 45, 1500, 10000, 0, 0, 1, 0, 0));
  1053. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, 5006, 1, 34000, 0));
  1054. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 15), 1500);
  1055. break;
  1056. case 15:
  1057. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 520, 135, 45, 8000, 10000, 0, 0, 1, 0, 0));
  1058. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 16), 7500);
  1059. break;
  1060. case 16:
  1061. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 1500, 110, 25, 10000, 13000, 0, 0, 1, 0, 0));
  1062. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 17), 9500);
  1063. break;
  1064. case 17:
  1065. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy, 930, 160, -20, 0, 1000, 0, 0, 1, 0, 0));
  1066. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy, 600, 180, -25, 0, 10000, 0, 0, 1, 0, 0));
  1067. broadCastPacket(_world, new MagicSkillUse(_world.scarletDummy, _world.overheadDummy, 5004, 1, 5800, 0));
  1068. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 18), 5000);
  1069. break;
  1070. case 18:
  1071. _world.activeScarlet = (L2GrandBossInstance) addSpawn(29046, -87789, -153295, -9176, 16384, false, 0, false, _world.getInstanceId());
  1072. _world.activeScarlet.setRHandId(FIRST_SCARLET_WEAPON);
  1073. _world.activeScarlet.setIsInvul(true);
  1074. _world.activeScarlet.setIsImmobilized(true);
  1075. _world.activeScarlet.disableAllSkills();
  1076. updateKnownList(_world, _world.activeScarlet);
  1077. broadCastPacket(_world, new SocialAction(_world.activeScarlet.getObjectId(), 3));
  1078. broadCastPacket(_world, new SpecialCamera(_world.scarletDummy, 800, 180, 10, 1000, 10000, 0, 0, 1, 0, 0));
  1079. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 19), 2100);
  1080. break;
  1081. case 19:
  1082. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 300, 60, 8, 0, 10000, 0, 0, 1, 0, 0));
  1083. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 20), 2000);
  1084. break;
  1085. case 20:
  1086. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 500, 90, 10, 3000, 5000, 0, 0, 1, 0, 0));
  1087. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), 100);
  1088. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 21), 3000);
  1089. break;
  1090. case 21:
  1091. for (int i = 0; i < PORTRAIT_SPAWNS.length; i++)
  1092. {
  1093. 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());
  1094. updateKnownList(_world, portrait);
  1095. _world.portraits.put(portrait, i);
  1096. }
  1097. _world.overheadDummy.deleteMe();
  1098. _world.scarletDummy.deleteMe();
  1099. _world.overheadDummy = null;
  1100. _world.scarletDummy = null;
  1101. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 22), 2000);
  1102. break;
  1103. case 22:
  1104. for (L2MonsterInstance demon : _world.demons)
  1105. {
  1106. demon.setIsImmobilized(false);
  1107. demon.enableAllSkills();
  1108. }
  1109. _world.activeScarlet.setIsInvul(false);
  1110. _world.activeScarlet.setIsImmobilized(false);
  1111. _world.activeScarlet.enableAllSkills();
  1112. _world.activeScarlet.setRunning();
  1113. _world.activeScarlet.doCast(INTRO_SKILL.getSkill());
  1114. _world.frintezza.enableAllSkills();
  1115. _world.frintezza.disableCoreAI(true);
  1116. _world.frintezza.setIsMortal(false);
  1117. startPc();
  1118. ThreadPoolManager.getInstance().scheduleGeneral(new DemonSpawnTask(_world), TIME_BETWEEN_DEMON_SPAWNS);
  1119. break;
  1120. case 23:
  1121. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 4));
  1122. break;
  1123. case 24:
  1124. stopPc();
  1125. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 250, 120, 15, 0, 1000, 0, 0, 1, 0, 0));
  1126. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 250, 120, 15, 0, 10000, 0, 0, 1, 0, 0));
  1127. _world.activeScarlet.abortAttack();
  1128. _world.activeScarlet.abortCast();
  1129. _world.activeScarlet.setIsInvul(true);
  1130. _world.activeScarlet.setIsImmobilized(true);
  1131. _world.activeScarlet.disableAllSkills();
  1132. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 25), 7000);
  1133. break;
  1134. case 25:
  1135. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, 5006, 1, 34000, 0));
  1136. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 500, 70, 15, 3000, 10000, 0, 0, 1, 0, 0));
  1137. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 26), 3000);
  1138. break;
  1139. case 26:
  1140. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 2500, 90, 12, 6000, 10000, 0, 0, 1, 0, 0));
  1141. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 27), 3000);
  1142. break;
  1143. case 27:
  1144. _world.scarlet_x = _world.activeScarlet.getX();
  1145. _world.scarlet_y = _world.activeScarlet.getY();
  1146. _world.scarlet_z = _world.activeScarlet.getZ();
  1147. _world.scarlet_h = _world.activeScarlet.getHeading();
  1148. if (_world.scarlet_h < 32768)
  1149. {
  1150. _world.scarlet_a = Math.abs(180 - (int) (_world.scarlet_h / 182.044444444));
  1151. }
  1152. else
  1153. {
  1154. _world.scarlet_a = Math.abs(540 - (int) (_world.scarlet_h / 182.044444444));
  1155. }
  1156. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 250, _world.scarlet_a, 12, 0, 1000, 0, 0, 1, 0, 0));
  1157. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 250, _world.scarlet_a, 12, 0, 10000, 0, 0, 1, 0, 0));
  1158. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 28), 500);
  1159. break;
  1160. case 28:
  1161. _world.activeScarlet.doDie(_world.activeScarlet);
  1162. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 450, _world.scarlet_a, 14, 8000, 8000, 0, 0, 1, 0, 0));
  1163. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 29), 6250);
  1164. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 30), 7200);
  1165. break;
  1166. case 29:
  1167. _world.activeScarlet.deleteMe();
  1168. _world.activeScarlet = null;
  1169. break;
  1170. case 30:
  1171. _world.activeScarlet = (L2GrandBossInstance) addSpawn(SCARLET2, _world.scarlet_x, _world.scarlet_y, _world.scarlet_z, _world.scarlet_h, false, 0, false, _world.getInstanceId());
  1172. _world.activeScarlet.setIsInvul(true);
  1173. _world.activeScarlet.setIsImmobilized(true);
  1174. _world.activeScarlet.disableAllSkills();
  1175. updateKnownList(_world, _world.activeScarlet);
  1176. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 450, _world.scarlet_a, 12, 500, 14000, 0, 0, 1, 0, 0));
  1177. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 31), 8100);
  1178. break;
  1179. case 31:
  1180. broadCastPacket(_world, new SocialAction(_world.activeScarlet.getObjectId(), 2));
  1181. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 32), 9000);
  1182. break;
  1183. case 32:
  1184. startPc();
  1185. _world.activeScarlet.setIsInvul(false);
  1186. _world.activeScarlet.setIsImmobilized(false);
  1187. _world.activeScarlet.enableAllSkills();
  1188. _world.isVideo = false;
  1189. break;
  1190. case 33:
  1191. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 300, _world.scarlet_a - 180, 5, 0, 7000, 0, 0, 1, 0, 0));
  1192. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet, 200, _world.scarlet_a, 85, 4000, 10000, 0, 0, 1, 0, 0));
  1193. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 34), 7400);
  1194. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 35), 7500);
  1195. break;
  1196. case 34:
  1197. _world.frintezza.doDie(_world.frintezza);
  1198. break;
  1199. case 35:
  1200. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 100, 120, 5, 0, 7000, 0, 0, 1, 0, 0));
  1201. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 100, 90, 5, 5000, 15000, 0, 0, 1, 0, 0));
  1202. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 36), 7000);
  1203. break;
  1204. case 36:
  1205. broadCastPacket(_world, new SpecialCamera(_world.frintezza, 900, 90, 25, 7000, 10000, 0, 0, 1, 0, 0));
  1206. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 37), 9000);
  1207. break;
  1208. case 37:
  1209. controlStatus(_world);
  1210. _world.isVideo = false;
  1211. startPc();
  1212. break;
  1213. }
  1214. }
  1215. private void stopPc()
  1216. {
  1217. for (int objId : _world.getAllowed())
  1218. {
  1219. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1220. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  1221. {
  1222. player.abortAttack();
  1223. player.abortCast();
  1224. player.disableAllSkills();
  1225. player.setTarget(null);
  1226. player.stopMove(null);
  1227. player.setIsImmobilized(true);
  1228. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1229. }
  1230. }
  1231. }
  1232. private void startPc()
  1233. {
  1234. for (int objId : _world.getAllowed())
  1235. {
  1236. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1237. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  1238. {
  1239. player.enableAllSkills();
  1240. player.setIsImmobilized(false);
  1241. }
  1242. }
  1243. }
  1244. private void sendPacketX(L2GameServerPacket packet1, L2GameServerPacket packet2, int x)
  1245. {
  1246. for (int objId : _world.getAllowed())
  1247. {
  1248. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1249. if ((player != null) && player.isOnline() && (player.getInstanceId() == _world.getInstanceId()))
  1250. {
  1251. if (player.getX() < x)
  1252. {
  1253. player.sendPacket(packet1);
  1254. }
  1255. else
  1256. {
  1257. player.sendPacket(packet2);
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. private class StatusTask implements Runnable
  1264. {
  1265. private final FETWorld _world;
  1266. private final int _status;
  1267. StatusTask(FETWorld world, int status)
  1268. {
  1269. _world = world;
  1270. _status = status;
  1271. }
  1272. @Override
  1273. public void run()
  1274. {
  1275. if (InstanceManager.getInstance().getWorld(_world.getInstanceId()) != _world)
  1276. {
  1277. return;
  1278. }
  1279. switch (_status)
  1280. {
  1281. case 0:
  1282. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(_world, 1), 2000);
  1283. for (int doorId : FIRST_ROOM_DOORS)
  1284. {
  1285. openDoor(doorId, _world.getInstanceId());
  1286. }
  1287. break;
  1288. case 1:
  1289. addAggroToMobs();
  1290. break;
  1291. case 2:
  1292. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(_world, 3), 100);
  1293. for (int doorId : SECOND_ROOM_DOORS)
  1294. {
  1295. openDoor(doorId, _world.getInstanceId());
  1296. }
  1297. break;
  1298. case 3:
  1299. addAggroToMobs();
  1300. break;
  1301. case 4:
  1302. controlStatus(_world);
  1303. break;
  1304. }
  1305. }
  1306. private void addAggroToMobs()
  1307. {
  1308. L2PcInstance target = L2World.getInstance().getPlayer(_world.getAllowed().get(getRandom(_world.getAllowed().size())));
  1309. if ((target == null) || (target.getInstanceId() != _world.getInstanceId()) || target.isDead() || target.isFakeDeath())
  1310. {
  1311. for (int objId : _world.getAllowed())
  1312. {
  1313. target = L2World.getInstance().getPlayer(objId);
  1314. if ((target != null) && (target.getInstanceId() == _world.getInstanceId()) && !target.isDead() && !target.isFakeDeath())
  1315. {
  1316. break;
  1317. }
  1318. target = null;
  1319. }
  1320. }
  1321. for (L2Npc mob : _world.npcList)
  1322. {
  1323. mob.setRunning();
  1324. if (target != null)
  1325. {
  1326. ((L2MonsterInstance) mob).addDamageHate(target, 0, 500);
  1327. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  1328. }
  1329. else
  1330. {
  1331. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, MOVE_TO_CENTER);
  1332. }
  1333. }
  1334. }
  1335. }
  1336. protected void setInstanceTimeRestrictions(FETWorld world)
  1337. {
  1338. Calendar reenter = Calendar.getInstance();
  1339. reenter.set(Calendar.MINUTE, RESET_MIN);
  1340. reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
  1341. // if time is >= RESET_HOUR - roll to the next day
  1342. if (reenter.getTimeInMillis() <= System.currentTimeMillis())
  1343. {
  1344. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1345. }
  1346. if (reenter.get(Calendar.DAY_OF_WEEK) <= RESET_DAY_1)
  1347. {
  1348. while (reenter.get(Calendar.DAY_OF_WEEK) != RESET_DAY_1)
  1349. {
  1350. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1351. }
  1352. }
  1353. else
  1354. {
  1355. while (reenter.get(Calendar.DAY_OF_WEEK) != RESET_DAY_2)
  1356. {
  1357. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1358. }
  1359. }
  1360. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
  1361. sm.addInstanceName(INSTANCEID);
  1362. // set instance reenter time for all allowed players
  1363. for (int objectId : world.getAllowed())
  1364. {
  1365. L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  1366. InstanceManager.getInstance().setInstanceTime(objectId, INSTANCEID, reenter.getTimeInMillis());
  1367. if ((player != null) && player.isOnline())
  1368. {
  1369. player.sendPacket(sm);
  1370. }
  1371. }
  1372. }
  1373. protected void broadCastPacket(FETWorld world, L2GameServerPacket packet)
  1374. {
  1375. for (int objId : world.getAllowed())
  1376. {
  1377. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1378. if ((player != null) && player.isOnline() && (player.getInstanceId() == world.getInstanceId()))
  1379. {
  1380. player.sendPacket(packet);
  1381. }
  1382. }
  1383. }
  1384. protected void updateKnownList(FETWorld world, L2Npc npc)
  1385. {
  1386. Map<Integer, L2PcInstance> npcKnownPlayers = npc.getKnownList().getKnownPlayers();
  1387. for (int objId : world.getAllowed())
  1388. {
  1389. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1390. if ((player != null) && player.isOnline() && (player.getInstanceId() == world.getInstanceId()))
  1391. {
  1392. npcKnownPlayers.put(player.getObjectId(), player);
  1393. }
  1394. }
  1395. }
  1396. @Override
  1397. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, L2Skill skill)
  1398. {
  1399. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1400. if (tmpworld instanceof FETWorld)
  1401. {
  1402. final FETWorld world = (FETWorld) tmpworld;
  1403. if ((npc.getId() == SCARLET1) && (world.getStatus() == 3) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.80)))
  1404. {
  1405. controlStatus(world);
  1406. }
  1407. else if ((npc.getId() == SCARLET1) && (world.getStatus() == 4) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.20)))
  1408. {
  1409. controlStatus(world);
  1410. }
  1411. if (skill != null)
  1412. {
  1413. // When Dewdrop of Destruction is used on Portraits they suicide.
  1414. if (Util.contains(PORTRAITS, npc.getId()) && (skill.getId() == DEWDROP_OF_DESTRUCTION_SKILL_ID))
  1415. {
  1416. npc.doDie(attacker);
  1417. }
  1418. else if ((npc.getId() == FRINTEZZA) && (skill.getId() == SOUL_BREAKING_ARROW_SKILL_ID))
  1419. {
  1420. npc.setScriptValue(1);
  1421. npc.setTarget(null);
  1422. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1423. }
  1424. }
  1425. }
  1426. return null;
  1427. }
  1428. @Override
  1429. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  1430. {
  1431. if (skill.isSuicideAttack())
  1432. {
  1433. return onKill(npc, null, false);
  1434. }
  1435. return super.onSpellFinished(npc, player, skill);
  1436. }
  1437. @Override
  1438. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  1439. {
  1440. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1441. if (tmpworld instanceof FETWorld)
  1442. {
  1443. FETWorld world = (FETWorld) tmpworld;
  1444. if (npc.getId() == HALL_ALARM)
  1445. {
  1446. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(world, 0), 2000);
  1447. if (debug)
  1448. {
  1449. _log.info("[Final Emperial Tomb] Hall alarm is disabled, doors will open!");
  1450. }
  1451. }
  1452. else if (npc.getId() == DARK_CHOIR_PLAYER)
  1453. {
  1454. world.darkChoirPlayerCount--;
  1455. if (world.darkChoirPlayerCount < 1)
  1456. {
  1457. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(world, 2), 2000);
  1458. if (debug)
  1459. {
  1460. _log.info("[Final Emperial Tomb] All Dark Choir Players are killed, doors will open!");
  1461. }
  1462. }
  1463. }
  1464. else if (npc.getId() == SCARLET2)
  1465. {
  1466. controlStatus(world);
  1467. }
  1468. else if (world.getStatus() <= 2)
  1469. {
  1470. if (npc.getId() == HALL_KEEPER_CAPTAIN)
  1471. {
  1472. if (getRandom(100) < 5)
  1473. {
  1474. npc.dropItem(player, DEWDROP_OF_DESTRUCTION_ITEM_ID, 1);
  1475. }
  1476. }
  1477. if (checkKillProgress(npc, world))
  1478. {
  1479. controlStatus(world);
  1480. }
  1481. }
  1482. else if (world.demons.contains(npc))
  1483. {
  1484. world.demons.remove(npc);
  1485. }
  1486. else if (world.portraits.containsKey(npc))
  1487. {
  1488. world.portraits.remove(npc);
  1489. }
  1490. }
  1491. return "";
  1492. }
  1493. @Override
  1494. public String onTalk(L2Npc npc, L2PcInstance player)
  1495. {
  1496. int npcId = npc.getId();
  1497. QuestState st = player.getQuestState(getName());
  1498. if (st == null)
  1499. {
  1500. st = newQuestState(player);
  1501. }
  1502. if (npcId == GUIDE)
  1503. {
  1504. enterInstance(player, "FinalEmperialTomb.xml", ENTER_TELEPORT);
  1505. }
  1506. else if (npc.getId() == CUBE)
  1507. {
  1508. int x = -87534 + getRandom(500);
  1509. int y = -153048 + getRandom(500);
  1510. player.teleToLocation(x, y, -9165);
  1511. return null;
  1512. }
  1513. return "";
  1514. }
  1515. public static void main(String[] args)
  1516. {
  1517. new FinalEmperialTomb();
  1518. }
  1519. }