DarkCloudMansion.java 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package instances.DarkCloudMansion;
  20. import instances.AbstractInstance;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.concurrent.ConcurrentHashMap;
  25. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  26. import com.l2jserver.gameserver.model.L2Party;
  27. import com.l2jserver.gameserver.model.Location;
  28. import com.l2jserver.gameserver.model.PcCondOverride;
  29. import com.l2jserver.gameserver.model.actor.L2Npc;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.entity.Instance;
  32. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  33. import com.l2jserver.gameserver.model.skills.Skill;
  34. import com.l2jserver.gameserver.network.NpcStringId;
  35. import com.l2jserver.gameserver.network.SystemMessageId;
  36. import com.l2jserver.gameserver.network.clientpackets.Say2;
  37. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  38. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  39. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  40. /**
  41. * Dark Cloud Mansion instance zone.
  42. */
  43. public final class DarkCloudMansion extends AbstractInstance
  44. {
  45. protected class DMCWorld extends InstanceWorld
  46. {
  47. protected Map<String, DMCRoom> rooms = new ConcurrentHashMap<>();
  48. }
  49. // NPCs
  50. private static int YIYEN = 32282;
  51. private static int SOFaith = 32288; // Symbol of Faith
  52. private static int SOAdversity = 32289; // Symbol of Adversity
  53. private static int SOAdventure = 32290; // Symbol of Adventure
  54. private static int SOTruth = 32291; // Symbol of Truth
  55. private static int BSM = 32324; // Black Stone Monolith
  56. private static int SC = 22402; // Shadow Column
  57. // Mobs
  58. private static int[] CCG =
  59. {
  60. 18369,
  61. 18370
  62. }; // Chromatic Crystal Golem
  63. private static int[] BM =
  64. {
  65. 22272,
  66. 22273,
  67. 22274
  68. }; // Beleth's Minions
  69. private static int[] HG =
  70. {
  71. 22264,
  72. 22264
  73. }; // [22318,22319] #Hall Guards
  74. private static int[] BS =
  75. {
  76. 18371,
  77. 18372,
  78. 18373,
  79. 18374,
  80. 18375,
  81. 18376,
  82. 18377
  83. }; // Beleth's Samples
  84. private static int[] TOKILL =
  85. {
  86. 18371,
  87. 18372,
  88. 18373,
  89. 18374,
  90. 18375,
  91. 18376,
  92. 18377,
  93. 22318,
  94. 22319,
  95. 22272,
  96. 22273,
  97. 22274,
  98. 18369,
  99. 18370,
  100. 22402,
  101. 22264
  102. };
  103. // Items
  104. private static int CC = 9690; // Contaminated Crystal
  105. // Misc
  106. private static final int TEMPLATE_ID = 9;
  107. private static int D1 = 24230001; // Starting Room
  108. private static int D2 = 24230002; // First Room
  109. private static int D3 = 24230005; // Second Room
  110. private static int D4 = 24230003; // Third Room
  111. private static int D5 = 24230004; // Forth Room
  112. private static int D6 = 24230006; // Fifth Room
  113. private static int W1 = 24230007; // Wall 1
  114. // private static int W2 = 24230008; // Wall 2
  115. // private static int W3 = 24230009; // Wall 3
  116. // private static int W4 = 24230010; // Wall 4
  117. // private static int W5 = 24230011; // Wall 5
  118. // private static int W6 = 24230012; // Wall 6
  119. // private static int W7 = 24230013; // Wall 7
  120. private static boolean debug = false;
  121. private static boolean noRndWalk = true;
  122. private static NpcStringId[] _spawnChat =
  123. {
  124. NpcStringId.IM_THE_REAL_ONE,
  125. NpcStringId.PICK_ME,
  126. NpcStringId.TRUST_ME,
  127. NpcStringId.NOT_THAT_DUDE_IM_THE_REAL_ONE,
  128. NpcStringId.DONT_BE_FOOLED_DONT_BE_FOOLED_IM_THE_REAL_ONE
  129. };
  130. private static NpcStringId[] _decayChat =
  131. {
  132. NpcStringId.IM_THE_REAL_ONE_PHEW,
  133. NpcStringId.CANT_YOU_EVEN_FIND_OUT,
  134. NpcStringId.FIND_ME
  135. };
  136. private static NpcStringId[] _successChat =
  137. {
  138. NpcStringId.HUH_HOW_DID_YOU_KNOW_IT_WAS_ME,
  139. NpcStringId.EXCELLENT_CHOICE_TEEHEE,
  140. NpcStringId.YOUVE_DONE_WELL,
  141. NpcStringId.OH_VERY_SENSIBLE
  142. };
  143. private static NpcStringId[] _faildChat =
  144. {
  145. NpcStringId.YOUVE_BEEN_FOOLED,
  146. NpcStringId.SORRY_BUT_IM_THE_FAKE_ONE
  147. };
  148. // @formatter:off
  149. // Second room - random monolith order
  150. private static int[][] MonolithOrder = new int[][]
  151. {
  152. {1, 2, 3, 4, 5, 6},
  153. {6, 5, 4, 3, 2, 1},
  154. {4 ,5, 6, 3, 2, 1},
  155. {2, 6, 3, 5, 1, 4},
  156. {4, 1, 5, 6, 2, 3},
  157. {3, 5, 1, 6, 2, 4},
  158. {6, 1, 3, 4, 5, 2},
  159. {5, 6, 1, 2, 4, 3},
  160. {5, 2, 6, 3, 4, 1},
  161. {1, 5, 2, 6, 3, 4},
  162. {1, 2, 3, 6, 5, 4},
  163. {6, 4, 3, 1, 5, 2},
  164. {3, 5, 2, 4, 1, 6},
  165. {3, 2, 4, 5, 1, 6},
  166. {5, 4, 3, 1, 6, 2},
  167. };
  168. // Second room - golem spawn locatons - random
  169. private static int[][] GolemSpawn = new int[][]
  170. {
  171. {CCG[0], 148060, 181389},
  172. {CCG[1], 147910, 181173},
  173. {CCG[0], 147810, 181334},
  174. {CCG[1], 147713, 181179},
  175. {CCG[0], 147569, 181410},
  176. {CCG[1], 147810, 181517},
  177. {CCG[0], 147805, 181281},
  178. };
  179. // forth room - random shadow column
  180. private static int[][] ColumnRows = new int[][]
  181. {
  182. {1, 1, 0, 1, 0},
  183. {0, 1, 1, 0, 1},
  184. {1, 0, 1, 1, 0},
  185. {0, 1, 0, 1, 1},
  186. {1, 0, 1, 0, 1},
  187. };
  188. // Fifth room - beleth order
  189. private static int[][] Beleths = new int[][]
  190. {
  191. {1, 0, 1, 0, 1, 0, 0},
  192. {0, 0, 1, 0, 1, 1, 0},
  193. {0, 0, 0, 1, 0, 1, 1},
  194. {1, 0, 1, 1, 0, 0, 0},
  195. {1, 1, 0, 0, 0, 1, 0},
  196. {0, 1, 0, 1, 0, 1, 0},
  197. {0, 0, 0, 1, 1, 1, 0},
  198. {1, 0, 1, 0, 0, 1, 0},
  199. {0, 1, 1, 0, 0, 0, 1},
  200. };
  201. // @formatter:on
  202. public DarkCloudMansion()
  203. {
  204. super(DarkCloudMansion.class.getSimpleName());
  205. addFirstTalkId(BSM, SOTruth);
  206. addStartNpc(YIYEN);
  207. addTalkId(YIYEN, SOTruth);
  208. addAttackId(SC);
  209. addAttackId(BS);
  210. addAttackId(CCG);
  211. addKillId(TOKILL);
  212. }
  213. protected static class DMCNpc
  214. {
  215. public L2Npc npc;
  216. public boolean isDead = false;
  217. public L2Npc golem = null;
  218. public int status = 0;
  219. public int order = 0;
  220. public int count = 0;
  221. }
  222. protected static class DMCRoom
  223. {
  224. public List<DMCNpc> npcList = new ArrayList<>();
  225. public int counter = 0;
  226. public int reset = 0;
  227. public int founded = 0;
  228. public int[] Order;
  229. }
  230. @Override
  231. protected boolean checkConditions(L2PcInstance player)
  232. {
  233. if (debug || player.canOverrideCond(PcCondOverride.INSTANCE_CONDITIONS))
  234. {
  235. return true;
  236. }
  237. final L2Party party = player.getParty();
  238. if (party == null)
  239. {
  240. player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
  241. return false;
  242. }
  243. if (party.getLeader() != player)
  244. {
  245. player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
  246. return false;
  247. }
  248. if (party.getMemberCount() > 2)
  249. {
  250. player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
  251. return false;
  252. }
  253. for (L2PcInstance partyMember : party.getMembers())
  254. {
  255. if (partyMember.getLevel() < 78)
  256. {
  257. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_S_LEVEL_REQUIREMENT_IS_NOT_SUFFICIENT_AND_CANNOT_BE_ENTERED);
  258. sm.addPcName(partyMember);
  259. player.sendPacket(sm);
  260. return false;
  261. }
  262. if (!partyMember.isInsideRadius(player, 1000, true, true))
  263. {
  264. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_LOCATION_WHICH_CANNOT_BE_ENTERED_THEREFORE_IT_CANNOT_BE_PROCESSED);
  265. sm.addPcName(partyMember);
  266. player.sendPacket(sm);
  267. return false;
  268. }
  269. }
  270. return true;
  271. }
  272. @Override
  273. public void onEnterInstance(L2PcInstance player, InstanceWorld world, boolean firstEntrance)
  274. {
  275. if (firstEntrance)
  276. {
  277. runStartRoom((DMCWorld) world);
  278. // teleport players
  279. if (debug && (player.getParty() == null))
  280. {
  281. world.addAllowed(player.getObjectId());
  282. teleportPlayer(player, new Location(146534, 180464, -6117), world.getInstanceId());
  283. }
  284. else
  285. {
  286. for (L2PcInstance partyMember : player.getParty().getMembers())
  287. {
  288. if (partyMember.getQuestState(getName()) == null)
  289. {
  290. newQuestState(partyMember);
  291. }
  292. world.addAllowed(partyMember.getObjectId());
  293. teleportPlayer(partyMember, new Location(146534, 180464, -6117), world.getInstanceId());
  294. }
  295. }
  296. }
  297. else
  298. {
  299. teleportPlayer(player, new Location(146534, 180464, -6117), world.getInstanceId());
  300. }
  301. }
  302. protected void runStartRoom(DMCWorld world)
  303. {
  304. world.setStatus(0);
  305. DMCRoom StartRoom = new DMCRoom();
  306. DMCNpc thisnpc;
  307. thisnpc = new DMCNpc();
  308. thisnpc.npc = addSpawn(BM[0], 146817, 180335, -6117, 0, false, 0, false, world.getInstanceId());
  309. StartRoom.npcList.add(thisnpc);
  310. if (noRndWalk)
  311. {
  312. thisnpc.npc.setIsNoRndWalk(true);
  313. }
  314. thisnpc = new DMCNpc();
  315. thisnpc.npc = addSpawn(BM[0], 146741, 180589, -6117, 0, false, 0, false, world.getInstanceId());
  316. StartRoom.npcList.add(thisnpc);
  317. if (noRndWalk)
  318. {
  319. thisnpc.npc.setIsNoRndWalk(true);
  320. }
  321. world.rooms.put("StartRoom", StartRoom);
  322. if (debug)
  323. {
  324. _log.info("DarkCloudMansion: first room spawned in instance " + world.getInstanceId());
  325. }
  326. }
  327. protected void spawnHall(DMCWorld world)
  328. {
  329. DMCRoom Hall = new DMCRoom();
  330. DMCNpc thisnpc;
  331. world.rooms.remove("Hall"); // remove room instance to avoid adding mob every time
  332. thisnpc = new DMCNpc();
  333. thisnpc.npc = addSpawn(BM[1], 147217, 180112, -6117, 0, false, 0, false, world.getInstanceId());
  334. if (noRndWalk)
  335. {
  336. thisnpc.npc.setIsNoRndWalk(true);
  337. }
  338. Hall.npcList.add(thisnpc);
  339. thisnpc = new DMCNpc();
  340. thisnpc.npc = addSpawn(BM[2], 147217, 180209, -6117, 0, false, 0, false, world.getInstanceId());
  341. if (noRndWalk)
  342. {
  343. thisnpc.npc.setIsNoRndWalk(true);
  344. }
  345. Hall.npcList.add(thisnpc);
  346. thisnpc = new DMCNpc();
  347. thisnpc.npc = addSpawn(BM[1], 148521, 180112, -6117, 0, false, 0, false, world.getInstanceId());
  348. if (noRndWalk)
  349. {
  350. thisnpc.npc.setIsNoRndWalk(true);
  351. }
  352. Hall.npcList.add(thisnpc);
  353. thisnpc = new DMCNpc();
  354. thisnpc.npc = addSpawn(BM[0], 148521, 180209, -6117, 0, false, 0, false, world.getInstanceId());
  355. if (noRndWalk)
  356. {
  357. thisnpc.npc.setIsNoRndWalk(true);
  358. }
  359. Hall.npcList.add(thisnpc);
  360. thisnpc = new DMCNpc();
  361. thisnpc.npc = addSpawn(BM[1], 148525, 180910, -6117, 0, false, 0, false, world.getInstanceId());
  362. if (noRndWalk)
  363. {
  364. thisnpc.npc.setIsNoRndWalk(true);
  365. }
  366. Hall.npcList.add(thisnpc);
  367. thisnpc = new DMCNpc();
  368. thisnpc.npc = addSpawn(BM[2], 148435, 180910, -6117, 0, false, 0, false, world.getInstanceId());
  369. if (noRndWalk)
  370. {
  371. thisnpc.npc.setIsNoRndWalk(true);
  372. }
  373. Hall.npcList.add(thisnpc);
  374. thisnpc = new DMCNpc();
  375. thisnpc.npc = addSpawn(BM[1], 147242, 180910, -6117, 0, false, 0, false, world.getInstanceId());
  376. if (noRndWalk)
  377. {
  378. thisnpc.npc.setIsNoRndWalk(true);
  379. }
  380. Hall.npcList.add(thisnpc);
  381. thisnpc = new DMCNpc();
  382. thisnpc.npc = addSpawn(BM[2], 147242, 180819, -6117, 0, false, 0, false, world.getInstanceId());
  383. if (noRndWalk)
  384. {
  385. thisnpc.npc.setIsNoRndWalk(true);
  386. }
  387. Hall.npcList.add(thisnpc);
  388. world.rooms.put("Hall", Hall);
  389. if (debug)
  390. {
  391. _log.info("DarkCloudMansion: hall spawned");
  392. }
  393. }
  394. protected void runHall(DMCWorld world)
  395. {
  396. spawnHall(world);
  397. world.setStatus(1);
  398. openDoor(D1, world.getInstanceId());
  399. }
  400. protected void runFirstRoom(DMCWorld world)
  401. {
  402. DMCRoom FirstRoom = new DMCRoom();
  403. DMCNpc thisnpc;
  404. thisnpc = new DMCNpc();
  405. thisnpc.npc = addSpawn(HG[1], 147842, 179837, -6117, 0, false, 0, false, world.getInstanceId());
  406. if (noRndWalk)
  407. {
  408. thisnpc.npc.setIsNoRndWalk(true);
  409. }
  410. FirstRoom.npcList.add(thisnpc);
  411. thisnpc = new DMCNpc();
  412. thisnpc.npc = addSpawn(HG[0], 147711, 179708, -6117, 0, false, 0, false, world.getInstanceId());
  413. if (noRndWalk)
  414. {
  415. thisnpc.npc.setIsNoRndWalk(true);
  416. }
  417. FirstRoom.npcList.add(thisnpc);
  418. thisnpc = new DMCNpc();
  419. thisnpc.npc = addSpawn(HG[1], 147842, 179552, -6117, 0, false, 0, false, world.getInstanceId());
  420. if (noRndWalk)
  421. {
  422. thisnpc.npc.setIsNoRndWalk(true);
  423. }
  424. FirstRoom.npcList.add(thisnpc);
  425. thisnpc = new DMCNpc();
  426. thisnpc.npc = addSpawn(HG[0], 147964, 179708, -6117, 0, false, 0, false, world.getInstanceId());
  427. if (noRndWalk)
  428. {
  429. thisnpc.npc.setIsNoRndWalk(true);
  430. }
  431. FirstRoom.npcList.add(thisnpc);
  432. world.rooms.put("FirstRoom", FirstRoom);
  433. world.setStatus(2);
  434. openDoor(D2, world.getInstanceId());
  435. if (debug)
  436. {
  437. _log.info("DarkCloudMansion: spawned first room");
  438. }
  439. }
  440. protected void runHall2(DMCWorld world)
  441. {
  442. addSpawn(SOFaith, 147818, 179643, -6117, 0, false, 0, false, world.getInstanceId());
  443. spawnHall(world);
  444. world.setStatus(3);
  445. }
  446. protected void runSecondRoom(DMCWorld world)
  447. {
  448. DMCRoom SecondRoom = new DMCRoom();
  449. DMCNpc thisnpc;
  450. // TODO: find a better way to initialize to [1,0,0,0,0,0,0]
  451. SecondRoom.Order = new int[7];
  452. SecondRoom.Order[0] = 1;
  453. for (int i = 1; i < 7; i++)
  454. {
  455. SecondRoom.Order[i] = 0;
  456. }
  457. int i = getRandom(MonolithOrder.length);
  458. thisnpc = new DMCNpc();
  459. thisnpc.npc = addSpawn(BSM, 147800, 181150, -6117, 0, false, 0, false, world.getInstanceId());
  460. thisnpc.order = MonolithOrder[i][0];
  461. SecondRoom.npcList.add(thisnpc);
  462. thisnpc = new DMCNpc();
  463. thisnpc.npc = addSpawn(BSM, 147900, 181215, -6117, 0, false, 0, false, world.getInstanceId());
  464. thisnpc.order = MonolithOrder[i][1];
  465. SecondRoom.npcList.add(thisnpc);
  466. thisnpc = new DMCNpc();
  467. thisnpc.npc = addSpawn(BSM, 147900, 181345, -6117, 0, false, 0, false, world.getInstanceId());
  468. thisnpc.order = MonolithOrder[i][2];
  469. SecondRoom.npcList.add(thisnpc);
  470. thisnpc = new DMCNpc();
  471. thisnpc.npc = addSpawn(BSM, 147800, 181410, -6117, 0, false, 0, false, world.getInstanceId());
  472. thisnpc.order = MonolithOrder[i][3];
  473. SecondRoom.npcList.add(thisnpc);
  474. thisnpc = new DMCNpc();
  475. thisnpc.npc = addSpawn(BSM, 147700, 181345, -6117, 0, false, 0, false, world.getInstanceId());
  476. thisnpc.order = MonolithOrder[i][4];
  477. SecondRoom.npcList.add(thisnpc);
  478. thisnpc = new DMCNpc();
  479. thisnpc.npc = addSpawn(BSM, 147700, 181215, -6117, 0, false, 0, false, world.getInstanceId());
  480. thisnpc.order = MonolithOrder[i][5];
  481. SecondRoom.npcList.add(thisnpc);
  482. world.rooms.put("SecondRoom", SecondRoom);
  483. world.setStatus(4);
  484. openDoor(D3, world.getInstanceId());
  485. if (debug)
  486. {
  487. _log.info("DarkCloudMansion: spawned second room");
  488. }
  489. }
  490. protected void runHall3(DMCWorld world)
  491. {
  492. addSpawn(SOAdversity, 147808, 181281, -6117, 16383, false, 0, false, world.getInstanceId());
  493. spawnHall(world);
  494. world.setStatus(5);
  495. }
  496. protected void runThirdRoom(DMCWorld world)
  497. {
  498. DMCRoom ThirdRoom = new DMCRoom();
  499. DMCNpc thisnpc = new DMCNpc();
  500. thisnpc.isDead = false;
  501. thisnpc.npc = addSpawn(BM[1], 148765, 180450, -6117, 0, false, 0, false, world.getInstanceId());
  502. if (noRndWalk)
  503. {
  504. thisnpc.npc.setIsNoRndWalk(true);
  505. }
  506. ThirdRoom.npcList.add(thisnpc);
  507. thisnpc.npc = addSpawn(BM[2], 148865, 180190, -6117, 0, false, 0, false, world.getInstanceId());
  508. if (noRndWalk)
  509. {
  510. thisnpc.npc.setIsNoRndWalk(true);
  511. }
  512. ThirdRoom.npcList.add(thisnpc);
  513. thisnpc.npc = addSpawn(BM[1], 148995, 180190, -6117, 0, false, 0, false, world.getInstanceId());
  514. if (noRndWalk)
  515. {
  516. thisnpc.npc.setIsNoRndWalk(true);
  517. }
  518. ThirdRoom.npcList.add(thisnpc);
  519. thisnpc.npc = addSpawn(BM[0], 149090, 180450, -6117, 0, false, 0, false, world.getInstanceId());
  520. if (noRndWalk)
  521. {
  522. thisnpc.npc.setIsNoRndWalk(true);
  523. }
  524. ThirdRoom.npcList.add(thisnpc);
  525. thisnpc.npc = addSpawn(BM[1], 148995, 180705, -6117, 0, false, 0, false, world.getInstanceId());
  526. if (noRndWalk)
  527. {
  528. thisnpc.npc.setIsNoRndWalk(true);
  529. }
  530. ThirdRoom.npcList.add(thisnpc);
  531. thisnpc.npc = addSpawn(BM[2], 148865, 180705, -6117, 0, false, 0, false, world.getInstanceId());
  532. if (noRndWalk)
  533. {
  534. thisnpc.npc.setIsNoRndWalk(true);
  535. }
  536. ThirdRoom.npcList.add(thisnpc);
  537. world.rooms.put("ThirdRoom", ThirdRoom);
  538. world.setStatus(6);
  539. openDoor(D4, world.getInstanceId());
  540. if (debug)
  541. {
  542. _log.info("DarkCloudMansion: spawned third room");
  543. }
  544. }
  545. protected void runThirdRoom2(DMCWorld world)
  546. {
  547. addSpawn(SOAdventure, 148910, 178397, -6117, 16383, false, 0, false, world.getInstanceId());
  548. DMCRoom ThirdRoom = new DMCRoom();
  549. DMCNpc thisnpc = new DMCNpc();
  550. thisnpc.isDead = false;
  551. thisnpc.npc = addSpawn(BM[1], 148765, 180450, -6117, 0, false, 0, false, world.getInstanceId());
  552. if (noRndWalk)
  553. {
  554. thisnpc.npc.setIsNoRndWalk(true);
  555. }
  556. ThirdRoom.npcList.add(thisnpc);
  557. thisnpc.npc = addSpawn(BM[2], 148865, 180190, -6117, 0, false, 0, false, world.getInstanceId());
  558. if (noRndWalk)
  559. {
  560. thisnpc.npc.setIsNoRndWalk(true);
  561. }
  562. ThirdRoom.npcList.add(thisnpc);
  563. thisnpc.npc = addSpawn(BM[1], 148995, 180190, -6117, 0, false, 0, false, world.getInstanceId());
  564. if (noRndWalk)
  565. {
  566. thisnpc.npc.setIsNoRndWalk(true);
  567. }
  568. ThirdRoom.npcList.add(thisnpc);
  569. thisnpc.npc = addSpawn(BM[0], 149090, 180450, -6117, 0, false, 0, false, world.getInstanceId());
  570. if (noRndWalk)
  571. {
  572. thisnpc.npc.setIsNoRndWalk(true);
  573. }
  574. ThirdRoom.npcList.add(thisnpc);
  575. thisnpc.npc = addSpawn(BM[1], 148995, 180705, -6117, 0, false, 0, false, world.getInstanceId());
  576. if (noRndWalk)
  577. {
  578. thisnpc.npc.setIsNoRndWalk(true);
  579. }
  580. ThirdRoom.npcList.add(thisnpc);
  581. thisnpc.npc = addSpawn(BM[2], 148865, 180705, -6117, 0, false, 0, false, world.getInstanceId());
  582. if (noRndWalk)
  583. {
  584. thisnpc.npc.setIsNoRndWalk(true);
  585. }
  586. ThirdRoom.npcList.add(thisnpc);
  587. world.rooms.put("ThirdRoom2", ThirdRoom);
  588. world.setStatus(8);
  589. if (debug)
  590. {
  591. _log.info("DarkCloudMansion: spawned third room second time");
  592. }
  593. }
  594. protected void runForthRoom(DMCWorld world)
  595. {
  596. DMCRoom ForthRoom = new DMCRoom();
  597. ForthRoom.counter = 0;
  598. DMCNpc thisnpc;
  599. int temp[] = new int[7];
  600. int templist[][] = new int[7][5];
  601. int xx = 0;
  602. for (int i = 0; i < 7; i++)
  603. {
  604. temp[i] = getRandom(ColumnRows.length);
  605. }
  606. for (int i = 0; i < 7; i++)
  607. {
  608. templist[i] = ColumnRows[temp[i]];
  609. }
  610. for (int x = 148660; x < 149285; x += 125)
  611. {
  612. int yy = 0;
  613. for (int y = 179280; y > 178405; y -= 125)
  614. {
  615. thisnpc = new DMCNpc();
  616. thisnpc.npc = addSpawn(SC, x, y, -6115, 16215, false, 0, false, world.getInstanceId());
  617. thisnpc.status = templist[yy][xx];
  618. thisnpc.order = yy;
  619. ForthRoom.npcList.add(thisnpc);
  620. yy++;
  621. }
  622. xx++;
  623. }
  624. // TODO: unify this into previous loop
  625. for (DMCNpc npc : ForthRoom.npcList)
  626. {
  627. if (npc.status == 0)
  628. {
  629. npc.npc.setIsInvul(true);
  630. }
  631. }
  632. world.rooms.put("ForthRoom", ForthRoom);
  633. world.setStatus(7);
  634. openDoor(D5, world.getInstanceId());
  635. if (debug)
  636. {
  637. _log.info("DarkCloudMansion: spawned forth room");
  638. }
  639. }
  640. protected void runFifthRoom(DMCWorld world)
  641. {
  642. spawnFifthRoom(world);
  643. world.setStatus(9);
  644. openDoor(D6, world.getInstanceId());
  645. if (debug)
  646. {
  647. _log.info("DarkCloudMansion: spawned fifth room");
  648. }
  649. }
  650. private void spawnFifthRoom(DMCWorld world)
  651. {
  652. int idx = 0;
  653. int temp[] = new int[6];
  654. DMCRoom FifthRoom = new DMCRoom();
  655. DMCNpc thisnpc;
  656. temp = Beleths[getRandom(Beleths.length)];
  657. FifthRoom.reset = 0;
  658. FifthRoom.founded = 0;
  659. for (int x = 148720; x < 149175; x += 65)
  660. {
  661. thisnpc = new DMCNpc();
  662. thisnpc.npc = addSpawn(BS[idx], x, 182145, -6117, 48810, false, 0, false, world.getInstanceId());
  663. thisnpc.npc.setIsNoRndWalk(true);
  664. thisnpc.order = idx;
  665. thisnpc.status = temp[idx];
  666. thisnpc.count = 0;
  667. FifthRoom.npcList.add(thisnpc);
  668. if ((temp[idx] == 1) && (getRandom(100) < 95))
  669. {
  670. thisnpc.npc.broadcastPacket(new NpcSay(thisnpc.npc.getObjectId(), 0, thisnpc.npc.getId(), _spawnChat[getRandom(_spawnChat.length)]));
  671. }
  672. else if ((temp[idx] != 1) && (getRandom(100) < 67))
  673. {
  674. thisnpc.npc.broadcastPacket(new NpcSay(thisnpc.npc.getObjectId(), 0, thisnpc.npc.getId(), _spawnChat[getRandom(_spawnChat.length)]));
  675. }
  676. idx++;
  677. }
  678. world.rooms.put("FifthRoom", FifthRoom);
  679. }
  680. protected boolean checkKillProgress(L2Npc npc, DMCRoom room)
  681. {
  682. boolean cont = true;
  683. for (DMCNpc npcobj : room.npcList)
  684. {
  685. if (npcobj.npc == npc)
  686. {
  687. npcobj.isDead = true;
  688. }
  689. if (npcobj.isDead == false)
  690. {
  691. cont = false;
  692. }
  693. }
  694. return cont;
  695. }
  696. protected void spawnRndGolem(DMCWorld world, DMCNpc npc)
  697. {
  698. if (npc.golem != null)
  699. {
  700. return;
  701. }
  702. int i = getRandom(GolemSpawn.length);
  703. int mobId = GolemSpawn[i][0];
  704. int x = GolemSpawn[i][1];
  705. int y = GolemSpawn[i][2];
  706. npc.golem = addSpawn(mobId, x, y, -6117, 0, false, 0, false, world.getInstanceId());
  707. if (noRndWalk)
  708. {
  709. npc.golem.setIsNoRndWalk(true);
  710. }
  711. }
  712. protected void checkStone(L2Npc npc, int order[], DMCNpc npcObj, DMCWorld world)
  713. {
  714. for (int i = 1; i < 7; i++)
  715. {
  716. // if there is a non zero value in the precedent step, the sequence is ok
  717. if ((order[i] == 0) && (order[i - 1] != 0))
  718. {
  719. if ((npcObj.order == i) && (npcObj.status == 0))
  720. {
  721. order[i] = 1;
  722. npcObj.status = 1;
  723. npcObj.isDead = true;
  724. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5441, 1, 1, 0));
  725. return;
  726. }
  727. }
  728. }
  729. spawnRndGolem(world, npcObj);
  730. }
  731. protected void endInstance(DMCWorld world)
  732. {
  733. world.setStatus(10);
  734. addSpawn(SOTruth, 148911, 181940, -6117, 16383, false, 0, false, world.getInstanceId());
  735. world.rooms.clear();
  736. if (debug)
  737. {
  738. _log.info("DarkCloudMansion: finished");
  739. }
  740. }
  741. protected void checkBelethSample(DMCWorld world, L2Npc npc, L2PcInstance player)
  742. {
  743. DMCRoom FifthRoom = world.rooms.get("FifthRoom");
  744. for (DMCNpc mob : FifthRoom.npcList)
  745. {
  746. if (mob.npc == npc)
  747. {
  748. if (mob.count == 0)
  749. {
  750. mob.count = 1;
  751. if (mob.status == 1)
  752. {
  753. mob.npc.broadcastPacket(new NpcSay(mob.npc.getObjectId(), Say2.NPC_ALL, mob.npc.getId(), _successChat[getRandom(_successChat.length)]));
  754. FifthRoom.founded += 1;
  755. startQuestTimer("decayMe", 1500, npc, player);
  756. }
  757. else
  758. {
  759. FifthRoom.reset = 1;
  760. mob.npc.broadcastPacket(new NpcSay(mob.npc.getObjectId(), Say2.NPC_ALL, mob.npc.getId(), _faildChat[getRandom(_faildChat.length)]));
  761. startQuestTimer("decayChatBelethSamples", 4000, npc, player);
  762. startQuestTimer("decayBelethSamples", 4500, npc, player);
  763. }
  764. }
  765. else
  766. {
  767. return;
  768. }
  769. }
  770. }
  771. }
  772. protected void killedBelethSample(DMCWorld world, L2Npc npc)
  773. {
  774. int decayedSamples = 0;
  775. DMCRoom FifthRoom = world.rooms.get("FifthRoom");
  776. for (DMCNpc mob : FifthRoom.npcList)
  777. {
  778. if (mob.npc == npc)
  779. {
  780. decayedSamples += 1;
  781. mob.count = 2;
  782. }
  783. else
  784. {
  785. if (mob.count == 2)
  786. {
  787. decayedSamples += 1;
  788. }
  789. }
  790. }
  791. if (FifthRoom.reset == 1)
  792. {
  793. for (DMCNpc mob : FifthRoom.npcList)
  794. {
  795. if ((mob.count == 0) || ((mob.status == 1) && (mob.count != 2)))
  796. {
  797. decayedSamples += 1;
  798. mob.npc.decayMe();
  799. mob.count = 2;
  800. }
  801. }
  802. if (decayedSamples == 7)
  803. {
  804. startQuestTimer("respawnFifth", 6000, npc, null);
  805. }
  806. }
  807. else
  808. {
  809. if ((FifthRoom.reset == 0) && (FifthRoom.founded == 3))
  810. {
  811. for (DMCNpc mob : FifthRoom.npcList)
  812. {
  813. mob.npc.decayMe();
  814. }
  815. endInstance(world);
  816. }
  817. }
  818. }
  819. protected boolean allStonesDone(DMCWorld world)
  820. {
  821. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  822. for (DMCNpc mob : SecondRoom.npcList)
  823. {
  824. if (mob.isDead)
  825. {
  826. continue;
  827. }
  828. return false;
  829. }
  830. return true;
  831. }
  832. protected void removeMonoliths(DMCWorld world)
  833. {
  834. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  835. for (DMCNpc mob : SecondRoom.npcList)
  836. {
  837. mob.npc.decayMe();
  838. }
  839. }
  840. protected void chkShadowColumn(DMCWorld world, L2Npc npc)
  841. {
  842. DMCRoom ForthRoom = world.rooms.get("ForthRoom");
  843. for (DMCNpc mob : ForthRoom.npcList)
  844. {
  845. if (mob.npc == npc)
  846. {
  847. for (int i = 0; i < 7; i++)
  848. {
  849. if ((mob.order == i) && (ForthRoom.counter == i))
  850. {
  851. openDoor(W1 + i, world.getInstanceId());
  852. ForthRoom.counter += 1;
  853. if (ForthRoom.counter == 7)
  854. {
  855. runThirdRoom2(world);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. @Override
  863. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  864. {
  865. if (npc == null)
  866. {
  867. return "";
  868. }
  869. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  870. final DMCWorld world;
  871. if (tmpworld instanceof DMCWorld)
  872. {
  873. world = (DMCWorld) tmpworld;
  874. }
  875. else
  876. {
  877. return "";
  878. }
  879. if (world.rooms.containsKey("FifthRoom"))
  880. {
  881. DMCRoom FifthRoom = world.rooms.get("FifthRoom");
  882. if (event.equalsIgnoreCase("decayMe"))
  883. {
  884. for (DMCNpc mob : FifthRoom.npcList)
  885. {
  886. if ((mob.npc == npc) || ((FifthRoom.reset == 0) && (FifthRoom.founded == 3)))
  887. {
  888. mob.npc.decayMe();
  889. mob.count = 2;
  890. }
  891. }
  892. if ((FifthRoom.reset == 0) && (FifthRoom.founded == 3))
  893. {
  894. endInstance(world);
  895. }
  896. }
  897. else if (event.equalsIgnoreCase("decayBelethSamples"))
  898. {
  899. for (DMCNpc mob : FifthRoom.npcList)
  900. {
  901. if (mob.count == 0)
  902. {
  903. mob.npc.decayMe();
  904. mob.count = 2;
  905. }
  906. }
  907. }
  908. else if (event.equalsIgnoreCase("decayChatBelethSamples"))
  909. {
  910. for (DMCNpc mob : FifthRoom.npcList)
  911. {
  912. if (mob.status == 1)
  913. {
  914. mob.npc.broadcastPacket(new NpcSay(mob.npc.getObjectId(), Say2.NPC_ALL, mob.npc.getId(), _decayChat[getRandom(_decayChat.length)]));
  915. }
  916. }
  917. }
  918. else if (event.equalsIgnoreCase("respawnFifth"))
  919. {
  920. spawnFifthRoom(world);
  921. }
  922. }
  923. return "";
  924. }
  925. @Override
  926. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  927. {
  928. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  929. final DMCWorld world;
  930. if (tmpworld instanceof DMCWorld)
  931. {
  932. world = (DMCWorld) tmpworld;
  933. if (world.getStatus() == 0)
  934. {
  935. if (checkKillProgress(npc, world.rooms.get("StartRoom")))
  936. {
  937. runHall(world);
  938. }
  939. }
  940. if (world.getStatus() == 1)
  941. {
  942. if (checkKillProgress(npc, world.rooms.get("Hall")))
  943. {
  944. runFirstRoom(world);
  945. }
  946. }
  947. if (world.getStatus() == 2)
  948. {
  949. if (checkKillProgress(npc, world.rooms.get("FirstRoom")))
  950. {
  951. runHall2(world);
  952. }
  953. }
  954. if (world.getStatus() == 3)
  955. {
  956. if (checkKillProgress(npc, world.rooms.get("Hall")))
  957. {
  958. runSecondRoom(world);
  959. }
  960. }
  961. if (world.getStatus() == 4)
  962. {
  963. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  964. for (DMCNpc mob : SecondRoom.npcList)
  965. {
  966. if (mob.golem == npc)
  967. {
  968. mob.golem = null;
  969. }
  970. }
  971. }
  972. if (world.getStatus() == 5)
  973. {
  974. if (checkKillProgress(npc, world.rooms.get("Hall")))
  975. {
  976. runThirdRoom(world);
  977. }
  978. }
  979. if (world.getStatus() == 6)
  980. {
  981. if (checkKillProgress(npc, world.rooms.get("ThirdRoom")))
  982. {
  983. runForthRoom(world);
  984. }
  985. }
  986. if (world.getStatus() == 7)
  987. {
  988. chkShadowColumn(world, npc);
  989. }
  990. if (world.getStatus() == 8)
  991. {
  992. if (checkKillProgress(npc, world.rooms.get("ThirdRoom2")))
  993. {
  994. runFifthRoom(world);
  995. }
  996. }
  997. if (world.getStatus() == 9)
  998. {
  999. killedBelethSample(world, npc);
  1000. }
  1001. }
  1002. return "";
  1003. }
  1004. @Override
  1005. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon, Skill skill)
  1006. {
  1007. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1008. final DMCWorld world;
  1009. if (tmpworld instanceof DMCWorld)
  1010. {
  1011. world = (DMCWorld) tmpworld;
  1012. if (world.getStatus() == 7)
  1013. {
  1014. DMCRoom ForthRoom = world.rooms.get("ForthRoom");
  1015. for (DMCNpc mob : ForthRoom.npcList)
  1016. {
  1017. if (mob.npc == npc)
  1018. {
  1019. if (mob.npc.isInvul() && (getRandom(100) < 12))
  1020. {
  1021. if (debug)
  1022. {
  1023. _log.info("DarkCloudMansion: spawn room 4 guard");
  1024. }
  1025. addSpawn(BM[getRandom(BM.length)], player.getX(), player.getY(), player.getZ(), 0, false, 0, false, world.getInstanceId());
  1026. }
  1027. }
  1028. }
  1029. }
  1030. if (world.getStatus() == 9)
  1031. {
  1032. checkBelethSample(world, npc, player);
  1033. }
  1034. }
  1035. return "";
  1036. }
  1037. @Override
  1038. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  1039. {
  1040. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1041. DMCWorld world;
  1042. if (tmpworld instanceof DMCWorld)
  1043. {
  1044. world = (DMCWorld) tmpworld;
  1045. if (world.getStatus() == 4)
  1046. {
  1047. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  1048. for (DMCNpc mob : SecondRoom.npcList)
  1049. {
  1050. if (mob.npc == npc)
  1051. {
  1052. checkStone(npc, SecondRoom.Order, mob, world);
  1053. }
  1054. }
  1055. if (allStonesDone(world))
  1056. {
  1057. removeMonoliths(world);
  1058. runHall3(world);
  1059. }
  1060. }
  1061. if ((npc.getId() == SOTruth) && (world.getStatus() == 10))
  1062. {
  1063. npc.showChatWindow(player);
  1064. if (!hasQuestItems(player, CC))
  1065. {
  1066. giveItems(player, CC, 1);
  1067. }
  1068. }
  1069. }
  1070. return "";
  1071. }
  1072. @Override
  1073. public String onTalk(L2Npc npc, L2PcInstance player)
  1074. {
  1075. final int npcId = npc.getId();
  1076. if (npcId == YIYEN)
  1077. {
  1078. enterInstance(player, new DMCWorld(), "DarkCloudMansion.xml", TEMPLATE_ID);
  1079. }
  1080. else
  1081. {
  1082. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1083. DMCWorld world;
  1084. if (tmpworld instanceof DMCWorld)
  1085. {
  1086. world = (DMCWorld) tmpworld;
  1087. }
  1088. else
  1089. {
  1090. return "";
  1091. }
  1092. if (npcId == SOTruth)
  1093. {
  1094. if (world.isAllowed(player.getObjectId()))
  1095. {
  1096. if (debug)
  1097. {
  1098. _log.info("DarkCloudMansion - id " + player.getObjectId() + " removed from allowed player in this Instances.");
  1099. }
  1100. world.removeAllowed(player.getObjectId());
  1101. }
  1102. teleportPlayer(player, new Location(139968, 150367, -3111), 0);
  1103. int instanceId = npc.getInstanceId();
  1104. Instance instance = InstanceManager.getInstance().getInstance(instanceId);
  1105. if (instance.getPlayers().isEmpty())
  1106. {
  1107. InstanceManager.getInstance().destroyInstance(instanceId);
  1108. }
  1109. return "";
  1110. }
  1111. }
  1112. return "";
  1113. }
  1114. }