Valakas.java 20 KB

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