Baium.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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 static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  21. import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  22. import java.util.ArrayList;
  23. import java.util.Collection;
  24. import java.util.List;
  25. import java.util.logging.Level;
  26. import javolution.util.FastList;
  27. import ai.npc.AbstractNpcAI;
  28. import com.l2jserver.Config;
  29. import com.l2jserver.gameserver.GeoData;
  30. import com.l2jserver.gameserver.ThreadPoolManager;
  31. import com.l2jserver.gameserver.datatables.SkillTable;
  32. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  33. import com.l2jserver.gameserver.model.L2Object;
  34. import com.l2jserver.gameserver.model.Location;
  35. import com.l2jserver.gameserver.model.StatsSet;
  36. import com.l2jserver.gameserver.model.actor.L2Character;
  37. import com.l2jserver.gameserver.model.actor.L2Npc;
  38. import com.l2jserver.gameserver.model.actor.instance.L2DecoyInstance;
  39. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  40. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  41. import com.l2jserver.gameserver.model.effects.L2Effect;
  42. import com.l2jserver.gameserver.model.quest.QuestTimer;
  43. import com.l2jserver.gameserver.model.skills.L2Skill;
  44. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  45. import com.l2jserver.gameserver.network.serverpackets.Earthquake;
  46. import com.l2jserver.gameserver.network.serverpackets.MoveToPawn;
  47. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  48. import com.l2jserver.gameserver.util.Util;
  49. /**
  50. * Baium's AI.<br>
  51. * Note1: if the server gets rebooted while players are still fighting Baium, there is no lock, but players also lose their ability to wake Baium up.<br>
  52. * However, should another person enter the room and wake him up, the players who had stayed inside may join the raid.<br>
  53. * This can be helpful for players who became victims of a reboot (they only need 1 new player to enter and wake up Baium) and is not too exploitable since any player wishing to exploit it would have to suffer 5 days of being parked in an empty room.<br>
  54. * Note2: Neither version of Baium should be a permanent spawn.<br>
  55. * This script is fully capable of spawning the statue-version when the lock expires and switching it to the mob version promptly.<br>
  56. * Additional notes ( source http://aleenaresron.blogspot.com/2006_08_01_archive.html ):
  57. * <ul>
  58. * <li>Baium only first respawns five days after his last death. And from those five days he will respawn within 1-8 hours of his last death. So, you have to know his last time of death.</li>
  59. * <li>If by some freak chance you are the only one in Baium's chamber and NO ONE comes in [ha, ha] you or someone else will have to wake Baium.<br>
  60. * There is a good chance that Baium will automatically kill whoever wakes him.<br>
  61. * There are some people that have been able to wake him and not die, however if you've already gone through the trouble of getting the bloody fabric and camped him out and researched his spawn time,<br>
  62. * are you willing to take that chance that you'll wake him and not be able to finish your quest? Doubtful. [ this powerful attack vs the player who wakes him up is NOT yet implemented here]</li>
  63. * <li>Once someone starts attacking Baium no one else can port into the chamber where he is. Unlike with the other raid bosses, you can just show up at any time as long as you are there when they die.<br>
  64. * Not true with Baium. Once he gets attacked, the port to Baium closes. byebye, see you in 5 days. If nobody attacks Baium for 30 minutes, he auto-despawns and unlocks the vortex.</li>
  65. * @author Fulminus version 0.1
  66. */
  67. public class Baium extends AbstractNpcAI
  68. {
  69. // NPCs
  70. private static final int STONE_BAIUM = 29025;
  71. private static final int ANGELIC_VORTEX = 31862;
  72. private static final int LIVE_BAIUM = 29020;
  73. private static final int ARCHANGEL = 29021;
  74. private static final int TELEPORT_CUBIC = 31842;
  75. // Item
  76. private static final int BLOODED_FABRIC = 4295;
  77. // Baium status tracking
  78. private static final byte ASLEEP = 0; // baium is in the stone version, waiting to be woken up. Entry is unlocked
  79. private static final byte AWAKE = 1; // baium is awake and fighting. Entry is locked.
  80. private static final byte DEAD = 2; // baium has been killed and has not yet spawned. Entry is locked
  81. // fixed archangel spawnloc
  82. private final static Location[] ANGEL_LOCATION =
  83. {
  84. new Location(114239, 17168, 10080, 63544),
  85. new Location(115780, 15564, 10080, 13620),
  86. new Location(114880, 16236, 10080, 5400),
  87. new Location(115168, 17200, 10080, 0),
  88. new Location(115792, 16608, 10080, 0)
  89. };
  90. private long _LastAttackVsBaiumTime = 0;
  91. protected final List<L2Npc> _Minions = new ArrayList<>(5);
  92. private L2BossZone _Zone;
  93. private L2Character _target;
  94. private L2Skill _skill;
  95. private Baium(String name, String descr)
  96. {
  97. super(name, descr);
  98. registerMobs(LIVE_BAIUM);
  99. // Quest NPC starter initialization
  100. addStartNpc(STONE_BAIUM, ANGELIC_VORTEX, TELEPORT_CUBIC);
  101. addTalkId(STONE_BAIUM, ANGELIC_VORTEX, TELEPORT_CUBIC);
  102. _Zone = GrandBossManager.getInstance().getZone(113100, 14500, 10077);
  103. StatsSet info = GrandBossManager.getInstance().getStatsSet(LIVE_BAIUM);
  104. int status = GrandBossManager.getInstance().getBossStatus(LIVE_BAIUM);
  105. if (status == DEAD)
  106. {
  107. // load the unlock date and time for baium from DB
  108. long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
  109. if (temp > 0)
  110. {
  111. // the unlock time has not yet expired. Mark Baium as currently locked (dead). Setup a timer
  112. // to fire at the correct time (calculate the time between now and the unlock time,
  113. // setup a timer to fire after that many msec)
  114. startQuestTimer("baium_unlock", temp, null, null);
  115. }
  116. else
  117. {
  118. // the time has already expired while the server was offline. Delete the saved time and
  119. // immediately spawn the stone-baium. Also the state need not be changed from ASLEEP
  120. addSpawn(STONE_BAIUM, 116033, 17447, 10107, -25348, false, 0);
  121. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, ASLEEP);
  122. }
  123. }
  124. else if (status == AWAKE)
  125. {
  126. int loc_x = info.getInteger("loc_x");
  127. int loc_y = info.getInteger("loc_y");
  128. int loc_z = info.getInteger("loc_z");
  129. int heading = info.getInteger("heading");
  130. final int hp = info.getInteger("currentHP");
  131. final int mp = info.getInteger("currentMP");
  132. L2GrandBossInstance baium = (L2GrandBossInstance) addSpawn(LIVE_BAIUM, loc_x, loc_y, loc_z, heading, false, 0);
  133. GrandBossManager.getInstance().addBoss(baium);
  134. final L2Npc _baium = baium;
  135. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  136. {
  137. @Override
  138. public void run()
  139. {
  140. try
  141. {
  142. _baium.setCurrentHpMp(hp, mp);
  143. _baium.setIsInvul(true);
  144. _baium.setIsImmobilized(true);
  145. _baium.setRunning();
  146. _baium.broadcastSocialAction(2);
  147. startQuestTimer("baium_wakeup", 15000, _baium, null);
  148. }
  149. catch (Exception e)
  150. {
  151. e.printStackTrace();
  152. }
  153. }
  154. }, 100L);
  155. }
  156. else
  157. {
  158. addSpawn(STONE_BAIUM, 116033, 17447, 10107, -25348, false, 0);
  159. }
  160. }
  161. @Override
  162. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  163. {
  164. if (event.equalsIgnoreCase("baium_unlock"))
  165. {
  166. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, ASLEEP);
  167. addSpawn(STONE_BAIUM, 116033, 17447, 10107, -25348, false, 0);
  168. }
  169. else if (event.equalsIgnoreCase("skill_range") && (npc != null))
  170. {
  171. callSkillAI(npc);
  172. }
  173. else if (event.equalsIgnoreCase("clean_player"))
  174. {
  175. _target = getRandomTarget(npc);
  176. }
  177. else if (event.equalsIgnoreCase("baium_wakeup") && (npc != null))
  178. {
  179. if (npc.getNpcId() == LIVE_BAIUM)
  180. {
  181. npc.broadcastSocialAction(1);
  182. npc.broadcastPacket(new Earthquake(npc.getX(), npc.getY(), npc.getZ(), 40, 5));
  183. // start monitoring baium's inactivity
  184. _LastAttackVsBaiumTime = System.currentTimeMillis();
  185. startQuestTimer("baium_despawn", 60000, npc, null, true);
  186. startQuestTimer("skill_range", 500, npc, null, true);
  187. final L2Npc baium = npc;
  188. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  189. {
  190. @Override
  191. public void run()
  192. {
  193. try
  194. {
  195. baium.setIsInvul(false);
  196. baium.setIsImmobilized(false);
  197. for (L2Npc minion : _Minions)
  198. {
  199. minion.setShowSummonAnimation(false);
  200. }
  201. }
  202. catch (Exception e)
  203. {
  204. _log.log(Level.WARNING, "", e);
  205. }
  206. }
  207. }, 11100L);
  208. // TODO: the person who woke baium up should be knocked across the room, onto a wall, and
  209. // lose massive amounts of HP.
  210. for (Location element : ANGEL_LOCATION)
  211. {
  212. L2Npc angel = addSpawn(ARCHANGEL, element, false, 0, true);
  213. angel.setIsInvul(true);
  214. _Minions.add(angel);
  215. }
  216. }
  217. // despawn the live baium after 30 minutes of inactivity
  218. // also check if the players are cheating, having pulled Baium outside his zone...
  219. }
  220. else if (event.equalsIgnoreCase("baium_despawn") && (npc != null))
  221. {
  222. if (npc.getNpcId() == LIVE_BAIUM)
  223. {
  224. // just in case the zone reference has been lost (somehow...), restore the reference
  225. if (_Zone == null)
  226. {
  227. _Zone = GrandBossManager.getInstance().getZone(113100, 14500, 10077);
  228. }
  229. if ((_LastAttackVsBaiumTime + 1800000) < System.currentTimeMillis())
  230. {
  231. npc.deleteMe(); // despawn the live-baium
  232. for (L2Npc minion : _Minions)
  233. {
  234. if (minion != null)
  235. {
  236. minion.getSpawn().stopRespawn();
  237. minion.deleteMe();
  238. }
  239. }
  240. _Minions.clear();
  241. addSpawn(STONE_BAIUM, 116033, 17447, 10107, -25348, false, 0); // spawn stone-baium
  242. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, ASLEEP); // mark that Baium is not awake any more
  243. _Zone.oustAllPlayers();
  244. cancelQuestTimer("baium_despawn", npc, null);
  245. }
  246. else if (((_LastAttackVsBaiumTime + 300000) < System.currentTimeMillis()) && (npc.getCurrentHp() < ((npc.getMaxHp() * 3) / 4.0)))
  247. {
  248. npc.setIsCastingNow(false); // just in case
  249. npc.setTarget(npc);
  250. L2Skill skill = SkillTable.getInstance().getInfo(4135, 1);
  251. if (skill.isMagic())
  252. {
  253. if (npc.isMuted())
  254. {
  255. return super.onAdvEvent(event, npc, player);
  256. }
  257. }
  258. else
  259. {
  260. if (npc.isPhysicalMuted())
  261. {
  262. return super.onAdvEvent(event, npc, player);
  263. }
  264. }
  265. npc.doCast(skill);
  266. npc.setIsCastingNow(true);
  267. }
  268. else if (!_Zone.isInsideZone(npc))
  269. {
  270. npc.teleToLocation(116033, 17447, 10104);
  271. }
  272. }
  273. }
  274. return super.onAdvEvent(event, npc, player);
  275. }
  276. @Override
  277. public String onTalk(L2Npc npc, L2PcInstance player)
  278. {
  279. int npcId = npc.getNpcId();
  280. String htmltext = "";
  281. if (_Zone == null)
  282. {
  283. _Zone = GrandBossManager.getInstance().getZone(113100, 14500, 10077);
  284. }
  285. if (_Zone == null)
  286. {
  287. return "<html><body>Angelic Vortex:<br>You may not enter while admin disabled this zone</body></html>";
  288. }
  289. if ((npcId == STONE_BAIUM) && (GrandBossManager.getInstance().getBossStatus(LIVE_BAIUM) == ASLEEP))
  290. {
  291. if (_Zone.isPlayerAllowed(player))
  292. {
  293. // once Baium is awaken, no more people may enter until he dies, the server reboots, or
  294. // 30 minutes pass with no attacks made against Baium.
  295. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, AWAKE);
  296. npc.deleteMe();
  297. L2GrandBossInstance baium = (L2GrandBossInstance) addSpawn(LIVE_BAIUM, npc, true);
  298. GrandBossManager.getInstance().addBoss(baium);
  299. final L2Npc _baium = baium;
  300. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  301. {
  302. @Override
  303. public void run()
  304. {
  305. try
  306. {
  307. _baium.setIsInvul(true);
  308. _baium.setRunning();
  309. _baium.broadcastSocialAction(2);
  310. startQuestTimer("baium_wakeup", 15000, _baium, null);
  311. _baium.setShowSummonAnimation(false);
  312. }
  313. catch (Throwable e)
  314. {
  315. _log.log(Level.WARNING, "", e);
  316. }
  317. }
  318. }, 100L);
  319. }
  320. else
  321. {
  322. htmltext = "Conditions are not right to wake up Baium";
  323. }
  324. }
  325. else if (npcId == ANGELIC_VORTEX)
  326. {
  327. if (player.isFlying())
  328. {
  329. // print "Player "+player.getName()+" attempted to enter Baium's lair while flying!";
  330. return "<html><body>Angelic Vortex:<br>You may not enter while flying a wyvern</body></html>";
  331. }
  332. if ((GrandBossManager.getInstance().getBossStatus(LIVE_BAIUM) == ASLEEP) && hasQuestItems(player, BLOODED_FABRIC))
  333. {
  334. takeItems(player, BLOODED_FABRIC, 1);
  335. // allow entry for the player for the next 30 secs (more than enough time for the TP to happen)
  336. // Note: this just means 30secs to get in, no limits on how long it takes before we get out.
  337. _Zone.allowPlayerEntry(player, 30);
  338. player.teleToLocation(113100, 14500, 10077);
  339. }
  340. else
  341. {
  342. npc.showChatWindow(player, 1);
  343. }
  344. }
  345. else if (npc.getNpcId() == TELEPORT_CUBIC)
  346. {
  347. int chance = getRandom(3);
  348. int x, y, z;
  349. switch (chance)
  350. {
  351. case 0:
  352. x = 108784 + getRandom(100);
  353. y = 16000 + getRandom(100);
  354. z = -4928;
  355. break;
  356. case 1:
  357. x = 113824 + getRandom(100);
  358. y = 10448 + getRandom(100);
  359. z = -5164;
  360. break;
  361. default:
  362. x = 115488 + getRandom(100);
  363. y = 22096 + getRandom(100);
  364. z = -5168;
  365. break;
  366. }
  367. player.teleToLocation(x, y, z);
  368. }
  369. return htmltext;
  370. }
  371. @Override
  372. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  373. {
  374. if (npc.isInvul())
  375. {
  376. npc.getAI().setIntention(AI_INTENTION_IDLE);
  377. return null;
  378. }
  379. else if ((npc.getNpcId() == LIVE_BAIUM) && !npc.isInvul())
  380. {
  381. callSkillAI(npc);
  382. }
  383. return super.onSpellFinished(npc, player, skill);
  384. }
  385. @Override
  386. public String onSpawn(L2Npc npc)
  387. {
  388. npc.disableCoreAI(true);
  389. return super.onSpawn(npc);
  390. }
  391. @Override
  392. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  393. {
  394. if (!_Zone.isInsideZone(attacker))
  395. {
  396. attacker.reduceCurrentHp(attacker.getCurrentHp(), attacker, false, false, null);
  397. return super.onAttack(npc, attacker, damage, isSummon);
  398. }
  399. if (npc.isInvul())
  400. {
  401. npc.getAI().setIntention(AI_INTENTION_IDLE);
  402. return super.onAttack(npc, attacker, damage, isSummon);
  403. }
  404. else if ((npc.getNpcId() == LIVE_BAIUM) && !npc.isInvul())
  405. {
  406. if (attacker.getMountType() == 1)
  407. {
  408. int sk_4258 = 0;
  409. L2Effect[] effects = attacker.getAllEffects();
  410. if ((effects != null) && (effects.length != 0))
  411. {
  412. for (L2Effect e : effects)
  413. {
  414. if (e.getSkill().getId() == 4258)
  415. {
  416. sk_4258 = 1;
  417. }
  418. }
  419. }
  420. if (sk_4258 == 0)
  421. {
  422. npc.setTarget(attacker);
  423. L2Skill skill = SkillTable.getInstance().getInfo(4258, 1);
  424. if (skill.isMagic())
  425. {
  426. if (npc.isMuted())
  427. {
  428. return super.onAttack(npc, attacker, damage, isSummon);
  429. }
  430. }
  431. else
  432. {
  433. if (npc.isPhysicalMuted())
  434. {
  435. return super.onAttack(npc, attacker, damage, isSummon);
  436. }
  437. }
  438. npc.doCast(skill);
  439. }
  440. }
  441. // update a variable with the last action against baium
  442. _LastAttackVsBaiumTime = System.currentTimeMillis();
  443. callSkillAI(npc);
  444. }
  445. return super.onAttack(npc, attacker, damage, isSummon);
  446. }
  447. @Override
  448. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  449. {
  450. cancelQuestTimer("baium_despawn", npc, null);
  451. npc.broadcastPacket(new PlaySound(1, "BS01_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  452. // spawn the "Teleportation Cubic" for 15 minutes (to allow players to exit the lair)
  453. addSpawn(TELEPORT_CUBIC, 115017, 15549, 10090, 0, false, 900000);
  454. // Calculate Min and Max respawn times randomly.
  455. long respawnTime = Config.BAIUM_SPAWN_INTERVAL + getRandom(-Config.BAIUM_SPAWN_RANDOM, Config.BAIUM_SPAWN_RANDOM);
  456. respawnTime *= 60 * 60 * 1000;
  457. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, DEAD);
  458. startQuestTimer("baium_unlock", respawnTime, null, null);
  459. // also save the respawn time so that the info is maintained past reboots
  460. StatsSet info = GrandBossManager.getInstance().getStatsSet(LIVE_BAIUM);
  461. info.set("respawn_time", (System.currentTimeMillis()) + respawnTime);
  462. GrandBossManager.getInstance().setStatsSet(LIVE_BAIUM, info);
  463. for (L2Npc minion : _Minions)
  464. {
  465. if (minion != null)
  466. {
  467. minion.getSpawn().stopRespawn();
  468. minion.deleteMe();
  469. }
  470. }
  471. _Minions.clear();
  472. final QuestTimer timer = getQuestTimer("skill_range", npc, null);
  473. if (timer != null)
  474. {
  475. timer.cancelAndRemove();
  476. }
  477. return super.onKill(npc, killer, isSummon);
  478. }
  479. public L2Character getRandomTarget(L2Npc npc)
  480. {
  481. FastList<L2Character> result = FastList.newInstance();
  482. Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values();
  483. {
  484. for (L2Object obj : objs)
  485. {
  486. if (obj.isPlayable() || (obj instanceof L2DecoyInstance))
  487. {
  488. if (obj.isPlayer())
  489. {
  490. if (obj.getActingPlayer().getAppearance().getInvisible())
  491. {
  492. continue;
  493. }
  494. }
  495. if (((((L2Character) obj).getZ() < (npc.getZ() - 100)) && (((L2Character) obj).getZ() > (npc.getZ() + 100))) || !(GeoData.getInstance().canSeeTarget(((L2Character) obj).getX(), ((L2Character) obj).getY(), ((L2Character) obj).getZ(), npc.getX(), npc.getY(), npc.getZ())))
  496. {
  497. continue;
  498. }
  499. }
  500. if (obj.isPlayable() || (obj instanceof L2DecoyInstance))
  501. {
  502. if (Util.checkIfInRange(9000, npc, obj, true) && !((L2Character) obj).isDead())
  503. {
  504. result.add((L2Character) obj);
  505. }
  506. }
  507. }
  508. }
  509. if (result.isEmpty())
  510. {
  511. for (L2Npc minion : _Minions)
  512. {
  513. if (minion != null)
  514. {
  515. result.add(minion);
  516. }
  517. }
  518. }
  519. if (result.isEmpty())
  520. {
  521. FastList.recycle(result);
  522. return null;
  523. }
  524. Object[] characters = result.toArray();
  525. QuestTimer timer = getQuestTimer("clean_player", npc, null);
  526. if (timer != null)
  527. {
  528. timer.cancelAndRemove();
  529. }
  530. startQuestTimer("clean_player", 20000, npc, null);
  531. L2Character target = (L2Character) characters[getRandom(characters.length)];
  532. FastList.recycle(result);
  533. return target;
  534. }
  535. public synchronized void callSkillAI(L2Npc npc)
  536. {
  537. if (npc.isInvul() || npc.isCastingNow())
  538. {
  539. return;
  540. }
  541. if ((_target == null) || _target.isDead() || !(_Zone.isInsideZone(_target)))
  542. {
  543. _target = getRandomTarget(npc);
  544. if (_target != null)
  545. {
  546. _skill = SkillTable.getInstance().getInfo(getRandomSkill(npc), 1);
  547. }
  548. }
  549. L2Character target = _target;
  550. L2Skill skill = _skill;
  551. if (skill == null)
  552. {
  553. skill = SkillTable.getInstance().getInfo(getRandomSkill(npc), 1);
  554. }
  555. if (skill.isMagic())
  556. {
  557. if (npc.isMuted())
  558. {
  559. return;
  560. }
  561. }
  562. else
  563. {
  564. if (npc.isPhysicalMuted())
  565. {
  566. return;
  567. }
  568. }
  569. if ((target == null) || target.isDead() || !(_Zone.isInsideZone(target)))
  570. {
  571. npc.setIsCastingNow(false);
  572. return;
  573. }
  574. if (Util.checkIfInRange(skill.getCastRange(), npc, target, true))
  575. {
  576. npc.getAI().setIntention(AI_INTENTION_IDLE);
  577. npc.setTarget(target);
  578. npc.setIsCastingNow(true);
  579. _target = null;
  580. _skill = null;
  581. if (getDist(skill.getCastRange()) > 0)
  582. {
  583. npc.broadcastPacket(new MoveToPawn(npc, target, getDist(skill.getCastRange())));
  584. }
  585. try
  586. {
  587. Thread.sleep(1000);
  588. npc.stopMove(null);
  589. npc.doCast(skill);
  590. }
  591. catch (Exception e)
  592. {
  593. e.printStackTrace();
  594. }
  595. }
  596. else
  597. {
  598. npc.getAI().setIntention(AI_INTENTION_FOLLOW, target, null);
  599. npc.setIsCastingNow(false);
  600. }
  601. }
  602. public int getRandomSkill(L2Npc npc)
  603. {
  604. int skill;
  605. if (npc.getCurrentHp() > ((npc.getMaxHp() * 3) / 4.0))
  606. {
  607. if (getRandom(100) < 10)
  608. {
  609. skill = 4128;
  610. }
  611. else if (getRandom(100) < 10)
  612. {
  613. skill = 4129;
  614. }
  615. else
  616. {
  617. skill = 4127;
  618. }
  619. }
  620. else if (npc.getCurrentHp() > ((npc.getMaxHp() * 2) / 4.0))
  621. {
  622. if (getRandom(100) < 10)
  623. {
  624. skill = 4131;
  625. }
  626. else if (getRandom(100) < 10)
  627. {
  628. skill = 4128;
  629. }
  630. else if (getRandom(100) < 10)
  631. {
  632. skill = 4129;
  633. }
  634. else
  635. {
  636. skill = 4127;
  637. }
  638. }
  639. else if (npc.getCurrentHp() > ((npc.getMaxHp() * 1) / 4.0))
  640. {
  641. if (getRandom(100) < 10)
  642. {
  643. skill = 4130;
  644. }
  645. else if (getRandom(100) < 10)
  646. {
  647. skill = 4131;
  648. }
  649. else if (getRandom(100) < 10)
  650. {
  651. skill = 4128;
  652. }
  653. else if (getRandom(100) < 10)
  654. {
  655. skill = 4129;
  656. }
  657. else
  658. {
  659. skill = 4127;
  660. }
  661. }
  662. else if (getRandom(100) < 10)
  663. {
  664. skill = 4130;
  665. }
  666. else if (getRandom(100) < 10)
  667. {
  668. skill = 4131;
  669. }
  670. else if (getRandom(100) < 10)
  671. {
  672. skill = 4128;
  673. }
  674. else if (getRandom(100) < 10)
  675. {
  676. skill = 4129;
  677. }
  678. else
  679. {
  680. skill = 4127;
  681. }
  682. return skill;
  683. }
  684. @Override
  685. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isSummon)
  686. {
  687. if (npc.isInvul())
  688. {
  689. npc.getAI().setIntention(AI_INTENTION_IDLE);
  690. return null;
  691. }
  692. npc.setTarget(caster);
  693. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  694. }
  695. public int getDist(int range)
  696. {
  697. int dist = 0;
  698. switch (range)
  699. {
  700. case -1:
  701. break;
  702. case 100:
  703. dist = 85;
  704. break;
  705. default:
  706. dist = range - 85;
  707. break;
  708. }
  709. return dist;
  710. }
  711. public static void main(String[] args)
  712. {
  713. new Baium(Baium.class.getSimpleName(), "ai");
  714. }
  715. }