DarkCloudMansion.java 30 KB

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