CrystalCaverns.java 69 KB

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