FinalEmperialTomb.java 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package instances.FinalEmperialTomb;
  16. import java.io.File;
  17. import java.util.Calendar;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.concurrent.ScheduledFuture;
  22. import java.util.concurrent.locks.Lock;
  23. import java.util.concurrent.locks.ReentrantLock;
  24. import java.util.logging.Level;
  25. import javax.xml.parsers.DocumentBuilderFactory;
  26. import javolution.util.FastList;
  27. import javolution.util.FastMap;
  28. import org.w3c.dom.Document;
  29. import org.w3c.dom.NamedNodeMap;
  30. import org.w3c.dom.Node;
  31. import com.l2jserver.Config;
  32. import com.l2jserver.gameserver.GeoData;
  33. import com.l2jserver.gameserver.ThreadPoolManager;
  34. import com.l2jserver.gameserver.ai.CtrlIntention;
  35. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  36. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  37. import com.l2jserver.gameserver.model.L2CharPosition;
  38. import com.l2jserver.gameserver.model.L2CommandChannel;
  39. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  40. import com.l2jserver.gameserver.model.L2Party;
  41. import com.l2jserver.gameserver.model.L2Territory;
  42. import com.l2jserver.gameserver.model.L2World;
  43. import com.l2jserver.gameserver.model.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:<br>
  69. * Test when Frintezza song use 5008 effect skill.<br>
  70. * Test deeply Scarlet van Halisha's AI.<br>
  71. * Use correct Song names.<br>
  72. * Use proper zone spawn system.
  73. * @author Gigiikun
  74. */
  75. public class FinalEmperialTomb extends Quest
  76. {
  77. private class FETWorld extends InstanceWorld
  78. {
  79. public Lock lock = new ReentrantLock();
  80. public FastList<L2Npc> npcList = new FastList<>();
  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<>();
  94. public Map<L2MonsterInstance, Integer> portraits = new FastMap<>();
  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. npcList.shared();
  103. }
  104. }
  105. protected 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 Map<Integer, L2Territory> _spawnZoneList = new HashMap<>();
  137. private final Map<Integer, List<FETSpawn>> _spawnList = new HashMap<>();
  138. private final List<Integer> _mustKillMobsId = new FastList<>();
  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. protected static final SkillHolder INTRO_SKILL = new SkillHolder(5004,1);
  156. private static final SkillHolder FIRST_MORPH_SKILL = new SkillHolder(5017,1);
  157. protected 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. protected static final int[] FIRST_ROOM_DOORS =
  167. {
  168. 17130051, 17130052, 17130053, 17130054, 17130055,
  169. 17130056, 17130057, 17130058
  170. };
  171. protected static final int[] SECOND_ROOM_DOORS =
  172. {
  173. 17130061, 17130062, 17130063, 17130064, 17130065,
  174. 17130066, 17130067, 17130068, 17130069, 17130070
  175. };
  176. protected static final int[] FIRST_ROUTE_DOORS = { 17130042, 17130043 };
  177. protected static final int[] SECOND_ROUTE_DOORS = { 17130045, 17130046 };
  178. protected 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. protected 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/spawnZones/final_emperial_tomb.xml");
  204. if (!file.exists())
  205. {
  206. _log.severe("[Final Emperial Tomb] Missing final_emperial_tomb.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.containsKey(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 final_emperial_tomb.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(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
  387. return false;
  388. }
  389. L2CommandChannel channel = player.getParty().getCommandChannel();
  390. if (channel == null)
  391. {
  392. player.sendPacket(SystemMessageId.NOT_IN_COMMAND_CHANNEL_CANT_ENTER);
  393. return false;
  394. }
  395. else if (channel.getLeader() != player)
  396. {
  397. player.sendPacket(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(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.broadcastPacket(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.broadcastPacket(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.broadcastPacket(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(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. if (!checkConditions(player))
  462. return 0;
  463. if (!player.isGM() && !player.destroyItemByItemId("QUEST", 8073, 1, player, true))
  464. return 0;
  465. instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  466. //Instance ins = InstanceManager.getInstance().getInstance(instanceId);
  467. //ins.setSpawnLoc(new int[]{player.getX(),player.getY(),player.getZ()});
  468. world = new FETWorld();
  469. world.instanceId = instanceId;
  470. world.status = 0;
  471. InstanceManager.getInstance().addWorld(world);
  472. controlStatus((FETWorld) world);
  473. _log.info("Final Emperial Tomb started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  474. // teleport players
  475. if (player.getParty() == null || player.getParty().getCommandChannel() == null)
  476. {
  477. world.allowed.add(player.getObjectId());
  478. teleportPlayer(player, coords, instanceId);
  479. }
  480. else
  481. {
  482. for (L2PcInstance channelMember : player.getParty().getCommandChannel().getMembers())
  483. {
  484. world.allowed.add(channelMember.getObjectId());
  485. teleportPlayer(channelMember, coords, instanceId);
  486. }
  487. }
  488. return instanceId;
  489. }
  490. protected boolean checkKillProgress(L2Npc mob, FETWorld world)
  491. {
  492. if (world.npcList.contains(mob))
  493. world.npcList.remove(mob);
  494. return world.npcList.isEmpty();
  495. }
  496. private void spawnFlaggedNPCs(FETWorld world, int flag)
  497. {
  498. if (world.lock.tryLock())
  499. {
  500. try
  501. {
  502. for (FETSpawn spw : _spawnList.get(flag))
  503. {
  504. if (spw.isZone)
  505. {
  506. for (int i = 0; i < spw.count; i++)
  507. {
  508. if (_spawnZoneList.containsKey(spw.zone))
  509. {
  510. int[] point = _spawnZoneList.get(spw.zone).getRandomPoint();
  511. spawn(world, spw.npcId, point[0], point[1], GeoData.getInstance().getSpawnHeight(point[0], point[1], point[2], point[3], null), getRandom(65535), spw.isNeededNextFlag);
  512. }
  513. else
  514. _log.info("[Final Emperial Tomb] Missing zone: " + spw.zone);
  515. }
  516. }
  517. else
  518. spawn(world, spw.npcId, spw.x, spw.y, spw.z, spw.h, spw.isNeededNextFlag);
  519. }
  520. }
  521. finally
  522. {
  523. world.lock.unlock();
  524. }
  525. }
  526. }
  527. protected boolean controlStatus(FETWorld world)
  528. {
  529. if (world.lock.tryLock())
  530. {
  531. try
  532. {
  533. if (debug)
  534. _log.info("[Final Emperial Tomb] Starting " + world.status + ". status.");
  535. world.npcList.clear();
  536. switch (world.status)
  537. {
  538. case 0:
  539. spawnFlaggedNPCs(world, 0);
  540. break;
  541. case 1:
  542. for (int doorId : FIRST_ROUTE_DOORS)
  543. openDoor(doorId, world.instanceId);
  544. spawnFlaggedNPCs(world, world.status);
  545. break;
  546. case 2:
  547. for (int doorId : SECOND_ROUTE_DOORS)
  548. openDoor(doorId, world.instanceId);
  549. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 0), 600000);
  550. break;
  551. case 3: // first morph
  552. if (world.songEffectTask != null)
  553. world.songEffectTask.cancel(false);
  554. world.songEffectTask = null;
  555. world.activeScarlet.setIsInvul(true);
  556. if (world.activeScarlet.isCastingNow())
  557. world.activeScarlet.abortCast();
  558. setInstanceTimeRestrictions(world);
  559. world.activeScarlet.doCast(FIRST_MORPH_SKILL.getSkill());
  560. ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(world, 2), 1500);
  561. break;
  562. case 4: // second morph
  563. world.isVideo = true;
  564. broadCastPacket(world, new MagicSkillCanceld(world.frintezza.getObjectId()));
  565. if (world.songEffectTask != null)
  566. world.songEffectTask.cancel(false);
  567. world.songEffectTask = null;
  568. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 23), 2000);
  569. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 24), 2100);
  570. break;
  571. case 5: // raid success
  572. world.isVideo = true;
  573. broadCastPacket(world, new MagicSkillCanceld(world.frintezza.getObjectId()));
  574. if (world.songTask != null)
  575. world.songTask.cancel(true);
  576. if (world.songEffectTask != null)
  577. world.songEffectTask.cancel(false);
  578. world.songTask = null;
  579. world.songEffectTask = null;
  580. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(world, 33), 500);
  581. break;
  582. case 6: // open doors
  583. InstanceManager.getInstance().getInstance(world.instanceId).setDuration(300000);
  584. for (int doorId : FIRST_ROOM_DOORS)
  585. openDoor(doorId, world.instanceId);
  586. for (int doorId : FIRST_ROUTE_DOORS)
  587. openDoor(doorId, world.instanceId);
  588. for (int doorId : SECOND_ROUTE_DOORS)
  589. openDoor(doorId, world.instanceId);
  590. for (int doorId : SECOND_ROOM_DOORS)
  591. closeDoor(doorId, world.instanceId);
  592. break;
  593. }
  594. world.status++;
  595. return true;
  596. }
  597. finally
  598. {
  599. world.lock.unlock();
  600. }
  601. }
  602. return false;
  603. }
  604. protected void spawn(FETWorld world, int npcId, int x, int y, int z, int h, boolean addToKillTable)
  605. {
  606. L2Npc npc = addSpawn(npcId, x, y, z, h, false, 0, false, world.instanceId);
  607. if (addToKillTable)
  608. world.npcList.add(npc);
  609. npc.setIsNoRndWalk(true);
  610. if (npc.isInstanceType(InstanceType.L2Attackable))
  611. ((L2Attackable) npc).setSeeThroughSilentMove(true);
  612. if (Util.contains(AI_DISABLED_MOBS, npcId))
  613. npc.disableCoreAI(true);
  614. if (npcId == DARK_CHOIR_PLAYER)
  615. world.darkChoirPlayerCount++;
  616. }
  617. private class DemonSpawnTask implements Runnable
  618. {
  619. private final FETWorld _world;
  620. DemonSpawnTask(FETWorld world)
  621. {
  622. _world = world;
  623. }
  624. @Override
  625. public void run()
  626. {
  627. if (InstanceManager.getInstance().getWorld(_world.instanceId) != _world || _world.portraits.isEmpty())
  628. {
  629. if (debug)
  630. _log.info("[Final Emperial Tomb] Instance is deleted or all Portraits is killed.");
  631. return;
  632. }
  633. for (int i : _world.portraits.values())
  634. {
  635. if (_world.demons.size() > MAX_DEMONS)
  636. break;
  637. 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);
  638. updateKnownList(_world, demon);
  639. _world.demons.add(demon);
  640. }
  641. ThreadPoolManager.getInstance().scheduleGeneral(new DemonSpawnTask(_world), TIME_BETWEEN_DEMON_SPAWNS);
  642. }
  643. }
  644. private class SongTask implements Runnable
  645. {
  646. private final FETWorld _world;
  647. private final int _status;
  648. SongTask(FETWorld world, int status)
  649. {
  650. _world = world;
  651. _status = status;
  652. }
  653. @Override
  654. public void run()
  655. {
  656. if (InstanceManager.getInstance().getWorld(_world.instanceId) != _world)
  657. return;
  658. switch (_status)
  659. {
  660. case 0: // new song play
  661. if (_world.isVideo)
  662. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), 1000);
  663. else if (_world.frintezza != null && !_world.frintezza.isDead())
  664. {
  665. int rnd = getRandom(100);
  666. for (int i = 0; i < FRINTEZZASONGLIST.length; i++)
  667. {
  668. if (rnd < FRINTEZZASONGLIST[i].chance)
  669. {
  670. _world.OnSong = FRINTEZZASONGLIST[i];
  671. broadCastPacket(_world, new ExShowScreenMessage(FRINTEZZASONGLIST[i].songName, 2, 500));
  672. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, FRINTEZZASONGLIST[i].skill.getSkillId(), FRINTEZZASONGLIST[i].skill.getSkillLvl(), FRINTEZZASONGLIST[i].skill.getSkill().getHitTime(), 0));
  673. _world.songEffectTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 1), FRINTEZZASONGLIST[i].skill.getSkill().getHitTime() - 10000);
  674. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), FRINTEZZASONGLIST[i].skill.getSkill().getHitTime());
  675. break;
  676. }
  677. }
  678. }
  679. break;
  680. case 1: // Frintezza song effect
  681. _world.songEffectTask = null;
  682. L2Skill skill = _world.OnSong.effectSkill.getSkill();
  683. if (skill == null)
  684. return;
  685. if (_world.frintezza != null && !_world.frintezza.isDead() && _world.activeScarlet != null && !_world.activeScarlet.isDead())
  686. {
  687. List<L2Character> targetList = new FastList<>();
  688. if (skill.getSkillType() == L2SkillType.STUN || skill.getSkillType() == L2SkillType.DEBUFF)
  689. {
  690. for (int objId : _world.allowed)
  691. {
  692. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  693. if (player != null && player.isOnline() && player.getInstanceId() == _world.instanceId)
  694. {
  695. if (!player.isDead())
  696. targetList.add(player);
  697. if (player.getPet() != null && !player.getPet().isDead())
  698. targetList.add(player.getPet());
  699. }
  700. }
  701. }
  702. else
  703. targetList.add(_world.activeScarlet);
  704. if (targetList.size() > 0)
  705. _world.frintezza.doCast(skill, targetList.get(0), targetList.toArray(new L2Character[targetList.size()]));
  706. }
  707. break;
  708. case 2: // finish morph
  709. _world.activeScarlet.setRHandId(SECOND_SCARLET_WEAPON);
  710. _world.activeScarlet.setIsInvul(false);
  711. break;
  712. }
  713. }
  714. }
  715. private class IntroTask implements Runnable
  716. {
  717. private final FETWorld _world;
  718. private final int _status;
  719. IntroTask(FETWorld world, int status)
  720. {
  721. _world = world;
  722. _status = status;
  723. }
  724. @Override
  725. public void run()
  726. {
  727. switch (_status)
  728. {
  729. case 0:
  730. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 1), 27000);
  731. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 2), 30000);
  732. broadCastPacket(_world, new Earthquake(-87784, -155083, -9087, 45, 27));
  733. break;
  734. case 1:
  735. for (int doorId : FIRST_ROOM_DOORS)
  736. closeDoor(doorId, _world.instanceId);
  737. for (int doorId : FIRST_ROUTE_DOORS)
  738. closeDoor(doorId, _world.instanceId);
  739. for (int doorId : SECOND_ROOM_DOORS)
  740. closeDoor(doorId, _world.instanceId);
  741. for (int doorId : SECOND_ROUTE_DOORS)
  742. closeDoor(doorId, _world.instanceId);
  743. addSpawn(29061, -87904, -141296, -9168, 0, false, 0, false, _world.instanceId);
  744. break;
  745. case 2:
  746. _world.frintezzaDummy = addSpawn(29052, -87784, -155083, -9087, 16048, false, 0, false, _world.instanceId);
  747. _world.frintezzaDummy.setIsInvul(true);
  748. _world.frintezzaDummy.setIsImmobilized(true);
  749. _world.overheadDummy = addSpawn(29052, -87784, -153298, -9175, 16384, false, 0, false, _world.instanceId);
  750. _world.overheadDummy.setIsInvul(true);
  751. _world.overheadDummy.setIsImmobilized(true);
  752. _world.overheadDummy.setCollisionHeight(600);
  753. broadCastPacket(_world, new NpcInfo(_world.overheadDummy, null));
  754. _world.portraitDummy1 = addSpawn(29052, -89566, -153168, -9165, 16048, false, 0, false, _world.instanceId);
  755. _world.portraitDummy1.setIsImmobilized(true);
  756. _world.portraitDummy1.setIsInvul(true);
  757. _world.portraitDummy3 = addSpawn(29052, -86004, -153168, -9165, 16048, false, 0, false, _world.instanceId);
  758. _world.portraitDummy3.setIsImmobilized(true);
  759. _world.portraitDummy3.setIsInvul(true);
  760. _world.scarletDummy = addSpawn(29053, -87784, -153298, -9175, 16384, false, 0, false, _world.instanceId);
  761. _world.scarletDummy.setIsInvul(true);
  762. _world.scarletDummy.setIsImmobilized(true);
  763. stopPc();
  764. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 3), 1000);
  765. break;
  766. case 3:
  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(), 0, 75, -89, 0, 100, 0, 0, 1, 0));
  769. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 300, 90, -10, 6500, 7000, 0, 0, 1, 0));
  770. _world.frintezza = (L2GrandBossInstance) addSpawn(FRINTEZZA, -87780, -155086, -9080, 16384, false, 0, false, _world.instanceId);
  771. _world.frintezza.setIsImmobilized(true);
  772. _world.frintezza.setIsInvul(true);
  773. _world.frintezza.disableAllSkills();
  774. updateKnownList(_world, _world.frintezza);
  775. for (int i = 0; i < PORTRAIT_SPAWNS.length; i++)
  776. {
  777. 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);
  778. demon.setIsImmobilized(true);
  779. demon.disableAllSkills();
  780. updateKnownList(_world, demon);
  781. _world.demons.add(demon);
  782. }
  783. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 4), 6500);
  784. break;
  785. case 4:
  786. broadCastPacket(_world, new SpecialCamera(_world.frintezzaDummy.getObjectId(), 1800, 90, 8, 6500, 7000, 0, 0, 1, 0));
  787. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 5), 900);
  788. break;
  789. case 5:
  790. broadCastPacket(_world, new SpecialCamera(_world.frintezzaDummy.getObjectId(), 140, 90, 10, 2500, 4500, 0, 0, 1, 0));
  791. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 6), 4000);
  792. break;
  793. case 6:
  794. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 40, 75, -10, 0, 1000, 0, 0, 1, 0));
  795. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 40, 75, -10, 0, 12000, 0, 0, 1, 0));
  796. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 7), 1350);
  797. break;
  798. case 7:
  799. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 2));
  800. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 8), 7000);
  801. break;
  802. case 8:
  803. _world.frintezzaDummy.deleteMe();
  804. _world.frintezzaDummy = null;
  805. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 9), 1000);
  806. break;
  807. case 9:
  808. broadCastPacket(_world, new SocialAction(_world.demons.get(1).getObjectId(), 1));
  809. broadCastPacket(_world, new SocialAction(_world.demons.get(2).getObjectId(), 1));
  810. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 10), 400);
  811. break;
  812. case 10:
  813. broadCastPacket(_world, new SocialAction(_world.demons.get(0).getObjectId(), 1));
  814. broadCastPacket(_world, new SocialAction(_world.demons.get(3).getObjectId(), 1));
  815. 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);
  816. 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);
  817. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 11), 2000);
  818. break;
  819. case 11:
  820. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 240, 90, 0, 0, 1000, 0, 0, 1, 0));
  821. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 240, 90, 25, 5500, 10000, 0, 0, 1, 0));
  822. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 3));
  823. _world.portraitDummy1.deleteMe();
  824. _world.portraitDummy3.deleteMe();
  825. _world.portraitDummy1 = null;
  826. _world.portraitDummy3 = null;
  827. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 12), 4500);
  828. break;
  829. case 12:
  830. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 195, 35, 0, 10000, 0, 0, 1, 0));
  831. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 13), 700);
  832. break;
  833. case 13:
  834. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 195, 35, 0, 10000, 0, 0, 1, 0));
  835. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 14), 1300);
  836. break;
  837. case 14:
  838. broadCastPacket(_world, new ExShowScreenMessage(NpcStringId.MOURNFUL_CHORALE_PRELUDE, 2, 5000));
  839. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 120, 180, 45, 1500, 10000, 0, 0, 1, 0));
  840. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, 5006, 1, 34000, 0));
  841. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 15), 1500);
  842. break;
  843. case 15:
  844. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 520, 135, 45, 8000, 10000, 0, 0, 1, 0));
  845. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 16), 7500);
  846. break;
  847. case 16:
  848. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 1500, 110, 25, 10000, 13000, 0, 0, 1, 0));
  849. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 17), 9500);
  850. break;
  851. case 17:
  852. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 930, 160, -20, 0, 1000, 0, 0, 1, 0));
  853. broadCastPacket(_world, new SpecialCamera(_world.overheadDummy.getObjectId(), 600, 180, -25, 0, 10000, 0, 0, 1, 0));
  854. broadCastPacket(_world, new MagicSkillUse(_world.scarletDummy, _world.overheadDummy, 5004, 1, 5800, 0));
  855. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 18), 5000);
  856. break;
  857. case 18:
  858. _world.activeScarlet = (L2GrandBossInstance) addSpawn(29046, -87789, -153295, -9176, 16384, false, 0, false, _world.instanceId);
  859. _world.activeScarlet.setRHandId(FIRST_SCARLET_WEAPON);
  860. _world.activeScarlet.setIsInvul(true);
  861. _world.activeScarlet.setIsImmobilized(true);
  862. _world.activeScarlet.disableAllSkills();
  863. updateKnownList(_world, _world.activeScarlet);
  864. broadCastPacket(_world, new SocialAction(_world.activeScarlet.getObjectId(), 3));
  865. broadCastPacket(_world, new SpecialCamera(_world.scarletDummy.getObjectId(), 800, 180, 10, 1000, 10000, 0, 0, 1, 0));
  866. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 19), 2100);
  867. break;
  868. case 19:
  869. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 300, 60, 8, 0, 10000, 0, 0, 1, 0));
  870. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 20), 2000);
  871. break;
  872. case 20:
  873. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 500, 90, 10, 3000, 5000, 0, 0, 1, 0));
  874. _world.songTask = ThreadPoolManager.getInstance().scheduleGeneral(new SongTask(_world, 0), 100);
  875. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 21), 3000);
  876. break;
  877. case 21:
  878. for (int i = 0; i < PORTRAIT_SPAWNS.length; i++)
  879. {
  880. 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);
  881. updateKnownList(_world, portrait);
  882. _world.portraits.put(portrait, i);
  883. }
  884. _world.overheadDummy.deleteMe();
  885. _world.scarletDummy.deleteMe();
  886. _world.overheadDummy = null;
  887. _world.scarletDummy = null;
  888. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 22), 2000);
  889. break;
  890. case 22:
  891. for (L2MonsterInstance demon : _world.demons)
  892. {
  893. demon.setIsImmobilized(false);
  894. demon.enableAllSkills();
  895. }
  896. _world.activeScarlet.setIsInvul(false);
  897. _world.activeScarlet.setIsImmobilized(false);
  898. _world.activeScarlet.enableAllSkills();
  899. _world.activeScarlet.setRunning();
  900. _world.activeScarlet.doCast(INTRO_SKILL.getSkill());
  901. _world.frintezza.enableAllSkills();
  902. _world.frintezza.disableCoreAI(true);
  903. _world.frintezza.setIsMortal(false);
  904. startPc();
  905. ThreadPoolManager.getInstance().scheduleGeneral(new DemonSpawnTask(_world), TIME_BETWEEN_DEMON_SPAWNS);
  906. break;
  907. case 23:
  908. broadCastPacket(_world, new SocialAction(_world.frintezza.getObjectId(), 4));
  909. break;
  910. case 24:
  911. stopPc();
  912. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 250, 120, 15, 0, 1000, 0, 0, 1, 0));
  913. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 250, 120, 15, 0, 10000, 0, 0, 1, 0));
  914. _world.activeScarlet.abortAttack();
  915. _world.activeScarlet.abortCast();
  916. _world.activeScarlet.setIsInvul(true);
  917. _world.activeScarlet.setIsImmobilized(true);
  918. _world.activeScarlet.disableAllSkills();
  919. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 25), 7000);
  920. break;
  921. case 25:
  922. broadCastPacket(_world, new MagicSkillUse(_world.frintezza, _world.frintezza, 5006, 1, 34000, 0));
  923. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 500, 70, 15, 3000, 10000, 0, 0, 1, 0));
  924. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 26), 3000);
  925. break;
  926. case 26:
  927. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 2500, 90, 12, 6000, 10000, 0, 0, 1, 0));
  928. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 27), 3000);
  929. break;
  930. case 27:
  931. _world.scarlet_x = _world.activeScarlet.getX();
  932. _world.scarlet_y = _world.activeScarlet.getY();
  933. _world.scarlet_z = _world.activeScarlet.getZ();
  934. _world.scarlet_h = _world.activeScarlet.getHeading();
  935. if (_world.scarlet_h < 32768)
  936. _world.scarlet_a = Math.abs(180 - (int) (_world.scarlet_h / 182.044444444));
  937. else
  938. _world.scarlet_a = Math.abs(540 - (int) (_world.scarlet_h / 182.044444444));
  939. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 250, _world.scarlet_a, 12, 0, 1000, 0, 0, 1, 0));
  940. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 250, _world.scarlet_a, 12, 0, 10000, 0, 0, 1, 0));
  941. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 28), 500);
  942. break;
  943. case 28:
  944. _world.activeScarlet.doDie(_world.activeScarlet);
  945. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 450, _world.scarlet_a, 14, 8000, 8000, 0, 0, 1, 0));
  946. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 29), 6250);
  947. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 30), 7200);
  948. break;
  949. case 29:
  950. _world.activeScarlet.deleteMe();
  951. _world.activeScarlet = null;
  952. break;
  953. case 30:
  954. _world.activeScarlet = (L2GrandBossInstance) addSpawn(SCARLET2, _world.scarlet_x, _world.scarlet_y, _world.scarlet_z, _world.scarlet_h, false, 0, false, _world.instanceId);
  955. _world.activeScarlet.setIsInvul(true);
  956. _world.activeScarlet.setIsImmobilized(true);
  957. _world.activeScarlet.disableAllSkills();
  958. updateKnownList(_world, _world.activeScarlet);
  959. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 450, _world.scarlet_a, 12, 500, 14000, 0, 0, 1, 0));
  960. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 31), 8100);
  961. break;
  962. case 31:
  963. broadCastPacket(_world, new SocialAction(_world.activeScarlet.getObjectId(), 2));
  964. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 32), 9000);
  965. break;
  966. case 32:
  967. startPc();
  968. _world.activeScarlet.setIsInvul(false);
  969. _world.activeScarlet.setIsImmobilized(false);
  970. _world.activeScarlet.enableAllSkills();
  971. _world.isVideo = false;
  972. break;
  973. case 33:
  974. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 300, _world.scarlet_a - 180, 5, 0, 7000, 0, 0, 1, 0));
  975. broadCastPacket(_world, new SpecialCamera(_world.activeScarlet.getObjectId(), 200, _world.scarlet_a, 85, 4000, 10000, 0, 0, 1, 0));
  976. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 34), 7400);
  977. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 35), 7500);
  978. break;
  979. case 34:
  980. _world.frintezza.doDie(_world.frintezza);
  981. break;
  982. case 35:
  983. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 120, 5, 0, 7000, 0, 0, 1, 0));
  984. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 100, 90, 5, 5000, 15000, 0, 0, 1, 0));
  985. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 36), 7000);
  986. break;
  987. case 36:
  988. broadCastPacket(_world, new SpecialCamera(_world.frintezza.getObjectId(), 900, 90, 25, 7000, 10000, 0, 0, 1, 0));
  989. ThreadPoolManager.getInstance().scheduleGeneral(new IntroTask(_world, 37), 9000);
  990. break;
  991. case 37:
  992. controlStatus(_world);
  993. _world.isVideo = false;
  994. startPc();
  995. break;
  996. }
  997. }
  998. private void stopPc()
  999. {
  1000. for (int objId : _world.allowed)
  1001. {
  1002. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1003. if (player != null && player.isOnline() && player.getInstanceId() == _world.instanceId)
  1004. {
  1005. player.abortAttack();
  1006. player.abortCast();
  1007. player.disableAllSkills();
  1008. player.setTarget(null);
  1009. player.stopMove(null);
  1010. player.setIsImmobilized(true);
  1011. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1012. }
  1013. }
  1014. }
  1015. private void startPc()
  1016. {
  1017. for (int objId : _world.allowed)
  1018. {
  1019. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1020. if (player != null && player.isOnline() && player.getInstanceId() == _world.instanceId)
  1021. {
  1022. player.enableAllSkills();
  1023. player.setIsImmobilized(false);
  1024. }
  1025. }
  1026. }
  1027. private void sendPacketX(L2GameServerPacket packet1, L2GameServerPacket packet2, int x)
  1028. {
  1029. for (int objId : _world.allowed)
  1030. {
  1031. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1032. if (player != null && player.isOnline() && player.getInstanceId() == _world.instanceId)
  1033. {
  1034. if (player.getX() < x)
  1035. player.sendPacket(packet1);
  1036. else
  1037. player.sendPacket(packet2);
  1038. }
  1039. }
  1040. }
  1041. }
  1042. private class StatusTask implements Runnable
  1043. {
  1044. private final FETWorld _world;
  1045. private final int _status;
  1046. StatusTask(FETWorld world, int status)
  1047. {
  1048. _world = world;
  1049. _status = status;
  1050. }
  1051. @Override
  1052. public void run()
  1053. {
  1054. if (InstanceManager.getInstance().getWorld(_world.instanceId) != _world)
  1055. return;
  1056. switch (_status)
  1057. {
  1058. case 0:
  1059. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(_world, 1), 2000);
  1060. for (int doorId : FIRST_ROOM_DOORS)
  1061. openDoor(doorId, _world.instanceId);
  1062. break;
  1063. case 1:
  1064. addAggroToMobs();
  1065. break;
  1066. case 2:
  1067. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(_world, 3), 100);
  1068. for (int doorId : SECOND_ROOM_DOORS)
  1069. openDoor(doorId, _world.instanceId);
  1070. break;
  1071. case 3:
  1072. addAggroToMobs();
  1073. break;
  1074. case 4:
  1075. controlStatus(_world);
  1076. break;
  1077. }
  1078. }
  1079. private void addAggroToMobs()
  1080. {
  1081. L2PcInstance target = L2World.getInstance().getPlayer(_world.allowed.get(getRandom(_world.allowed.size())));
  1082. if (target == null || target.getInstanceId() != _world.instanceId || target.isDead() || target.isFakeDeath())
  1083. for (int objId : _world.allowed)
  1084. {
  1085. target = L2World.getInstance().getPlayer(objId);
  1086. if (target != null && target.getInstanceId() == _world.instanceId && !target.isDead() && !target.isFakeDeath())
  1087. break;
  1088. target = null;
  1089. }
  1090. for (L2Npc mob : _world.npcList)
  1091. {
  1092. mob.setRunning();
  1093. if (target != null)
  1094. {
  1095. ((L2MonsterInstance) mob).addDamageHate(target, 0, 500);
  1096. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  1097. }
  1098. else
  1099. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, MOVE_TO_CENTER);
  1100. }
  1101. }
  1102. }
  1103. protected void setInstanceTimeRestrictions(FETWorld world)
  1104. {
  1105. Calendar reenter = Calendar.getInstance();
  1106. reenter.set(Calendar.MINUTE, RESET_MIN);
  1107. reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
  1108. // if time is >= RESET_HOUR - roll to the next day
  1109. if (reenter.getTimeInMillis() <= System.currentTimeMillis())
  1110. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1111. if (reenter.get(Calendar.DAY_OF_WEEK) <= RESET_DAY_1)
  1112. while (reenter.get(Calendar.DAY_OF_WEEK) != RESET_DAY_1)
  1113. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1114. else
  1115. while (reenter.get(Calendar.DAY_OF_WEEK) != RESET_DAY_2)
  1116. reenter.add(Calendar.DAY_OF_MONTH, 1);
  1117. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
  1118. sm.addInstanceName(INSTANCEID);
  1119. // set instance reenter time for all allowed players
  1120. for (int objectId : world.allowed)
  1121. {
  1122. L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  1123. InstanceManager.getInstance().setInstanceTime(objectId, INSTANCEID, reenter.getTimeInMillis());
  1124. if (player != null && player.isOnline())
  1125. player.sendPacket(sm);
  1126. }
  1127. }
  1128. protected void broadCastPacket(FETWorld world, L2GameServerPacket packet)
  1129. {
  1130. for (int objId : world.allowed)
  1131. {
  1132. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1133. if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
  1134. player.sendPacket(packet);
  1135. }
  1136. }
  1137. protected void updateKnownList(FETWorld world, L2Npc npc)
  1138. {
  1139. Map<Integer, L2PcInstance> npcKnownPlayers = npc.getKnownList().getKnownPlayers();
  1140. for (int objId : world.allowed)
  1141. {
  1142. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  1143. if (player != null && player.isOnline() && player.getInstanceId() == world.instanceId)
  1144. npcKnownPlayers.put(player.getObjectId(), player);
  1145. }
  1146. }
  1147. @Override
  1148. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  1149. {
  1150. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1151. if (tmpworld instanceof FETWorld)
  1152. {
  1153. FETWorld world = (FETWorld) tmpworld;
  1154. if (npc.getNpcId() == SCARLET1 && world.status == 3 && npc.getCurrentHp() < npc.getMaxHp() * 0.80)
  1155. {
  1156. controlStatus(world);
  1157. }
  1158. else if (npc.getNpcId() == SCARLET1 && world.status == 4 && npc.getCurrentHp() < npc.getMaxHp() * 0.20)
  1159. {
  1160. controlStatus(world);
  1161. }
  1162. }
  1163. return null;
  1164. }
  1165. @Override
  1166. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  1167. {
  1168. if (skill.isSuicideAttack())
  1169. {
  1170. return onKill(npc, null, false);
  1171. }
  1172. return super.onSpellFinished(npc, player, skill);
  1173. }
  1174. @Override
  1175. public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  1176. {
  1177. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1178. if (tmpworld instanceof FETWorld)
  1179. {
  1180. FETWorld world = (FETWorld) tmpworld;
  1181. if (npc.getNpcId() == HALL_ALARM)
  1182. {
  1183. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(world, 0), 2000);
  1184. if (debug)
  1185. _log.info("[Final Emperial Tomb] Hall alarm is disabled, doors will open!");
  1186. }
  1187. else if (npc.getNpcId() == DARK_CHOIR_PLAYER)
  1188. {
  1189. world.darkChoirPlayerCount--;
  1190. if (world.darkChoirPlayerCount < 1)
  1191. {
  1192. ThreadPoolManager.getInstance().scheduleGeneral(new StatusTask(world, 2), 2000);
  1193. if (debug)
  1194. _log.info("[Final Emperial Tomb] All Dark Choir Players are killed, doors will open!");
  1195. }
  1196. }
  1197. else if (npc.getNpcId() == SCARLET2)
  1198. {
  1199. controlStatus(world);
  1200. }
  1201. else if (world.status <= 2)
  1202. {
  1203. if (checkKillProgress(npc, world))
  1204. controlStatus(world);
  1205. }
  1206. else if (world.demons.contains(npc))
  1207. {
  1208. world.demons.remove(npc);
  1209. }
  1210. else if (world.portraits.containsKey(npc))
  1211. {
  1212. world.portraits.remove(npc);
  1213. }
  1214. }
  1215. return "";
  1216. }
  1217. @Override
  1218. public String onTalk(L2Npc npc, L2PcInstance player)
  1219. {
  1220. int npcId = npc.getNpcId();
  1221. QuestState st = player.getQuestState(qn);
  1222. if (st == null)
  1223. st = newQuestState(player);
  1224. if (npcId == GUIDE)
  1225. {
  1226. enterInstance(player, "FinalEmperialTomb.xml", ENTER_TELEPORT);
  1227. }
  1228. else if (npc.getNpcId() == CUBE)
  1229. {
  1230. int x = -87534 + getRandom(500);
  1231. int y = -153048 + getRandom(500);
  1232. player.teleToLocation(x, y, -9165);
  1233. return null;
  1234. }
  1235. return "";
  1236. }
  1237. public FinalEmperialTomb(int questId, String name, String descr)
  1238. {
  1239. super(questId, name, descr);
  1240. load();
  1241. addStartNpc(GUIDE);
  1242. addTalkId(GUIDE);
  1243. addStartNpc(CUBE);
  1244. addTalkId(CUBE);
  1245. addKillId(HALL_ALARM);
  1246. addKillId(DARK_CHOIR_PLAYER);
  1247. addAttackId(SCARLET1);
  1248. addKillId(SCARLET2);
  1249. addKillId(PORTRAITS);
  1250. addKillId(DEMONS);
  1251. for (int mobId : _mustKillMobsId)
  1252. {
  1253. addKillId(mobId);
  1254. }
  1255. addSpellFinishedId(18333);
  1256. }
  1257. public static void main(String[] args)
  1258. {
  1259. // now call the constructor (starts up the)
  1260. new FinalEmperialTomb(-1, qn, "instances");
  1261. }
  1262. }