CrystalCaverns.java 68 KB

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