FinalEmperialTomb.java 50 KB

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