Beleth.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package ai.individual;
  20. import java.util.List;
  21. import java.util.concurrent.CopyOnWriteArrayList;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.ai.CtrlIntention;
  25. import com.l2jserver.gameserver.cache.HtmCache;
  26. import com.l2jserver.gameserver.data.xml.impl.DoorData;
  27. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  28. import com.l2jserver.gameserver.instancemanager.MapRegionManager;
  29. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  30. import com.l2jserver.gameserver.model.L2Object;
  31. import com.l2jserver.gameserver.model.Location;
  32. import com.l2jserver.gameserver.model.StatsSet;
  33. import com.l2jserver.gameserver.model.TeleportWhereType;
  34. import com.l2jserver.gameserver.model.actor.L2Attackable;
  35. import com.l2jserver.gameserver.model.actor.L2Character;
  36. import com.l2jserver.gameserver.model.actor.L2Npc;
  37. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  39. import com.l2jserver.gameserver.model.effects.L2EffectType;
  40. import com.l2jserver.gameserver.model.holders.ItemHolder;
  41. import com.l2jserver.gameserver.model.holders.SkillHolder;
  42. import com.l2jserver.gameserver.model.skills.Skill;
  43. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  44. import com.l2jserver.gameserver.network.serverpackets.DoorStatusUpdate;
  45. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  46. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  47. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  48. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  49. import com.l2jserver.gameserver.network.serverpackets.StaticObject;
  50. import com.l2jserver.gameserver.util.Util;
  51. /**
  52. * Beleth's AI.
  53. * @author Treat, Sahar
  54. */
  55. public final class Beleth extends AbstractNpcAI
  56. {
  57. // Status
  58. private static final int ALIVE = 0;
  59. private static final int INIT = 1;
  60. private static final int FIGHT = 2;
  61. private static final int DEAD = 3;
  62. // NPCs
  63. private static final int REAL_BELETH = 29118;
  64. private static final int FAKE_BELETH = 29119;
  65. private static final int STONE_COFFIN = 32470;
  66. private static final int ELF = 29128;
  67. private static final int WHIRPOOL = 29125;
  68. // Zones
  69. private static final L2ZoneType ZONE = ZoneManager.getInstance().getZoneById(12018);
  70. private static final Location BELETH_SPAWN = new Location(16323, 213059, -9357, 49152);
  71. // Skills
  72. private static final SkillHolder BLEED = new SkillHolder(5495, 1);
  73. private static final SkillHolder FIREBALL = new SkillHolder(5496, 1);
  74. private static final SkillHolder HORN_OF_RISING = new SkillHolder(5497, 1);
  75. private static final SkillHolder LIGHTENING = new SkillHolder(5499, 1);
  76. // Doors
  77. private static final int DOOR1 = 20240001;
  78. private static final int DOOR2 = 20240002;
  79. private static final int DOOR3 = 20240003;
  80. // Items
  81. private static final ItemHolder RING = new ItemHolder(10314, 1);
  82. // Variables
  83. private L2Npc _camera1;
  84. private L2Npc _camera2;
  85. private L2Npc _camera3;
  86. private L2Npc _camera4;
  87. private L2Npc _whirpool;
  88. private L2Npc _beleth;
  89. private L2Npc _priest;
  90. private L2Npc _stone;
  91. private L2PcInstance _killer;
  92. private int _allowedObjId;
  93. private int _killedCount;
  94. private long _lastAttack;
  95. private final List<L2Npc> _minions = new CopyOnWriteArrayList<>();
  96. private Beleth()
  97. {
  98. super(Beleth.class.getSimpleName(), "ai/individual");
  99. addEnterZoneId(ZONE.getId());
  100. registerMobs(REAL_BELETH, FAKE_BELETH);
  101. addStartNpc(STONE_COFFIN);
  102. addTalkId(STONE_COFFIN);
  103. addFirstTalkId(ELF);
  104. StatsSet info = GrandBossManager.getInstance().getStatsSet(REAL_BELETH);
  105. int status = GrandBossManager.getInstance().getBossStatus(REAL_BELETH);
  106. if (status == DEAD)
  107. {
  108. final long time = (info.getLong("respawn_time") - System.currentTimeMillis());
  109. if (time > 0)
  110. {
  111. startQuestTimer("BELETH_UNLOCK", time, null, null);
  112. }
  113. else
  114. {
  115. GrandBossManager.getInstance().setBossStatus(REAL_BELETH, ALIVE);
  116. }
  117. }
  118. else if (status != ALIVE)
  119. {
  120. GrandBossManager.getInstance().setBossStatus(REAL_BELETH, ALIVE);
  121. }
  122. DoorData.getInstance().getDoor(DOOR1).openMe();
  123. }
  124. @Override
  125. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  126. {
  127. switch (event)
  128. {
  129. case "BELETH_UNLOCK":
  130. {
  131. GrandBossManager.getInstance().setBossStatus(REAL_BELETH, ALIVE);
  132. DoorData.getInstance().getDoor(DOOR1).openMe();
  133. break;
  134. }
  135. case "CAST":
  136. {
  137. if (!npc.isDead() && !npc.isCastingNow())
  138. {
  139. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  140. npc.doCast(FIREBALL.getSkill());
  141. }
  142. break;
  143. }
  144. case "SPAWN1":
  145. {
  146. ZONE.getCharactersInside().forEach(c ->
  147. {
  148. c.disableAllSkills();
  149. c.setIsInvul(true);
  150. c.setIsImmobilized(true);
  151. });
  152. _camera1 = addSpawn(29120, new Location(16323, 213142, -9357));
  153. _camera2 = addSpawn(29121, new Location(16323, 210741, -9357));
  154. _camera3 = addSpawn(29122, new Location(16323, 213170, -9357));
  155. _camera4 = addSpawn(29123, new Location(16323, 214917, -9356));
  156. ZONE.broadcastPacket(new PlaySound(1, "BS07_A", 1, _camera1.getObjectId(), _camera1.getX(), _camera1.getY(), _camera1.getZ()));
  157. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 75, -25, 0, 2500, 0, 0, 1, 0, 0));
  158. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 75, -25, 0, 2500, 0, 0, 1, 0, 0));
  159. startQuestTimer("SPAWN2", 300, null, null);
  160. break;
  161. }
  162. case "SPAWN2":
  163. {
  164. ZONE.broadcastPacket(new SpecialCamera(_camera1, 1800, -45, -45, 5000, 5000, 0, 0, 1, 0, 0));
  165. startQuestTimer("SPAWN3", 4900, null, null);
  166. break;
  167. }
  168. case "SPAWN3":
  169. {
  170. ZONE.broadcastPacket(new SpecialCamera(_camera1, 2500, -120, -45, 5000, 5000, 0, 0, 1, 0, 0));
  171. startQuestTimer("SPAWN4", 4900, null, null);
  172. break;
  173. }
  174. case "SPAWN4":
  175. {
  176. ZONE.broadcastPacket(new SpecialCamera(_camera2, 2200, 130, 0, 0, 1500, -20, 15, 1, 0, 0));
  177. startQuestTimer("SPAWN5", 1400, null, null);
  178. break;
  179. }
  180. case "SPAWN5":
  181. {
  182. ZONE.broadcastPacket(new SpecialCamera(_camera2, 2300, 100, 0, 2000, 4500, 0, 10, 1, 0, 0));
  183. startQuestTimer("SPAWN6", 2500, null, null);
  184. break;
  185. }
  186. case "SPAWN6":
  187. {
  188. final L2DoorInstance door = DoorData.getInstance().getDoor(DOOR1);
  189. door.closeMe();
  190. ZONE.broadcastPacket(new StaticObject(door, false));
  191. ZONE.broadcastPacket(new DoorStatusUpdate(door));
  192. startQuestTimer("SPAWN7", 1700, null, null);
  193. break;
  194. }
  195. case "SPAWN7":
  196. {
  197. ZONE.broadcastPacket(new SpecialCamera(_camera4, 1500, 210, 0, 0, 1500, 0, 0, 1, 0, 0));
  198. ZONE.broadcastPacket(new SpecialCamera(_camera4, 900, 255, 0, 5000, 6500, 0, 10, 1, 0, 0));
  199. startQuestTimer("SPAWN8", 6000, null, null);
  200. break;
  201. }
  202. case "SPAWN8":
  203. {
  204. _whirpool = addSpawn(WHIRPOOL, new Location(16323, 214917, -9356));
  205. ZONE.broadcastPacket(new SpecialCamera(_camera4, 900, 255, 0, 0, 1500, 0, 10, 1, 0, 0));
  206. startQuestTimer("SPAWN9", 1000, null, null);
  207. break;
  208. }
  209. case "SPAWN9":
  210. {
  211. ZONE.broadcastPacket(new SpecialCamera(_camera4, 1000, 255, 0, 7000, 17000, 0, 25, 1, 0, 0));
  212. startQuestTimer("SPAWN10", 3000, null, null);
  213. break;
  214. }
  215. case "SPAWN10":
  216. {
  217. _beleth = addSpawn(REAL_BELETH, new Location(16321, 214211, -9352, 49369));
  218. _beleth.disableAllSkills();
  219. _beleth.setIsInvul(true);
  220. _beleth.setIsImmobilized(true);
  221. startQuestTimer("SPAWN11", 200, null, null);
  222. break;
  223. }
  224. case "SPAWN11":
  225. {
  226. ZONE.broadcastPacket(new SocialAction(_beleth.getObjectId(), 1));
  227. for (int i = 0; i < 6; i++)
  228. {
  229. int x = (int) ((150 * Math.cos(i * 1.046666667)) + 16323);
  230. int y = (int) ((150 * Math.sin(i * 1.046666667)) + 213059);
  231. L2Npc minion = addSpawn(FAKE_BELETH, new Location(x, y, -9357, 49152));
  232. minion.setShowSummonAnimation(true);
  233. minion.decayMe();
  234. _minions.add(minion);
  235. }
  236. startQuestTimer("SPAWN12", 6800, null, null);
  237. break;
  238. }
  239. case "SPAWN12":
  240. {
  241. ZONE.broadcastPacket(new SpecialCamera(_beleth, 0, 270, -5, 0, 4000, 0, 0, 1, 0, 0));
  242. startQuestTimer("SPAWN13", 3500, null, null);
  243. break;
  244. }
  245. case "SPAWN13":
  246. {
  247. ZONE.broadcastPacket(new SpecialCamera(_beleth, 800, 270, 10, 3000, 6000, 0, 0, 1, 0, 0));
  248. startQuestTimer("SPAWN14", 5000, null, null);
  249. break;
  250. }
  251. case "SPAWN14":
  252. {
  253. ZONE.broadcastPacket(new SpecialCamera(_camera3, 100, 270, 15, 0, 5000, 0, 0, 1, 0, 0));
  254. ZONE.broadcastPacket(new SpecialCamera(_camera3, 100, 270, 15, 0, 5000, 0, 0, 1, 0, 0));
  255. startQuestTimer("SPAWN15", 100, null, null);
  256. break;
  257. }
  258. case "SPAWN15":
  259. {
  260. ZONE.broadcastPacket(new SpecialCamera(_camera3, 100, 270, 15, 3000, 6000, 0, 5, 1, 0, 0));
  261. startQuestTimer("SPAWN16", 1400, null, null);
  262. break;
  263. }
  264. case "SPAWN16":
  265. {
  266. _beleth.teleToLocation(BELETH_SPAWN);
  267. startQuestTimer("SPAWN17", 200, null, null);
  268. break;
  269. }
  270. case "SPAWN17":
  271. {
  272. ZONE.broadcastPacket(new MagicSkillUse(_beleth, _beleth, 5532, 1, 2000, 0));
  273. startQuestTimer("SPAWN18", 2000, null, null);
  274. break;
  275. }
  276. case "SPAWN18":
  277. {
  278. ZONE.broadcastPacket(new SpecialCamera(_camera3, 700, 270, 20, 1500, 8000, 0, 0, 1, 0, 0));
  279. startQuestTimer("SPAWN19", 6900, null, null);
  280. break;
  281. }
  282. case "SPAWN19":
  283. {
  284. ZONE.broadcastPacket(new SpecialCamera(_camera3, 40, 260, 0, 0, 4000, 0, 0, 1, 0, 0));
  285. for (L2Npc fakeBeleth : _minions)
  286. {
  287. fakeBeleth.spawnMe();
  288. fakeBeleth.disableAllSkills();
  289. fakeBeleth.setIsInvul(true);
  290. fakeBeleth.setIsImmobilized(true);
  291. }
  292. startQuestTimer("SPAWN20", 3000, null, null);
  293. break;
  294. }
  295. case "SPAWN20":
  296. {
  297. ZONE.broadcastPacket(new SpecialCamera(_camera3, 40, 280, 0, 0, 4000, 5, 0, 1, 0, 0));
  298. startQuestTimer("SPAWN21", 3000, null, null);
  299. break;
  300. }
  301. case "SPAWN21":
  302. {
  303. ZONE.broadcastPacket(new SpecialCamera(_camera3, 5, 250, 5, 0, 13000, 20, 15, 1, 0, 0));
  304. startQuestTimer("SPAWN22", 1000, null, null);
  305. break;
  306. }
  307. case "SPAWN22":
  308. {
  309. ZONE.broadcastPacket(new SocialAction(_beleth.getObjectId(), 3));
  310. startQuestTimer("SPAWN23", 4000, null, null);
  311. break;
  312. }
  313. case "SPAWN23":
  314. {
  315. ZONE.broadcastPacket(new MagicSkillUse(_beleth, _beleth, 5533, 1, 2000, 0));
  316. startQuestTimer("SPAWN24", 6800, null, null);
  317. break;
  318. }
  319. case "SPAWN24":
  320. {
  321. _beleth.deleteMe();
  322. _beleth = null;
  323. for (L2Npc fakeBeleth : _minions)
  324. {
  325. fakeBeleth.deleteMe();
  326. }
  327. _minions.clear();
  328. _camera1.deleteMe();
  329. _camera2.deleteMe();
  330. _camera3.deleteMe();
  331. _camera4.deleteMe();
  332. for (L2Character c : ZONE.getCharactersInside())
  333. {
  334. c.enableAllSkills();
  335. c.setIsInvul(false);
  336. c.setIsImmobilized(false);
  337. }
  338. _lastAttack = System.currentTimeMillis();
  339. startQuestTimer("CHECK_ATTACK", 60000, null, null);
  340. startQuestTimer("SPAWN25", 60000, null, null);
  341. break;
  342. }
  343. case "SPAWN25":
  344. {
  345. _minions.clear();
  346. int a = 0;
  347. for (int i = 0; i < 16; i++)
  348. {
  349. a++;
  350. int x = (int) ((650 * Math.cos(i * 0.39)) + 16323);
  351. int y = (int) ((650 * Math.sin(i * 0.39)) + 213170);
  352. npc = addSpawn(FAKE_BELETH, new Location(x, y, -9357, 49152));
  353. _minions.add(npc);
  354. if (a >= 2)
  355. {
  356. npc.setIsOverloaded(true);
  357. a = 0;
  358. }
  359. }
  360. int[] xm = new int[16];
  361. int[] ym = new int[16];
  362. for (int i = 0; i < 4; i++)
  363. {
  364. xm[i] = (int) ((1700 * Math.cos((i * 1.57) + 0.78)) + 16323);
  365. ym[i] = (int) ((1700 * Math.sin((i * 1.57) + 0.78)) + 213170);
  366. npc = addSpawn(FAKE_BELETH, new Location(xm[i], ym[i], -9357, 49152));
  367. npc.setIsImmobilized(true);
  368. _minions.add(npc);
  369. }
  370. xm[4] = (xm[0] + xm[1]) / 2;
  371. ym[4] = (ym[0] + ym[1]) / 2;
  372. npc = addSpawn(FAKE_BELETH, new Location(xm[4], ym[4], -9357, 49152));
  373. npc.setIsImmobilized(true);
  374. _minions.add(npc);
  375. xm[5] = (xm[1] + xm[2]) / 2;
  376. ym[5] = (ym[1] + ym[2]) / 2;
  377. npc = addSpawn(FAKE_BELETH, new Location(xm[5], ym[5], -9357, 49152));
  378. npc.setIsImmobilized(true);
  379. _minions.add(npc);
  380. xm[6] = (xm[2] + xm[3]) / 2;
  381. ym[6] = (ym[2] + ym[3]) / 2;
  382. npc = addSpawn(FAKE_BELETH, new Location(xm[6], ym[6], -9357, 49152));
  383. npc.setIsImmobilized(true);
  384. _minions.add(npc);
  385. xm[7] = (xm[3] + xm[0]) / 2;
  386. ym[7] = (ym[3] + ym[0]) / 2;
  387. npc = addSpawn(FAKE_BELETH, new Location(xm[7], ym[7], -9357, 49152));
  388. npc.setIsImmobilized(true);
  389. _minions.add(npc);
  390. xm[8] = (xm[0] + xm[4]) / 2;
  391. ym[8] = (ym[0] + ym[4]) / 2;
  392. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[8], ym[8], -9357, 49152)));
  393. xm[9] = (xm[4] + xm[1]) / 2;
  394. ym[9] = (ym[4] + ym[1]) / 2;
  395. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[9], ym[9], -9357, 49152)));
  396. xm[10] = (xm[1] + xm[5]) / 2;
  397. ym[10] = (ym[1] + ym[5]) / 2;
  398. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[10], ym[10], -9357, 49152)));
  399. xm[11] = (xm[5] + xm[2]) / 2;
  400. ym[11] = (ym[5] + ym[2]) / 2;
  401. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[11], ym[11], -9357, 49152)));
  402. xm[12] = (xm[2] + xm[6]) / 2;
  403. ym[12] = (ym[2] + ym[6]) / 2;
  404. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[12], ym[12], -9357, 49152)));
  405. xm[13] = (xm[6] + xm[3]) / 2;
  406. ym[13] = (ym[6] + ym[3]) / 2;
  407. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[13], ym[13], -9357, 49152)));
  408. xm[14] = (xm[3] + xm[7]) / 2;
  409. ym[14] = (ym[3] + ym[7]) / 2;
  410. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[14], ym[14], -9357, 49152)));
  411. xm[15] = (xm[7] + xm[0]) / 2;
  412. ym[15] = (ym[7] + ym[0]) / 2;
  413. _minions.add(addSpawn(FAKE_BELETH, new Location(xm[15], ym[15], -9357, 49152)));
  414. _allowedObjId = _minions.get(getRandom(_minions.size())).getObjectId();
  415. break;
  416. }
  417. case "SPAWN_REAL":
  418. {
  419. _beleth = addSpawn(REAL_BELETH, new Location(16323, 213170, -9357, 49152));
  420. break;
  421. }
  422. case "SPAWN26":
  423. {
  424. _beleth.doDie(null);
  425. _camera1 = addSpawn(29122, new Location(16323, 213170, -9357));
  426. _camera1.broadcastPacket(new PlaySound(1, "BS07_D", 1, _camera1.getObjectId(), _camera1.getX(), _camera1.getY(), _camera1.getZ()));
  427. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 290, 25, 0, 10000, 0, 0, 1, 0, 0));
  428. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 290, 25, 0, 10000, 0, 0, 1, 0, 0));
  429. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 110, 25, 4000, 10000, 0, 0, 1, 0, 0));
  430. ZONE.broadcastPacket(new SocialAction(_beleth.getObjectId(), 5));
  431. startQuestTimer("SPAWN27", 4000, null, null);
  432. break;
  433. }
  434. case "SPAWN27":
  435. {
  436. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 295, 25, 4000, 5000, 0, 0, 1, 0, 0));
  437. startQuestTimer("SPAWN28", 4500, null, null);
  438. break;
  439. }
  440. case "SPAWN28":
  441. {
  442. ZONE.broadcastPacket(new SpecialCamera(_camera1, 400, 295, 10, 4000, 11000, 0, 25, 1, 0, 0));
  443. startQuestTimer("SPAWN29", 9000, null, null);
  444. break;
  445. }
  446. case "SPAWN29":
  447. {
  448. ZONE.broadcastPacket(new SpecialCamera(_camera1, 250, 90, 25, 0, 1000, 0, 0, 1, 0, 0));
  449. ZONE.broadcastPacket(new SpecialCamera(_camera1, 250, 90, 25, 0, 10000, 0, 0, 1, 0, 0));
  450. startQuestTimer("SPAWN30", 2000, null, null);
  451. break;
  452. }
  453. case "SPAWN30":
  454. {
  455. _priest.spawnMe();
  456. _beleth.deleteMe();
  457. _camera2 = addSpawn(29121, new Location(14056, 213170, -9357));
  458. startQuestTimer("SPAWN31", 3500, null, null);
  459. break;
  460. }
  461. case "SPAWN31":
  462. {
  463. ZONE.broadcastPacket(new SpecialCamera(_camera2, 800, 180, 0, 0, 4000, 0, 10, 1, 0, 0));
  464. ZONE.broadcastPacket(new SpecialCamera(_camera2, 800, 180, 0, 0, 4000, 0, 10, 1, 0, 0));
  465. L2DoorInstance door2 = DoorData.getInstance().getDoor(DOOR2);
  466. door2.openMe();
  467. ZONE.broadcastPacket(new StaticObject(door2, false));
  468. ZONE.broadcastPacket(new DoorStatusUpdate(door2));
  469. DoorData.getInstance().getDoor(DOOR3).openMe();
  470. _camera1.deleteMe();
  471. _camera2.deleteMe();
  472. _whirpool.deleteMe();
  473. for (L2Character c : ZONE.getCharactersInside())
  474. {
  475. c.enableAllSkills();
  476. c.setIsInvul(false);
  477. c.setIsImmobilized(false);
  478. }
  479. break;
  480. }
  481. case "CHECK_ATTACK":
  482. {
  483. if ((_lastAttack + 900000) < System.currentTimeMillis())
  484. {
  485. GrandBossManager.getInstance().setBossStatus(REAL_BELETH, ALIVE);
  486. for (L2Character charInside : ZONE.getCharactersInside())
  487. {
  488. if (charInside != null)
  489. {
  490. if (charInside.isNpc())
  491. {
  492. charInside.deleteMe();
  493. }
  494. else if (charInside.isPlayer())
  495. {
  496. charInside.teleToLocation(MapRegionManager.getInstance().getTeleToLocation(charInside, TeleportWhereType.TOWN));
  497. }
  498. }
  499. }
  500. cancelQuestTimer("CHECK_ATTACK", null, null);
  501. }
  502. else
  503. {
  504. startQuestTimer("CHECK_ATTACK", 60000, null, null);
  505. }
  506. break;
  507. }
  508. }
  509. return super.onAdvEvent(event, npc, player);
  510. }
  511. @Override
  512. public String onEnterZone(L2Character character, L2ZoneType zone)
  513. {
  514. if (character.isPlayer() && (GrandBossManager.getInstance().getBossStatus(REAL_BELETH) == INIT))
  515. {
  516. if (_priest != null)
  517. {
  518. _priest.deleteMe();
  519. }
  520. if (_stone != null)
  521. {
  522. _stone.deleteMe();
  523. }
  524. GrandBossManager.getInstance().setBossStatus(REAL_BELETH, FIGHT);
  525. startQuestTimer("SPAWN1", 300000, null, null);
  526. }
  527. return super.onEnterZone(character, zone);
  528. }
  529. @Override
  530. public String onSkillSee(L2Npc npc, L2PcInstance player, Skill skill, L2Object[] targets, boolean isSummon)
  531. {
  532. if (!npc.isDead() && (npc.getId() == REAL_BELETH) && !npc.isCastingNow() && skill.hasEffectType(L2EffectType.HEAL) && (getRandom(100) < 80))
  533. {
  534. npc.setTarget(player);
  535. npc.doCast(HORN_OF_RISING.getSkill());
  536. }
  537. return null;
  538. }
  539. @Override
  540. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isSummon)
  541. {
  542. if (!npc.isDead() && !npc.isCastingNow())
  543. {
  544. if (getRandom(100) < 40)
  545. {
  546. if (!npc.getKnownList().getKnownPlayersInRadius(200).isEmpty())
  547. {
  548. npc.doCast(BLEED.getSkill());
  549. return null;
  550. }
  551. }
  552. npc.setTarget(player);
  553. npc.doCast(FIREBALL.getSkill());
  554. }
  555. return null;
  556. }
  557. @Override
  558. public String onSpellFinished(L2Npc npc, L2PcInstance player, Skill skill)
  559. {
  560. if (!npc.isDead() && !npc.isCastingNow())
  561. {
  562. if (!player.isDead())
  563. {
  564. final double distance2 = npc.calculateDistance(player, false, false);
  565. if ((distance2 > 890) && !npc.isMovementDisabled())
  566. {
  567. npc.setTarget(player);
  568. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
  569. double speed = npc.isRunning() ? npc.getRunSpeed() : npc.getWalkSpeed();
  570. int time = (int) (((distance2 - 890) / speed) * 1000);
  571. startQuestTimer("CAST", time, npc, null);
  572. }
  573. else if (distance2 < 890)
  574. {
  575. npc.setTarget(player);
  576. npc.doCast(FIREBALL.getSkill());
  577. }
  578. return null;
  579. }
  580. if (getRandom(100) < 40)
  581. {
  582. if (!npc.getKnownList().getKnownPlayersInRadius(200).isEmpty())
  583. {
  584. npc.doCast(LIGHTENING.getSkill());
  585. return null;
  586. }
  587. }
  588. for (L2PcInstance plr : npc.getKnownList().getKnownPlayersInRadius(950))
  589. {
  590. npc.setTarget(plr);
  591. npc.doCast(FIREBALL.getSkill());
  592. return null;
  593. }
  594. ((L2Attackable) npc).clearAggroList();
  595. }
  596. return null;
  597. }
  598. @Override
  599. public String onSpawn(L2Npc npc)
  600. {
  601. npc.setRunning();
  602. if (!npc.getKnownList().getKnownPlayersInRadius(300).isEmpty() && (getRandom(100) < 60))
  603. {
  604. npc.doCast(BLEED.getSkill());
  605. }
  606. if (npc.getId() == REAL_BELETH)
  607. {
  608. npc.getSpawn().setRespawnDelay(0);
  609. }
  610. return null;
  611. }
  612. @Override
  613. public String onTalk(L2Npc npc, L2PcInstance player)
  614. {
  615. String html;
  616. if ((_killer != null) && (player.getObjectId() == _killer.getObjectId()))
  617. {
  618. _killer = null;
  619. giveItems(player, RING);
  620. html = "32470a.htm";
  621. }
  622. else
  623. {
  624. html = "32470b.htm";
  625. }
  626. return HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/default/" + html);
  627. }
  628. @Override
  629. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  630. {
  631. return onTalk(npc, player);
  632. }
  633. @Override
  634. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  635. {
  636. if (getRandom(100) < 40)
  637. {
  638. return null;
  639. }
  640. final double distance = npc.calculateDistance(attacker, false, false);
  641. if ((distance > 500) || (getRandom(100) < 80))
  642. {
  643. for (L2Npc beleth : _minions)
  644. {
  645. if ((beleth != null) && !beleth.isDead() && Util.checkIfInRange(900, beleth, attacker, false) && !beleth.isCastingNow())
  646. {
  647. beleth.setTarget(attacker);
  648. beleth.doCast(FIREBALL.getSkill());
  649. }
  650. }
  651. if ((_beleth != null) && !_beleth.isDead() && Util.checkIfInRange(900, _beleth, attacker, false) && !_beleth.isCastingNow())
  652. {
  653. _beleth.setTarget(attacker);
  654. _beleth.doCast(FIREBALL.getSkill());
  655. }
  656. }
  657. else if (!npc.isDead() && !npc.isCastingNow())
  658. {
  659. if (!npc.getKnownList().getKnownPlayersInRadius(200).isEmpty())
  660. {
  661. npc.doCast(LIGHTENING.getSkill());
  662. return null;
  663. }
  664. ((L2Attackable) npc).clearAggroList();
  665. }
  666. return null;
  667. }
  668. @Override
  669. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  670. {
  671. if (npc.getId() == REAL_BELETH)
  672. {
  673. cancelQuestTimer("CHECK_ATTACK", null, null);
  674. setBelethKiller(killer);
  675. GrandBossManager.getInstance().setBossStatus(REAL_BELETH, DEAD);
  676. final long respawnTime = (Config.BELETH_SPAWN_INTERVAL + getRandom(-Config.BELETH_SPAWN_RANDOM, Config.BELETH_SPAWN_RANDOM)) * 3600000;
  677. StatsSet info = GrandBossManager.getInstance().getStatsSet(REAL_BELETH);
  678. info.set("respawn_time", System.currentTimeMillis() + respawnTime);
  679. GrandBossManager.getInstance().setStatsSet(REAL_BELETH, info);
  680. startQuestTimer("BELETH_UNLOCK", respawnTime, null, null);
  681. deleteAll();
  682. npc.deleteMe();
  683. for (L2Character c : ZONE.getCharactersInside())
  684. {
  685. c.disableAllSkills();
  686. c.setIsInvul(true);
  687. c.setIsImmobilized(true);
  688. }
  689. _beleth = addSpawn(REAL_BELETH, new Location(16323, 213170, -9357, 49152));
  690. _beleth.disableAllSkills();
  691. _beleth.setIsInvul(true);
  692. _beleth.setIsImmobilized(true);
  693. _priest = addSpawn(ELF, new Location(_beleth));
  694. _priest.setShowSummonAnimation(true);
  695. _priest.decayMe();
  696. _stone = addSpawn(STONE_COFFIN, new Location(12470, 215607, -9381, 49152));
  697. startQuestTimer("SPAWN26", 1000, null, null);
  698. }
  699. else if (npc.getObjectId() == _allowedObjId)
  700. {
  701. deleteAll();
  702. _killedCount++;
  703. if (_killedCount >= 5)
  704. {
  705. startQuestTimer("SPAWN_REAL", 60000, null, null);
  706. }
  707. else
  708. {
  709. startQuestTimer("SPAWN25", 60000, null, null);
  710. }
  711. }
  712. return null;
  713. }
  714. private void setBelethKiller(L2PcInstance killer)
  715. {
  716. if (killer.getParty() != null)
  717. {
  718. if (killer.getParty().getCommandChannel() != null)
  719. {
  720. _killer = killer.getParty().getCommandChannel().getLeader();
  721. }
  722. else
  723. {
  724. _killer = killer.getParty().getLeader();
  725. }
  726. }
  727. else
  728. {
  729. _killer = killer;
  730. }
  731. }
  732. private void deleteAll()
  733. {
  734. _minions.stream().filter(n -> !n.isDead()).forEach(n ->
  735. {
  736. n.abortCast();
  737. n.setTarget(null);
  738. n.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  739. n.deleteMe();
  740. });
  741. _allowedObjId = 0;
  742. }
  743. public static void main(String[] args)
  744. {
  745. new Beleth();
  746. }
  747. }