CrystalCaverns.java 68 KB

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