DarkCloudMansion.java 31 KB

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