FinalEmperialTomb.java 52 KB

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