FleeNpc.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ai.group_template.L2AttackableAIScript;
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.model.L2CharPosition;
  19. import com.l2jserver.gameserver.model.actor.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.util.Rnd;
  22. public class FleeNpc extends L2AttackableAIScript
  23. {
  24. private final int[] _npcId =
  25. {
  26. 20432, 22228, 18150, 18151, 18152, 18153, 18154, 18155, 18156, 18157
  27. };
  28. public FleeNpc(int questId, String name, String descr)
  29. {
  30. super(questId, name, descr);
  31. registerMobs(_npcId, QuestEventType.ON_ATTACK);
  32. }
  33. @Override
  34. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  35. {
  36. if (npc.getNpcId() >= 18150 && npc.getNpcId() <= 18157)
  37. {
  38. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition((npc.getX() + Rnd.get(-40, 40)), (npc.getY() + Rnd.get(-40, 40)), npc.getZ(), npc.getHeading()));
  39. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  40. return null;
  41. }
  42. else if (npc.getNpcId() == 20432 || npc.getNpcId() == 22228)
  43. {
  44. if (Rnd.get(3) == 2)
  45. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition((npc.getX() + Rnd.get(-200, 200)), (npc.getY() + Rnd.get(-200, 200)), npc.getZ(), npc.getHeading()));
  46. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  47. return null;
  48. }
  49. return super.onAttack(npc, attacker, damage, isPet);
  50. }
  51. // Register the new Script at the Script System
  52. public static void main(String[] args)
  53. {
  54. new FleeNpc(-1, "FleeNpc", "Ai for Flee Npcs");
  55. }
  56. }