FleeNpc.java 2.4 KB

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