FinalEmperialTomb.java 53 KB

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