Baium.java 22 KB

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