FleeMonsters.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2004-2015 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.group_template;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.GeoData;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.L2Summon;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.interfaces.ILocational;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * Flee Monsters AI.
  31. * @author Pandragon, NosBit
  32. */
  33. public final class FleeMonsters extends AbstractNpcAI
  34. {
  35. // NPCs
  36. private static final int[] MOBS =
  37. {
  38. 18150, // Victim
  39. 18151, // Victim
  40. 18152, // Victim
  41. 18153, // Victim
  42. 18154, // Victim
  43. 18155, // Victim
  44. 18156, // Victim
  45. 18157, // Victim
  46. 20002, // Rabbit
  47. 20432, // Elpy
  48. 22228, // Grey Elpy
  49. 25604, // Mutated Elpy
  50. };
  51. // Misc
  52. private static final int FLEE_DISTANCE = 500;
  53. private FleeMonsters()
  54. {
  55. super(FleeMonsters.class.getSimpleName(), "ai/group_template");
  56. addAttackId(MOBS);
  57. }
  58. @Override
  59. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  60. {
  61. npc.disableCoreAI(true);
  62. npc.setRunning();
  63. final L2Summon summon = isSummon ? attacker.getSummon() : null;
  64. final ILocational attackerLoc = summon == null ? attacker : summon;
  65. final double radians = Math.toRadians(Util.calculateAngleFrom(attackerLoc, npc));
  66. final int posX = (int) (npc.getX() + (FLEE_DISTANCE * Math.cos(radians)));
  67. final int posY = (int) (npc.getY() + (FLEE_DISTANCE * Math.sin(radians)));
  68. final int posZ = npc.getZ();
  69. final Location destination = GeoData.getInstance().moveCheck(npc.getX(), npc.getY(), npc.getZ(), posX, posY, posZ, attacker.getInstanceId());
  70. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
  71. return super.onAttack(npc, attacker, damage, isSummon);
  72. }
  73. public static void main(String[] args)
  74. {
  75. new FleeMonsters();
  76. }
  77. }