CrystalCaverns.java 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. /*
  2. Todo:
  3. 1. Kechi's Henchmans spawn animation is missing.
  4. 2. NPC related Traps are not supported by core, so Darnels and Lahm door trap is not working.
  5. 3. Need retail spawn for Coral Garden (EmeraldSteam/Square - done).
  6. 4. Baylor Raid is missing a lot of things
  7. This script takes the best elements of different versions and combines them into one script to get the most optimal and retail-like experience.
  8. Original sources: theone, L2JEmu, L2JOfficial, L2JFree
  9. Contributing authors: TGS, Lantoc, Janiii, Gigiikun, RosT
  10. Please maintain consistency between the Crystal Caverns scripts.
  11. */
  12. package instances.CrystalCaverns;
  13. import java.util.List;
  14. import java.util.Map;
  15. import javolution.util.FastList;
  16. import javolution.util.FastMap;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.GeoData;
  19. import com.l2jserver.gameserver.ai.CtrlIntention;
  20. import com.l2jserver.gameserver.datatables.SkillTable;
  21. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  22. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  23. import com.l2jserver.gameserver.model.L2CharPosition;
  24. import com.l2jserver.gameserver.model.L2ItemInstance;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.L2Party;
  27. import com.l2jserver.gameserver.model.L2Skill;
  28. import com.l2jserver.gameserver.model.L2Skill.SkillTargetType;
  29. import com.l2jserver.gameserver.model.L2World;
  30. import com.l2jserver.gameserver.model.Location;
  31. import com.l2jserver.gameserver.model.actor.L2Attackable;
  32. import com.l2jserver.gameserver.model.actor.L2Character;
  33. import com.l2jserver.gameserver.model.actor.L2Npc;
  34. import com.l2jserver.gameserver.model.actor.L2Summon;
  35. import com.l2jserver.gameserver.model.actor.L2Trap;
  36. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  37. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  39. import com.l2jserver.gameserver.model.entity.Instance;
  40. import com.l2jserver.gameserver.model.quest.Quest;
  41. import com.l2jserver.gameserver.model.quest.QuestState;
  42. import com.l2jserver.gameserver.model.quest.State;
  43. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  44. import com.l2jserver.gameserver.network.SystemMessageId;
  45. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  46. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  47. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  48. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  49. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  50. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  51. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  52. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  53. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  54. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  55. import com.l2jserver.gameserver.util.Util;
  56. import com.l2jserver.util.Rnd;
  57. public class CrystalCaverns extends Quest
  58. {
  59. private static class CrystalGolem
  60. {
  61. public L2ItemInstance foodItem = null;
  62. public boolean isAtDestination = false;
  63. public L2CharPosition oldpos = null;
  64. }
  65. private class CCWorld extends InstanceWorld
  66. {
  67. public Map<L2Npc,Boolean> npcList1 = new FastMap<L2Npc,Boolean>();
  68. public L2Npc tears;
  69. public boolean isUsedInvulSkill = false;
  70. public long dragonScaleStart = 0;
  71. public int dragonScaleNeed = 0;
  72. public int cleanedRooms = 0;
  73. public long endTime = 0;
  74. public List<L2Npc> copys = new FastList<L2Npc>();
  75. public Map<L2Npc,CrystalGolem> crystalGolems = new FastMap<L2Npc,CrystalGolem>();
  76. public int correctGolems = 0;
  77. public boolean[] OracleTriggered = {false,false,false};
  78. public int kechisHenchmanSpawn = 0;
  79. public int[] roomsStatus = {0,0,0,0}; // 0: not spawned, 1: spawned, 2: cleared
  80. public Map<L2DoorInstance, L2PcInstance> openedDoors = new FastMap<L2DoorInstance, L2PcInstance>();
  81. public Map<Integer, Map<L2Npc,Boolean>> npcList2 = new FastMap<Integer, Map<L2Npc,Boolean>>();
  82. public Map<L2Npc,L2Npc> oracles = new FastMap<L2Npc,L2Npc>();
  83. public List<L2Npc> keyKeepers = new FastList<L2Npc>();
  84. public List<L2Npc> guards = new FastList<L2Npc>();
  85. public List<L2Npc> oracle = new FastList<L2Npc>();
  86. // baylor variables
  87. private List<L2PcInstance> _raiders = new FastList<L2PcInstance>();
  88. private int _raidStatus = 0;
  89. private long _dragonClawStart = 0;
  90. private int _dragonClawNeed = 0;
  91. private List<L2Npc> _animationMobs = new FastList<L2Npc>();
  92. private L2Npc _camera = null;
  93. private L2Npc _baylor = null;
  94. private L2Npc _alarm = null;
  95. public CCWorld(Long time)
  96. {
  97. endTime = time;
  98. }
  99. }
  100. private static final String qn = "CrystalCaverns";
  101. private static final int INSTANCEID = 10; // this is the client number
  102. private static final boolean debug = false;
  103. //Items
  104. private static final int WHITE_SEED = 9597;
  105. private static final int BLACK_SEED = 9598;
  106. private static final int CONT_CRYSTAL = 9690; //Contaminated Crystal
  107. private static final int RED_CORAL = 9692; //Red Coral
  108. private static final int CRYSTALFOOD = 9693; //Food item for Crystal Golems
  109. final private static int RACE_KEY = 9694; // Race Key for Emerald doors
  110. private static final int BOSS_CRYSTAL_1 = 9695; //Clear Crystal
  111. private static final int BOSS_CRYSTAL_2 = 9696; //Clear Crystal
  112. private static final int BOSS_CRYSTAL_3 = 9697; //Clear Crystal
  113. //NPCs
  114. private static final int ORACLE_GUIDE_1 = 32281;
  115. private static final int ORACLE_GUIDE_2 = 32278;
  116. private static final int ORACLE_GUIDE_3 = 32280;
  117. private static final int ORACLE_GUIDE_4 = 32279;
  118. private static final int CRYSTAL_GOLEM = 32328;
  119. private static final int[] DOOR_OPENING_TRAP = { 18378, 143682, 142492, -11886, 16384 };
  120. //mobs
  121. private static final int GK1 = 22275;
  122. private static final int GK2 = 22277;
  123. private static final int TOURMALINE = 22292;
  124. private static final int TEROD = 22301;
  125. private static final int DOLPH = 22299;
  126. private static final int WEYLIN = 22298;
  127. private static final int GUARDIAN = 22303;
  128. private static final int GUARDIAN2 = 22304;
  129. private static final int TEARS = 25534;
  130. private static final int TEARS_COPY = 25535;
  131. private static final int KECHI = 25532;
  132. private static final int KECHIGUARD = 25533;
  133. private static final int BAYLOR = 29099;
  134. private static final int DARNEL = 25531;
  135. private final static int ALARMID = 18474;
  136. // private static final int[] BOSSCR = {9695,9696,9697};
  137. private static final int[] CGMOBS = {22311,22312,22313,22314,22315,22316,22317};
  138. private static final int[] SPAWN = {60000, 120000, 90000, 60000, 50000, 40000}; // Kechi Hencmans spawn times
  139. private static final int[] MOBLIST = {22279,22280,22281,22282,22283,22285,22286,22287,22288,22289,22293,22294,22295,22296,22297,22305,22306,22307,22416,22418,22419,22420};
  140. // Doors/Walls/Zones
  141. private static final int DOOR1 = 24220021;
  142. private static final int DOOR2 = 24220024;
  143. private static final int DOOR3 = 24220023;
  144. private static final int DOOR4 = 24220061;
  145. private static final int DOOR5 = 24220025;
  146. private static final int DOOR6 = 24220022;
  147. private static final int[] ZONES = {20105,20106,20107};
  148. // Baylor alarm spawns
  149. private final static int[][] ALARMSPAWN = {{153572,141277,-12738},{153572,142852,-12738},
  150. {154358,142075,-12738},{152788,142075,-12738}
  151. };
  152. // Oracle order
  153. private static final int[][] ordreOracle1 = {
  154. {32274, 147090, 152505, -12169, 31613},
  155. {32275, 147090, 152575, -12169, 31613},
  156. {32274, 147090, 152645, -12169, 31613},
  157. {32274, 147090, 152715, -12169, 31613}
  158. };
  159. private static final int[][] ordreOracle2 = {
  160. {32274, 149783, 152505, -12169, 31613},
  161. // {32274, 149783, 152575, -12169, 31613},
  162. {32274, 149783, 152645, -12169, 31613},
  163. {32276, 149783, 152715, -12169, 31613}
  164. };
  165. private static final int[][] ordreOracle3 = {
  166. {32274, 152461, 152505, -12169, 31613},
  167. // {32274, 152461, 152575, -12169, 31613},
  168. {32277, 152461, 152645, -12169, 31613}
  169. // {32274, 152461, 152715, -12169, 31613}
  170. };
  171. //Hall spawns
  172. private static int[][] SPAWNS= {{141842, 152556, -11814, 50449},{141503, 153395, -11814, 40738},
  173. {141070, 153201, -11814, 39292},{141371, 152986, -11814, 35575},
  174. {141602, 154188, -11814, 24575},{141382, 154719, -11814, 37640},
  175. {141376, 154359, -11814, 12054},{140895, 154383, -11814, 37508},
  176. {140972, 154740, -11814, 52690},{141045, 154504, -11814, 50674},
  177. {140757, 152740, -11814, 39463},{140406, 152376, -11814, 16599},
  178. {140268, 152007, -11817, 45316},{139996, 151485, -11814, 47403},
  179. {140378, 151190, -11814, 58116},{140521, 150711, -11815, 55997},
  180. {140816, 150215, -11814, 53682},{141528, 149909, -11814, 22020},
  181. {141644, 150360, -11817, 13283},{142048, 150695, -11815, 5929},
  182. {141852, 151065, -11817, 27071},{142408, 151211, -11815, 2402},
  183. {142481, 151762, -11815, 12876},{141929, 152193, -11815, 27511},
  184. {142083, 151791, -11814, 47176},{141435, 150402, -11814, 41798},
  185. {140390, 151199, -11814, 50069},{140557, 151849, -11814, 45293},
  186. {140964, 153445, -11814, 56672},{142851, 154109, -11814, 24920},
  187. {142379, 154725, -11814, 30342},{142816, 154712, -11814, 33193},
  188. {142276, 154223, -11814, 33922},{142459, 154490, -11814, 33184},
  189. {142819, 154372, -11814, 21318},{141157, 154541, -11814, 27090},
  190. {141095, 150281, -11814, 55186}
  191. };
  192. //first spawns
  193. private static int[][] FIRST_SPAWNS= {{22276, 148109, 149601, -12132, 34490},{22276, 148017, 149529, -12132, 33689},
  194. {22278, 148065, 151202, -12132, 35323},{22278, 147966, 151117, -12132, 33234},
  195. {22279, 144063, 150238, -12132, 29654},{22279, 144300, 149118, -12135, 5520},
  196. {22279, 144397, 149337, -12132, 644},{22279, 144426, 150639, -12132, 50655},
  197. {22282, 145841, 151097, -12132, 31810},{22282, 144387, 149958, -12132, 61173},
  198. {22282, 145821, 149498, -12132, 31490},{22282, 146619, 149694, -12132, 33374},
  199. {22282, 146669, 149244, -12132, 31360},{22284, 144147, 151375, -12132, 58395},
  200. {22284, 144485, 151067, -12132, 64786},{22284, 144356, 149571, -12132, 63516},
  201. {22285, 144151, 150962, -12132, 664},{22285, 146657, 151365, -12132, 33154},
  202. {22285, 146623, 150857, -12132, 28034},{22285, 147046, 151089, -12132, 32941},
  203. {22285, 145704, 151255, -12132, 32523},{22285, 145359, 151101, -12132, 32767},
  204. {22285, 147785, 150817, -12132, 27423},{22285, 147727, 151375, -12132, 37117},
  205. {22285, 145428, 149494, -12132, 890},{22285, 145601, 149682, -12132, 32442},
  206. {22285, 147003, 149476, -12132, 31554},{22285, 147738, 149210, -12132, 20971},
  207. {22285, 147769, 149757, -12132, 34980}
  208. };
  209. // Emerald Square
  210. private static int[][] EMERALD_SPAWNS = {{22280, 144437, 143395, -11969, 34248},{22281, 149241, 143735, -12230, 24575},
  211. {22281, 147917, 146861, -12289, 60306},{22281, 144406, 147782, -12133, 14349},
  212. {22281, 144960, 146881, -12039, 23881},{22281, 144985, 147679, -12135, 27594},
  213. {22283, 147784, 143540, -12222, 2058},{22283, 149091, 143491, -12230, 24836},
  214. {22287, 144479, 147569, -12133, 20723},{22287, 145158, 146986, -12058, 21970},
  215. {22287, 145142, 147175, -12092, 24420},{22287, 145110, 147133, -12088, 22465},
  216. {22287, 144664, 146604, -12028, 14861},{22287, 144596, 146600, -12028, 14461},
  217. {22288, 143925, 146773, -12037, 10813},{22288, 144415, 147070, -12069, 8568},
  218. {22288, 143794, 145584, -12027, 14849},{22288, 143429, 146166, -12030, 4078},
  219. {22288, 144477, 147009, -12056, 8752},{22289, 142577, 145319, -12029, 5403},
  220. {22289, 143831, 146902, -12051, 9717},{22289, 143714, 146705, -12028, 10044},
  221. {22289, 143937, 147134, -12078, 7517},{22293, 143356, 145287, -12027, 8126},
  222. {22293, 143462, 144352, -12008, 25905},{22293, 143745, 142529, -11882, 17102},
  223. {22293, 144574, 144032, -12005, 34668},{22295, 143992, 142419, -11884, 19697},
  224. {22295, 144671, 143966, -12004, 32088},{22295, 144440, 143269, -11957, 34169},
  225. {22295, 142642, 146362, -12028, 281},{22295, 143865, 142707, -11881, 21326},
  226. {22295, 143573, 142530, -11879, 16141},{22295, 143148, 146039, -12031, 65014},
  227. {22295, 143001, 144853, -12014, 0},{22296, 147505, 146580, -12260, 59041},
  228. {22296, 149366, 146932, -12358, 39407},{22296, 149284, 147029, -12352, 41120},
  229. {22296, 149439, 143940, -12230, 23189},{22296, 147698, 143995, -12220, 27028},
  230. {22296, 141885, 144969, -12007, 2526},{22296, 147843, 143763, -12220, 28386},
  231. {22296, 144753, 143650, -11982, 35429},{22296, 147613, 146760, -12271, 56296}
  232. };
  233. private static int[][] ROOM1_SPAWNS = {{22288, 143114, 140027, -11888, 15025},{22288, 142173, 140973, -11888, 55698},
  234. {22289, 143210, 140577, -11888, 17164},{22289, 142638, 140107, -11888, 6571},
  235. {22297, 142547, 140938, -11888, 48556},{22298, 142690, 140479, -11887, 7663}
  236. };
  237. private static int[][] ROOM2_SPAWNS = {{22303, 146276, 141483, -11880, 34643},{22287, 145707, 142161, -11880, 28799},
  238. {22288, 146857, 142129, -11880, 33647},{22288, 146869, 142000, -11880, 31215},
  239. {22289, 146897, 140880, -11880, 19210}
  240. };
  241. private static int[][] ROOM3_SPAWNS = {{22302, 145123, 143713, -12808, 65323},{22294, 145188, 143331, -12808, 496},
  242. {22294, 145181, 144104, -12808, 64415},{22293, 144994, 143431, -12808, 65431},
  243. {22293, 144976, 143915, -12808, 61461}
  244. };
  245. private static int[][] ROOM4_SPAWNS = {{22304, 150563, 142240, -12108, 16454},{22294, 150769, 142495, -12108, 16870},
  246. {22281, 150783, 141995, -12108, 20033},{22283, 150273, 141983, -12108, 16043},
  247. {22294, 150276, 142492, -12108, 13540}
  248. };
  249. // Steam Corridor
  250. private static int[][] STEAM1_SPAWNS= {{22305, 145260, 152387, -12165, 32767},{22305, 144967, 152390, -12165, 30464},
  251. {22305, 145610, 152586, -12165, 17107},{22305, 145620, 152397, -12165, 8191},
  252. {22418, 146081, 152847, -12165, 31396},{22418, 146795, 152641, -12165, 33850}
  253. // {22308, 145093, 152502, -12165, 31841},{22308, 146158, 152776, -12165, 30810},
  254. // {22308, 146116, 152976, -12133, 32571},
  255. };
  256. private static int[][] STEAM2_SPAWNS= {{22306, 147740, 152767, -12165, 65043},{22306, 148215, 152828, -12165, 970},
  257. {22306, 147743, 152846, -12165, 64147},// {22308, 147849, 152854, -12165, 60534},
  258. // {22308, 147754, 152908, -12141, 59827},{22308, 148194, 152681, -12165, 63620},
  259. // {22308, 147767, 152939, -12133, 63381},{22309, 147737, 152671, -12165, 65320},
  260. {22418, 148207, 152725, -12165, 61801},{22419, 149058, 152828, -12165, 64564}
  261. };
  262. private static int[][] STEAM3_SPAWNS= {{22307, 150735, 152316, -12145, 31930},{22307, 150725, 152467, -12165, 33635},
  263. {22307, 151058, 152316, -12146, 65342},{22307, 151057, 152461, -12165, 2171}
  264. /*{22308, 150794, 152455, -12165, 31613},{22308, 150665, 152383, -12165, 32767},
  265. {22308, 151697, 152621, -12167, 31423},{22309, 151061, 152581, -12165, 6228},
  266. {22309, 150653, 152253, -12132, 31343},{22309, 150628, 152431, -12165, 33022},
  267. {22309, 151620, 152487, -12165, 30114},{22309, 151672, 152544, -12165, 31846},
  268. {22309, 150488, 152350, -12165, 29072},{22310, 151139, 152238, -12132, 1069}*/
  269. };
  270. private static int[][] STEAM4_SPAWNS= {//{22308, 151707, 150199, -12165, 32859},{22308, 152091, 150140, -12165, 32938},
  271. // {22308, 149757, 150204, -12138, 65331},{22308, 149950, 150307, -12132, 62437},
  272. //{22308, 149901, 150322, -12132, 62136},{22309, 150071, 150173, -12165, 64943},
  273. {22416, 151636, 150280, -12142, 36869},{22416, 149893, 150232, -12165, 64258},
  274. {22416, 149864, 150110, -12165, 65054},{22416, 151926, 150218, -12165, 31613},
  275. {22420, 149986, 150051, -12165, 105},{22420, 151970, 149997, -12165, 32170},
  276. {22420, 150744, 150006, -12165, 63}// ,{22417, 149782, 150188, -12151, 64001}
  277. };
  278. // Instance reenter time
  279. // default: 86400000ms(24h)
  280. private static final int INSTANCEPENALTY = 86400000;
  281. private static final int DRAGONSCALETIME = 3000;
  282. private static final int DRAGONCLAWTIME = 3000;
  283. private static class teleCoord {int instanceId; int x; int y; int z;}
  284. protected void openDoor(int doorId,int instanceId)
  285. {
  286. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(instanceId).getDoors())
  287. if (door.getDoorId() == doorId)
  288. door.openMe();
  289. }
  290. protected void closeDoor(int doorId,int instanceId)
  291. {
  292. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(instanceId).getDoors())
  293. if (door.getDoorId() == doorId)
  294. if (door.getOpen())
  295. door.closeMe();
  296. }
  297. private boolean checkConditions(L2PcInstance player)
  298. {
  299. if (debug)
  300. return true;
  301. L2Party party = player.getParty();
  302. if (party == null)
  303. {
  304. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  305. return false;
  306. }
  307. if (party.getLeader() != player)
  308. {
  309. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  310. return false;
  311. }
  312. for (L2PcInstance partyMember : party.getPartyMembers())
  313. {
  314. if (partyMember.getLevel() < 78)
  315. {
  316. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  317. sm.addPcName(partyMember);
  318. party.broadcastToPartyMembers(sm);
  319. return false;
  320. }
  321. L2ItemInstance item = partyMember.getInventory().getItemByItemId(CONT_CRYSTAL);
  322. if (item == null)
  323. {
  324. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  325. sm.addPcName(partyMember);
  326. party.broadcastToPartyMembers(sm);
  327. return false;
  328. }
  329. if (!Util.checkIfInRange(1000, player, partyMember, true))
  330. {
  331. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  332. sm.addPcName(partyMember);
  333. party.broadcastToPartyMembers(sm);
  334. return false;
  335. }
  336. Long reentertime = InstanceManager.getInstance().getInstanceTime(partyMember.getObjectId(), INSTANCEID);
  337. if (System.currentTimeMillis() < reentertime)
  338. {
  339. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
  340. sm.addPcName(partyMember);
  341. party.broadcastToPartyMembers(sm);
  342. return false;
  343. }
  344. }
  345. return true;
  346. }
  347. private boolean checkOracleConditions(L2PcInstance player)
  348. {
  349. if (debug)
  350. return true;
  351. L2Party party = player.getParty();
  352. if (party == null)
  353. {
  354. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  355. return false;
  356. }
  357. if (party.getLeader() != player)
  358. {
  359. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  360. return false;
  361. }
  362. for (L2PcInstance partyMember : party.getPartyMembers())
  363. {
  364. L2ItemInstance item = partyMember.getInventory().getItemByItemId(RED_CORAL);
  365. if (item == null)
  366. {
  367. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  368. sm.addPcName(partyMember);
  369. party.broadcastToPartyMembers(sm);
  370. return false;
  371. }
  372. if (!Util.checkIfInRange(1000, player, partyMember, true))
  373. {
  374. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  375. sm.addPcName(partyMember);
  376. party.broadcastToPartyMembers(sm);
  377. return false;
  378. }
  379. }
  380. return true;
  381. }
  382. private boolean checkBaylorConditions(L2PcInstance player)
  383. {
  384. L2Party party = player.getParty();
  385. if (party == null)
  386. {
  387. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  388. return false;
  389. }
  390. if (party.getLeader() != player)
  391. {
  392. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  393. return false;
  394. }
  395. for (L2PcInstance partyMember : party.getPartyMembers())
  396. {
  397. L2ItemInstance item1 = partyMember.getInventory().getItemByItemId(BOSS_CRYSTAL_1);
  398. L2ItemInstance item2 = partyMember.getInventory().getItemByItemId(BOSS_CRYSTAL_2);
  399. L2ItemInstance item3 = partyMember.getInventory().getItemByItemId(BOSS_CRYSTAL_3);
  400. if (item1 == null || item2 == null || item3 == null)
  401. {
  402. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  403. sm.addPcName(partyMember);
  404. party.broadcastToPartyMembers(sm);
  405. return false;
  406. }
  407. if (!Util.checkIfInRange(1000, player, partyMember, true))
  408. {
  409. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  410. sm.addPcName(partyMember);
  411. party.broadcastToPartyMembers(sm);
  412. return false;
  413. }
  414. }
  415. return true;
  416. }
  417. // this should be handled from skill effect
  418. private void Throw(L2Character effector, L2Character effected)
  419. {
  420. // Get current position of the L2Character
  421. final int curX = effected.getX();
  422. final int curY = effected.getY();
  423. final int curZ = effected.getZ();
  424. // Calculate distance between effector and effected current position
  425. double dx = effector.getX() - curX;
  426. double dy = effector.getY() - curY;
  427. double dz = effector.getZ() - curZ;
  428. double distance = Math.sqrt(dx * dx + dy * dy);
  429. int offset = Math.min((int) distance + 300, 1400);
  430. double cos;
  431. double sin;
  432. // approximation for moving futher when z coordinates are different
  433. // TODO: handle Z axis movement better
  434. offset += Math.abs(dz);
  435. if (offset < 5)
  436. offset = 5;
  437. if (distance < 1)
  438. return;
  439. // Calculate movement angles needed
  440. sin = dy / distance;
  441. cos = dx / distance;
  442. // Calculate the new destination with offset included
  443. int _x = effector.getX() - (int) (offset * cos);
  444. int _y = effector.getY() - (int) (offset * sin);
  445. int _z = effected.getZ();
  446. if (Config.GEODATA > 0)
  447. {
  448. Location destiny = GeoData.getInstance().moveCheck(effected.getX(), effected.getY(), effected.getZ(), _x, _y, _z, effected.getInstanceId());
  449. _x = destiny.getX();
  450. _y = destiny.getY();
  451. }
  452. effected.broadcastPacket(new FlyToLocation(effected, _x, _y, _z, FlyType.THROW_UP));
  453. // maybe is need force set X,Y,Z
  454. effected.setXYZ(_x, _y, _z);
  455. effected.broadcastPacket(new ValidateLocation(effected));
  456. }
  457. private void teleportplayer(L2PcInstance player, teleCoord teleto)
  458. {
  459. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  460. player.setInstanceId(teleto.instanceId);
  461. player.teleToLocation(teleto.x, teleto.y, teleto.z);
  462. return;
  463. }
  464. protected int enterInstance(L2PcInstance player, String template, teleCoord teleto)
  465. {
  466. //check for existing instances for this player
  467. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  468. //existing instance
  469. if (world != null)
  470. {
  471. if (!(world instanceof CCWorld))
  472. {
  473. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  474. return 0;
  475. }
  476. teleto.instanceId = world.instanceId;
  477. teleportplayer(player,teleto);
  478. return world.instanceId;
  479. }
  480. //New instance
  481. else
  482. {
  483. if (!checkConditions(player))
  484. return 0;
  485. L2Party party = player.getParty();
  486. int instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  487. world = new CCWorld(System.currentTimeMillis() + 5400000);
  488. world.instanceId = instanceId;
  489. world.templateId = INSTANCEID;
  490. InstanceManager.getInstance().addWorld(world);
  491. _log.info("Crystal Caverns started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  492. runOracle((CCWorld)world);
  493. // teleport players
  494. teleto.instanceId = instanceId;
  495. if (player.getParty() == null)
  496. {
  497. // this can happen only if debug is true
  498. player.sendMessage("Welcome to Crystal Caverns.");
  499. InstanceManager.getInstance().setInstanceTime(player.getObjectId(), INSTANCEID, ((System.currentTimeMillis() + INSTANCEPENALTY)));
  500. teleportplayer(player,teleto);
  501. world.allowed.add(player.getObjectId());
  502. }
  503. else
  504. {
  505. for (L2PcInstance partyMember : party.getPartyMembers())
  506. {
  507. partyMember.sendMessage("Welcome to Crystal Caverns.");
  508. InstanceManager.getInstance().setInstanceTime(partyMember.getObjectId(), INSTANCEID, ((System.currentTimeMillis() + INSTANCEPENALTY)));
  509. teleportplayer(partyMember,teleto);
  510. world.allowed.add(partyMember.getObjectId());
  511. }
  512. }
  513. return instanceId;
  514. }
  515. }
  516. protected void exitInstance(L2PcInstance player, teleCoord tele)
  517. {
  518. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  519. player.setInstanceId(0);
  520. player.teleToLocation(tele.x, tele.y, tele.z);
  521. }
  522. protected void stopAttack(L2PcInstance player)
  523. {
  524. player.setTarget(null);
  525. player.abortAttack();
  526. player.abortCast();
  527. player.breakAttack();
  528. player.breakCast();
  529. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  530. L2Summon pet = player.getPet();
  531. if (pet != null)
  532. {
  533. pet.setTarget(null);
  534. pet.abortAttack();
  535. pet.abortCast();
  536. pet.breakAttack();
  537. pet.breakCast();
  538. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  539. }
  540. }
  541. protected void runOracle(CCWorld world)
  542. {
  543. world.status = 0;
  544. world.oracle.add(addSpawn(ORACLE_GUIDE_1, 143172, 148894, -11975, 0, false,0,false,world.instanceId));
  545. }
  546. protected void runEmerald(CCWorld world)
  547. {
  548. world.status = 1;
  549. runFirst(world);
  550. openDoor(DOOR1, world.instanceId);
  551. }
  552. protected void runCoral(CCWorld world)
  553. {
  554. world.status = 1;
  555. runHall(world);
  556. openDoor(DOOR2, world.instanceId);
  557. openDoor(DOOR5, world.instanceId);
  558. }
  559. protected void runHall(CCWorld world)
  560. {
  561. world.status = 2;
  562. for (int[] spawn : SPAWNS)
  563. {
  564. L2Npc mob = addSpawn(CGMOBS[Rnd.get(CGMOBS.length)], spawn[0], spawn[1], spawn[2], spawn[3], false,0,false,world.instanceId);
  565. world.npcList1.put(mob, false);
  566. }
  567. }
  568. protected void runFirst(CCWorld world)
  569. {
  570. world.status = 2;
  571. world.keyKeepers.add(addSpawn(GK1, 148206, 149486, -12140, 32308, false,0,false,world.instanceId));
  572. world.keyKeepers.add(addSpawn(GK2, 148203, 151093, -12140, 31100, false,0,false,world.instanceId));
  573. for (int[] spawn : FIRST_SPAWNS)
  574. {
  575. addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  576. }
  577. }
  578. protected void runEmeraldSquare(CCWorld world)
  579. {
  580. world.status = 3;
  581. Map<L2Npc,Boolean> spawnList = new FastMap<L2Npc, Boolean>();
  582. for (int[] spawn : EMERALD_SPAWNS)
  583. {
  584. L2Npc mob = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  585. spawnList.put(mob, false);
  586. }
  587. world.npcList2.put(0, spawnList);
  588. }
  589. protected void runEmeraldRooms(CCWorld world, int[][] spawnList, int room)
  590. {
  591. Map<L2Npc,Boolean> spawned = new FastMap<L2Npc, Boolean>();
  592. for (int[] spawn : spawnList)
  593. {
  594. L2Npc mob = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  595. spawned.put(mob, false);
  596. }
  597. if (room == 1) // spawn Lahm
  598. addSpawn(32359, 142110, 139896, -11888, 8033, false,0,false,world.instanceId);
  599. world.npcList2.put(room, spawned);
  600. world.roomsStatus[room-1] = 1;
  601. }
  602. protected void runDarnel(CCWorld world)
  603. {
  604. world.status = 9;
  605. addSpawn(DARNEL, 152759, 145949, -12588, 21592, false,0,false,world.instanceId);
  606. // TODO: missing traps
  607. openDoor(24220005,world.instanceId);
  608. openDoor(24220006,world.instanceId);
  609. }
  610. protected void runSteamRooms(CCWorld world, int[][] spawnList, int status)
  611. {
  612. world.status = status;
  613. Map<L2Npc,Boolean> spawned = new FastMap<L2Npc, Boolean>();
  614. for (int[] spawn : spawnList)
  615. {
  616. L2Npc mob = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  617. spawned.put(mob, false);
  618. }
  619. world.npcList2.put(0, spawned);
  620. }
  621. protected void runSteamOracles(CCWorld world, int[][] oracleOrder)
  622. {
  623. world.oracles.clear();
  624. for(int[] oracle : oracleOrder)
  625. {
  626. world.oracles.put(addSpawn(oracle[0], oracle[1], oracle[2], oracle[3], oracle[4], false,0,false,world.instanceId), null);
  627. }
  628. }
  629. protected boolean checkKillProgress(int room, L2Npc mob, CCWorld world)
  630. {
  631. if (world.npcList2.get(room).containsKey(mob))
  632. world.npcList2.get(room).put(mob, true);
  633. for(boolean isDead: world.npcList2.get(room).values())
  634. if (!isDead)
  635. return false;
  636. return true;
  637. }
  638. /* protected void runBaylorRoom(CCWorld world)
  639. {
  640. world.status = 30;
  641. addSpawn(29101,152758,143479,-12706,52961,false,0,false,world.instanceId,0);//up power
  642. addSpawn(29101,151951,142078,-12706,65203,false,0,false,world.instanceId,0);//up power
  643. addSpawn(29101,154396,140667,-12706,22197,false,0,false,world.instanceId,0);//up power
  644. addSpawn(29102,152162,141249,-12706,5511,false,0,false,world.instanceId,0);//down power
  645. addSpawn(29102,153571,140458,-12706,16699,false,0,false,world.instanceId,0);//down power
  646. addSpawn(29102,154976,141265,-12706,26908,false,0,false,world.instanceId,0);//down power
  647. addSpawn(29102,155203,142071,-12706,31560,false,0,false,world.instanceId,0);//down power
  648. addSpawn(29102,154380,143468,-12708,43943,false,0,false,world.instanceId,0);//down power
  649. addSpawn(32271,153573,142069,-9722,11175,false,0,false,world.instanceId);
  650. world.Baylor = addSpawn(BAYLOR,153557,142089,-12735,11175,false,0,false,world.instanceId,0);
  651. }*/
  652. @Override
  653. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  654. {
  655. if (npc.getNpcId() == ORACLE_GUIDE_1)
  656. {
  657. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  658. if (tmpworld instanceof CCWorld)
  659. {
  660. CCWorld world = (CCWorld) tmpworld;
  661. if (world.status == 0 && world.oracle.contains(npc))
  662. {
  663. String htmltext = "32281.htm";
  664. return htmltext;
  665. }
  666. }
  667. npc.showChatWindow(player);
  668. return null;
  669. }
  670. else if (npc.getNpcId() >= 32275 && npc.getNpcId() <= 32277)
  671. {
  672. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  673. if (tmpworld instanceof CCWorld)
  674. {
  675. CCWorld world = (CCWorld) tmpworld;
  676. if (!world.OracleTriggered[npc.getNpcId() - 32275])
  677. {
  678. String htmltext = "no.htm";
  679. return htmltext;
  680. }
  681. npc.showChatWindow(player);
  682. return null;
  683. }
  684. }
  685. else if (npc.getNpcId() == 32274)
  686. {
  687. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  688. if (tmpworld instanceof CCWorld)
  689. {
  690. String htmltext = "no.htm";
  691. return htmltext;
  692. }
  693. }
  694. else if (npc.getNpcId() == 32279)
  695. {
  696. QuestState st = player.getQuestState("131_BirdInACage");
  697. String htmltext = "32279.htm";
  698. if (st != null && st.getState() != State.COMPLETED)
  699. htmltext = "32279-01.htm";
  700. return htmltext;
  701. }
  702. else if (npc.getNpcId() == CRYSTAL_GOLEM)
  703. player.sendPacket(ActionFailed.STATIC_PACKET);
  704. return"";
  705. }
  706. @Override
  707. public String onSkillSee (L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  708. {
  709. boolean doReturn = true;
  710. for(L2Object obj: targets)
  711. if (obj == npc)
  712. doReturn = false;
  713. if (doReturn)
  714. return super.onSkillSee(npc, caster, skill, targets, isPet);
  715. switch(skill.getId())
  716. {
  717. case 1011:
  718. case 1015:
  719. case 1217:
  720. case 1218:
  721. case 1401:
  722. case 2360:
  723. case 2369:
  724. case 5146:
  725. doReturn = false;
  726. break;
  727. default:
  728. doReturn = true;
  729. }
  730. if (doReturn)
  731. return super.onSkillSee(npc, caster, skill, targets, isPet);
  732. if (npc.getNpcId() >= 32275 && npc.getNpcId() <= 32277 && skill.getId() != 2360 && skill.getId() != 2369)
  733. {
  734. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  735. if (tmpworld instanceof CCWorld && Rnd.get(100) < 15)
  736. {
  737. for(L2Npc oracle : ((CCWorld) tmpworld).oracles.keySet())
  738. if (oracle != npc)
  739. oracle.decayMe();
  740. ((CCWorld) tmpworld).OracleTriggered[npc.getNpcId() - 32275] = true;
  741. }
  742. }
  743. else if (npc.isInvul() && npc.getNpcId() == BAYLOR && skill.getId() == 2360 && caster != null)
  744. {
  745. if (caster.getParty() == null)
  746. {
  747. return super.onSkillSee(npc, caster, skill, targets, isPet);
  748. }
  749. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  750. if (tmpworld instanceof CCWorld)
  751. {
  752. CCWorld world = (CCWorld) tmpworld;
  753. if ((world._dragonClawStart + DRAGONCLAWTIME) <= System.currentTimeMillis() || world._dragonClawNeed <= 0)
  754. {
  755. world._dragonClawStart = System.currentTimeMillis();
  756. world._dragonClawNeed = caster.getParty().getMemberCount() - 1;
  757. }
  758. else
  759. {
  760. world._dragonClawNeed--;
  761. }
  762. if (world._dragonClawNeed == 0)
  763. {
  764. npc.stopSkillEffects(5225);
  765. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5480, 1, 4000, 0));
  766. if (world._raidStatus == 3)
  767. world._raidStatus++;
  768. }
  769. }
  770. }
  771. else if (npc.isInvul() && npc.getNpcId() == TEARS && skill.getId() == 2369 && caster != null)
  772. {
  773. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  774. if (tmpworld instanceof CCWorld)
  775. {
  776. CCWorld world = (CCWorld) tmpworld;
  777. if (caster.getParty() == null)
  778. {
  779. return super.onSkillSee(npc, caster, skill, targets, isPet);
  780. }
  781. else if ((world.dragonScaleStart + DRAGONSCALETIME) <= System.currentTimeMillis() || world.dragonScaleNeed <= 0)
  782. {
  783. world.dragonScaleStart = System.currentTimeMillis();
  784. world.dragonScaleNeed = caster.getParty().getMemberCount() - 1;
  785. }
  786. else
  787. {
  788. world.dragonScaleNeed--;
  789. }
  790. if (world.dragonScaleNeed == 0 && Rnd.get(100) < 80)
  791. npc.setIsInvul(false);
  792. }
  793. }
  794. return super.onSkillSee(npc, caster, skill, targets, isPet);
  795. }
  796. @Override
  797. public String onAttack (L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  798. {
  799. if (npc.getNpcId() == TEARS)
  800. {
  801. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  802. if (tmpworld instanceof CCWorld)
  803. {
  804. CCWorld world = (CCWorld) tmpworld;
  805. if (world.status != 4 && attacker != null)
  806. {
  807. // Lucky cheater, the code only kicks his/her ass out of the dungeon
  808. teleCoord tele = new teleCoord();
  809. tele.x = 149361;
  810. tele.y = 172327;
  811. tele.z = -945;
  812. exitInstance(attacker,tele);
  813. world.allowed.remove(world.allowed.indexOf(attacker.getObjectId()));
  814. }
  815. else if (world.tears != npc)
  816. return "";
  817. else if (!world.copys.isEmpty())
  818. {
  819. boolean notAOE = true;
  820. if (skill != null && (skill.getTargetType() == SkillTargetType.TARGET_AREA
  821. || skill.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  822. || skill.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  823. || skill.getTargetType() == SkillTargetType.TARGET_AURA
  824. || skill.getTargetType() == SkillTargetType.TARGET_FRONT_AURA
  825. || skill.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA))
  826. notAOE = false;
  827. if (notAOE)
  828. {
  829. for (L2Npc copy : world.copys)
  830. copy.onDecay();
  831. world.copys.clear();
  832. }
  833. return "";
  834. }
  835. int maxHp = npc.getMaxHp();
  836. double nowHp = npc.getStatus().getCurrentHp();
  837. int rand = Rnd.get(1000);
  838. if (nowHp < maxHp * 0.4 && rand < 5)
  839. {
  840. L2Party party = attacker.getParty();
  841. if (party != null)
  842. for (L2PcInstance partyMember : party.getPartyMembers())
  843. stopAttack(partyMember);
  844. else
  845. stopAttack(attacker);
  846. L2Character target = npc.getAI().getAttackTarget();
  847. for (int i = 0; i < 10; i++)
  848. {
  849. L2Npc copy = addSpawn(TEARS_COPY,npc.getX(),npc.getY(),npc.getZ(),0,false,0,false,attacker.getInstanceId());
  850. copy.setRunning();
  851. ((L2Attackable) copy).addDamageHate(target, 0, 99999);
  852. copy.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  853. copy.setCurrentHp(nowHp);
  854. world.copys.add(copy);
  855. }
  856. }
  857. else if (nowHp < maxHp * 0.15 && !world.isUsedInvulSkill)
  858. {
  859. if (rand > 994 || nowHp < maxHp * 0.1)
  860. {
  861. world.isUsedInvulSkill = true;
  862. npc.setIsInvul(true);
  863. }
  864. }
  865. }
  866. }
  867. return null;
  868. }
  869. @Override
  870. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  871. {
  872. if (npc.getNpcId() == BAYLOR && skill.getId() == 5225)
  873. {
  874. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  875. if (tmpworld instanceof CCWorld)
  876. ((CCWorld) tmpworld)._raidStatus++;
  877. }
  878. return super.onSpellFinished(npc, player, skill);
  879. }
  880. @Override
  881. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  882. {
  883. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  884. if (tmpworld instanceof CCWorld)
  885. {
  886. CCWorld world = (CCWorld) tmpworld;
  887. teleCoord teleto = new teleCoord();
  888. teleto.instanceId = world.instanceId;
  889. if (event.equalsIgnoreCase("TeleportOut"))
  890. {
  891. teleCoord tele = new teleCoord();
  892. tele.x = 149413;
  893. tele.y = 173078;
  894. tele.z = -5014;
  895. exitInstance(player,tele);
  896. }
  897. else if (event.equalsIgnoreCase("TeleportParme"))
  898. {
  899. teleCoord tele = new teleCoord();
  900. tele.x = 153689;
  901. tele.y = 142226;
  902. tele.z = -9750;
  903. tele.instanceId = world.instanceId;
  904. teleportplayer(player,tele);
  905. }
  906. else if (event.equalsIgnoreCase("Timer2")||event.equalsIgnoreCase("Timer3")||event.equalsIgnoreCase("Timer4")||event.equalsIgnoreCase("Timer5"))
  907. {
  908. teleto.x = 144653;
  909. teleto.y = 152606;
  910. teleto.z = -12126;
  911. if (player.getInstanceId() == world.instanceId)
  912. {
  913. teleportplayer(player,teleto);
  914. player.stopSkillEffects(5239);
  915. SkillTable.getInstance().getInfo(5239, 1).getEffects(player, player);
  916. startQuestTimer("Timer2",300000,npc,player);
  917. }
  918. }
  919. else if (event.equalsIgnoreCase("Timer21")||event.equalsIgnoreCase("Timer31")||event.equalsIgnoreCase("Timer41")||event.equalsIgnoreCase("Timer51"))
  920. {
  921. InstanceManager.getInstance().getInstance(world.instanceId).removeNpcs();
  922. world.npcList2.clear();
  923. runSteamRooms(world, STEAM1_SPAWNS, 22);
  924. startQuestTimer("Timer21",300000,npc,null);
  925. }
  926. else if (event.equalsIgnoreCase("checkKechiAttack"))
  927. {
  928. if (npc.isInCombat())
  929. {
  930. startQuestTimer("spawnGuards", SPAWN[0], npc, null);
  931. cancelQuestTimers("checkKechiAttack");
  932. closeDoor(DOOR4,npc.getInstanceId());
  933. closeDoor(DOOR3,npc.getInstanceId());
  934. }
  935. else
  936. startQuestTimer("checkKechiAttack", 1000, npc, null);
  937. }
  938. else if (event.equalsIgnoreCase("spawnGuards"))
  939. {
  940. world.kechisHenchmanSpawn++;
  941. world.guards.add(addSpawn(KECHIGUARD,153622,149699,-12131,56890,false,0,false,world.instanceId));
  942. world.guards.add(addSpawn(KECHIGUARD,153609,149622,-12131,64023,false,0,false,world.instanceId));
  943. world.guards.add(addSpawn(KECHIGUARD,153606,149428,-12131,64541,false,0,false,world.instanceId));
  944. world.guards.add(addSpawn(KECHIGUARD,153601,149534,-12131,64901,false,0,false,world.instanceId));
  945. world.guards.add(addSpawn(KECHIGUARD,153620,149354,-12131,1164,false,0,false,world.instanceId));
  946. world.guards.add(addSpawn(KECHIGUARD,153637,149776,-12131,61733,false,0,false,world.instanceId));
  947. world.guards.add(addSpawn(KECHIGUARD,153638,149292,-12131,64071,false,0,false,world.instanceId));
  948. world.guards.add(addSpawn(KECHIGUARD,153647,149857,-12131,59402,false,0,false,world.instanceId));
  949. world.guards.add(addSpawn(KECHIGUARD,153661,149227,-12131,65275,false,0,false,world.instanceId));
  950. if (world.kechisHenchmanSpawn <= 5)
  951. startQuestTimer("spawnGuards", SPAWN[world.kechisHenchmanSpawn], npc, null);
  952. else
  953. cancelQuestTimers("spawnGuards");
  954. }
  955. else if (event.equalsIgnoreCase("EmeraldSteam"))
  956. {
  957. runEmerald(world);
  958. for(L2Npc oracle: world.oracle)
  959. oracle.decayMe();
  960. }
  961. else if (event.equalsIgnoreCase("CoralGarden"))
  962. {
  963. runCoral(world);
  964. for(L2Npc oracle: world.oracle)
  965. oracle.decayMe();
  966. }
  967. else if (event.equalsIgnoreCase("spawn_oracle"))
  968. {
  969. addSpawn(32271,153572,142075,-9728,10800,false,0,false,world.instanceId);
  970. addSpawn((Rnd.get(10) < 5 ? 29116:29117),npc.getX(),npc.getY(),npc.getZ(),npc.getHeading(),false,0,false,world.instanceId); // Baylor's Chest
  971. addSpawn(ORACLE_GUIDE_4,153572,142075,-12738,10800,false,0,false,world.instanceId);
  972. this.cancelQuestTimer("baylor_despawn", npc, null);
  973. this.cancelQuestTimers("baylor_skill");
  974. }
  975. else if (event.equalsIgnoreCase("baylorEffect0"))
  976. {
  977. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  978. npc.broadcastPacket(new SocialAction(npc,1));
  979. startQuestTimer("baylorCamera0",11000, npc, null);
  980. startQuestTimer("baylorEffect1",19000, npc, null);
  981. }
  982. else if (event.equalsIgnoreCase("baylorCamera0"))
  983. {
  984. npc.broadcastPacket(new SpecialCamera(npc.getObjectId(),500,-45,170,5000,9000,0,0,1,0));
  985. }
  986. else if (event.equalsIgnoreCase("baylorEffect1"))
  987. {
  988. npc.broadcastPacket(new SpecialCamera(npc.getObjectId(),300,0,120,2000,5000,0,0,1,0));
  989. npc.broadcastPacket(new SocialAction(npc,3));
  990. startQuestTimer("baylorEffect2",4000, npc, null);
  991. }
  992. else if (event.equalsIgnoreCase("baylorEffect2"))
  993. {
  994. npc.broadcastPacket(new SpecialCamera(npc.getObjectId(),747,0,160,2000,3000,0,0,1,0));
  995. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5402, 1, 2000, 0));
  996. startQuestTimer("RaidStart",2000, npc, null);
  997. }
  998. else if (event.equalsIgnoreCase("BaylorMinions"))
  999. {
  1000. for(int i = 0; i < 10; i++)
  1001. {
  1002. int radius = 300;
  1003. int x = (int) (radius * Math.cos(i * 0.618));
  1004. int y = (int) (radius * Math.sin(i * 0.618));
  1005. L2Npc mob = addSpawn(29104,153571 + x,142075 + y, -12737,0,false, 0, false, world.instanceId);
  1006. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1007. world._animationMobs.add(mob);
  1008. }
  1009. startQuestTimer("baylorEffect0",200, npc, null);
  1010. }
  1011. else if (event.equalsIgnoreCase("RaidStart"))
  1012. {
  1013. world._camera.decayMe();
  1014. world._camera = null;
  1015. npc.setIsParalyzed(false);
  1016. for(L2PcInstance p : world._raiders)
  1017. {
  1018. p.setIsParalyzed(false);
  1019. Throw(npc, p);
  1020. if (p.getPet() != null)
  1021. Throw(npc, p.getPet());
  1022. }
  1023. world._raidStatus = 0;
  1024. for(L2Npc mob : world._animationMobs)
  1025. {
  1026. mob.doDie(mob);
  1027. }
  1028. world._animationMobs.clear();
  1029. startQuestTimer("baylor_despawn",60000, npc, null, true);
  1030. startQuestTimer("checkBaylorAttack", 1000, npc, null);
  1031. }
  1032. else if (event.equalsIgnoreCase("checkBaylorAttack"))
  1033. {
  1034. if (npc.isInCombat())
  1035. {
  1036. cancelQuestTimers("checkBaylorAttack");
  1037. startQuestTimer("baylor_alarm",40000, npc, null);
  1038. startQuestTimer("baylor_skill",5000, npc, null, true);
  1039. world._raidStatus++;
  1040. }
  1041. else
  1042. startQuestTimer("checkBaylorAttack", 1000, npc, null);
  1043. }
  1044. else if (event.equalsIgnoreCase("baylor_alarm"))
  1045. {
  1046. if (world._alarm == null)
  1047. {
  1048. int[] spawnLoc = ALARMSPAWN[Rnd.get(ALARMSPAWN.length)];
  1049. npc.addSkill(SkillTable.getInstance().getInfo(5244, 1));
  1050. npc.addSkill(SkillTable.getInstance().getInfo(5245, 1));
  1051. world._alarm = addSpawn(ALARMID,spawnLoc[0],spawnLoc[1],spawnLoc[2],10800,false,0,false,world.instanceId);
  1052. world._alarm.disableCoreAI(true);
  1053. world._alarm.setIsImmobilized(true);
  1054. world._alarm.broadcastPacket(new CreatureSay(world._alarm.getObjectId(),1,world._alarm.getName(),"Alarm signal was switched off! All will in the danger, if we do not take measures immediately!"));
  1055. }
  1056. }
  1057. else if (event.equalsIgnoreCase("baylor_skill"))
  1058. {
  1059. if (world._baylor == null)
  1060. {
  1061. cancelQuestTimers("baylor_skill");
  1062. }
  1063. else
  1064. {
  1065. int maxHp = npc.getMaxHp();
  1066. double nowHp = npc.getStatus().getCurrentHp();
  1067. int rand = Rnd.get(100);
  1068. if (nowHp < maxHp * 0.2 && world._raidStatus < 3 && npc.getFirstEffect(5224) == null && npc.getFirstEffect(5225) == null)
  1069. {
  1070. if (nowHp < maxHp * 0.15 && world._raidStatus == 2)
  1071. {
  1072. npc.doCast(SkillTable.getInstance().getInfo(5225, 1));
  1073. npc.broadcastPacket(new CreatureSay(npc.getObjectId(),1,npc.getName(),"Demons King Beleth, give me power! Aaaaa!!!"));
  1074. }
  1075. else if (rand < 10 || nowHp < maxHp * 0.15)
  1076. {
  1077. npc.doCast(SkillTable.getInstance().getInfo(5225, 1));
  1078. npc.broadcastPacket(new CreatureSay(npc.getObjectId(),1,npc.getName(),"Demons King Beleth, give me power! Aaaaa!!!"));
  1079. startQuestTimer("baylor_remove_invul",30000, world._baylor, null);
  1080. }
  1081. }
  1082. else if (nowHp < maxHp * 0.3 && rand > 50 && npc.getFirstEffect(5225) == null && npc.getFirstEffect(5224) == null)
  1083. {
  1084. npc.doCast(SkillTable.getInstance().getInfo(5224, 1));
  1085. }
  1086. else if (rand < 33)
  1087. {
  1088. npc.setTarget(world._raiders.get(Rnd.get(world._raiders.size())));
  1089. npc.doCast(SkillTable.getInstance().getInfo(5229, 1));
  1090. }
  1091. }
  1092. }
  1093. else if (event.equalsIgnoreCase("baylor_remove_invul"))
  1094. {
  1095. npc.stopSkillEffects(5225);
  1096. }
  1097. else if (event.equalsIgnoreCase("Baylor"))
  1098. {
  1099. world._baylor = addSpawn(29099,153572,142075,-12738,10800,false,0,false,world.instanceId);
  1100. world._baylor.setIsParalyzed(true);
  1101. world._camera = addSpawn(29120,153273,141400,-12738,10800,false,0,false,world.instanceId);
  1102. world._camera.broadcastPacket(new SpecialCamera(world._camera.getObjectId(),700,-45,160,500,15200,0,0,1,0));
  1103. startQuestTimer("baylorMinions",2000, world._baylor, null);
  1104. }
  1105. else if (!event.endsWith("Food"))
  1106. return "";
  1107. else if (event.equalsIgnoreCase("autoFood"))
  1108. {
  1109. if (!world.crystalGolems.containsKey(npc))
  1110. world.crystalGolems.put(npc, new CrystalGolem());
  1111. if (world.status != 3 || !world.crystalGolems.containsKey(npc)
  1112. || world.crystalGolems.get(npc).foodItem != null || world.crystalGolems.get(npc).isAtDestination)
  1113. return "";
  1114. CrystalGolem cryGolem = world.crystalGolems.get(npc);
  1115. List<L2Object> crystals = new FastList<L2Object>();
  1116. for (L2Object object : L2World.getInstance().getVisibleObjects(npc, 300))
  1117. {
  1118. if (object instanceof L2ItemInstance && ((L2ItemInstance)object).getItemId()== CRYSTALFOOD)
  1119. crystals.add(object);
  1120. }
  1121. int minDist = 300000;
  1122. for (L2Object crystal : crystals)
  1123. {
  1124. int dx = npc.getX() - crystal.getX();
  1125. int dy = npc.getY() - crystal.getY();
  1126. int d = dx * dx + dy * dy;
  1127. if (d < minDist)
  1128. {
  1129. minDist = d;
  1130. cryGolem.foodItem = (L2ItemInstance)crystal;
  1131. }
  1132. }
  1133. if (minDist != 300000)
  1134. startQuestTimer("getFood",2000,npc,null);
  1135. else
  1136. {
  1137. if (Rnd.get(100) < 5)
  1138. npc.broadcastPacket(new CreatureSay(npc.getObjectId(),1,npc.getName(),"ah ... I am so hungry ..."));
  1139. startQuestTimer("autoFood",2000,npc,null);
  1140. }
  1141. return "";
  1142. }
  1143. else if (!world.crystalGolems.containsKey(npc) || world.crystalGolems.get(npc).isAtDestination)
  1144. return "";
  1145. else if (event.equalsIgnoreCase("backFood"))
  1146. {
  1147. if (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE)
  1148. {
  1149. cancelQuestTimers("backFood");
  1150. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  1151. world.crystalGolems.get(npc).foodItem = null;
  1152. startQuestTimer("autoFood",2000,npc,null);
  1153. }
  1154. }
  1155. else if (event.equalsIgnoreCase("reachFood"))
  1156. {
  1157. CrystalGolem cryGolem = world.crystalGolems.get(npc);
  1158. int dx;
  1159. int dy;
  1160. if (cryGolem.foodItem == null || !cryGolem.foodItem.isVisible())
  1161. {
  1162. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, cryGolem.oldpos);
  1163. cancelQuestTimers("reachFood");
  1164. startQuestTimer("backFood", 2000, npc, null, true);
  1165. return "";
  1166. }
  1167. else if (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE)
  1168. {
  1169. L2World.getInstance().removeVisibleObject(cryGolem.foodItem, cryGolem.foodItem.getWorldRegion());
  1170. L2World.getInstance().removeObject(cryGolem.foodItem);
  1171. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  1172. cryGolem.foodItem = null;
  1173. dx = npc.getX() - 142999;
  1174. dy = npc.getY() - 151671;
  1175. int d1 = dx * dx + dy * dy;
  1176. dx = npc.getX() - 139494;
  1177. dy = npc.getY() - 151668;
  1178. int d2 = dx * dx + dy * dy;
  1179. if (d1 < 10000 || d2 < 10000)
  1180. {
  1181. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5441, 1, 1, 0));
  1182. cryGolem.isAtDestination = true;
  1183. world.correctGolems++;
  1184. if (world.correctGolems >= 2)
  1185. {
  1186. openDoor(24220026,world.instanceId);
  1187. world.status = 4;
  1188. }
  1189. }
  1190. else
  1191. startQuestTimer("autoFood",2000,npc,null);
  1192. cancelQuestTimers("reachFood");
  1193. }
  1194. return "";
  1195. }
  1196. else if (event.equalsIgnoreCase("getFood"))
  1197. {
  1198. CrystalGolem cryGolem = world.crystalGolems.get(npc);
  1199. L2CharPosition newpos = new L2CharPosition(cryGolem.foodItem.getX(), cryGolem.foodItem.getY(), cryGolem.foodItem.getZ(), 0);
  1200. cryGolem.oldpos = new L2CharPosition(npc.getX(), npc.getY(), npc.getZ(), npc.getHeading());
  1201. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, newpos);
  1202. startQuestTimer("reachFood", 2000, npc, null, true);
  1203. cancelQuestTimers("getFood");
  1204. }
  1205. }
  1206. return "";
  1207. }
  1208. private void giveRewards(L2PcInstance player, int instanceId, int bossCry, boolean isBaylor)
  1209. {
  1210. final int num = Math.max((int)Config.RATE_DROP_ITEMS_BY_RAID, 1);
  1211. L2Party party = player.getParty();
  1212. if (party != null)
  1213. {
  1214. for (L2PcInstance partyMember : party.getPartyMembers())
  1215. if (partyMember.getInstanceId() == instanceId)
  1216. {
  1217. QuestState st = partyMember.getQuestState(qn);
  1218. if (st == null)
  1219. st = newQuestState(partyMember);
  1220. if (!isBaylor && st.getQuestItemsCount(CONT_CRYSTAL) > 0)
  1221. {
  1222. st.takeItems(CONT_CRYSTAL, 1);
  1223. st.giveItems(bossCry, 1);
  1224. }
  1225. if (Rnd.get(10) < 5)
  1226. st.giveItems(WHITE_SEED, num);
  1227. else
  1228. st.giveItems(BLACK_SEED, num);
  1229. }
  1230. }
  1231. else if (player.getInstanceId() == instanceId)
  1232. {
  1233. QuestState st = player.getQuestState(qn);
  1234. if (st == null)
  1235. st = newQuestState(player);
  1236. if (!isBaylor && st.getQuestItemsCount(CONT_CRYSTAL) > 0)
  1237. {
  1238. st.takeItems(CONT_CRYSTAL, 1);
  1239. st.giveItems(bossCry, 1);
  1240. }
  1241. if (Rnd.get(10) < 5)
  1242. st.giveItems(WHITE_SEED, num);
  1243. else
  1244. st.giveItems(BLACK_SEED, num);
  1245. }
  1246. }
  1247. @Override
  1248. public String onKill( L2Npc npc, L2PcInstance player, boolean isPet)
  1249. {
  1250. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1251. if (tmpworld instanceof CCWorld)
  1252. {
  1253. CCWorld world = (CCWorld) tmpworld;
  1254. if (world.status == 2 && world.npcList1.containsKey(npc))
  1255. {
  1256. world.npcList1.put(npc, true);
  1257. for (boolean isDead : world.npcList1.values())
  1258. if (!isDead)
  1259. return "";
  1260. world.status = 3;
  1261. world.tears = addSpawn(TEARS,144298,154420,-11854,32767,false,0,false,world.instanceId); // Tears
  1262. CrystalGolem crygolem1 = new CrystalGolem();
  1263. CrystalGolem crygolem2 = new CrystalGolem();
  1264. world.crystalGolems.put(addSpawn(CRYSTAL_GOLEM,140547,151670,-11813,32767,false,0,false,world.instanceId),crygolem1);
  1265. world.crystalGolems.put(addSpawn(CRYSTAL_GOLEM,141941,151684,-11813,63371,false,0,false,world.instanceId),crygolem2);
  1266. for (L2Npc crygolem : world.crystalGolems.keySet())
  1267. startQuestTimer("autoFood",2000,crygolem,null);
  1268. }
  1269. else if (world.status == 4 && npc.getNpcId() == TEARS)
  1270. {
  1271. InstanceManager.getInstance().getInstance(world.instanceId).setDuration(300000);
  1272. addSpawn(32280,144312,154420,-11855,0,false,0,false,world.instanceId);
  1273. giveRewards(player, npc.getInstanceId(), BOSS_CRYSTAL_3, false);
  1274. }
  1275. else if (world.status == 2 && world.keyKeepers.contains(npc))
  1276. {
  1277. if (npc.getNpcId() == GK1)
  1278. {
  1279. ((L2MonsterInstance)npc).dropItem(player, 9698, 1);
  1280. runEmeraldSquare(world);
  1281. }
  1282. else if (npc.getNpcId() == GK2)
  1283. {
  1284. ((L2MonsterInstance)npc).dropItem(player, 9699, 1);
  1285. runSteamRooms(world, STEAM1_SPAWNS, 22);
  1286. L2Party party = player.getParty();
  1287. if (party != null)
  1288. for(L2PcInstance partyMember : party.getPartyMembers())
  1289. {
  1290. if (partyMember.getInstanceId() == world.instanceId)
  1291. {
  1292. SkillTable.getInstance().getInfo(5239, 1).getEffects(partyMember, partyMember);
  1293. startQuestTimer("Timer2",300000,npc,partyMember);
  1294. }
  1295. }
  1296. else
  1297. {
  1298. SkillTable.getInstance().getInfo(5239, 1).getEffects(player, player);
  1299. startQuestTimer("Timer2",300000,npc,player);
  1300. }
  1301. startQuestTimer("Timer21",300000,npc,null);
  1302. }
  1303. for (L2Npc gk : world.keyKeepers)
  1304. if (gk != npc)
  1305. gk.decayMe();
  1306. }
  1307. else if (world.status == 3)
  1308. {
  1309. if (checkKillProgress(0,npc,world))
  1310. {
  1311. world.status = 4;
  1312. addSpawn(TOURMALINE, 148202, 144791, -12235, 0, false,0,false,world.instanceId);
  1313. }
  1314. else
  1315. return "";
  1316. }
  1317. else if (world.status == 4)
  1318. {
  1319. if (npc.getNpcId() == TOURMALINE)
  1320. {
  1321. world.status = 5;
  1322. addSpawn(TEROD, 147777, 146780, -12281, 0, false,0,false,world.instanceId);
  1323. }
  1324. }
  1325. else if (world.status == 5)
  1326. {
  1327. if (npc.getNpcId() == TEROD)
  1328. {
  1329. world.status = 6;
  1330. addSpawn(TOURMALINE, 143694, 142659, -11882, 0, false,0,false,world.instanceId);
  1331. }
  1332. }
  1333. else if (world.status == 6)
  1334. {
  1335. if (npc.getNpcId() == TOURMALINE)
  1336. {
  1337. world.status = 7;
  1338. addSpawn(DOLPH, 142054,143288, -11825, 0, false,0,false,world.instanceId);
  1339. }
  1340. }
  1341. else if (world.status == 7)
  1342. {
  1343. if (npc.getNpcId() == DOLPH)
  1344. {
  1345. world.status = 8;
  1346. // first door opener trap
  1347. addTrap(DOOR_OPENING_TRAP[0], DOOR_OPENING_TRAP[1], DOOR_OPENING_TRAP[2], DOOR_OPENING_TRAP[3], DOOR_OPENING_TRAP[4], null, world.instanceId);
  1348. }
  1349. }
  1350. else if (world.status == 8)
  1351. {
  1352. for(int i = 0; i < 4;i++)
  1353. {
  1354. if (world.roomsStatus[i] == 1 && checkKillProgress(i+1, npc, world))
  1355. {
  1356. world.roomsStatus[i] = 2;
  1357. }
  1358. if (world.roomsStatus[i] == 2)
  1359. {
  1360. world.cleanedRooms++;
  1361. if (world.cleanedRooms == 21)
  1362. runDarnel(world);
  1363. }
  1364. }
  1365. }
  1366. else if (world.status >= 22 && world.status <= 25)
  1367. {
  1368. if (npc.getNpcId() == 22416)
  1369. {
  1370. for(L2Npc oracle:world.oracles.keySet())
  1371. if (world.oracles.get(oracle) == npc)
  1372. world.oracles.put(oracle, null);
  1373. }
  1374. if (checkKillProgress(0, npc, world))
  1375. {
  1376. world.npcList2.clear();
  1377. int[][] oracleOrder;
  1378. switch(world.status)
  1379. {
  1380. case 22:
  1381. closeDoor(DOOR6,npc.getInstanceId());
  1382. oracleOrder = ordreOracle1;
  1383. break;
  1384. case 23:
  1385. oracleOrder = ordreOracle2;
  1386. break;
  1387. case 24:
  1388. oracleOrder = ordreOracle3;
  1389. break;
  1390. case 25:
  1391. world.status = 26;
  1392. L2Party party = player.getParty();
  1393. if (party != null)
  1394. for(L2PcInstance partyMember : party.getPartyMembers())
  1395. partyMember.stopSkillEffects(5239);
  1396. cancelQuestTimers("Timer5");
  1397. cancelQuestTimers("Timer51");
  1398. openDoor(DOOR3,npc.getInstanceId());
  1399. openDoor(DOOR4,npc.getInstanceId());
  1400. L2Npc kechi = addSpawn(KECHI, 154069, 149525, -12158, 51165, false,0,false,world.instanceId);
  1401. startQuestTimer("checkKechiAttack", 1000, kechi, null);
  1402. return "";
  1403. default:
  1404. _log.warning("CrystalCavern-SteamCorridor: status " + world.status + " error. OracleOrder not found in " + world.instanceId);
  1405. return "";
  1406. }
  1407. runSteamOracles(world, oracleOrder);
  1408. }
  1409. }
  1410. else if ((world.status == 9 && npc.getNpcId() == DARNEL) || (world.status == 26 && npc.getNpcId() == KECHI))
  1411. {
  1412. InstanceManager.getInstance().getInstance(world.instanceId).setDuration(300000);
  1413. int bossCry;
  1414. if (npc.getNpcId() == KECHI)
  1415. {
  1416. bossCry = BOSS_CRYSTAL_2;
  1417. cancelQuestTimers("spawnGuards");
  1418. addSpawn(32280,154077,149527,-12159,0,false,0,false,world.instanceId);
  1419. }
  1420. else if (npc.getNpcId() == DARNEL)
  1421. {
  1422. bossCry = BOSS_CRYSTAL_1;
  1423. addSpawn(32280,152761,145950,-12588,0,false,0,false,world.instanceId);
  1424. }
  1425. else
  1426. {
  1427. // something is wrong
  1428. return "";
  1429. }
  1430. giveRewards(player, npc.getInstanceId(), bossCry, false);
  1431. }
  1432. if (npc.getNpcId() == ALARMID)
  1433. {
  1434. world._baylor.removeSkill(5244);
  1435. world._baylor.removeSkill(5245);
  1436. world._alarm = null;
  1437. if (world._baylor.getMaxHp() * 0.3 < world._baylor.getStatus().getCurrentHp())
  1438. startQuestTimer("baylor_alarm",40000, world._baylor, null);
  1439. }
  1440. else if (npc.getNpcId() == BAYLOR)
  1441. {
  1442. world.status = 31;
  1443. world._baylor = null;
  1444. npc.broadcastPacket(new PlaySound(1, "BS01_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  1445. Instance baylorInstance = InstanceManager.getInstance().getInstance(npc.getInstanceId());
  1446. baylorInstance.setDuration(300000);
  1447. this.startQuestTimer("spawn_oracle", 1000, npc, null);
  1448. giveRewards(player, npc.getInstanceId(), -1, true);
  1449. }
  1450. }
  1451. return "";
  1452. }
  1453. @Override
  1454. public String onTalk (L2Npc npc, L2PcInstance player)
  1455. {
  1456. int npcId = npc.getNpcId();
  1457. QuestState st = player.getQuestState(qn);
  1458. if (st == null)
  1459. st = newQuestState(player);
  1460. if (npcId == ORACLE_GUIDE_1)
  1461. {
  1462. teleCoord tele = new teleCoord();
  1463. tele.x = 143348;
  1464. tele.y = 148707;
  1465. tele.z = -11972;
  1466. enterInstance(player, "CrystalCaverns.xml", tele);
  1467. return "";
  1468. }
  1469. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  1470. if (tmpworld instanceof CCWorld)
  1471. {
  1472. CCWorld world = (CCWorld) tmpworld;
  1473. if (npcId == CRYSTAL_GOLEM)
  1474. {
  1475. }
  1476. else if (npc.getNpcId() >= 32275 && npc.getNpcId() <= 32277 && world.OracleTriggered[npc.getNpcId() - 32275])
  1477. {
  1478. boolean doTeleport = false;
  1479. teleCoord teleto = new teleCoord();
  1480. teleto.instanceId = npc.getInstanceId();
  1481. L2Party party = player.getParty();
  1482. doTeleport = true;
  1483. switch(npc.getNpcId())
  1484. {
  1485. case 32275:
  1486. if (world.status == 22)
  1487. runSteamRooms(world, STEAM2_SPAWNS, 23);
  1488. teleto.x = 147529;
  1489. teleto.y = 152587;
  1490. teleto.z = -12169;
  1491. cancelQuestTimers("Timer2");
  1492. cancelQuestTimers("Timer21");
  1493. if (party != null)
  1494. for(L2PcInstance partyMember : party.getPartyMembers())
  1495. {
  1496. if (partyMember.getInstanceId() == world.instanceId)
  1497. {
  1498. partyMember.stopSkillEffects(5239);
  1499. SkillTable.getInstance().getInfo(5239, 2).getEffects(partyMember, partyMember);
  1500. startQuestTimer("Timer3",600000,npc,partyMember);
  1501. }
  1502. }
  1503. else
  1504. {
  1505. player.stopSkillEffects(5239);
  1506. SkillTable.getInstance().getInfo(5239, 2).getEffects(player, player);
  1507. startQuestTimer("Timer3",600000,npc,player);
  1508. }
  1509. startQuestTimer("Timer31",600000,npc,null);
  1510. break;
  1511. case 32276:
  1512. if (world.status == 23)
  1513. runSteamRooms(world, STEAM3_SPAWNS, 24);
  1514. teleto.x = 150194;
  1515. teleto.y = 152610;
  1516. teleto.z = -12169;
  1517. cancelQuestTimers("Timer3");
  1518. cancelQuestTimers("Timer31");
  1519. if (party != null)
  1520. for(L2PcInstance partyMember : party.getPartyMembers())
  1521. {
  1522. if (partyMember.getInstanceId() == world.instanceId)
  1523. {
  1524. partyMember.stopSkillEffects(5239);
  1525. SkillTable.getInstance().getInfo(5239, 4).getEffects(partyMember, partyMember);
  1526. startQuestTimer("Timer4",1200000,npc,partyMember);
  1527. }
  1528. }
  1529. else
  1530. {
  1531. player.stopSkillEffects(5239);
  1532. SkillTable.getInstance().getInfo(5239, 4).getEffects(player, player);
  1533. startQuestTimer("Timer4",1200000,npc,player);
  1534. }
  1535. startQuestTimer("Timer41",1200000,npc,null);
  1536. break;
  1537. case 32277:
  1538. if (world.status == 24)
  1539. runSteamRooms(world, STEAM4_SPAWNS, 25);
  1540. teleto.x = 149743;
  1541. teleto.y = 149986;
  1542. teleto.z = -12141;
  1543. cancelQuestTimers("Timer4");
  1544. cancelQuestTimers("Timer41");
  1545. if (party != null)
  1546. for(L2PcInstance partyMember : party.getPartyMembers())
  1547. {
  1548. if (partyMember.getInstanceId() == world.instanceId)
  1549. {
  1550. partyMember.stopSkillEffects(5239);
  1551. SkillTable.getInstance().getInfo(5239, 3).getEffects(partyMember, partyMember);
  1552. startQuestTimer("Timer5",900000,npc,partyMember);
  1553. }
  1554. }
  1555. else
  1556. {
  1557. player.stopSkillEffects(5239);
  1558. SkillTable.getInstance().getInfo(5239, 3).getEffects(player, player);
  1559. startQuestTimer("Timer5",900000,npc,player);
  1560. }
  1561. startQuestTimer("Timer51",900000,npc,null);
  1562. break;
  1563. default:
  1564. // something is wrong
  1565. doTeleport = false;
  1566. }
  1567. if (doTeleport)
  1568. {
  1569. if (!checkOracleConditions(player))
  1570. return "";
  1571. else if (player.getParty() != null)
  1572. for(L2PcInstance partyMember : party.getPartyMembers())
  1573. {
  1574. partyMember.destroyItemByItemId("Quest", RED_CORAL, 1, player, true);
  1575. teleportplayer(partyMember,teleto);
  1576. }
  1577. else
  1578. {
  1579. teleportplayer(player,teleto);
  1580. }
  1581. }
  1582. }
  1583. else if (npc.getNpcId() == ORACLE_GUIDE_3)
  1584. {
  1585. if (world.status < 30 && checkBaylorConditions(player))
  1586. {
  1587. world._raiders.clear();
  1588. L2Party party = player.getParty();
  1589. if (party == null)
  1590. world._raiders.add(player);
  1591. else
  1592. {
  1593. for (L2PcInstance partyMember : party.getPartyMembers())
  1594. {
  1595. int rnd = Rnd.get(100);
  1596. partyMember.destroyItemByItemId("Quest", (rnd < 33 ? BOSS_CRYSTAL_1:(rnd < 67 ? BOSS_CRYSTAL_2:BOSS_CRYSTAL_3)), 1, partyMember, true);
  1597. world._raiders.add(partyMember);
  1598. }
  1599. }
  1600. }
  1601. else
  1602. return "";
  1603. world.status = 30;
  1604. long time = world.endTime - System.currentTimeMillis();
  1605. Instance baylorInstance = InstanceManager.getInstance().getInstance(world.instanceId);
  1606. baylorInstance.setDuration((int) time);
  1607. int radius = 150;
  1608. int i = 0;
  1609. int members = world._raiders.size();
  1610. for(L2PcInstance p : world._raiders)
  1611. {
  1612. int x = (int) (radius * Math.cos(i * 2 * Math.PI / members));
  1613. int y = (int) (radius * Math.sin(i++ * 2 * Math.PI / members));
  1614. p.teleToLocation(153571 + x, 142075 + y, -12737);
  1615. L2Summon pet = p.getPet();
  1616. if (pet != null)
  1617. {
  1618. pet.teleToLocation(153571 + x, 142075 + y, -12737, true);
  1619. pet.broadcastPacket(new ValidateLocation(pet));
  1620. }
  1621. p.setIsParalyzed(true);
  1622. p.broadcastPacket(new ValidateLocation(p));
  1623. }
  1624. startQuestTimer("Baylor", 30000, npc, null);
  1625. }
  1626. else if (npc.getNpcId() == ORACLE_GUIDE_4 && world.status == 31)
  1627. {
  1628. teleCoord teleto = new teleCoord();
  1629. teleto.instanceId = npc.getInstanceId();
  1630. teleto.x = 153522;
  1631. teleto.y = 144212;
  1632. teleto.z = -9747;
  1633. teleportplayer(player,teleto);
  1634. }
  1635. }
  1636. return "";
  1637. }
  1638. @Override
  1639. public String onTrapAction(L2Trap trap, L2Character trigger, TrapAction action)
  1640. {
  1641. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(trap.getInstanceId());
  1642. if (tmpworld instanceof CCWorld)
  1643. {
  1644. CCWorld world = (CCWorld) tmpworld;
  1645. switch(action)
  1646. {
  1647. case TRAP_DISARMED:
  1648. if (trap.getNpcId() == DOOR_OPENING_TRAP[0])
  1649. {
  1650. openDoor(24220001, world.instanceId);
  1651. runEmeraldRooms(world, ROOM1_SPAWNS, 1);
  1652. }
  1653. break;
  1654. }
  1655. }
  1656. return null;
  1657. }
  1658. @Override
  1659. public String onEnterZone(L2Character character, L2ZoneType zone)
  1660. {
  1661. if (character instanceof L2PcInstance)
  1662. {
  1663. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(character.getInstanceId());
  1664. if (tmpworld instanceof CCWorld)
  1665. {
  1666. CCWorld world = (CCWorld) tmpworld;
  1667. if (world.status == 8)
  1668. {
  1669. int room;
  1670. int[][] spawns;
  1671. switch(zone.getId())
  1672. {
  1673. case 20105:
  1674. spawns = ROOM2_SPAWNS;
  1675. room = 2;
  1676. break;
  1677. case 20106:
  1678. spawns = ROOM3_SPAWNS;
  1679. room = 3;
  1680. break;
  1681. case 20107:
  1682. spawns = ROOM4_SPAWNS;
  1683. room = 4;
  1684. break;
  1685. default:
  1686. return super.onEnterZone(character,zone);
  1687. }
  1688. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(world.instanceId).getDoors())
  1689. if (door.getDoorId() == (room + 24220000))
  1690. {
  1691. if (door.getOpen())
  1692. return "";
  1693. else
  1694. {
  1695. QuestState st = ((L2PcInstance)character).getQuestState(qn);
  1696. if (st == null)
  1697. st = newQuestState((L2PcInstance)character);
  1698. if (st.getQuestItemsCount(RACE_KEY) == 0)
  1699. return "";
  1700. if (world.roomsStatus[zone.getId() - 20104] == 0)
  1701. runEmeraldRooms(world, spawns, room);
  1702. door.openMe();
  1703. st.takeItems(RACE_KEY, 1);
  1704. world.openedDoors.put(door, (L2PcInstance)character);
  1705. }
  1706. break;
  1707. }
  1708. }
  1709. }
  1710. }
  1711. return super.onEnterZone(character,zone);
  1712. }
  1713. @Override
  1714. public String onExitZone(L2Character character, L2ZoneType zone)
  1715. {
  1716. if (character instanceof L2PcInstance)
  1717. {
  1718. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(character.getInstanceId());
  1719. if (tmpworld instanceof CCWorld)
  1720. {
  1721. CCWorld world = (CCWorld) tmpworld;
  1722. if (world.status == 8)
  1723. {
  1724. int doorId;
  1725. switch(zone.getId())
  1726. {
  1727. case 20105:
  1728. doorId = 24220002;
  1729. break;
  1730. case 20106:
  1731. doorId = 24220003;
  1732. break;
  1733. case 20107:
  1734. doorId = 24220004;
  1735. break;
  1736. default:
  1737. return super.onExitZone(character,zone);
  1738. }
  1739. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(world.instanceId).getDoors())
  1740. if (door.getDoorId() == doorId)
  1741. {
  1742. if (door.getOpen() && world.openedDoors.get(door) == character)
  1743. {
  1744. door.closeMe();
  1745. world.openedDoors.remove(door);
  1746. }
  1747. break;
  1748. }
  1749. }
  1750. }
  1751. }
  1752. return super.onExitZone(character,zone);
  1753. }
  1754. public CrystalCaverns(int questId, String name, String descr)
  1755. {
  1756. super(questId, name, descr);
  1757. addStartNpc(ORACLE_GUIDE_1);
  1758. addTalkId(ORACLE_GUIDE_1);
  1759. addTalkId(ORACLE_GUIDE_3);
  1760. addStartNpc(ORACLE_GUIDE_4);
  1761. addFirstTalkId(ORACLE_GUIDE_4);
  1762. addTalkId(ORACLE_GUIDE_4);
  1763. addFirstTalkId(CRYSTAL_GOLEM);
  1764. addAttackId(TEARS);
  1765. addTrapActionId(DOOR_OPENING_TRAP[0]);
  1766. addKillId(TEARS);
  1767. addKillId(GK1);
  1768. addKillId(GK2);
  1769. addKillId(TEROD);
  1770. addKillId(WEYLIN);
  1771. addKillId(DOLPH);
  1772. addKillId(DARNEL);
  1773. addKillId(KECHI);
  1774. addKillId(GUARDIAN);
  1775. addKillId(GUARDIAN2);
  1776. addKillId(TOURMALINE);
  1777. addKillId(BAYLOR);
  1778. addSpellFinishedId(BAYLOR);
  1779. addKillId(ALARMID);
  1780. int[] Talk = {32275,32276,32277};
  1781. for(int npc : Talk)
  1782. addTalkId(npc);
  1783. int[] firstTalk = {32274,32275,32276,32277,ORACLE_GUIDE_1,ORACLE_GUIDE_2};
  1784. for(int npc : firstTalk)
  1785. addFirstTalkId(npc);
  1786. int[] skillSee = {25534,32275,32276,32277,BAYLOR};
  1787. for(int npc : skillSee)
  1788. addSkillSeeId(npc);
  1789. for(int mob : MOBLIST)
  1790. addKillId(mob);
  1791. for (int mob : CGMOBS)
  1792. addKillId(mob);
  1793. for (int zones : ZONES)
  1794. {
  1795. addEnterZoneId(zones);
  1796. addExitZoneId(zones);
  1797. }
  1798. }
  1799. public static void main(String[] args)
  1800. {
  1801. // now call the constructor (starts up the)
  1802. new CrystalCaverns(-1,qn,"instances");
  1803. }
  1804. }