Baium.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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.group_template.L2AttackableAIScript;
  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.L2Effect;
  30. import com.l2jserver.gameserver.model.L2Object;
  31. import com.l2jserver.gameserver.model.L2Skill;
  32. import com.l2jserver.gameserver.model.Location;
  33. import com.l2jserver.gameserver.model.StatsSet;
  34. import com.l2jserver.gameserver.model.actor.L2Character;
  35. import com.l2jserver.gameserver.model.actor.L2Npc;
  36. import com.l2jserver.gameserver.model.actor.L2Playable;
  37. import com.l2jserver.gameserver.model.actor.instance.L2DecoyInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  39. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  40. import com.l2jserver.gameserver.model.quest.QuestTimer;
  41. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  42. import com.l2jserver.gameserver.network.serverpackets.Earthquake;
  43. import com.l2jserver.gameserver.network.serverpackets.MoveToPawn;
  44. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  45. import com.l2jserver.gameserver.util.Util;
  46. import com.l2jserver.util.Rnd;
  47. /**
  48. * 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
  49. * 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
  50. * 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
  51. * 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
  52. * 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
  53. * 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.
  54. * 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
  55. * @author Fulminus version 0.1
  56. */
  57. public class Baium extends L2AttackableAIScript
  58. {
  59. private L2Character _target;
  60. private L2Skill _skill;
  61. private static final int STONE_BAIUM = 29025;
  62. private static final int ANGELIC_VORTEX = 31862;
  63. private static final int LIVE_BAIUM = 29020;
  64. private static final int ARCHANGEL = 29021;
  65. // Baium status tracking
  66. private static final byte ASLEEP = 0; // baium is in the stone version, waiting to be woken up. Entry is unlocked
  67. private static final byte AWAKE = 1; // baium is awake and fighting. Entry is locked.
  68. private static final byte DEAD = 2; // baium has been killed and has not yet spawned. Entry is locked
  69. // fixed archangel spawnloc
  70. private final static Location[] ANGEL_LOCATION =
  71. {
  72. new Location(114239, 17168, 10080, 63544),
  73. new Location(115780, 15564, 10080, 13620),
  74. new Location(114880, 16236, 10080, 5400),
  75. new Location(115168, 17200, 10080, 0),
  76. new Location(115792, 16608, 10080, 0)
  77. };
  78. private long _LastAttackVsBaiumTime = 0;
  79. private final List<L2Npc> _Minions = new ArrayList<L2Npc>(5);
  80. private L2BossZone _Zone;
  81. public Baium(int questId, String name, String descr)
  82. {
  83. super(questId, name, descr);
  84. int[] mob =
  85. {
  86. LIVE_BAIUM
  87. };
  88. registerMobs(mob);
  89. // Quest NPC starter initialization
  90. addStartNpc(STONE_BAIUM, ANGELIC_VORTEX);
  91. addTalkId(STONE_BAIUM, ANGELIC_VORTEX);
  92. _Zone = GrandBossManager.getInstance().getZone(113100, 14500, 10077);
  93. StatsSet info = GrandBossManager.getInstance().getStatsSet(LIVE_BAIUM);
  94. int status = GrandBossManager.getInstance().getBossStatus(LIVE_BAIUM);
  95. if (status == DEAD)
  96. {
  97. // load the unlock date and time for baium from DB
  98. long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
  99. if (temp > 0)
  100. {
  101. // the unlock time has not yet expired. Mark Baium as currently locked (dead). Setup a timer
  102. // to fire at the correct time (calculate the time between now and the unlock time,
  103. // setup a timer to fire after that many msec)
  104. startQuestTimer("baium_unlock", temp, null, null);
  105. }
  106. else
  107. {
  108. // the time has already expired while the server was offline. Delete the saved time and
  109. // immediately spawn the stone-baium. Also the state need not be changed from ASLEEP
  110. addSpawn(STONE_BAIUM, 116033, 17447, 10104, 40188, false, 0);
  111. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, ASLEEP);
  112. }
  113. }
  114. else if (status == AWAKE)
  115. {
  116. int loc_x = info.getInteger("loc_x");
  117. int loc_y = info.getInteger("loc_y");
  118. int loc_z = info.getInteger("loc_z");
  119. int heading = info.getInteger("heading");
  120. final int hp = info.getInteger("currentHP");
  121. final int mp = info.getInteger("currentMP");
  122. L2GrandBossInstance baium = (L2GrandBossInstance) addSpawn(LIVE_BAIUM, loc_x, loc_y, loc_z, heading, false, 0);
  123. GrandBossManager.getInstance().addBoss(baium);
  124. final L2Npc _baium = baium;
  125. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  126. {
  127. @Override
  128. public void run()
  129. {
  130. try
  131. {
  132. _baium.setCurrentHpMp(hp, mp);
  133. _baium.setIsInvul(true);
  134. _baium.setIsImmobilized(true);
  135. _baium.setRunning();
  136. _baium.broadcastSocialAction(2);
  137. startQuestTimer("baium_wakeup", 15000, _baium, null);
  138. }
  139. catch (Exception e)
  140. {
  141. e.printStackTrace();
  142. }
  143. }
  144. }, 100L);
  145. }
  146. else
  147. addSpawn(STONE_BAIUM, 116033, 17447, 10104, 40188, false, 0);
  148. }
  149. @Override
  150. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  151. {
  152. if (event.equalsIgnoreCase("baium_unlock"))
  153. {
  154. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, ASLEEP);
  155. addSpawn(STONE_BAIUM, 116033, 17447, 10104, 40188, false, 0);
  156. }
  157. else if (event.equalsIgnoreCase("skill_range") && npc != null)
  158. {
  159. callSkillAI(npc);
  160. }
  161. else if (event.equalsIgnoreCase("clean_player"))
  162. {
  163. _target = getRandomTarget(npc);
  164. }
  165. else if (event.equalsIgnoreCase("baium_wakeup") && npc != null)
  166. {
  167. if (npc.getNpcId() == LIVE_BAIUM)
  168. {
  169. npc.broadcastSocialAction(1);
  170. npc.broadcastPacket(new Earthquake(npc.getX(), npc.getY(), npc.getZ(), 40, 5));
  171. // start monitoring baium's inactivity
  172. _LastAttackVsBaiumTime = System.currentTimeMillis();
  173. startQuestTimer("baium_despawn", 60000, npc, null, true);
  174. startQuestTimer("skill_range", 500, npc, null, true);
  175. final L2Npc baium = npc;
  176. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  177. {
  178. @Override
  179. public void run()
  180. {
  181. try
  182. {
  183. baium.setIsInvul(false);
  184. baium.setIsImmobilized(false);
  185. for (L2Npc minion : _Minions)
  186. minion.setShowSummonAnimation(false);
  187. }
  188. catch (Exception e)
  189. {
  190. _log.log(Level.WARNING, "", e);
  191. }
  192. }
  193. }, 11100L);
  194. // TODO: the person who woke baium up should be knocked across the room, onto a wall, and
  195. // lose massive amounts of HP.
  196. for (int i = 0; i < ANGEL_LOCATION.length; i++)
  197. {
  198. L2Npc angel = addSpawn(ARCHANGEL, ANGEL_LOCATION[i], false, 0, true);
  199. angel.setIsInvul(true);
  200. _Minions.add(angel);
  201. }
  202. }
  203. // despawn the live baium after 30 minutes of inactivity
  204. // also check if the players are cheating, having pulled Baium outside his zone...
  205. }
  206. else if (event.equalsIgnoreCase("baium_despawn") && npc != null)
  207. {
  208. if (npc.getNpcId() == LIVE_BAIUM)
  209. {
  210. // just in case the zone reference has been lost (somehow...), restore the reference
  211. if (_Zone == null)
  212. _Zone = GrandBossManager.getInstance().getZone(113100, 14500, 10077);
  213. if (_LastAttackVsBaiumTime + 1800000 < System.currentTimeMillis())
  214. {
  215. npc.deleteMe(); // despawn the live-baium
  216. for (L2Npc minion : _Minions)
  217. if (minion != null)
  218. {
  219. minion.getSpawn().stopRespawn();
  220. minion.deleteMe();
  221. }
  222. _Minions.clear();
  223. addSpawn(STONE_BAIUM, 116033, 17447, 10104, 40188, false, 0); // spawn stone-baium
  224. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, ASLEEP); // mark that Baium is not awake any more
  225. _Zone.oustAllPlayers();
  226. cancelQuestTimer("baium_despawn", npc, null);
  227. }
  228. else if ((_LastAttackVsBaiumTime + 300000 < System.currentTimeMillis()) && npc.getCurrentHp() < ((npc.getMaxHp() * 3) / 4.0))
  229. {
  230. npc.setIsCastingNow(false); // just in case
  231. npc.setTarget(npc);
  232. L2Skill skill = SkillTable.getInstance().getInfo(4135, 1);
  233. if (skill.isMagic())
  234. {
  235. if (npc.isMuted())
  236. return super.onAdvEvent(event, npc, player);
  237. }
  238. else
  239. {
  240. if (npc.isPhysicalMuted())
  241. return super.onAdvEvent(event, npc, player);
  242. }
  243. npc.doCast(skill);
  244. npc.setIsCastingNow(true);
  245. }
  246. else if (!_Zone.isInsideZone(npc))
  247. npc.teleToLocation(116033, 17447, 10104);
  248. }
  249. }
  250. return super.onAdvEvent(event, npc, player);
  251. }
  252. @Override
  253. public String onTalk(L2Npc npc, L2PcInstance player)
  254. {
  255. int npcId = npc.getNpcId();
  256. String htmltext = "";
  257. if (_Zone == null)
  258. _Zone = GrandBossManager.getInstance().getZone(113100, 14500, 10077);
  259. if (_Zone == null)
  260. return "<html><body>Angelic Vortex:<br>You may not enter while admin disabled this zone</body></html>";
  261. if (npcId == STONE_BAIUM && GrandBossManager.getInstance().getBossStatus(LIVE_BAIUM) == ASLEEP)
  262. {
  263. if (_Zone.isPlayerAllowed(player))
  264. {
  265. // once Baium is awaken, no more people may enter until he dies, the server reboots, or
  266. // 30 minutes pass with no attacks made against Baium.
  267. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, AWAKE);
  268. npc.deleteMe();
  269. L2GrandBossInstance baium = (L2GrandBossInstance) addSpawn(LIVE_BAIUM, npc, true);
  270. GrandBossManager.getInstance().addBoss(baium);
  271. final L2Npc _baium = baium;
  272. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  273. {
  274. @Override
  275. public void run()
  276. {
  277. try
  278. {
  279. _baium.setIsInvul(true);
  280. _baium.setRunning();
  281. _baium.broadcastSocialAction(2);
  282. startQuestTimer("baium_wakeup", 15000, _baium, null);
  283. _baium.setShowSummonAnimation(false);
  284. }
  285. catch (Throwable e)
  286. {
  287. _log.log(Level.WARNING, "", e);
  288. }
  289. }
  290. }, 100L);
  291. }
  292. else
  293. htmltext = "Conditions are not right to wake up Baium";
  294. }
  295. else if (npcId == ANGELIC_VORTEX)
  296. {
  297. if (player.isFlying())
  298. {
  299. // print "Player "+player.getName()+" attempted to enter Baium's lair while flying!";
  300. return "<html><body>Angelic Vortex:<br>You may not enter while flying a wyvern</body></html>";
  301. }
  302. if (GrandBossManager.getInstance().getBossStatus(LIVE_BAIUM) == ASLEEP && player.getQuestState("baium").getQuestItemsCount(4295) > 0) // bloody fabric
  303. {
  304. player.getQuestState("baium").takeItems(4295, 1);
  305. // allow entry for the player for the next 30 secs (more than enough time for the TP to happen)
  306. // Note: this just means 30secs to get in, no limits on how long it takes before we get out.
  307. _Zone.allowPlayerEntry(player, 30);
  308. player.teleToLocation(113100, 14500, 10077);
  309. }
  310. else
  311. npc.showChatWindow(player, 1);
  312. }
  313. return htmltext;
  314. }
  315. @Override
  316. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  317. {
  318. if (npc.isInvul())
  319. {
  320. npc.getAI().setIntention(AI_INTENTION_IDLE);
  321. return null;
  322. }
  323. else if (npc.getNpcId() == LIVE_BAIUM && !npc.isInvul())
  324. {
  325. callSkillAI(npc);
  326. }
  327. return super.onSpellFinished(npc, player, skill);
  328. }
  329. @Override
  330. public String onSpawn(L2Npc npc)
  331. {
  332. npc.disableCoreAI(true);
  333. return super.onSpawn(npc);
  334. }
  335. @Override
  336. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  337. {
  338. if (!_Zone.isInsideZone(attacker))
  339. {
  340. attacker.reduceCurrentHp(attacker.getCurrentHp(), attacker, false, false, null);
  341. return super.onAttack(npc, attacker, damage, isPet);
  342. }
  343. if (npc.isInvul())
  344. {
  345. npc.getAI().setIntention(AI_INTENTION_IDLE);
  346. return super.onAttack(npc, attacker, damage, isPet);
  347. }
  348. else if (npc.getNpcId() == LIVE_BAIUM && !npc.isInvul())
  349. {
  350. if (attacker.getMountType() == 1)
  351. {
  352. int sk_4258 = 0;
  353. L2Effect[] effects = attacker.getAllEffects();
  354. if (effects != null && effects.length != 0)
  355. {
  356. for (L2Effect e : effects)
  357. {
  358. if (e.getSkill().getId() == 4258)
  359. sk_4258 = 1;
  360. }
  361. }
  362. if (sk_4258 == 0)
  363. {
  364. npc.setTarget(attacker);
  365. L2Skill skill = SkillTable.getInstance().getInfo(4258, 1);
  366. if (skill.isMagic())
  367. {
  368. if (npc.isMuted())
  369. return super.onAttack(npc, attacker, damage, isPet);
  370. }
  371. else
  372. {
  373. if (npc.isPhysicalMuted())
  374. return super.onAttack(npc, attacker, damage, isPet);
  375. }
  376. npc.doCast(skill);
  377. }
  378. }
  379. // update a variable with the last action against baium
  380. _LastAttackVsBaiumTime = System.currentTimeMillis();
  381. callSkillAI(npc);
  382. }
  383. return super.onAttack(npc, attacker, damage, isPet);
  384. }
  385. @Override
  386. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  387. {
  388. cancelQuestTimer("baium_despawn", npc, null);
  389. npc.broadcastPacket(new PlaySound(1, "BS01_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  390. // spawn the "Teleportation Cubic" for 15 minutes (to allow players to exit the lair)
  391. addSpawn(29055, 115203, 16620, 10078, 0, false, 900000); // //should we teleport everyone out if the cubic despawns??
  392. // "lock" baium for 5 days and 1 to 8 hours [i.e. 432,000,000 + 1*3,600,000 + random-less-than(8*3,600,000) millisecs]
  393. long respawnTime = (long) Config.Interval_Of_Baium_Spawn + Rnd.get(Config.Random_Of_Baium_Spawn);
  394. GrandBossManager.getInstance().setBossStatus(LIVE_BAIUM, DEAD);
  395. startQuestTimer("baium_unlock", respawnTime, null, null);
  396. // also save the respawn time so that the info is maintained past reboots
  397. StatsSet info = GrandBossManager.getInstance().getStatsSet(LIVE_BAIUM);
  398. info.set("respawn_time", (System.currentTimeMillis()) + respawnTime);
  399. GrandBossManager.getInstance().setStatsSet(LIVE_BAIUM, info);
  400. for (L2Npc minion : _Minions)
  401. if (minion != null)
  402. {
  403. minion.getSpawn().stopRespawn();
  404. minion.deleteMe();
  405. }
  406. _Minions.clear();
  407. if (getQuestTimer("skill_range", npc, null) != null)
  408. getQuestTimer("skill_range", npc, null).cancel();
  409. return super.onKill(npc, killer, isPet);
  410. }
  411. public L2Character getRandomTarget(L2Npc npc)
  412. {
  413. FastList<L2Character> result = FastList.newInstance();
  414. Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values();
  415. {
  416. for (L2Object obj : objs)
  417. {
  418. if (obj instanceof L2Playable || obj instanceof L2DecoyInstance)
  419. {
  420. if (obj instanceof L2PcInstance)
  421. {
  422. if (((L2PcInstance) obj).getAppearance().getInvisible())
  423. continue;
  424. }
  425. 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())))
  426. continue;
  427. }
  428. if (obj instanceof L2Playable || obj instanceof L2DecoyInstance)
  429. {
  430. if (Util.checkIfInRange(9000, npc, obj, true) && !((L2Character) obj).isDead())
  431. result.add((L2Character) obj);
  432. }
  433. }
  434. }
  435. if (result.isEmpty())
  436. {
  437. for (L2Npc minion : _Minions)
  438. if (minion != null)
  439. result.add(minion);
  440. }
  441. if (result.isEmpty())
  442. {
  443. FastList.recycle(result);
  444. return null;
  445. }
  446. Object[] characters = result.toArray();
  447. QuestTimer timer = getQuestTimer("clean_player", npc, null);
  448. if (timer != null)
  449. timer.cancel();
  450. startQuestTimer("clean_player", 20000, npc, null);
  451. L2Character target = (L2Character) characters[Rnd.get(characters.length)];
  452. FastList.recycle(result);
  453. return target;
  454. }
  455. public synchronized void callSkillAI(L2Npc npc)
  456. {
  457. if (npc.isInvul() || npc.isCastingNow())
  458. return;
  459. if (_target == null || _target.isDead() || !(_Zone.isInsideZone(_target)))
  460. {
  461. _target = getRandomTarget(npc);
  462. if (_target != null)
  463. _skill = SkillTable.getInstance().getInfo(getRandomSkill(npc), 1);
  464. }
  465. L2Character target = _target;
  466. L2Skill skill = _skill;
  467. if (skill == null)
  468. skill = SkillTable.getInstance().getInfo(getRandomSkill(npc), 1);
  469. if (skill.isMagic())
  470. {
  471. if (npc.isMuted())
  472. return;
  473. }
  474. else
  475. {
  476. if (npc.isPhysicalMuted())
  477. return;
  478. }
  479. if (target == null || target.isDead() || !(_Zone.isInsideZone(target)))
  480. {
  481. npc.setIsCastingNow(false);
  482. return;
  483. }
  484. if (Util.checkIfInRange(skill.getCastRange(), npc, target, true))
  485. {
  486. npc.getAI().setIntention(AI_INTENTION_IDLE);
  487. npc.setTarget(target);
  488. npc.setIsCastingNow(true);
  489. _target = null;
  490. _skill = null;
  491. if (getDist(skill.getCastRange()) > 0)
  492. npc.broadcastPacket(new MoveToPawn(npc, target, getDist(skill.getCastRange())));
  493. try
  494. {
  495. Thread.sleep(1000);
  496. npc.stopMove(null);
  497. npc.doCast(skill);
  498. }
  499. catch (Exception e)
  500. {
  501. e.printStackTrace();
  502. }
  503. }
  504. else
  505. {
  506. npc.getAI().setIntention(AI_INTENTION_FOLLOW, target, null);
  507. npc.setIsCastingNow(false);
  508. }
  509. }
  510. public int getRandomSkill(L2Npc npc)
  511. {
  512. int skill;
  513. if (npc.getCurrentHp() > ((npc.getMaxHp() * 3) / 4.0))
  514. {
  515. if (Rnd.get(100) < 10)
  516. skill = 4128;
  517. else if (Rnd.get(100) < 10)
  518. skill = 4129;
  519. else
  520. skill = 4127;
  521. }
  522. else if (npc.getCurrentHp() > ((npc.getMaxHp() * 2) / 4.0))
  523. {
  524. if (Rnd.get(100) < 10)
  525. skill = 4131;
  526. else if (Rnd.get(100) < 10)
  527. skill = 4128;
  528. else if (Rnd.get(100) < 10)
  529. skill = 4129;
  530. else
  531. skill = 4127;
  532. }
  533. else if (npc.getCurrentHp() > ((npc.getMaxHp() * 1) / 4.0))
  534. {
  535. if (Rnd.get(100) < 10)
  536. skill = 4130;
  537. else if (Rnd.get(100) < 10)
  538. skill = 4131;
  539. else if (Rnd.get(100) < 10)
  540. skill = 4128;
  541. else if (Rnd.get(100) < 10)
  542. skill = 4129;
  543. else
  544. skill = 4127;
  545. }
  546. else if (Rnd.get(100) < 10)
  547. skill = 4130;
  548. else if (Rnd.get(100) < 10)
  549. skill = 4131;
  550. else if (Rnd.get(100) < 10)
  551. skill = 4128;
  552. else if (Rnd.get(100) < 10)
  553. skill = 4129;
  554. else
  555. skill = 4127;
  556. return skill;
  557. }
  558. @Override
  559. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  560. {
  561. if (npc.isInvul())
  562. {
  563. npc.getAI().setIntention(AI_INTENTION_IDLE);
  564. return null;
  565. }
  566. npc.setTarget(caster);
  567. return super.onSkillSee(npc, caster, skill, targets, isPet);
  568. }
  569. public int getDist(int range)
  570. {
  571. int dist = 0;
  572. switch (range)
  573. {
  574. case -1:
  575. break;
  576. case 100:
  577. dist = 85;
  578. break;
  579. default:
  580. dist = range - 85;
  581. break;
  582. }
  583. return dist;
  584. }
  585. public static void main(String[] args)
  586. {
  587. // Quest class and state definition
  588. new Baium(-1, "baium", "ai");
  589. }
  590. }