FinalEmperialTomb.java 51 KB

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