CrystalCaverns.java 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  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.NpcStringId;
  45. import com.l2jserver.gameserver.network.SystemMessageId;
  46. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  47. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  48. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  49. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  50. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  51. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  52. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  53. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  54. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  55. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  56. import com.l2jserver.gameserver.util.Util;
  57. import com.l2jserver.util.Rnd;
  58. public class CrystalCaverns extends Quest
  59. {
  60. private static class CrystalGolem
  61. {
  62. public L2ItemInstance foodItem = null;
  63. public boolean isAtDestination = false;
  64. public L2CharPosition oldpos = null;
  65. }
  66. private class CCWorld extends InstanceWorld
  67. {
  68. public Map<L2Npc,Boolean> npcList1 = new FastMap<L2Npc,Boolean>();
  69. public L2Npc tears;
  70. public boolean isUsedInvulSkill = false;
  71. public long dragonScaleStart = 0;
  72. public int dragonScaleNeed = 0;
  73. public int cleanedRooms = 0;
  74. public long endTime = 0;
  75. public List<L2Npc> copys = new FastList<L2Npc>();
  76. public Map<L2Npc,CrystalGolem> crystalGolems = new FastMap<L2Npc,CrystalGolem>();
  77. public int correctGolems = 0;
  78. public boolean[] OracleTriggered = {false,false,false};
  79. public int kechisHenchmanSpawn = 0;
  80. public int[] roomsStatus = {0,0,0,0}; // 0: not spawned, 1: spawned, 2: cleared
  81. public Map<L2DoorInstance, L2PcInstance> openedDoors = new FastMap<L2DoorInstance, L2PcInstance>();
  82. public Map<Integer, Map<L2Npc,Boolean>> npcList2 = new FastMap<Integer, Map<L2Npc,Boolean>>();
  83. public Map<L2Npc,L2Npc> oracles = new FastMap<L2Npc,L2Npc>();
  84. public List<L2Npc> keyKeepers = new FastList<L2Npc>();
  85. public List<L2Npc> guards = new FastList<L2Npc>();
  86. public List<L2Npc> oracle = new FastList<L2Npc>();
  87. // baylor variables
  88. private List<L2PcInstance> _raiders = new FastList<L2PcInstance>();
  89. private int _raidStatus = 0;
  90. private long _dragonClawStart = 0;
  91. private int _dragonClawNeed = 0;
  92. private List<L2Npc> _animationMobs = new FastList<L2Npc>();
  93. private L2Npc _camera = null;
  94. private L2Npc _baylor = null;
  95. private L2Npc _alarm = null;
  96. public CCWorld(Long time)
  97. {
  98. endTime = time;
  99. }
  100. }
  101. private static final String qn = "CrystalCaverns";
  102. private static final int INSTANCEID = 10; // this is the client number
  103. private static final boolean debug = false;
  104. //Items
  105. private static final int WHITE_SEED = 9597;
  106. private static final int BLACK_SEED = 9598;
  107. private static final int CONT_CRYSTAL = 9690; //Contaminated Crystal
  108. private static final int RED_CORAL = 9692; //Red Coral
  109. private static final int CRYSTALFOOD = 9693; //Food item for Crystal Golems
  110. final private static int RACE_KEY = 9694; // Race Key for Emerald doors
  111. private static final int BOSS_CRYSTAL_1 = 9695; //Clear Crystal
  112. private static final int BOSS_CRYSTAL_2 = 9696; //Clear Crystal
  113. private static final int BOSS_CRYSTAL_3 = 9697; //Clear Crystal
  114. //NPCs
  115. private static final int ORACLE_GUIDE_1 = 32281;
  116. private static final int ORACLE_GUIDE_2 = 32278;
  117. private static final int ORACLE_GUIDE_3 = 32280;
  118. private static final int ORACLE_GUIDE_4 = 32279;
  119. private static final int CRYSTAL_GOLEM = 32328;
  120. private static final int[] DOOR_OPENING_TRAP = { 18378, 143682, 142492, -11886, 16384 };
  121. //mobs
  122. private static final int GK1 = 22275;
  123. private static final int GK2 = 22277;
  124. private static final int TOURMALINE = 22292;
  125. private static final int TEROD = 22301;
  126. private static final int DOLPH = 22299;
  127. private static final int WEYLIN = 22298;
  128. private static final int GUARDIAN = 22303;
  129. private static final int GUARDIAN2 = 22304;
  130. private static final int TEARS = 25534;
  131. private static final int TEARS_COPY = 25535;
  132. private static final int KECHI = 25532;
  133. private static final int KECHIGUARD = 25533;
  134. private static final int BAYLOR = 29099;
  135. private static final int DARNEL = 25531;
  136. private final static int ALARMID = 18474;
  137. // private static final int[] BOSSCR = {9695,9696,9697};
  138. private static final int[] CGMOBS = {22311,22312,22313,22314,22315,22316,22317};
  139. private static final int[] SPAWN = {60000, 120000, 90000, 60000, 50000, 40000}; // Kechi Hencmans spawn times
  140. 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};
  141. // Doors/Walls/Zones
  142. private static final int DOOR1 = 24220021;
  143. private static final int DOOR2 = 24220024;
  144. private static final int DOOR3 = 24220023;
  145. private static final int DOOR4 = 24220061;
  146. private static final int DOOR5 = 24220025;
  147. private static final int DOOR6 = 24220022;
  148. private static final int[] ZONES = {20105,20106,20107};
  149. // Baylor alarm spawns
  150. private final static int[][] ALARMSPAWN = {{153572,141277,-12738},{153572,142852,-12738},
  151. {154358,142075,-12738},{152788,142075,-12738}
  152. };
  153. // Oracle order
  154. private static final int[][] ordreOracle1 = {
  155. {32274, 147090, 152505, -12169, 31613},
  156. {32275, 147090, 152575, -12169, 31613},
  157. {32274, 147090, 152645, -12169, 31613},
  158. {32274, 147090, 152715, -12169, 31613}
  159. };
  160. private static final int[][] ordreOracle2 = {
  161. {32274, 149783, 152505, -12169, 31613},
  162. // {32274, 149783, 152575, -12169, 31613},
  163. {32274, 149783, 152645, -12169, 31613},
  164. {32276, 149783, 152715, -12169, 31613}
  165. };
  166. private static final int[][] ordreOracle3 = {
  167. {32274, 152461, 152505, -12169, 31613},
  168. // {32274, 152461, 152575, -12169, 31613},
  169. {32277, 152461, 152645, -12169, 31613}
  170. // {32274, 152461, 152715, -12169, 31613}
  171. };
  172. //Hall spawns
  173. private static int[][] SPAWNS= {{141842, 152556, -11814, 50449},{141503, 153395, -11814, 40738},
  174. {141070, 153201, -11814, 39292},{141371, 152986, -11814, 35575},
  175. {141602, 154188, -11814, 24575},{141382, 154719, -11814, 37640},
  176. {141376, 154359, -11814, 12054},{140895, 154383, -11814, 37508},
  177. {140972, 154740, -11814, 52690},{141045, 154504, -11814, 50674},
  178. {140757, 152740, -11814, 39463},{140406, 152376, -11814, 16599},
  179. {140268, 152007, -11817, 45316},{139996, 151485, -11814, 47403},
  180. {140378, 151190, -11814, 58116},{140521, 150711, -11815, 55997},
  181. {140816, 150215, -11814, 53682},{141528, 149909, -11814, 22020},
  182. {141644, 150360, -11817, 13283},{142048, 150695, -11815, 5929},
  183. {141852, 151065, -11817, 27071},{142408, 151211, -11815, 2402},
  184. {142481, 151762, -11815, 12876},{141929, 152193, -11815, 27511},
  185. {142083, 151791, -11814, 47176},{141435, 150402, -11814, 41798},
  186. {140390, 151199, -11814, 50069},{140557, 151849, -11814, 45293},
  187. {140964, 153445, -11814, 56672},{142851, 154109, -11814, 24920},
  188. {142379, 154725, -11814, 30342},{142816, 154712, -11814, 33193},
  189. {142276, 154223, -11814, 33922},{142459, 154490, -11814, 33184},
  190. {142819, 154372, -11814, 21318},{141157, 154541, -11814, 27090},
  191. {141095, 150281, -11814, 55186}
  192. };
  193. //first spawns
  194. private static int[][] FIRST_SPAWNS= {{22276, 148109, 149601, -12132, 34490},{22276, 148017, 149529, -12132, 33689},
  195. {22278, 148065, 151202, -12132, 35323},{22278, 147966, 151117, -12132, 33234},
  196. {22279, 144063, 150238, -12132, 29654},{22279, 144300, 149118, -12135, 5520},
  197. {22279, 144397, 149337, -12132, 644},{22279, 144426, 150639, -12132, 50655},
  198. {22282, 145841, 151097, -12132, 31810},{22282, 144387, 149958, -12132, 61173},
  199. {22282, 145821, 149498, -12132, 31490},{22282, 146619, 149694, -12132, 33374},
  200. {22282, 146669, 149244, -12132, 31360},{22284, 144147, 151375, -12132, 58395},
  201. {22284, 144485, 151067, -12132, 64786},{22284, 144356, 149571, -12132, 63516},
  202. {22285, 144151, 150962, -12132, 664},{22285, 146657, 151365, -12132, 33154},
  203. {22285, 146623, 150857, -12132, 28034},{22285, 147046, 151089, -12132, 32941},
  204. {22285, 145704, 151255, -12132, 32523},{22285, 145359, 151101, -12132, 32767},
  205. {22285, 147785, 150817, -12132, 27423},{22285, 147727, 151375, -12132, 37117},
  206. {22285, 145428, 149494, -12132, 890},{22285, 145601, 149682, -12132, 32442},
  207. {22285, 147003, 149476, -12132, 31554},{22285, 147738, 149210, -12132, 20971},
  208. {22285, 147769, 149757, -12132, 34980}
  209. };
  210. // Emerald Square
  211. private static int[][] EMERALD_SPAWNS = {{22280, 144437, 143395, -11969, 34248},{22281, 149241, 143735, -12230, 24575},
  212. {22281, 147917, 146861, -12289, 60306},{22281, 144406, 147782, -12133, 14349},
  213. {22281, 144960, 146881, -12039, 23881},{22281, 144985, 147679, -12135, 27594},
  214. {22283, 147784, 143540, -12222, 2058},{22283, 149091, 143491, -12230, 24836},
  215. {22287, 144479, 147569, -12133, 20723},{22287, 145158, 146986, -12058, 21970},
  216. {22287, 145142, 147175, -12092, 24420},{22287, 145110, 147133, -12088, 22465},
  217. {22287, 144664, 146604, -12028, 14861},{22287, 144596, 146600, -12028, 14461},
  218. {22288, 143925, 146773, -12037, 10813},{22288, 144415, 147070, -12069, 8568},
  219. {22288, 143794, 145584, -12027, 14849},{22288, 143429, 146166, -12030, 4078},
  220. {22288, 144477, 147009, -12056, 8752},{22289, 142577, 145319, -12029, 5403},
  221. {22289, 143831, 146902, -12051, 9717},{22289, 143714, 146705, -12028, 10044},
  222. {22289, 143937, 147134, -12078, 7517},{22293, 143356, 145287, -12027, 8126},
  223. {22293, 143462, 144352, -12008, 25905},{22293, 143745, 142529, -11882, 17102},
  224. {22293, 144574, 144032, -12005, 34668},{22295, 143992, 142419, -11884, 19697},
  225. {22295, 144671, 143966, -12004, 32088},{22295, 144440, 143269, -11957, 34169},
  226. {22295, 142642, 146362, -12028, 281},{22295, 143865, 142707, -11881, 21326},
  227. {22295, 143573, 142530, -11879, 16141},{22295, 143148, 146039, -12031, 65014},
  228. {22295, 143001, 144853, -12014, 0},{22296, 147505, 146580, -12260, 59041},
  229. {22296, 149366, 146932, -12358, 39407},{22296, 149284, 147029, -12352, 41120},
  230. {22296, 149439, 143940, -12230, 23189},{22296, 147698, 143995, -12220, 27028},
  231. {22296, 141885, 144969, -12007, 2526},{22296, 147843, 143763, -12220, 28386},
  232. {22296, 144753, 143650, -11982, 35429},{22296, 147613, 146760, -12271, 56296}
  233. };
  234. private static int[][] ROOM1_SPAWNS = {{22288, 143114, 140027, -11888, 15025},{22288, 142173, 140973, -11888, 55698},
  235. {22289, 143210, 140577, -11888, 17164},{22289, 142638, 140107, -11888, 6571},
  236. {22297, 142547, 140938, -11888, 48556},{22298, 142690, 140479, -11887, 7663}
  237. };
  238. private static int[][] ROOM2_SPAWNS = {{22303, 146276, 141483, -11880, 34643},{22287, 145707, 142161, -11880, 28799},
  239. {22288, 146857, 142129, -11880, 33647},{22288, 146869, 142000, -11880, 31215},
  240. {22289, 146897, 140880, -11880, 19210}
  241. };
  242. private static int[][] ROOM3_SPAWNS = {{22302, 145123, 143713, -12808, 65323},{22294, 145188, 143331, -12808, 496},
  243. {22294, 145181, 144104, -12808, 64415},{22293, 144994, 143431, -12808, 65431},
  244. {22293, 144976, 143915, -12808, 61461}
  245. };
  246. private static int[][] ROOM4_SPAWNS = {{22304, 150563, 142240, -12108, 16454},{22294, 150769, 142495, -12108, 16870},
  247. {22281, 150783, 141995, -12108, 20033},{22283, 150273, 141983, -12108, 16043},
  248. {22294, 150276, 142492, -12108, 13540}
  249. };
  250. // Steam Corridor
  251. private static int[][] STEAM1_SPAWNS= {{22305, 145260, 152387, -12165, 32767},{22305, 144967, 152390, -12165, 30464},
  252. {22305, 145610, 152586, -12165, 17107},{22305, 145620, 152397, -12165, 8191},
  253. {22418, 146081, 152847, -12165, 31396},{22418, 146795, 152641, -12165, 33850}
  254. // {22308, 145093, 152502, -12165, 31841},{22308, 146158, 152776, -12165, 30810},
  255. // {22308, 146116, 152976, -12133, 32571},
  256. };
  257. private static int[][] STEAM2_SPAWNS= {{22306, 147740, 152767, -12165, 65043},{22306, 148215, 152828, -12165, 970},
  258. {22306, 147743, 152846, -12165, 64147},// {22308, 147849, 152854, -12165, 60534},
  259. // {22308, 147754, 152908, -12141, 59827},{22308, 148194, 152681, -12165, 63620},
  260. // {22308, 147767, 152939, -12133, 63381},{22309, 147737, 152671, -12165, 65320},
  261. {22418, 148207, 152725, -12165, 61801},{22419, 149058, 152828, -12165, 64564}
  262. };
  263. private static int[][] STEAM3_SPAWNS= {{22307, 150735, 152316, -12145, 31930},{22307, 150725, 152467, -12165, 33635},
  264. {22307, 151058, 152316, -12146, 65342},{22307, 151057, 152461, -12165, 2171}
  265. /*{22308, 150794, 152455, -12165, 31613},{22308, 150665, 152383, -12165, 32767},
  266. {22308, 151697, 152621, -12167, 31423},{22309, 151061, 152581, -12165, 6228},
  267. {22309, 150653, 152253, -12132, 31343},{22309, 150628, 152431, -12165, 33022},
  268. {22309, 151620, 152487, -12165, 30114},{22309, 151672, 152544, -12165, 31846},
  269. {22309, 150488, 152350, -12165, 29072},{22310, 151139, 152238, -12132, 1069}*/
  270. };
  271. private static int[][] STEAM4_SPAWNS= {//{22308, 151707, 150199, -12165, 32859},{22308, 152091, 150140, -12165, 32938},
  272. // {22308, 149757, 150204, -12138, 65331},{22308, 149950, 150307, -12132, 62437},
  273. //{22308, 149901, 150322, -12132, 62136},{22309, 150071, 150173, -12165, 64943},
  274. {22416, 151636, 150280, -12142, 36869},{22416, 149893, 150232, -12165, 64258},
  275. {22416, 149864, 150110, -12165, 65054},{22416, 151926, 150218, -12165, 31613},
  276. {22420, 149986, 150051, -12165, 105},{22420, 151970, 149997, -12165, 32170},
  277. {22420, 150744, 150006, -12165, 63}// ,{22417, 149782, 150188, -12151, 64001}
  278. };
  279. // Instance reenter time
  280. // default: 86400000ms(24h)
  281. private static final int INSTANCEPENALTY = 86400000;
  282. private static final int DRAGONSCALETIME = 3000;
  283. private static final int DRAGONCLAWTIME = 3000;
  284. private static class teleCoord {int instanceId; int x; int y; int z;}
  285. protected void openDoor(int doorId,int instanceId)
  286. {
  287. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(instanceId).getDoors())
  288. if (door.getDoorId() == doorId)
  289. door.openMe();
  290. }
  291. protected void closeDoor(int doorId,int instanceId)
  292. {
  293. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(instanceId).getDoors())
  294. if (door.getDoorId() == doorId)
  295. if (door.getOpen())
  296. door.closeMe();
  297. }
  298. private boolean checkConditions(L2PcInstance player)
  299. {
  300. if (debug)
  301. return true;
  302. L2Party party = player.getParty();
  303. if (party == null)
  304. {
  305. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  306. return false;
  307. }
  308. if (party.getLeader() != player)
  309. {
  310. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  311. return false;
  312. }
  313. for (L2PcInstance partyMember : party.getPartyMembers())
  314. {
  315. if (partyMember.getLevel() < 78)
  316. {
  317. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  318. sm.addPcName(partyMember);
  319. party.broadcastToPartyMembers(sm);
  320. return false;
  321. }
  322. L2ItemInstance item = partyMember.getInventory().getItemByItemId(CONT_CRYSTAL);
  323. if (item == null)
  324. {
  325. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  326. sm.addPcName(partyMember);
  327. party.broadcastToPartyMembers(sm);
  328. return false;
  329. }
  330. if (!Util.checkIfInRange(1000, player, partyMember, true))
  331. {
  332. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  333. sm.addPcName(partyMember);
  334. party.broadcastToPartyMembers(sm);
  335. return false;
  336. }
  337. Long reentertime = InstanceManager.getInstance().getInstanceTime(partyMember.getObjectId(), INSTANCEID);
  338. if (System.currentTimeMillis() < reentertime)
  339. {
  340. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
  341. sm.addPcName(partyMember);
  342. party.broadcastToPartyMembers(sm);
  343. return false;
  344. }
  345. }
  346. return true;
  347. }
  348. private boolean checkOracleConditions(L2PcInstance player)
  349. {
  350. if (debug)
  351. return true;
  352. L2Party party = player.getParty();
  353. if (party == null)
  354. {
  355. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  356. return false;
  357. }
  358. if (party.getLeader() != player)
  359. {
  360. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  361. return false;
  362. }
  363. for (L2PcInstance partyMember : party.getPartyMembers())
  364. {
  365. L2ItemInstance item = partyMember.getInventory().getItemByItemId(RED_CORAL);
  366. if (item == null)
  367. {
  368. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  369. sm.addPcName(partyMember);
  370. party.broadcastToPartyMembers(sm);
  371. return false;
  372. }
  373. if (!Util.checkIfInRange(1000, player, partyMember, true))
  374. {
  375. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  376. sm.addPcName(partyMember);
  377. party.broadcastToPartyMembers(sm);
  378. return false;
  379. }
  380. }
  381. return true;
  382. }
  383. private boolean checkBaylorConditions(L2PcInstance player)
  384. {
  385. L2Party party = player.getParty();
  386. if (party == null)
  387. {
  388. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  389. return false;
  390. }
  391. if (party.getLeader() != player)
  392. {
  393. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  394. return false;
  395. }
  396. for (L2PcInstance partyMember : party.getPartyMembers())
  397. {
  398. L2ItemInstance item1 = partyMember.getInventory().getItemByItemId(BOSS_CRYSTAL_1);
  399. L2ItemInstance item2 = partyMember.getInventory().getItemByItemId(BOSS_CRYSTAL_2);
  400. L2ItemInstance item3 = partyMember.getInventory().getItemByItemId(BOSS_CRYSTAL_3);
  401. if (item1 == null || item2 == null || item3 == null)
  402. {
  403. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ITEM_REQUIREMENT_NOT_SUFFICIENT);
  404. sm.addPcName(partyMember);
  405. party.broadcastToPartyMembers(sm);
  406. return false;
  407. }
  408. if (!Util.checkIfInRange(1000, player, partyMember, true))
  409. {
  410. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  411. sm.addPcName(partyMember);
  412. party.broadcastToPartyMembers(sm);
  413. return false;
  414. }
  415. }
  416. return true;
  417. }
  418. // this should be handled from skill effect
  419. private void Throw(L2Character effector, L2Character effected)
  420. {
  421. // Get current position of the L2Character
  422. final int curX = effected.getX();
  423. final int curY = effected.getY();
  424. final int curZ = effected.getZ();
  425. // Calculate distance between effector and effected current position
  426. double dx = effector.getX() - curX;
  427. double dy = effector.getY() - curY;
  428. double dz = effector.getZ() - curZ;
  429. double distance = Math.sqrt(dx * dx + dy * dy);
  430. int offset = Math.min((int) distance + 300, 1400);
  431. double cos;
  432. double sin;
  433. // approximation for moving futher when z coordinates are different
  434. // TODO: handle Z axis movement better
  435. offset += Math.abs(dz);
  436. if (offset < 5)
  437. offset = 5;
  438. if (distance < 1)
  439. return;
  440. // Calculate movement angles needed
  441. sin = dy / distance;
  442. cos = dx / distance;
  443. // Calculate the new destination with offset included
  444. int _x = effector.getX() - (int) (offset * cos);
  445. int _y = effector.getY() - (int) (offset * sin);
  446. int _z = effected.getZ();
  447. if (Config.GEODATA > 0)
  448. {
  449. Location destiny = GeoData.getInstance().moveCheck(effected.getX(), effected.getY(), effected.getZ(), _x, _y, _z, effected.getInstanceId());
  450. _x = destiny.getX();
  451. _y = destiny.getY();
  452. }
  453. effected.broadcastPacket(new FlyToLocation(effected, _x, _y, _z, FlyType.THROW_UP));
  454. // maybe is need force set X,Y,Z
  455. effected.setXYZ(_x, _y, _z);
  456. effected.broadcastPacket(new ValidateLocation(effected));
  457. }
  458. private void teleportplayer(L2PcInstance player, teleCoord teleto)
  459. {
  460. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  461. player.setInstanceId(teleto.instanceId);
  462. player.teleToLocation(teleto.x, teleto.y, teleto.z);
  463. return;
  464. }
  465. protected int enterInstance(L2PcInstance player, String template, teleCoord teleto)
  466. {
  467. //check for existing instances for this player
  468. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  469. //existing instance
  470. if (world != null)
  471. {
  472. if (!(world instanceof CCWorld))
  473. {
  474. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  475. return 0;
  476. }
  477. teleto.instanceId = world.instanceId;
  478. teleportplayer(player,teleto);
  479. return world.instanceId;
  480. }
  481. //New instance
  482. else
  483. {
  484. if (!checkConditions(player))
  485. return 0;
  486. L2Party party = player.getParty();
  487. int instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  488. world = new CCWorld(System.currentTimeMillis() + 5400000);
  489. world.instanceId = instanceId;
  490. world.templateId = INSTANCEID;
  491. InstanceManager.getInstance().addWorld(world);
  492. _log.info("Crystal Caverns started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  493. runOracle((CCWorld)world);
  494. // teleport players
  495. teleto.instanceId = instanceId;
  496. if (player.getParty() == null)
  497. {
  498. // this can happen only if debug is true
  499. player.sendMessage("Welcome to Crystal Caverns.");
  500. InstanceManager.getInstance().setInstanceTime(player.getObjectId(), INSTANCEID, ((System.currentTimeMillis() + INSTANCEPENALTY)));
  501. teleportplayer(player,teleto);
  502. world.allowed.add(player.getObjectId());
  503. }
  504. else
  505. {
  506. for (L2PcInstance partyMember : party.getPartyMembers())
  507. {
  508. partyMember.sendMessage("Welcome to Crystal Caverns.");
  509. InstanceManager.getInstance().setInstanceTime(partyMember.getObjectId(), INSTANCEID, ((System.currentTimeMillis() + INSTANCEPENALTY)));
  510. teleportplayer(partyMember,teleto);
  511. world.allowed.add(partyMember.getObjectId());
  512. }
  513. }
  514. return instanceId;
  515. }
  516. }
  517. protected void exitInstance(L2PcInstance player, teleCoord tele)
  518. {
  519. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  520. player.setInstanceId(0);
  521. player.teleToLocation(tele.x, tele.y, tele.z);
  522. }
  523. protected void stopAttack(L2PcInstance player)
  524. {
  525. player.setTarget(null);
  526. player.abortAttack();
  527. player.abortCast();
  528. player.breakAttack();
  529. player.breakCast();
  530. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  531. L2Summon pet = player.getPet();
  532. if (pet != null)
  533. {
  534. pet.setTarget(null);
  535. pet.abortAttack();
  536. pet.abortCast();
  537. pet.breakAttack();
  538. pet.breakCast();
  539. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  540. }
  541. }
  542. protected void runOracle(CCWorld world)
  543. {
  544. world.status = 0;
  545. world.oracle.add(addSpawn(ORACLE_GUIDE_1, 143172, 148894, -11975, 0, false,0,false,world.instanceId));
  546. }
  547. protected void runEmerald(CCWorld world)
  548. {
  549. world.status = 1;
  550. runFirst(world);
  551. openDoor(DOOR1, world.instanceId);
  552. }
  553. protected void runCoral(CCWorld world)
  554. {
  555. world.status = 1;
  556. runHall(world);
  557. openDoor(DOOR2, world.instanceId);
  558. openDoor(DOOR5, world.instanceId);
  559. }
  560. protected void runHall(CCWorld world)
  561. {
  562. world.status = 2;
  563. for (int[] spawn : SPAWNS)
  564. {
  565. L2Npc mob = addSpawn(CGMOBS[Rnd.get(CGMOBS.length)], spawn[0], spawn[1], spawn[2], spawn[3], false,0,false,world.instanceId);
  566. world.npcList1.put(mob, false);
  567. }
  568. }
  569. protected void runFirst(CCWorld world)
  570. {
  571. world.status = 2;
  572. world.keyKeepers.add(addSpawn(GK1, 148206, 149486, -12140, 32308, false,0,false,world.instanceId));
  573. world.keyKeepers.add(addSpawn(GK2, 148203, 151093, -12140, 31100, false,0,false,world.instanceId));
  574. for (int[] spawn : FIRST_SPAWNS)
  575. {
  576. addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  577. }
  578. }
  579. protected void runEmeraldSquare(CCWorld world)
  580. {
  581. world.status = 3;
  582. Map<L2Npc,Boolean> spawnList = new FastMap<L2Npc, Boolean>();
  583. for (int[] spawn : EMERALD_SPAWNS)
  584. {
  585. L2Npc mob = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  586. spawnList.put(mob, false);
  587. }
  588. world.npcList2.put(0, spawnList);
  589. }
  590. protected void runEmeraldRooms(CCWorld world, int[][] spawnList, int room)
  591. {
  592. Map<L2Npc,Boolean> spawned = new FastMap<L2Npc, Boolean>();
  593. for (int[] spawn : spawnList)
  594. {
  595. L2Npc mob = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  596. spawned.put(mob, false);
  597. }
  598. if (room == 1) // spawn Lahm
  599. addSpawn(32359, 142110, 139896, -11888, 8033, false,0,false,world.instanceId);
  600. world.npcList2.put(room, spawned);
  601. world.roomsStatus[room-1] = 1;
  602. }
  603. protected void runDarnel(CCWorld world)
  604. {
  605. world.status = 9;
  606. addSpawn(DARNEL, 152759, 145949, -12588, 21592, false,0,false,world.instanceId);
  607. // TODO: missing traps
  608. openDoor(24220005,world.instanceId);
  609. openDoor(24220006,world.instanceId);
  610. }
  611. protected void runSteamRooms(CCWorld world, int[][] spawnList, int status)
  612. {
  613. world.status = status;
  614. Map<L2Npc,Boolean> spawned = new FastMap<L2Npc, Boolean>();
  615. for (int[] spawn : spawnList)
  616. {
  617. L2Npc mob = addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false,0,false,world.instanceId);
  618. spawned.put(mob, false);
  619. }
  620. world.npcList2.put(0, spawned);
  621. }
  622. protected void runSteamOracles(CCWorld world, int[][] oracleOrder)
  623. {
  624. world.oracles.clear();
  625. for(int[] oracle : oracleOrder)
  626. {
  627. world.oracles.put(addSpawn(oracle[0], oracle[1], oracle[2], oracle[3], oracle[4], false,0,false,world.instanceId), null);
  628. }
  629. }
  630. protected boolean checkKillProgress(int room, L2Npc mob, CCWorld world)
  631. {
  632. if (world.npcList2.get(room).containsKey(mob))
  633. world.npcList2.get(room).put(mob, true);
  634. for(boolean isDead: world.npcList2.get(room).values())
  635. if (!isDead)
  636. return false;
  637. return true;
  638. }
  639. /* protected void runBaylorRoom(CCWorld world)
  640. {
  641. world.status = 30;
  642. addSpawn(29101,152758,143479,-12706,52961,false,0,false,world.instanceId,0);//up power
  643. addSpawn(29101,151951,142078,-12706,65203,false,0,false,world.instanceId,0);//up power
  644. addSpawn(29101,154396,140667,-12706,22197,false,0,false,world.instanceId,0);//up power
  645. addSpawn(29102,152162,141249,-12706,5511,false,0,false,world.instanceId,0);//down power
  646. addSpawn(29102,153571,140458,-12706,16699,false,0,false,world.instanceId,0);//down power
  647. addSpawn(29102,154976,141265,-12706,26908,false,0,false,world.instanceId,0);//down power
  648. addSpawn(29102,155203,142071,-12706,31560,false,0,false,world.instanceId,0);//down power
  649. addSpawn(29102,154380,143468,-12708,43943,false,0,false,world.instanceId,0);//down power
  650. addSpawn(32271,153573,142069,-9722,11175,false,0,false,world.instanceId);
  651. world.Baylor = addSpawn(BAYLOR,153557,142089,-12735,11175,false,0,false,world.instanceId,0);
  652. }*/
  653. @Override
  654. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  655. {
  656. if (npc.getNpcId() == ORACLE_GUIDE_1)
  657. {
  658. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  659. if (tmpworld instanceof CCWorld)
  660. {
  661. CCWorld world = (CCWorld) tmpworld;
  662. if (world.status == 0 && world.oracle.contains(npc))
  663. {
  664. String htmltext = "32281.htm";
  665. return htmltext;
  666. }
  667. }
  668. npc.showChatWindow(player);
  669. return null;
  670. }
  671. else if (npc.getNpcId() >= 32275 && npc.getNpcId() <= 32277)
  672. {
  673. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  674. if (tmpworld instanceof CCWorld)
  675. {
  676. CCWorld world = (CCWorld) tmpworld;
  677. if (!world.OracleTriggered[npc.getNpcId() - 32275])
  678. {
  679. String htmltext = "no.htm";
  680. return htmltext;
  681. }
  682. npc.showChatWindow(player);
  683. return null;
  684. }
  685. }
  686. else if (npc.getNpcId() == 32274)
  687. {
  688. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  689. if (tmpworld instanceof CCWorld)
  690. {
  691. String htmltext = "no.htm";
  692. return htmltext;
  693. }
  694. }
  695. else if (npc.getNpcId() == 32279)
  696. {
  697. QuestState st = player.getQuestState("131_BirdInACage");
  698. String htmltext = "32279.htm";
  699. if (st != null && st.getState() != State.COMPLETED)
  700. htmltext = "32279-01.htm";
  701. return htmltext;
  702. }
  703. else if (npc.getNpcId() == CRYSTAL_GOLEM)
  704. player.sendPacket(ActionFailed.STATIC_PACKET);
  705. return"";
  706. }
  707. @Override
  708. public String onSkillSee (L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  709. {
  710. boolean doReturn = true;
  711. for(L2Object obj: targets)
  712. if (obj == npc)
  713. doReturn = false;
  714. if (doReturn)
  715. return super.onSkillSee(npc, caster, skill, targets, isPet);
  716. switch(skill.getId())
  717. {
  718. case 1011:
  719. case 1015:
  720. case 1217:
  721. case 1218:
  722. case 1401:
  723. case 2360:
  724. case 2369:
  725. case 5146:
  726. doReturn = false;
  727. break;
  728. default:
  729. doReturn = true;
  730. }
  731. if (doReturn)
  732. return super.onSkillSee(npc, caster, skill, targets, isPet);
  733. if (npc.getNpcId() >= 32275 && npc.getNpcId() <= 32277 && skill.getId() != 2360 && skill.getId() != 2369)
  734. {
  735. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  736. if (tmpworld instanceof CCWorld && Rnd.get(100) < 15)
  737. {
  738. for(L2Npc oracle : ((CCWorld) tmpworld).oracles.keySet())
  739. if (oracle != npc)
  740. oracle.decayMe();
  741. ((CCWorld) tmpworld).OracleTriggered[npc.getNpcId() - 32275] = true;
  742. }
  743. }
  744. else if (npc.isInvul() && npc.getNpcId() == BAYLOR && skill.getId() == 2360 && caster != null)
  745. {
  746. if (caster.getParty() == null)
  747. {
  748. return super.onSkillSee(npc, caster, skill, targets, isPet);
  749. }
  750. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  751. if (tmpworld instanceof CCWorld)
  752. {
  753. CCWorld world = (CCWorld) tmpworld;
  754. if ((world._dragonClawStart + DRAGONCLAWTIME) <= System.currentTimeMillis() || world._dragonClawNeed <= 0)
  755. {
  756. world._dragonClawStart = System.currentTimeMillis();
  757. world._dragonClawNeed = caster.getParty().getMemberCount() - 1;
  758. }
  759. else
  760. {
  761. world._dragonClawNeed--;
  762. }
  763. if (world._dragonClawNeed == 0)
  764. {
  765. npc.stopSkillEffects(5225);
  766. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5480, 1, 4000, 0));
  767. if (world._raidStatus == 3)
  768. world._raidStatus++;
  769. }
  770. }
  771. }
  772. else if (npc.isInvul() && npc.getNpcId() == TEARS && skill.getId() == 2369 && caster != null)
  773. {
  774. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  775. if (tmpworld instanceof CCWorld)
  776. {
  777. CCWorld world = (CCWorld) tmpworld;
  778. if (caster.getParty() == null)
  779. {
  780. return super.onSkillSee(npc, caster, skill, targets, isPet);
  781. }
  782. else if ((world.dragonScaleStart + DRAGONSCALETIME) <= System.currentTimeMillis() || world.dragonScaleNeed <= 0)
  783. {
  784. world.dragonScaleStart = System.currentTimeMillis();
  785. world.dragonScaleNeed = caster.getParty().getMemberCount() - 1;
  786. }
  787. else
  788. {
  789. world.dragonScaleNeed--;
  790. }
  791. if (world.dragonScaleNeed == 0 && Rnd.get(100) < 80)
  792. npc.setIsInvul(false);
  793. }
  794. }
  795. return super.onSkillSee(npc, caster, skill, targets, isPet);
  796. }
  797. @Override
  798. public String onAttack (L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  799. {
  800. if (npc.getNpcId() == TEARS)
  801. {
  802. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  803. if (tmpworld instanceof CCWorld)
  804. {
  805. CCWorld world = (CCWorld) tmpworld;
  806. if (world.status != 4 && attacker != null)
  807. {
  808. // Lucky cheater, the code only kicks his/her ass out of the dungeon
  809. teleCoord tele = new teleCoord();
  810. tele.x = 149361;
  811. tele.y = 172327;
  812. tele.z = -945;
  813. exitInstance(attacker,tele);
  814. world.allowed.remove(world.allowed.indexOf(attacker.getObjectId()));
  815. }
  816. else if (world.tears != npc)
  817. return "";
  818. else if (!world.copys.isEmpty())
  819. {
  820. boolean notAOE = true;
  821. if (skill != null && (skill.getTargetType() == SkillTargetType.TARGET_AREA
  822. || skill.getTargetType() == SkillTargetType.TARGET_FRONT_AREA
  823. || skill.getTargetType() == SkillTargetType.TARGET_BEHIND_AREA
  824. || skill.getTargetType() == SkillTargetType.TARGET_AURA
  825. || skill.getTargetType() == SkillTargetType.TARGET_FRONT_AURA
  826. || skill.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA))
  827. notAOE = false;
  828. if (notAOE)
  829. {
  830. for (L2Npc copy : world.copys)
  831. copy.onDecay();
  832. world.copys.clear();
  833. }
  834. return "";
  835. }
  836. int maxHp = npc.getMaxHp();
  837. double nowHp = npc.getStatus().getCurrentHp();
  838. int rand = Rnd.get(1000);
  839. if (nowHp < maxHp * 0.4 && rand < 5)
  840. {
  841. L2Party party = attacker.getParty();
  842. if (party != null)
  843. for (L2PcInstance partyMember : party.getPartyMembers())
  844. stopAttack(partyMember);
  845. else
  846. stopAttack(attacker);
  847. L2Character target = npc.getAI().getAttackTarget();
  848. for (int i = 0; i < 10; i++)
  849. {
  850. L2Npc copy = addSpawn(TEARS_COPY,npc.getX(),npc.getY(),npc.getZ(),0,false,0,false,attacker.getInstanceId());
  851. copy.setRunning();
  852. ((L2Attackable) copy).addDamageHate(target, 0, 99999);
  853. copy.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  854. copy.setCurrentHp(nowHp);
  855. world.copys.add(copy);
  856. }
  857. }
  858. else if (nowHp < maxHp * 0.15 && !world.isUsedInvulSkill)
  859. {
  860. if (rand > 994 || nowHp < maxHp * 0.1)
  861. {
  862. world.isUsedInvulSkill = true;
  863. npc.setIsInvul(true);
  864. }
  865. }
  866. }
  867. }
  868. return null;
  869. }
  870. @Override
  871. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  872. {
  873. if (npc.getNpcId() == BAYLOR && skill.getId() == 5225)
  874. {
  875. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  876. if (tmpworld instanceof CCWorld)
  877. ((CCWorld) tmpworld)._raidStatus++;
  878. }
  879. return super.onSpellFinished(npc, player, skill);
  880. }
  881. @Override
  882. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  883. {
  884. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  885. if (tmpworld instanceof CCWorld)
  886. {
  887. CCWorld world = (CCWorld) tmpworld;
  888. teleCoord teleto = new teleCoord();
  889. teleto.instanceId = world.instanceId;
  890. if (event.equalsIgnoreCase("TeleportOut"))
  891. {
  892. teleCoord tele = new teleCoord();
  893. tele.x = 149413;
  894. tele.y = 173078;
  895. tele.z = -5014;
  896. exitInstance(player,tele);
  897. }
  898. else if (event.equalsIgnoreCase("TeleportParme"))
  899. {
  900. teleCoord tele = new teleCoord();
  901. tele.x = 153689;
  902. tele.y = 142226;
  903. tele.z = -9750;
  904. tele.instanceId = world.instanceId;
  905. teleportplayer(player,tele);
  906. }
  907. else if (event.equalsIgnoreCase("Timer2")||event.equalsIgnoreCase("Timer3")||event.equalsIgnoreCase("Timer4")||event.equalsIgnoreCase("Timer5"))
  908. {
  909. teleto.x = 144653;
  910. teleto.y = 152606;
  911. teleto.z = -12126;
  912. if (player.getInstanceId() == world.instanceId)
  913. {
  914. teleportplayer(player,teleto);
  915. player.stopSkillEffects(5239);
  916. SkillTable.getInstance().getInfo(5239, 1).getEffects(player, player);
  917. startQuestTimer("Timer2",300000,npc,player);
  918. }
  919. }
  920. else if (event.equalsIgnoreCase("Timer21")||event.equalsIgnoreCase("Timer31")||event.equalsIgnoreCase("Timer41")||event.equalsIgnoreCase("Timer51"))
  921. {
  922. InstanceManager.getInstance().getInstance(world.instanceId).removeNpcs();
  923. world.npcList2.clear();
  924. runSteamRooms(world, STEAM1_SPAWNS, 22);
  925. startQuestTimer("Timer21",300000,npc,null);
  926. }
  927. else if (event.equalsIgnoreCase("checkKechiAttack"))
  928. {
  929. if (npc.isInCombat())
  930. {
  931. startQuestTimer("spawnGuards", SPAWN[0], npc, null);
  932. cancelQuestTimers("checkKechiAttack");
  933. closeDoor(DOOR4,npc.getInstanceId());
  934. closeDoor(DOOR3,npc.getInstanceId());
  935. }
  936. else
  937. startQuestTimer("checkKechiAttack", 1000, npc, null);
  938. }
  939. else if (event.equalsIgnoreCase("spawnGuards"))
  940. {
  941. world.kechisHenchmanSpawn++;
  942. world.guards.add(addSpawn(KECHIGUARD,153622,149699,-12131,56890,false,0,false,world.instanceId));
  943. world.guards.add(addSpawn(KECHIGUARD,153609,149622,-12131,64023,false,0,false,world.instanceId));
  944. world.guards.add(addSpawn(KECHIGUARD,153606,149428,-12131,64541,false,0,false,world.instanceId));
  945. world.guards.add(addSpawn(KECHIGUARD,153601,149534,-12131,64901,false,0,false,world.instanceId));
  946. world.guards.add(addSpawn(KECHIGUARD,153620,149354,-12131,1164,false,0,false,world.instanceId));
  947. world.guards.add(addSpawn(KECHIGUARD,153637,149776,-12131,61733,false,0,false,world.instanceId));
  948. world.guards.add(addSpawn(KECHIGUARD,153638,149292,-12131,64071,false,0,false,world.instanceId));
  949. world.guards.add(addSpawn(KECHIGUARD,153647,149857,-12131,59402,false,0,false,world.instanceId));
  950. world.guards.add(addSpawn(KECHIGUARD,153661,149227,-12131,65275,false,0,false,world.instanceId));
  951. if (world.kechisHenchmanSpawn <= 5)
  952. startQuestTimer("spawnGuards", SPAWN[world.kechisHenchmanSpawn], npc, null);
  953. else
  954. cancelQuestTimers("spawnGuards");
  955. }
  956. else if (event.equalsIgnoreCase("EmeraldSteam"))
  957. {
  958. runEmerald(world);
  959. for(L2Npc oracle: world.oracle)
  960. oracle.decayMe();
  961. }
  962. else if (event.equalsIgnoreCase("CoralGarden"))
  963. {
  964. runCoral(world);
  965. for(L2Npc oracle: world.oracle)
  966. oracle.decayMe();
  967. }
  968. else if (event.equalsIgnoreCase("spawn_oracle"))
  969. {
  970. addSpawn(32271,153572,142075,-9728,10800,false,0,false,world.instanceId);
  971. addSpawn((Rnd.get(10) < 5 ? 29116:29117),npc.getX(),npc.getY(),npc.getZ(),npc.getHeading(),false,0,false,world.instanceId); // Baylor's Chest
  972. addSpawn(ORACLE_GUIDE_4,153572,142075,-12738,10800,false,0,false,world.instanceId);
  973. this.cancelQuestTimer("baylor_despawn", npc, null);
  974. this.cancelQuestTimers("baylor_skill");
  975. }
  976. else if (event.equalsIgnoreCase("baylorEffect0"))
  977. {
  978. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  979. npc.broadcastPacket(new SocialAction(npc,1));
  980. startQuestTimer("baylorCamera0",11000, npc, null);
  981. startQuestTimer("baylorEffect1",19000, npc, null);
  982. }
  983. else if (event.equalsIgnoreCase("baylorCamera0"))
  984. {
  985. npc.broadcastPacket(new SpecialCamera(npc.getObjectId(),500,-45,170,5000,9000,0,0,1,0));
  986. }
  987. else if (event.equalsIgnoreCase("baylorEffect1"))
  988. {
  989. npc.broadcastPacket(new SpecialCamera(npc.getObjectId(),300,0,120,2000,5000,0,0,1,0));
  990. npc.broadcastPacket(new SocialAction(npc,3));
  991. startQuestTimer("baylorEffect2",4000, npc, null);
  992. }
  993. else if (event.equalsIgnoreCase("baylorEffect2"))
  994. {
  995. npc.broadcastPacket(new SpecialCamera(npc.getObjectId(),747,0,160,2000,3000,0,0,1,0));
  996. npc.broadcastPacket(new MagicSkillUse(npc, npc, 5402, 1, 2000, 0));
  997. startQuestTimer("RaidStart",2000, npc, null);
  998. }
  999. else if (event.equalsIgnoreCase("BaylorMinions"))
  1000. {
  1001. for(int i = 0; i < 10; i++)
  1002. {
  1003. int radius = 300;
  1004. int x = (int) (radius * Math.cos(i * 0.618));
  1005. int y = (int) (radius * Math.sin(i * 0.618));
  1006. L2Npc mob = addSpawn(29104,153571 + x,142075 + y, -12737,0,false, 0, false, world.instanceId);
  1007. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1008. world._animationMobs.add(mob);
  1009. }
  1010. startQuestTimer("baylorEffect0",200, npc, null);
  1011. }
  1012. else if (event.equalsIgnoreCase("RaidStart"))
  1013. {
  1014. world._camera.decayMe();
  1015. world._camera = null;
  1016. npc.setIsParalyzed(false);
  1017. for(L2PcInstance p : world._raiders)
  1018. {
  1019. p.setIsParalyzed(false);
  1020. Throw(npc, p);
  1021. if (p.getPet() != null)
  1022. Throw(npc, p.getPet());
  1023. }
  1024. world._raidStatus = 0;
  1025. for(L2Npc mob : world._animationMobs)
  1026. {
  1027. mob.doDie(mob);
  1028. }
  1029. world._animationMobs.clear();
  1030. startQuestTimer("baylor_despawn",60000, npc, null, true);
  1031. startQuestTimer("checkBaylorAttack", 1000, npc, null);
  1032. }
  1033. else if (event.equalsIgnoreCase("checkBaylorAttack"))
  1034. {
  1035. if (npc.isInCombat())
  1036. {
  1037. cancelQuestTimers("checkBaylorAttack");
  1038. startQuestTimer("baylor_alarm",40000, npc, null);
  1039. startQuestTimer("baylor_skill",5000, npc, null, true);
  1040. world._raidStatus++;
  1041. }
  1042. else
  1043. startQuestTimer("checkBaylorAttack", 1000, npc, null);
  1044. }
  1045. else if (event.equalsIgnoreCase("baylor_alarm"))
  1046. {
  1047. if (world._alarm == null)
  1048. {
  1049. int[] spawnLoc = ALARMSPAWN[Rnd.get(ALARMSPAWN.length)];
  1050. npc.addSkill(SkillTable.getInstance().getInfo(5244, 1));
  1051. npc.addSkill(SkillTable.getInstance().getInfo(5245, 1));
  1052. world._alarm = addSpawn(ALARMID,spawnLoc[0],spawnLoc[1],spawnLoc[2],10800,false,0,false,world.instanceId);
  1053. world._alarm.disableCoreAI(true);
  1054. world._alarm.setIsImmobilized(true);
  1055. 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));
  1056. }
  1057. }
  1058. else if (event.equalsIgnoreCase("baylor_skill"))
  1059. {
  1060. if (world._baylor == null)
  1061. {
  1062. cancelQuestTimers("baylor_skill");
  1063. }
  1064. else
  1065. {
  1066. int maxHp = npc.getMaxHp();
  1067. double nowHp = npc.getStatus().getCurrentHp();
  1068. int rand = Rnd.get(100);
  1069. if (nowHp < maxHp * 0.2 && world._raidStatus < 3 && npc.getFirstEffect(5224) == null && npc.getFirstEffect(5225) == null)
  1070. {
  1071. if (nowHp < maxHp * 0.15 && world._raidStatus == 2)
  1072. {
  1073. npc.doCast(SkillTable.getInstance().getInfo(5225, 1));
  1074. npc.broadcastPacket(new CreatureSay(npc.getObjectId(),1,npc.getName(),NpcStringId.DEMON_KING_BELETH_GIVE_ME_THE_POWER_AAAHH));
  1075. }
  1076. else if (rand < 10 || nowHp < maxHp * 0.15)
  1077. {
  1078. npc.doCast(SkillTable.getInstance().getInfo(5225, 1));
  1079. npc.broadcastPacket(new CreatureSay(npc.getObjectId(),1,npc.getName(),NpcStringId.DEMON_KING_BELETH_GIVE_ME_THE_POWER_AAAHH));
  1080. startQuestTimer("baylor_remove_invul",30000, world._baylor, null);
  1081. }
  1082. }
  1083. else if (nowHp < maxHp * 0.3 && rand > 50 && npc.getFirstEffect(5225) == null && npc.getFirstEffect(5224) == null)
  1084. {
  1085. npc.doCast(SkillTable.getInstance().getInfo(5224, 1));
  1086. }
  1087. else if (rand < 33)
  1088. {
  1089. npc.setTarget(world._raiders.get(Rnd.get(world._raiders.size())));
  1090. npc.doCast(SkillTable.getInstance().getInfo(5229, 1));
  1091. }
  1092. }
  1093. }
  1094. else if (event.equalsIgnoreCase("baylor_remove_invul"))
  1095. {
  1096. npc.stopSkillEffects(5225);
  1097. }
  1098. else if (event.equalsIgnoreCase("Baylor"))
  1099. {
  1100. world._baylor = addSpawn(29099,153572,142075,-12738,10800,false,0,false,world.instanceId);
  1101. world._baylor.setIsParalyzed(true);
  1102. world._camera = addSpawn(29120,153273,141400,-12738,10800,false,0,false,world.instanceId);
  1103. world._camera.broadcastPacket(new SpecialCamera(world._camera.getObjectId(),700,-45,160,500,15200,0,0,1,0));
  1104. startQuestTimer("baylorMinions",2000, world._baylor, null);
  1105. }
  1106. else if (!event.endsWith("Food"))
  1107. return "";
  1108. else if (event.equalsIgnoreCase("autoFood"))
  1109. {
  1110. if (!world.crystalGolems.containsKey(npc))
  1111. world.crystalGolems.put(npc, new CrystalGolem());
  1112. if (world.status != 3 || !world.crystalGolems.containsKey(npc)
  1113. || 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<L2Object>();
  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 (Rnd.get(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.getPartyMembers())
  1216. if (partyMember.getInstanceId() == instanceId)
  1217. {
  1218. QuestState st = partyMember.getQuestState(qn);
  1219. if (st == null)
  1220. st = newQuestState(partyMember);
  1221. if (!isBaylor && st.getQuestItemsCount(CONT_CRYSTAL) > 0)
  1222. {
  1223. st.takeItems(CONT_CRYSTAL, 1);
  1224. st.giveItems(bossCry, 1);
  1225. }
  1226. if (Rnd.get(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.getQuestItemsCount(CONT_CRYSTAL) > 0)
  1238. {
  1239. st.takeItems(CONT_CRYSTAL, 1);
  1240. st.giveItems(bossCry, 1);
  1241. }
  1242. if (Rnd.get(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.getPartyMembers())
  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.getPartyMembers())
  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.getPartyMembers())
  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.getPartyMembers())
  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.getPartyMembers())
  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 (player.getParty() != null)
  1573. for(L2PcInstance partyMember : party.getPartyMembers())
  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.getPartyMembers())
  1595. {
  1596. //int rnd = Rnd.get(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. return "";
  1694. else
  1695. {
  1696. QuestState st = ((L2PcInstance)character).getQuestState(qn);
  1697. if (st == null)
  1698. st = newQuestState((L2PcInstance)character);
  1699. if (st.getQuestItemsCount(RACE_KEY) == 0)
  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. }
  1707. break;
  1708. }
  1709. }
  1710. }
  1711. }
  1712. return super.onEnterZone(character,zone);
  1713. }
  1714. @Override
  1715. public String onExitZone(L2Character character, L2ZoneType zone)
  1716. {
  1717. if (character instanceof L2PcInstance)
  1718. {
  1719. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(character.getInstanceId());
  1720. if (tmpworld instanceof CCWorld)
  1721. {
  1722. CCWorld world = (CCWorld) tmpworld;
  1723. if (world.status == 8)
  1724. {
  1725. int doorId;
  1726. switch(zone.getId())
  1727. {
  1728. case 20105:
  1729. doorId = 24220002;
  1730. break;
  1731. case 20106:
  1732. doorId = 24220003;
  1733. break;
  1734. case 20107:
  1735. doorId = 24220004;
  1736. break;
  1737. default:
  1738. return super.onExitZone(character,zone);
  1739. }
  1740. for (L2DoorInstance door : InstanceManager.getInstance().getInstance(world.instanceId).getDoors())
  1741. if (door.getDoorId() == doorId)
  1742. {
  1743. if (door.getOpen() && world.openedDoors.get(door) == character)
  1744. {
  1745. door.closeMe();
  1746. world.openedDoors.remove(door);
  1747. }
  1748. break;
  1749. }
  1750. }
  1751. }
  1752. }
  1753. return super.onExitZone(character,zone);
  1754. }
  1755. public CrystalCaverns(int questId, String name, String descr)
  1756. {
  1757. super(questId, name, descr);
  1758. addStartNpc(ORACLE_GUIDE_1);
  1759. addTalkId(ORACLE_GUIDE_1);
  1760. addTalkId(ORACLE_GUIDE_3);
  1761. addStartNpc(ORACLE_GUIDE_4);
  1762. addFirstTalkId(ORACLE_GUIDE_4);
  1763. addTalkId(ORACLE_GUIDE_4);
  1764. addFirstTalkId(CRYSTAL_GOLEM);
  1765. addAttackId(TEARS);
  1766. addTrapActionId(DOOR_OPENING_TRAP[0]);
  1767. addKillId(TEARS);
  1768. addKillId(GK1);
  1769. addKillId(GK2);
  1770. addKillId(TEROD);
  1771. addKillId(WEYLIN);
  1772. addKillId(DOLPH);
  1773. addKillId(DARNEL);
  1774. addKillId(KECHI);
  1775. addKillId(GUARDIAN);
  1776. addKillId(GUARDIAN2);
  1777. addKillId(TOURMALINE);
  1778. addKillId(BAYLOR);
  1779. addSpellFinishedId(BAYLOR);
  1780. addKillId(ALARMID);
  1781. int[] Talk = {32275,32276,32277};
  1782. for(int npc : Talk)
  1783. addTalkId(npc);
  1784. int[] firstTalk = {32274,32275,32276,32277,ORACLE_GUIDE_1,ORACLE_GUIDE_2};
  1785. for(int npc : firstTalk)
  1786. addFirstTalkId(npc);
  1787. int[] skillSee = {25534,32275,32276,32277,BAYLOR};
  1788. for(int npc : skillSee)
  1789. addSkillSeeId(npc);
  1790. for(int mob : MOBLIST)
  1791. addKillId(mob);
  1792. for (int mob : CGMOBS)
  1793. addKillId(mob);
  1794. for (int zones : ZONES)
  1795. {
  1796. addEnterZoneId(zones);
  1797. addExitZoneId(zones);
  1798. }
  1799. }
  1800. public static void main(String[] args)
  1801. {
  1802. // now call the constructor (starts up the)
  1803. new CrystalCaverns(-1,qn,"instances");
  1804. }
  1805. }