DarkCloudMansion.java 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. package instances.DarkCloudMansion;
  2. import javolution.util.FastList;
  3. import javolution.util.FastMap;
  4. import com.l2jserver.gameserver.ai.CtrlIntention;
  5. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  6. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  7. import com.l2jserver.gameserver.model.L2Party;
  8. import com.l2jserver.gameserver.model.L2Skill;
  9. import com.l2jserver.gameserver.model.actor.L2Npc;
  10. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  11. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  12. import com.l2jserver.gameserver.model.entity.Instance;
  13. import com.l2jserver.gameserver.model.quest.Quest;
  14. import com.l2jserver.gameserver.model.quest.QuestState;
  15. import com.l2jserver.gameserver.network.SystemMessageId;
  16. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  17. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  18. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  19. import com.l2jserver.util.Rnd;
  20. public class DarkCloudMansion extends Quest
  21. {
  22. public DarkCloudMansion(int questId, String name, String descr)
  23. {
  24. super(questId, name, descr);
  25. addFirstTalkId(BSM);
  26. addFirstTalkId(SOTruth);
  27. addStartNpc(YIYEN);
  28. addTalkId(YIYEN);
  29. addTalkId(SOTruth);
  30. addAttackId(SC);
  31. for (int mob : BS)
  32. addAttackId(mob);
  33. for (int mob : CCG)
  34. addAttackId(mob);
  35. for (int mob : TOKILL )
  36. addKillId(mob);
  37. }
  38. private static class DMCNpc
  39. {
  40. public L2Npc npc;
  41. public boolean isDead = false;
  42. public L2Npc golem = null;
  43. public int status = 0;
  44. public int order = 0;
  45. public int count = 0;
  46. }
  47. private static class DMCRoom
  48. {
  49. public FastList<DMCNpc> npcList = new FastList<DMCNpc>();
  50. public int counter = 0;
  51. public int reset = 0;
  52. public int founded = 0;
  53. public int[] Order;
  54. }
  55. private class DMCWorld extends InstanceWorld
  56. {
  57. public FastMap<String,DMCRoom> rooms = new FastMap<String,DMCRoom>();
  58. public DMCWorld()
  59. {
  60. }
  61. }
  62. private static boolean debug = false;
  63. private static boolean noRndWalk = true;
  64. private static String qn = "DarkCloudMansion";
  65. private static final int INSTANCEID = 9;
  66. private static class teleCoord {int instanceId; int x; int y; int z;}
  67. //Items
  68. private static int CC = 9690; //Contaminated Crystal
  69. //NPCs
  70. private static int YIYEN = 32282;
  71. private static int SOFaith = 32288; //Symbol of Faith
  72. private static int SOAdversity = 32289; //Symbol of Adversity
  73. private static int SOAdventure = 32290; //Symbol of Adventure
  74. private static int SOTruth = 32291; //Symbol of Truth
  75. private static int BSM = 32324; //Black Stone Monolith
  76. private static int SC = 22402; //Shadow Column
  77. //Mobs
  78. private static int[] CCG = {18369,18370}; //Chromatic Crystal Golem
  79. private static int[] BM = {22272,22273,22274}; //Beleth's Minions
  80. private static int[] HG = {22264,22264}; //[22318,22319] #Hall Guards
  81. private static int[] BS = {18371,18372,18373,18374,18375,18376,18377}; //Beleth's Samples
  82. private static int[] TOKILL = {18371,18372,18373,18374,18375,18376,18377,22318,22319,22272,22273,22274,18369,18370,22402,22264};
  83. //Doors/Walls
  84. private static int D1 = 24230001; //Starting Room
  85. private static int D2 = 24230002; //First Room
  86. private static int D3 = 24230005; //Second Room
  87. private static int D4 = 24230003; //Third Room
  88. private static int D5 = 24230004; //Forth Room
  89. private static int D6 = 24230006; //Fifth Room
  90. private static int W1 = 24230007; //Wall 1
  91. /*private static int W2 = 24230008; //Wall 2
  92. private static int W3 = 24230009; //Wall 3
  93. private static int W4 = 24230010; //Wall 4
  94. private static int W5 = 24230011; //Wall 5
  95. private static int W6 = 24230012; //Wall 6
  96. private static int W7 = 24230013; //Wall 7*/
  97. private static int[] _spawnChat =
  98. {
  99. 1800043, // I'm the real one!
  100. 1800044, // Pick me!
  101. 1800045, // Trust me!
  102. 1800046, // Not that dude, I'm the real one!
  103. 1800047 // Don't be fooled! Don't be fooled! I'm the real one!!
  104. };
  105. private static int[] _decayChat =
  106. {
  107. 1800051, // I'm the real one! Phew!!
  108. 1800052, // Can't you even find out?
  109. 1800053 // Find me!
  110. };
  111. private static int[] _successChat =
  112. {
  113. 1800054, // Huh?! How did you know it was me?
  114. 1800055, // Excellent choice! Teehee!
  115. 1800056, // You've done well!
  116. 1800057 // Oh... very sensible?
  117. };
  118. private static int[] _faildChat =
  119. {
  120. 1800049, // You've been fooled!
  121. 1800050 // Sorry, but...I'm the fake one.
  122. };
  123. //Second room - random monolith order
  124. private static int[][] MonolithOrder = new int[][]
  125. {
  126. {1,2,3,4,5,6},
  127. {6,5,4,3,2,1},
  128. {4,5,6,3,2,1},
  129. {2,6,3,5,1,4},
  130. {4,1,5,6,2,3},
  131. {3,5,1,6,2,4},
  132. {6,1,3,4,5,2},
  133. {5,6,1,2,4,3},
  134. {5,2,6,3,4,1},
  135. {1,5,2,6,3,4},
  136. {1,2,3,6,5,4},
  137. {6,4,3,1,5,2},
  138. {3,5,2,4,1,6},
  139. {3,2,4,5,1,6},
  140. {5,4,3,1,6,2},
  141. };
  142. //Second room - golem spawn locatons - random
  143. private static int[][] GolemSpawn = new int[][]
  144. {
  145. {CCG[0],148060,181389},
  146. {CCG[1],147910,181173},
  147. {CCG[0],147810,181334},
  148. {CCG[1],147713,181179},
  149. {CCG[0],147569,181410},
  150. {CCG[1],147810,181517},
  151. {CCG[0],147805,181281}
  152. };
  153. //forth room - random shadow column
  154. private static int[][] ColumnRows = new int[][]
  155. {
  156. {1,1,0,1,0},
  157. {0,1,1,0,1},
  158. {1,0,1,1,0},
  159. {0,1,0,1,1},
  160. {1,0,1,0,1}
  161. };
  162. //Fifth room - beleth order
  163. private static int[][] Beleths = new int[][]
  164. {
  165. {1,0,1,0,1,0,0},
  166. {0,0,1,0,1,1,0},
  167. {0,0,0,1,0,1,1},
  168. {1,0,1,1,0,0,0},
  169. {1,1,0,0,0,1,0},
  170. {0,1,0,1,0,1,0},
  171. {0,0,0,1,1,1,0},
  172. {1,0,1,0,0,1,0},
  173. {0,1,1,0,0,0,1}
  174. };
  175. protected void openDoor(int doorId,int instanceId)
  176. {
  177. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(instanceId).getDoors())
  178. {
  179. if (door.getDoorId() == doorId)
  180. door.openMe();
  181. }
  182. }
  183. private boolean checkConditions(L2PcInstance player)
  184. {
  185. if (debug)
  186. return true;
  187. else
  188. {
  189. L2Party party = player.getParty();
  190. if (party == null)
  191. {
  192. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  193. return false;
  194. }
  195. if (party.getLeader() != player)
  196. {
  197. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  198. return false;
  199. }
  200. if (party.getMemberCount() > 2)
  201. {
  202. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER));
  203. return false;
  204. }
  205. for (L2PcInstance partyMember : party.getPartyMembers())
  206. {
  207. if (partyMember.getLevel() < 78)
  208. {
  209. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  210. sm.addPcName(partyMember);
  211. player.sendPacket(sm);
  212. return false;
  213. }
  214. if (!partyMember.isInsideRadius(player, 1000, true, true))
  215. {
  216. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  217. sm.addPcName(partyMember);
  218. player.sendPacket(sm);
  219. return false;
  220. }
  221. }
  222. return true;
  223. }
  224. }
  225. private void teleportplayer(L2PcInstance player, teleCoord teleto)
  226. {
  227. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  228. player.setInstanceId(teleto.instanceId);
  229. player.teleToLocation(teleto.x, teleto.y, teleto.z);
  230. return;
  231. }
  232. protected int enterInstance(L2PcInstance player, String template, teleCoord teleto)
  233. {
  234. int instanceId = 0;
  235. //check for existing instances for this player
  236. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  237. //existing instance
  238. if (world != null)
  239. {
  240. if (!(world instanceof DMCWorld))
  241. {
  242. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  243. return 0;
  244. }
  245. teleto.instanceId = world.instanceId;
  246. teleportplayer(player,teleto);
  247. return instanceId;
  248. }
  249. //New instance
  250. else
  251. {
  252. if (!checkConditions(player))
  253. return 0;
  254. L2Party party = player.getParty();
  255. instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  256. world = new DMCWorld();
  257. world.instanceId = instanceId;
  258. world.templateId = INSTANCEID;
  259. InstanceManager.getInstance().addWorld(world);
  260. _log.info("DarkCloudMansion: started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  261. runStartRoom((DMCWorld)world);
  262. // teleport players
  263. teleto.instanceId = instanceId;
  264. if (debug && party == null)
  265. {
  266. world.allowed.add(player.getObjectId());
  267. teleportplayer(player,teleto);
  268. }
  269. else
  270. {
  271. for (L2PcInstance partyMember : party.getPartyMembers())
  272. {
  273. if (partyMember.getQuestState(qn) == null)
  274. newQuestState(partyMember);
  275. world.allowed.add(partyMember.getObjectId());
  276. teleportplayer(partyMember,teleto);
  277. }
  278. }
  279. return instanceId;
  280. }
  281. }
  282. protected void exitInstance(L2PcInstance player, teleCoord tele)
  283. {
  284. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  285. player.setInstanceId(0);
  286. player.teleToLocation(tele.x, tele.y, tele.z);
  287. }
  288. protected void runStartRoom(DMCWorld world)
  289. {
  290. world.status = 0;
  291. DMCRoom StartRoom = new DMCRoom();
  292. DMCNpc thisnpc;
  293. thisnpc = new DMCNpc();
  294. thisnpc.npc = addSpawn(BM[0],146817,180335,-6117,0,false,0,false, world.instanceId);
  295. StartRoom.npcList.add(thisnpc);
  296. if (noRndWalk)
  297. thisnpc.npc.setIsNoRndWalk(true);
  298. thisnpc = new DMCNpc();
  299. thisnpc.npc = addSpawn(BM[0],146741,180589,-6117,0,false,0,false, world.instanceId);
  300. StartRoom.npcList.add(thisnpc);
  301. if (noRndWalk)
  302. thisnpc.npc.setIsNoRndWalk(true);
  303. world.rooms.put("StartRoom", StartRoom);
  304. if (debug)
  305. _log.info("DarkCloudMansion: first room spawned in instance " + world.instanceId);
  306. }
  307. protected void spawnHall(DMCWorld world)
  308. {
  309. DMCRoom Hall = new DMCRoom();
  310. DMCNpc thisnpc;
  311. world.rooms.remove("Hall"); //remove room instance to avoid adding mob every time
  312. thisnpc = new DMCNpc();
  313. thisnpc.npc = addSpawn(BM[1],147217,180112,-6117,0,false,0,false, world.instanceId);
  314. if (noRndWalk)
  315. thisnpc.npc.setIsNoRndWalk(true);
  316. Hall.npcList.add(thisnpc);
  317. thisnpc = new DMCNpc();
  318. thisnpc.npc = addSpawn(BM[2],147217,180209,-6117,0,false,0,false, world.instanceId);
  319. if (noRndWalk)
  320. thisnpc.npc.setIsNoRndWalk(true);
  321. Hall.npcList.add(thisnpc);
  322. thisnpc = new DMCNpc();
  323. thisnpc.npc = addSpawn(BM[1],148521,180112,-6117,0,false,0,false, world.instanceId);
  324. if (noRndWalk)
  325. thisnpc.npc.setIsNoRndWalk(true);
  326. Hall.npcList.add(thisnpc);
  327. thisnpc = new DMCNpc();
  328. thisnpc.npc = addSpawn(BM[0],148521,180209,-6117,0,false,0,false, world.instanceId);
  329. if (noRndWalk)
  330. thisnpc.npc.setIsNoRndWalk(true);
  331. Hall.npcList.add(thisnpc);
  332. thisnpc = new DMCNpc();
  333. thisnpc.npc = addSpawn(BM[1],148525,180910,-6117,0,false,0,false, world.instanceId);
  334. if (noRndWalk)
  335. thisnpc.npc.setIsNoRndWalk(true);
  336. Hall.npcList.add(thisnpc);
  337. thisnpc = new DMCNpc();
  338. thisnpc.npc = addSpawn(BM[2],148435,180910,-6117,0,false,0,false, world.instanceId);
  339. if (noRndWalk)
  340. thisnpc.npc.setIsNoRndWalk(true);
  341. Hall.npcList.add(thisnpc);
  342. thisnpc = new DMCNpc();
  343. thisnpc.npc = addSpawn(BM[1],147242,180910,-6117,0,false,0,false, world.instanceId);
  344. if (noRndWalk)
  345. thisnpc.npc.setIsNoRndWalk(true);
  346. Hall.npcList.add(thisnpc);
  347. thisnpc = new DMCNpc();
  348. thisnpc.npc = addSpawn(BM[2],147242,180819,-6117,0,false,0,false, world.instanceId);
  349. if (noRndWalk)
  350. thisnpc.npc.setIsNoRndWalk(true);
  351. Hall.npcList.add(thisnpc);
  352. world.rooms.put("Hall", Hall);
  353. if (debug)
  354. _log.info("DarkCloudMansion: hall spawned");
  355. }
  356. protected void runHall(DMCWorld world)
  357. {
  358. spawnHall(world);
  359. world.status = 1;
  360. openDoor(D1, world.instanceId);
  361. }
  362. protected void runFirstRoom(DMCWorld world)
  363. {
  364. DMCRoom FirstRoom = new DMCRoom();
  365. DMCNpc thisnpc;
  366. thisnpc = new DMCNpc();
  367. thisnpc.npc = addSpawn(HG[1],147842,179837,-6117,0,false,0,false, world.instanceId);
  368. if (noRndWalk)
  369. thisnpc.npc.setIsNoRndWalk(true);
  370. FirstRoom.npcList.add(thisnpc);
  371. thisnpc = new DMCNpc();
  372. thisnpc.npc = addSpawn(HG[0],147711,179708,-6117,0,false,0,false, world.instanceId);
  373. if (noRndWalk)
  374. thisnpc.npc.setIsNoRndWalk(true);
  375. FirstRoom.npcList.add(thisnpc);
  376. thisnpc = new DMCNpc();
  377. thisnpc.npc = addSpawn(HG[1],147842,179552,-6117,0,false,0,false, world.instanceId);
  378. if (noRndWalk)
  379. thisnpc.npc.setIsNoRndWalk(true);
  380. FirstRoom.npcList.add(thisnpc);
  381. thisnpc = new DMCNpc();
  382. thisnpc.npc = addSpawn(HG[0],147964,179708,-6117,0,false,0,false, world.instanceId);
  383. if (noRndWalk)
  384. thisnpc.npc.setIsNoRndWalk(true);
  385. FirstRoom.npcList.add(thisnpc);
  386. world.rooms.put("FirstRoom", FirstRoom);
  387. world.status = 2;
  388. openDoor(D2, world.instanceId);
  389. if (debug)
  390. _log.info("DarkCloudMansion: spawned first room");
  391. }
  392. protected void runHall2(DMCWorld world)
  393. {
  394. addSpawn(SOFaith,147818,179643,-6117,0,false,0,false,world.instanceId);
  395. spawnHall(world);
  396. world.status = 3;
  397. }
  398. protected void runSecondRoom(DMCWorld world)
  399. {
  400. DMCRoom SecondRoom = new DMCRoom();
  401. DMCNpc thisnpc;
  402. // TODO: find a better way to initialize to [1,0,0,0,0,0,0]
  403. SecondRoom.Order = new int[7];
  404. SecondRoom.Order[0] = 1;
  405. for (int i=1;i<7;i++)
  406. SecondRoom.Order[i] = 0;
  407. int i = Rnd.get(MonolithOrder.length);
  408. thisnpc = new DMCNpc();
  409. thisnpc.npc = addSpawn(BSM,147800,181150,-6117,0,false,0,false, world.instanceId);
  410. thisnpc.order = MonolithOrder[i][0];
  411. SecondRoom.npcList.add(thisnpc);
  412. thisnpc = new DMCNpc();
  413. thisnpc.npc = addSpawn(BSM,147900,181215,-6117,0,false,0,false, world.instanceId);
  414. thisnpc.order = MonolithOrder[i][1];
  415. SecondRoom.npcList.add(thisnpc);
  416. thisnpc = new DMCNpc();
  417. thisnpc.npc = addSpawn(BSM,147900,181345,-6117,0,false,0,false, world.instanceId);
  418. thisnpc.order = MonolithOrder[i][2];
  419. SecondRoom.npcList.add(thisnpc);
  420. thisnpc = new DMCNpc();
  421. thisnpc.npc = addSpawn(BSM,147800,181410,-6117,0,false,0,false, world.instanceId);
  422. thisnpc.order = MonolithOrder[i][3];
  423. SecondRoom.npcList.add(thisnpc);
  424. thisnpc = new DMCNpc();
  425. thisnpc.npc = addSpawn(BSM,147700,181345,-6117,0,false,0,false, world.instanceId);
  426. thisnpc.order = MonolithOrder[i][4];
  427. SecondRoom.npcList.add(thisnpc);
  428. thisnpc = new DMCNpc();
  429. thisnpc.npc = addSpawn(BSM,147700,181215,-6117,0,false,0,false, world.instanceId);
  430. thisnpc.order = MonolithOrder[i][5];
  431. SecondRoom.npcList.add(thisnpc);
  432. world.rooms.put("SecondRoom", SecondRoom);
  433. world.status = 4;
  434. openDoor(D3, world.instanceId);
  435. if (debug)
  436. _log.info("DarkCloudMansion: spawned second room");
  437. }
  438. protected void runHall3(DMCWorld world)
  439. {
  440. addSpawn(SOAdversity,147808,181281,-6117,16383,false,0,false,world.instanceId);
  441. spawnHall(world);
  442. world.status = 5;
  443. }
  444. protected void runThirdRoom(DMCWorld world)
  445. {
  446. DMCRoom ThirdRoom = new DMCRoom();
  447. DMCNpc thisnpc = new DMCNpc();
  448. thisnpc.isDead = false;
  449. thisnpc.npc = addSpawn(BM[1],148765,180450,-6117,0,false,0,false,world.instanceId);
  450. if (noRndWalk)
  451. thisnpc.npc.setIsNoRndWalk(true);
  452. ThirdRoom.npcList.add(thisnpc);
  453. thisnpc.npc = addSpawn(BM[2],148865,180190,-6117,0,false,0,false,world.instanceId);
  454. if (noRndWalk)
  455. thisnpc.npc.setIsNoRndWalk(true);
  456. ThirdRoom.npcList.add(thisnpc);
  457. thisnpc.npc = addSpawn(BM[1],148995,180190,-6117,0,false,0,false,world.instanceId);
  458. if (noRndWalk)
  459. thisnpc.npc.setIsNoRndWalk(true);
  460. ThirdRoom.npcList.add(thisnpc);
  461. thisnpc.npc = addSpawn(BM[0],149090,180450,-6117,0,false,0,false,world.instanceId);
  462. if (noRndWalk)
  463. thisnpc.npc.setIsNoRndWalk(true);
  464. ThirdRoom.npcList.add(thisnpc);
  465. thisnpc.npc = addSpawn(BM[1],148995,180705,-6117,0,false,0,false,world.instanceId);
  466. if (noRndWalk)
  467. thisnpc.npc.setIsNoRndWalk(true);
  468. ThirdRoom.npcList.add(thisnpc);
  469. thisnpc.npc = addSpawn(BM[2],148865,180705,-6117,0,false,0,false,world.instanceId);
  470. if (noRndWalk)
  471. thisnpc.npc.setIsNoRndWalk(true);
  472. ThirdRoom.npcList.add(thisnpc);
  473. world.rooms.put("ThirdRoom", ThirdRoom);
  474. world.status = 6;
  475. openDoor(D4, world.instanceId);
  476. if (debug)
  477. _log.info("DarkCloudMansion: spawned third room");
  478. }
  479. protected void runThirdRoom2(DMCWorld world)
  480. {
  481. addSpawn(SOAdventure,148910,178397,-6117,16383,false,0,false,world.instanceId);
  482. DMCRoom ThirdRoom = new DMCRoom();
  483. DMCNpc thisnpc = new DMCNpc();
  484. thisnpc.isDead = false;
  485. thisnpc.npc = addSpawn(BM[1],148765,180450,-6117,0,false,0,false,world.instanceId);
  486. if (noRndWalk)
  487. thisnpc.npc.setIsNoRndWalk(true);
  488. ThirdRoom.npcList.add(thisnpc);
  489. thisnpc.npc = addSpawn(BM[2],148865,180190,-6117,0,false,0,false,world.instanceId);
  490. if (noRndWalk)
  491. thisnpc.npc.setIsNoRndWalk(true);
  492. ThirdRoom.npcList.add(thisnpc);
  493. thisnpc.npc = addSpawn(BM[1],148995,180190,-6117,0,false,0,false,world.instanceId);
  494. if (noRndWalk)
  495. thisnpc.npc.setIsNoRndWalk(true);
  496. ThirdRoom.npcList.add(thisnpc);
  497. thisnpc.npc = addSpawn(BM[0],149090,180450,-6117,0,false,0,false,world.instanceId);
  498. if (noRndWalk)
  499. thisnpc.npc.setIsNoRndWalk(true);
  500. ThirdRoom.npcList.add(thisnpc);
  501. thisnpc.npc = addSpawn(BM[1],148995,180705,-6117,0,false,0,false,world.instanceId);
  502. if (noRndWalk)
  503. thisnpc.npc.setIsNoRndWalk(true);
  504. ThirdRoom.npcList.add(thisnpc);
  505. thisnpc.npc = addSpawn(BM[2],148865,180705,-6117,0,false,0,false,world.instanceId);
  506. if (noRndWalk)
  507. thisnpc.npc.setIsNoRndWalk(true);
  508. ThirdRoom.npcList.add(thisnpc);
  509. world.rooms.put("ThirdRoom2", ThirdRoom);
  510. world.status = 8;
  511. if (debug)
  512. _log.info("DarkCloudMansion: spawned third room second time");
  513. }
  514. protected void runForthRoom(DMCWorld world)
  515. {
  516. DMCRoom ForthRoom = new DMCRoom();
  517. ForthRoom.counter = 0;
  518. DMCNpc thisnpc;
  519. int temp[] = new int[7];
  520. int templist[][] = new int[7][5];
  521. int xx = 0;
  522. for (int i = 0; i < 7; i++)
  523. temp[i] = Rnd.get(ColumnRows.length );
  524. for (int i=0; i < 7; i++)
  525. templist[i] = ColumnRows[temp[i]];
  526. for (int x = 148660; x<149285; x += 125)
  527. {
  528. int yy = 0;
  529. for (int y = 179280; y > 178405; y -= 125)
  530. {
  531. thisnpc = new DMCNpc();
  532. thisnpc.npc = addSpawn(SC,x,y,-6115,16215,false,0,false,world.instanceId);
  533. thisnpc.status = templist[yy][xx];
  534. thisnpc.order = yy;
  535. ForthRoom.npcList.add(thisnpc);
  536. yy++;
  537. }
  538. xx++;
  539. }
  540. //TODO: unify this into previous loop
  541. for (DMCNpc npc : ForthRoom.npcList)
  542. {
  543. if (npc.status == 0)
  544. npc.npc.setIsInvul(true);
  545. }
  546. world.rooms.put("ForthRoom", ForthRoom);
  547. world.status = 7;
  548. openDoor(D5, world.instanceId);
  549. if (debug)
  550. _log.info("DarkCloudMansion: spawned forth room");
  551. }
  552. protected void runFifthRoom(DMCWorld world)
  553. {
  554. spawnFifthRoom(world);
  555. world.status = 9;
  556. openDoor(D6,world.instanceId);
  557. if (debug)
  558. _log.info("DarkCloudMansion: spawned fifth room");
  559. }
  560. private void spawnFifthRoom(DMCWorld world)
  561. {
  562. int idx = 0;
  563. int temp[] = new int[6];
  564. DMCRoom FifthRoom = new DMCRoom();
  565. DMCNpc thisnpc;
  566. temp = Beleths[Rnd.get(Beleths.length)];
  567. FifthRoom.reset = 0;
  568. FifthRoom.founded = 0;
  569. for (int x = 148720; x < 149175; x += 65)
  570. {
  571. thisnpc = new DMCNpc();
  572. thisnpc.npc = addSpawn(BS[idx],x,182145,-6117,48810,false,0,false,world.instanceId);
  573. thisnpc.npc.setIsNoRndWalk(true);
  574. thisnpc.order = idx;
  575. thisnpc.status = temp[idx];
  576. thisnpc.count = 0;
  577. FifthRoom.npcList.add(thisnpc);
  578. if (temp[idx] == 1 && Rnd.get(100) < 95)
  579. thisnpc.npc.broadcastPacket(new NpcSay(thisnpc.npc.getObjectId(), 0, thisnpc.npc.getNpcId(), _spawnChat[Rnd.get(_spawnChat.length)]));
  580. else if (temp[idx] != 1 && Rnd.get(100) < 67)
  581. thisnpc.npc.broadcastPacket(new NpcSay(thisnpc.npc.getObjectId(), 0, thisnpc.npc.getNpcId(), _spawnChat[Rnd.get(_spawnChat.length)]));
  582. idx++ ;
  583. }
  584. world.rooms.put("FifthRoom", FifthRoom);
  585. }
  586. protected boolean checkKillProgress(L2Npc npc, DMCRoom room)
  587. {
  588. boolean cont = true;
  589. for (DMCNpc npcobj : room.npcList)
  590. {
  591. if (npcobj.npc == npc)
  592. npcobj.isDead = true;
  593. if (npcobj.isDead == false)
  594. cont = false;
  595. }
  596. return cont;
  597. }
  598. protected void spawnRndGolem(DMCWorld world, DMCNpc npc)
  599. {
  600. if (npc.golem != null)
  601. return;
  602. int i = Rnd.get(GolemSpawn.length);
  603. int mobId = GolemSpawn[i][0];
  604. int x = GolemSpawn[i][1];
  605. int y = GolemSpawn[i][2];
  606. npc.golem = addSpawn(mobId,x,y,-6117,0,false,0,false,world.instanceId);
  607. if (noRndWalk)
  608. npc.golem.setIsNoRndWalk(true);
  609. }
  610. protected void checkStone(L2Npc npc, int order[], DMCNpc npcObj, DMCWorld world)
  611. {
  612. for (int i=1; i<7; i++)
  613. {
  614. //if there is a non zero value in the precedent step, the sequence is ok
  615. if (order[i] == 0 && order[i-1] != 0)
  616. {
  617. if (npcObj.order == i && npcObj.status == 0)
  618. {
  619. order[i] = 1;
  620. npcObj.status = 1;
  621. npcObj.isDead = true;
  622. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5441, 1, 1, 0));
  623. return;
  624. }
  625. }
  626. }
  627. spawnRndGolem(world, npcObj);
  628. }
  629. protected void endInstance(DMCWorld world)
  630. {
  631. world.status = 10;
  632. addSpawn(SOTruth,148911,181940,-6117,16383,false,0,false,world.instanceId);
  633. world.rooms.clear();
  634. if (debug)
  635. _log.info("DarkCloudMansion: finished");
  636. }
  637. protected void checkBelethSample(DMCWorld world, L2Npc npc, L2PcInstance player)
  638. {
  639. DMCRoom FifthRoom = world.rooms.get("FifthRoom");
  640. for (DMCNpc mob : FifthRoom.npcList)
  641. {
  642. if (mob.npc == npc)
  643. {
  644. if (mob.count == 0)
  645. {
  646. mob.count = 1;
  647. if (mob.status == 1)
  648. {
  649. mob.npc.broadcastPacket(new NpcSay(mob.npc.getObjectId(), 0, mob.npc.getNpcId(), _successChat[Rnd.get(_successChat.length)]));
  650. FifthRoom.founded += 1;
  651. startQuestTimer("decayMe",1500, npc, player);
  652. }
  653. else
  654. {
  655. FifthRoom.reset = 1;
  656. mob.npc.broadcastPacket(new NpcSay(mob.npc.getObjectId(), 0, mob.npc.getNpcId(), _faildChat[Rnd.get(_faildChat.length)]));
  657. startQuestTimer("decayChatBelethSamples",4000, npc, player);
  658. startQuestTimer("decayBelethSamples",4500, npc, player);
  659. }
  660. }
  661. else
  662. return;
  663. }
  664. }
  665. }
  666. protected void killedBelethSample(DMCWorld world, L2Npc npc)
  667. {
  668. int decayedSamples = 0;
  669. DMCRoom FifthRoom = world.rooms.get("FifthRoom");
  670. for (DMCNpc mob : FifthRoom.npcList)
  671. {
  672. if (mob.npc == npc)
  673. {
  674. decayedSamples += 1;
  675. mob.count = 2;
  676. }
  677. else
  678. {
  679. if (mob.count == 2)
  680. decayedSamples += 1;
  681. }
  682. }
  683. if (FifthRoom.reset == 1)
  684. {
  685. for (DMCNpc mob : FifthRoom.npcList)
  686. {
  687. if (mob.count == 0 || (mob.status == 1 && mob.count != 2))
  688. {
  689. decayedSamples += 1;
  690. mob.npc.decayMe();
  691. mob.count = 2;
  692. }
  693. }
  694. if (decayedSamples == 7)
  695. startQuestTimer("respawnFifth", 6000, npc, null);
  696. }
  697. else
  698. {
  699. if (FifthRoom.reset == 0 && FifthRoom.founded == 3)
  700. {
  701. for (DMCNpc mob : FifthRoom.npcList)
  702. mob.npc.decayMe();
  703. endInstance(world);
  704. }
  705. }
  706. }
  707. protected boolean allStonesDone(DMCWorld world)
  708. {
  709. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  710. for (DMCNpc mob : SecondRoom.npcList)
  711. {
  712. if (mob.isDead)
  713. continue;
  714. else
  715. return false;
  716. }
  717. return true;
  718. }
  719. protected void removeMonoliths(DMCWorld world)
  720. {
  721. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  722. for (DMCNpc mob : SecondRoom.npcList)
  723. mob.npc.decayMe();
  724. }
  725. protected void chkShadowColumn(DMCWorld world, L2Npc npc)
  726. {
  727. DMCRoom ForthRoom = world.rooms.get("ForthRoom");
  728. for (DMCNpc mob : ForthRoom.npcList)
  729. {
  730. if (mob.npc == npc)
  731. {
  732. for (int i = 0;i <7; i++)
  733. {
  734. if (mob.order == i && ForthRoom.counter == i)
  735. {
  736. openDoor(W1+i, world.instanceId);
  737. ForthRoom.counter += 1;
  738. if (ForthRoom.counter == 7)
  739. runThirdRoom2(world);
  740. }
  741. }
  742. }
  743. }
  744. }
  745. @Override
  746. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  747. {
  748. if (npc == null)
  749. return "";
  750. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  751. DMCWorld world;
  752. if (tmpworld instanceof DMCWorld)
  753. world = (DMCWorld)tmpworld;
  754. else
  755. return "";
  756. if (world.rooms.containsKey("FifthRoom"))
  757. {
  758. DMCRoom FifthRoom = world.rooms.get("FifthRoom");
  759. if (event.equalsIgnoreCase("decayMe"))
  760. {
  761. for (DMCNpc mob : FifthRoom.npcList)
  762. {
  763. if (mob.npc == npc || (FifthRoom.reset == 0 && FifthRoom.founded == 3))
  764. {
  765. mob.npc.decayMe();
  766. mob.count = 2;
  767. }
  768. }
  769. if (FifthRoom.reset == 0 && FifthRoom.founded == 3)
  770. endInstance(world);
  771. }
  772. else if (event.equalsIgnoreCase("decayBelethSamples"))
  773. {
  774. for (DMCNpc mob : FifthRoom.npcList)
  775. {
  776. if (mob.count == 0)
  777. {
  778. mob.npc.decayMe();
  779. mob.count = 2;
  780. }
  781. }
  782. }
  783. else if (event.equalsIgnoreCase("decayChatBelethSamples"))
  784. {
  785. for (DMCNpc mob : FifthRoom.npcList)
  786. {
  787. if (mob.status == 1)
  788. mob.npc.broadcastPacket(new NpcSay(mob.npc.getObjectId(), 0, mob.npc.getNpcId(), _decayChat[Rnd.get(_decayChat.length)]));
  789. }
  790. }
  791. else if (event.equalsIgnoreCase("respawnFifth"))
  792. {
  793. spawnFifthRoom(world);
  794. }
  795. }
  796. return "";
  797. }
  798. @Override
  799. public String onKill( L2Npc npc, L2PcInstance player, boolean isPet)
  800. {
  801. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  802. DMCWorld world;
  803. if (tmpworld instanceof DMCWorld)
  804. {
  805. world = (DMCWorld)tmpworld;
  806. if (world.status==0)
  807. {
  808. if (checkKillProgress(npc, world.rooms.get("StartRoom")))
  809. runHall(world);
  810. }
  811. if (world.status==1)
  812. {
  813. if (checkKillProgress(npc,world.rooms.get("Hall")))
  814. runFirstRoom(world);
  815. }
  816. if (world.status==2)
  817. {
  818. if (checkKillProgress(npc,world.rooms.get("FirstRoom")))
  819. runHall2(world);
  820. }
  821. if (world.status==3)
  822. {
  823. if (checkKillProgress(npc,world.rooms.get("Hall")))
  824. runSecondRoom(world);
  825. }
  826. if (world.status==4)
  827. {
  828. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  829. for (DMCNpc mob : SecondRoom.npcList)
  830. {
  831. if (mob.golem == npc)
  832. mob.golem = null;
  833. }
  834. }
  835. if (world.status==5)
  836. {
  837. if (checkKillProgress(npc,world.rooms.get("Hall")))
  838. runThirdRoom(world);
  839. }
  840. if (world.status==6)
  841. {
  842. if (checkKillProgress(npc,world.rooms.get("ThirdRoom")))
  843. runForthRoom(world);
  844. }
  845. if (world.status==7)
  846. chkShadowColumn(world,npc);
  847. if (world.status==8)
  848. {
  849. if (checkKillProgress(npc,world.rooms.get("ThirdRoom2")))
  850. runFifthRoom(world);
  851. }
  852. if (world.status==9)
  853. killedBelethSample(world,npc);
  854. }
  855. return "";
  856. }
  857. @Override
  858. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isPet, L2Skill skill)
  859. {
  860. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  861. DMCWorld world;
  862. if (tmpworld instanceof DMCWorld)
  863. {
  864. world = (DMCWorld)tmpworld;
  865. if (world.status == 7)
  866. {
  867. DMCRoom ForthRoom = world.rooms.get("ForthRoom");
  868. for (DMCNpc mob : ForthRoom.npcList)
  869. {
  870. if (mob.npc == npc)
  871. {
  872. if (mob.npc.isInvul() && Rnd.get(100) < 12)
  873. {
  874. if (debug)
  875. _log.info("DarkCloudMansion: spawn room 4 guard");
  876. addSpawn(BM[Rnd.get(BM.length)],player.getX(),player.getY(),player.getZ(),0,false,0,false,world.instanceId);
  877. }
  878. }
  879. }
  880. }
  881. if (world.status == 9)
  882. checkBelethSample(world,npc,player);
  883. }
  884. return "";
  885. }
  886. @Override
  887. public String onFirstTalk (L2Npc npc, L2PcInstance player)
  888. {
  889. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  890. DMCWorld world;
  891. if (tmpworld instanceof DMCWorld)
  892. {
  893. world = (DMCWorld)tmpworld;
  894. if (world.status==4)
  895. {
  896. DMCRoom SecondRoom = world.rooms.get("SecondRoom");
  897. for (DMCNpc mob : SecondRoom.npcList)
  898. {
  899. if (mob.npc == npc)
  900. checkStone(npc,SecondRoom.Order,mob,world);
  901. }
  902. if (allStonesDone(world))
  903. {
  904. removeMonoliths(world);
  905. runHall3(world);
  906. }
  907. }
  908. if (npc.getNpcId() == SOTruth && world.status == 10)
  909. {
  910. npc.showChatWindow(player);
  911. QuestState st = player.getQuestState(qn);
  912. if (st == null)
  913. st = newQuestState(player);
  914. if (st.getQuestItemsCount(CC) < 1)
  915. st.giveItems(CC,1);
  916. }
  917. }
  918. return "";
  919. }
  920. @Override
  921. public String onTalk (L2Npc npc, L2PcInstance player)
  922. {
  923. int npcId = npc.getNpcId();
  924. if (npcId == YIYEN)
  925. {
  926. teleCoord tele = new teleCoord();
  927. tele.x = 146534;
  928. tele.y = 180464;
  929. tele.z = -6117;
  930. enterInstance(player, "DarkCloudMansion.xml", tele);
  931. }
  932. else
  933. {
  934. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  935. DMCWorld world;
  936. if (tmpworld instanceof DMCWorld)
  937. world = (DMCWorld)tmpworld;
  938. else
  939. return "";
  940. if (npcId == SOTruth)
  941. {
  942. teleCoord tele = new teleCoord();
  943. tele.x = 139968;
  944. tele.y = 150367;
  945. tele.z = -3111;
  946. if (world.allowed.contains(player.getObjectId()))
  947. {
  948. if (debug)
  949. _log.info("DarkCloudMansion - id " + player.getObjectId() + " removed from allowed player in this Instances.");
  950. world.allowed.remove(world.allowed.indexOf(player.getObjectId()));
  951. }
  952. exitInstance(player,tele);
  953. int instanceId = npc.getInstanceId();
  954. Instance instance = InstanceManager.getInstance().getInstance(instanceId);
  955. if (instance.getPlayers().isEmpty())
  956. InstanceManager.getInstance().destroyInstance(instanceId);
  957. return "";
  958. }
  959. }
  960. return "";
  961. }
  962. public static void main(String[] args)
  963. {
  964. // now call the constructor (starts up the)
  965. new DarkCloudMansion(-1,"DarkCloudMansion",qn);
  966. }
  967. }