FinalEmperialTomb.java 51 KB

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