FinalEmperialTomb.java 52 KB

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