FleeMonsters.java 2.9 KB

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