FinalEmperialTomb.java 50 KB

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