DarkCloudMansion.java 31 KB

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