Valakas.java 20 KB

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