Valakas.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*
  2. * Copyright (C) 2004-2013 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.ArrayList;
  21. import java.util.List;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.GeoData;
  25. import com.l2jserver.gameserver.ai.CtrlIntention;
  26. import com.l2jserver.gameserver.datatables.SkillTable;
  27. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  28. import com.l2jserver.gameserver.model.L2CharPosition;
  29. import com.l2jserver.gameserver.model.Location;
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.gameserver.model.actor.L2Character;
  32. import com.l2jserver.gameserver.model.actor.L2Npc;
  33. import com.l2jserver.gameserver.model.actor.L2Playable;
  34. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.effects.L2Effect;
  37. import com.l2jserver.gameserver.model.holders.SkillHolder;
  38. import com.l2jserver.gameserver.model.skills.L2Skill;
  39. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  40. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  41. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  42. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  43. import com.l2jserver.gameserver.util.Util;
  44. /**
  45. * Valakas' AI.
  46. * @author Tryskell
  47. */
  48. public class Valakas extends AbstractNpcAI
  49. {
  50. // NPCs
  51. private static final int VALAKAS = 29028;
  52. // Skills
  53. private static final SkillHolder VALAKAS_LAVA_SKIN = new SkillHolder(4680, 1);
  54. private static final SkillHolder[] VALAKAS_REGULAR_SKILLS =
  55. {
  56. new SkillHolder(4681, 1), // Valakas Trample
  57. new SkillHolder(4682, 1), // Valakas Trample
  58. new SkillHolder(4683, 1), // Valakas Dragon Breath
  59. new SkillHolder(4689, 1)
  60. // Valakas Fear TODO: has two levels only level one is used.
  61. };
  62. private static final SkillHolder[] VALAKAS_LOWHP_SKILLS =
  63. {
  64. new SkillHolder(4681, 1), // Valakas Trample
  65. new SkillHolder(4682, 1), // Valakas Trample
  66. new SkillHolder(4683, 1), // Valakas Dragon Breath
  67. new SkillHolder(4689, 1), // Valakas Fear TODO: has two levels only level one is used.
  68. new SkillHolder(4690, 1)
  69. // Valakas Meteor Storm
  70. };
  71. private static final SkillHolder[] VALAKAS_AOE_SKILLS =
  72. {
  73. new SkillHolder(4683, 1), // Valakas Dragon Breath
  74. new SkillHolder(4684, 1), // Valakas Dragon Breath
  75. new SkillHolder(4685, 1), // Valakas Tail Stomp
  76. new SkillHolder(4686, 1), // Valakas Tail Stomp
  77. new SkillHolder(4688, 1), // Valakas Stun
  78. new SkillHolder(4689, 1), // Valakas Fear TODO: has two levels only level one is used.
  79. new SkillHolder(4690, 1)
  80. // Valakas Meteor Storm
  81. };
  82. // Locations
  83. private static final Location TELEPORT_CUBE_LOCATIONS[] =
  84. {
  85. new Location(214880, -116144, -1644),
  86. new Location(213696, -116592, -1644),
  87. new Location(212112, -116688, -1644),
  88. new Location(211184, -115472, -1664),
  89. new Location(210336, -114592, -1644),
  90. new Location(211360, -113904, -1644),
  91. new Location(213152, -112352, -1644),
  92. new Location(214032, -113232, -1644),
  93. new Location(214752, -114592, -1644),
  94. new Location(209824, -115568, -1421),
  95. new Location(210528, -112192, -1403),
  96. new Location(213120, -111136, -1408),
  97. new Location(215184, -111504, -1392),
  98. new Location(215456, -117328, -1392),
  99. new Location(213200, -118160, -1424)
  100. };
  101. // Valakas status.
  102. private static final byte DORMANT = 0; // Valakas is spawned and no one has entered yet. Entry is unlocked.
  103. private static final byte WAITING = 1; // Valakas is spawned and someone has entered, triggering a 30 minute window for additional people to enter. Entry is unlocked.
  104. private static final byte FIGHTING = 2; // Valakas is engaged in battle, annihilating his foes. Entry is locked.
  105. private static final byte DEAD = 3; // Valakas has been killed. Entry is locked.
  106. // Misc
  107. private long _timeTracker = 0; // Time tracker for last attack on Valakas.
  108. private L2Playable _actualVictim; // Actual target of Valakas.
  109. private static L2BossZone ZONE;
  110. private Valakas(String name, String descr)
  111. {
  112. super(name, descr);
  113. registerMobs(VALAKAS);
  114. ZONE = GrandBossManager.getInstance().getZone(212852, -114842, -1632);
  115. final StatsSet info = GrandBossManager.getInstance().getStatsSet(VALAKAS);
  116. final int status = GrandBossManager.getInstance().getBossStatus(VALAKAS);
  117. if (status == DEAD)
  118. {
  119. // load the unlock date and time for valakas from DB
  120. long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
  121. if (temp > 0)
  122. {
  123. // The time has not yet expired. Mark Valakas as currently locked (dead).
  124. startQuestTimer("valakas_unlock", temp, null, null);
  125. }
  126. else
  127. {
  128. // The time has expired while the server was offline. Spawn valakas in his cave as DORMANT.
  129. final L2Npc valakas = addSpawn(VALAKAS, -105200, -253104, -15264, 0, false, 0);
  130. GrandBossManager.getInstance().setBossStatus(VALAKAS, DORMANT);
  131. GrandBossManager.getInstance().addBoss((L2GrandBossInstance) valakas);
  132. valakas.setIsInvul(true);
  133. valakas.setRunning();
  134. valakas.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  135. }
  136. }
  137. else
  138. {
  139. final int loc_x = info.getInteger("loc_x");
  140. final int loc_y = info.getInteger("loc_y");
  141. final int loc_z = info.getInteger("loc_z");
  142. final int heading = info.getInteger("heading");
  143. final int hp = info.getInteger("currentHP");
  144. final int mp = info.getInteger("currentMP");
  145. final L2Npc valakas = addSpawn(VALAKAS, loc_x, loc_y, loc_z, heading, false, 0);
  146. GrandBossManager.getInstance().addBoss((L2GrandBossInstance) valakas);
  147. valakas.setCurrentHpMp(hp, mp);
  148. valakas.setRunning();
  149. // Start timers.
  150. if (status == FIGHTING)
  151. {
  152. // stores current time for inactivity task.
  153. _timeTracker = System.currentTimeMillis();
  154. startQuestTimer("regen_task", 60000, valakas, null, true);
  155. startQuestTimer("skill_task", 2000, valakas, null, true);
  156. }
  157. else
  158. {
  159. valakas.setIsInvul(true);
  160. valakas.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  161. // Start timer to lock entry after 30 minutes
  162. if (status == WAITING)
  163. {
  164. startQuestTimer("beginning", Config.Valakas_Wait_Time, valakas, null);
  165. }
  166. }
  167. }
  168. }
  169. @Override
  170. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  171. {
  172. if (npc != null)
  173. {
  174. if (event.equalsIgnoreCase("beginning"))
  175. {
  176. // Stores current time
  177. _timeTracker = System.currentTimeMillis();
  178. // Teleport Valakas to his lair.
  179. npc.teleToLocation(212852, -114842, -1632);
  180. // Sound + socialAction.
  181. for (L2PcInstance plyr : ZONE.getPlayersInside())
  182. {
  183. plyr.sendPacket(new PlaySound(1, "B03_A", 0, 0, 0, 0, 0));
  184. plyr.sendPacket(new SocialAction(npc.getObjectId(), 3));
  185. }
  186. // Launch the cinematic, and tasks (regen + skill).
  187. startQuestTimer("spawn_1", 1700, npc, null); // 1700
  188. startQuestTimer("spawn_2", 3200, npc, null); // 1500
  189. startQuestTimer("spawn_3", 6500, npc, null); // 3300
  190. startQuestTimer("spawn_4", 9400, npc, null); // 2900
  191. startQuestTimer("spawn_5", 12100, npc, null); // 2700
  192. startQuestTimer("spawn_6", 12430, npc, null); // 330
  193. startQuestTimer("spawn_7", 15430, npc, null); // 3000
  194. startQuestTimer("spawn_8", 16830, npc, null); // 1400
  195. startQuestTimer("spawn_9", 23530, npc, null); // 6700 - end of cinematic
  196. startQuestTimer("spawn_10", 26000, npc, null); // 2500 - AI + unlock
  197. }
  198. // Regeneration && inactivity task
  199. else if (event.equalsIgnoreCase("regen_task"))
  200. {
  201. // Inactivity task - 15min
  202. if (GrandBossManager.getInstance().getBossStatus(VALAKAS) == FIGHTING)
  203. {
  204. if ((_timeTracker + 900000) < System.currentTimeMillis())
  205. {
  206. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  207. npc.teleToLocation(-105200, -253104, -15264);
  208. GrandBossManager.getInstance().setBossStatus(VALAKAS, DORMANT);
  209. npc.setCurrentHpMp(npc.getMaxHp(), npc.getMaxMp());
  210. // Drop all players from the zone.
  211. ZONE.oustAllPlayers();
  212. // Cancel skill_task and regen_task.
  213. cancelQuestTimer("regen_task", npc, null);
  214. cancelQuestTimer("skill_task", npc, null);
  215. return null;
  216. }
  217. }
  218. int lvl = 0;
  219. // Verify if "Valakas Regeneration" skill is active.
  220. final L2Effect[] effects = npc.getAllEffects();
  221. if ((effects != null) && (effects.length != 0))
  222. {
  223. for (L2Effect e : effects)
  224. {
  225. if (e.getSkill().getId() == 4629)
  226. {
  227. lvl = e.getSkill().getLevel();
  228. break;
  229. }
  230. }
  231. }
  232. // Current HPs are inferior to 25% ; apply lvl 4 of regen skill.
  233. if ((npc.getCurrentHp() < (npc.getMaxHp() / 4)) && (lvl != 4))
  234. {
  235. npc.setTarget(npc);
  236. npc.doCast(SkillTable.getInstance().getInfo(4691, 4));
  237. }
  238. // Current HPs are inferior to 50% ; apply lvl 3 of regen skill.
  239. else if ((npc.getCurrentHp() < ((npc.getMaxHp() * 2) / 4.0)) && (lvl != 3))
  240. {
  241. npc.setTarget(npc);
  242. npc.doCast(SkillTable.getInstance().getInfo(4691, 3));
  243. }
  244. // Current HPs are inferior to 75% ; apply lvl 2 of regen skill.
  245. else if ((npc.getCurrentHp() < ((npc.getMaxHp() * 3) / 4.0)) && (lvl != 2))
  246. {
  247. npc.setTarget(npc);
  248. npc.doCast(SkillTable.getInstance().getInfo(4691, 2));
  249. }
  250. // Apply lvl 1.
  251. else if (lvl != 1)
  252. {
  253. npc.setTarget(npc);
  254. npc.doCast(SkillTable.getInstance().getInfo(4691, 1));
  255. }
  256. }
  257. // Spawn cinematic, regen_task and choose of skill.
  258. else if (event.equalsIgnoreCase("spawn_1"))
  259. {
  260. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1800, 180, -1, 1500, 10000, 0, 0, 1, 0));
  261. }
  262. else if (event.equalsIgnoreCase("spawn_2"))
  263. {
  264. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1300, 180, -5, 3000, 10000, 0, -5, 1, 0));
  265. }
  266. else if (event.equalsIgnoreCase("spawn_3"))
  267. {
  268. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 500, 180, -8, 600, 10000, 0, 60, 1, 0));
  269. }
  270. else if (event.equalsIgnoreCase("spawn_4"))
  271. {
  272. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 800, 180, -8, 2700, 10000, 0, 30, 1, 0));
  273. }
  274. else if (event.equalsIgnoreCase("spawn_5"))
  275. {
  276. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 200, 250, 70, 0, 10000, 30, 80, 1, 0));
  277. }
  278. else if (event.equalsIgnoreCase("spawn_6"))
  279. {
  280. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1100, 250, 70, 2500, 10000, 30, 80, 1, 0));
  281. }
  282. else if (event.equalsIgnoreCase("spawn_7"))
  283. {
  284. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 700, 150, 30, 0, 10000, -10, 60, 1, 0));
  285. }
  286. else if (event.equalsIgnoreCase("spawn_8"))
  287. {
  288. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1200, 150, 20, 2900, 10000, -10, 30, 1, 0));
  289. }
  290. else if (event.equalsIgnoreCase("spawn_9"))
  291. {
  292. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 750, 170, -10, 3400, 4000, 10, -15, 1, 0));
  293. }
  294. else if (event.equalsIgnoreCase("spawn_10"))
  295. {
  296. GrandBossManager.getInstance().setBossStatus(VALAKAS, FIGHTING);
  297. npc.setIsInvul(false);
  298. startQuestTimer("regen_task", 60000, npc, null, true);
  299. startQuestTimer("skill_task", 2000, npc, null, true);
  300. }
  301. // Death cinematic, spawn of Teleport Cubes.
  302. else if (event.equalsIgnoreCase("die_1"))
  303. {
  304. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 2000, 130, -1, 0, 10000, 0, 0, 1, 1));
  305. }
  306. else if (event.equalsIgnoreCase("die_2"))
  307. {
  308. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1100, 210, -5, 3000, 10000, -13, 0, 1, 1));
  309. }
  310. else if (event.equalsIgnoreCase("die_3"))
  311. {
  312. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1300, 200, -8, 3000, 10000, 0, 15, 1, 1));
  313. }
  314. else if (event.equalsIgnoreCase("die_4"))
  315. {
  316. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1000, 190, 0, 500, 10000, 0, 10, 1, 1));
  317. }
  318. else if (event.equalsIgnoreCase("die_5"))
  319. {
  320. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1700, 120, 0, 2500, 10000, 12, 40, 1, 1));
  321. }
  322. else if (event.equalsIgnoreCase("die_6"))
  323. {
  324. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1700, 20, 0, 700, 10000, 10, 10, 1, 1));
  325. }
  326. else if (event.equalsIgnoreCase("die_7"))
  327. {
  328. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1700, 10, 0, 1000, 10000, 20, 70, 1, 1));
  329. }
  330. else if (event.equalsIgnoreCase("die_8"))
  331. {
  332. ZONE.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1700, 10, 0, 300, 250, 20, -20, 1, 1));
  333. for (Location loc : TELEPORT_CUBE_LOCATIONS)
  334. {
  335. addSpawn(31759, loc, false, 900000);
  336. }
  337. startQuestTimer("remove_players", 900000, null, null);
  338. }
  339. else if (event.equalsIgnoreCase("skill_task"))
  340. {
  341. callSkillAI(npc);
  342. }
  343. }
  344. else
  345. {
  346. if (event.equalsIgnoreCase("valakas_unlock"))
  347. {
  348. final L2Npc valakas = addSpawn(VALAKAS, -105200, -253104, -15264, 32768, false, 0);
  349. GrandBossManager.getInstance().addBoss((L2GrandBossInstance) valakas);
  350. GrandBossManager.getInstance().setBossStatus(VALAKAS, DORMANT);
  351. }
  352. else if (event.equalsIgnoreCase("remove_players"))
  353. {
  354. ZONE.oustAllPlayers();
  355. }
  356. }
  357. return super.onAdvEvent(event, npc, player);
  358. }
  359. @Override
  360. public String onSpawn(L2Npc npc)
  361. {
  362. npc.disableCoreAI(true);
  363. return super.onSpawn(npc);
  364. }
  365. @Override
  366. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  367. {
  368. if (!ZONE.isInsideZone(attacker))
  369. {
  370. attacker.doDie(attacker);
  371. return null;
  372. }
  373. if (npc.isInvul())
  374. {
  375. return null;
  376. }
  377. if (GrandBossManager.getInstance().getBossStatus(VALAKAS) != FIGHTING)
  378. {
  379. attacker.teleToLocation(150037, -57255, -2976);
  380. return null;
  381. }
  382. // Debuff strider-mounted players.
  383. if (attacker.getMountType() == 1)
  384. {
  385. final L2Skill skill = SkillTable.getInstance().getInfo(4258, 1);
  386. if (attacker.getFirstEffect(skill) == null)
  387. {
  388. npc.setTarget(attacker);
  389. npc.doCast(skill);
  390. }
  391. }
  392. _timeTracker = System.currentTimeMillis();
  393. return super.onAttack(npc, attacker, damage, isPet);
  394. }
  395. @Override
  396. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  397. {
  398. // Cancel skill_task and regen_task.
  399. cancelQuestTimer("regen_task", npc, null);
  400. cancelQuestTimer("skill_task", npc, null);
  401. // Launch death animation.
  402. ZONE.broadcastPacket(new PlaySound(1, "B03_D", 0, 0, 0, 0, 0));
  403. startQuestTimer("die_1", 300, npc, null); // 300
  404. startQuestTimer("die_2", 600, npc, null); // 300
  405. startQuestTimer("die_3", 3800, npc, null); // 3200
  406. startQuestTimer("die_4", 8200, npc, null); // 4400
  407. startQuestTimer("die_5", 8700, npc, null); // 500
  408. startQuestTimer("die_6", 13300, npc, null); // 4600
  409. startQuestTimer("die_7", 14000, npc, null); // 700
  410. startQuestTimer("die_8", 16500, npc, null); // 2500
  411. GrandBossManager.getInstance().setBossStatus(VALAKAS, DEAD);
  412. // Calculate Min and Max respawn times randomly.
  413. long respawnTime = getRandom((Config.Interval_Of_Valakas_Spawn - Config.Random_Of_Valakas_Spawn), (Config.Interval_Of_Valakas_Spawn + Config.Random_Of_Valakas_Spawn));
  414. startQuestTimer("valakas_unlock", respawnTime, null, null);
  415. // also save the respawn time so that the info is maintained past reboots
  416. StatsSet info = GrandBossManager.getInstance().getStatsSet(VALAKAS);
  417. info.set("respawn_time", (System.currentTimeMillis() + respawnTime));
  418. GrandBossManager.getInstance().setStatsSet(VALAKAS, info);
  419. return super.onKill(npc, killer, isPet);
  420. }
  421. @Override
  422. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isPet)
  423. {
  424. return null;
  425. }
  426. private void callSkillAI(L2Npc npc)
  427. {
  428. if (npc.isInvul() || npc.isCastingNow())
  429. {
  430. return;
  431. }
  432. // Pickup a target if no or dead victim. 10% luck he decides to reconsiders his target.
  433. if ((_actualVictim == null) || _actualVictim.isDead() || !(npc.getKnownList().knowsObject(_actualVictim)) || (getRandom(10) == 0))
  434. {
  435. _actualVictim = getRandomTarget(npc);
  436. }
  437. // If result is still null, Valakas will roam. Don't go deeper in skill AI.
  438. if (_actualVictim == null)
  439. {
  440. if (getRandom(10) == 0)
  441. {
  442. int x = npc.getX();
  443. int y = npc.getY();
  444. int z = npc.getZ();
  445. int posX = x + getRandom(-1400, 1400);
  446. int posY = y + getRandom(-1400, 1400);
  447. if (GeoData.getInstance().canMoveFromToTarget(x, y, z, posX, posY, z, npc.getInstanceId()))
  448. {
  449. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, z, 0));
  450. }
  451. }
  452. return;
  453. }
  454. final L2Skill skill = getRandomSkill(npc).getSkill();
  455. // Cast the skill or follow the target.
  456. if (Util.checkIfInRange((skill.getCastRange() < 600) ? 600 : skill.getCastRange(), npc, _actualVictim, true))
  457. {
  458. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  459. npc.setIsCastingNow(true);
  460. npc.setTarget(_actualVictim);
  461. npc.doCast(skill);
  462. }
  463. else
  464. {
  465. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, _actualVictim, null);
  466. npc.setIsCastingNow(false);
  467. }
  468. }
  469. /**
  470. * Pick a random skill.<br>
  471. * Valakas will mostly use utility skills. If Valakas feels surrounded, he will use AoE skills.<br>
  472. * Lower than 50% HPs, he will begin to use Meteor skill.
  473. * @param npc valakas
  474. * @return a skill holder
  475. */
  476. private SkillHolder getRandomSkill(L2Npc npc)
  477. {
  478. final int hpRatio = (int) ((npc.getCurrentHp() / npc.getMaxHp()) * 100);
  479. // Valakas Lava Skin has priority.
  480. if ((hpRatio < 75) && (getRandom(150) == 0) && (npc.getFirstEffect(VALAKAS_LAVA_SKIN.getSkillId()) == null))
  481. {
  482. return VALAKAS_LAVA_SKIN;
  483. }
  484. // Valakas will use mass spells if he feels surrounded.
  485. if (Util.getPlayersCountInRadius(1200, npc, false, false) >= 20)
  486. {
  487. return VALAKAS_AOE_SKILLS[getRandom(VALAKAS_AOE_SKILLS.length)];
  488. }
  489. if (hpRatio > 50)
  490. {
  491. return VALAKAS_REGULAR_SKILLS[getRandom(VALAKAS_REGULAR_SKILLS.length)];
  492. }
  493. return VALAKAS_LOWHP_SKILLS[getRandom(VALAKAS_LOWHP_SKILLS.length)];
  494. }
  495. /**
  496. * Pickup a random L2Playable from the zone, deads targets aren't included.
  497. * @param npc
  498. * @return a random L2Playable.
  499. */
  500. private L2Playable getRandomTarget(L2Npc npc)
  501. {
  502. List<L2Playable> result = new ArrayList<>();
  503. for (L2Character obj : npc.getKnownList().getKnownCharacters())
  504. {
  505. if ((obj == null) || obj.isPet())
  506. {
  507. continue;
  508. }
  509. else if (!obj.isDead() && obj.isPlayable())
  510. {
  511. result.add((L2Playable) obj);
  512. }
  513. }
  514. return (result.isEmpty()) ? null : result.get(getRandom(result.size()));
  515. }
  516. public static void main(String[] args)
  517. {
  518. new Valakas(Valakas.class.getSimpleName(), "ai");
  519. }
  520. }