RangeGuard.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 java.util.List;
  21. import ai.npc.AbstractNpcAI;
  22. import com.l2jserver.gameserver.datatables.NpcData;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.L2Playable;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  27. import com.l2jserver.gameserver.model.holders.SkillHolder;
  28. import com.l2jserver.gameserver.model.skills.Skill;
  29. import com.l2jserver.gameserver.util.Util;
  30. /**
  31. * Range Guard AI.
  32. * @author St3eT.
  33. */
  34. public final class RangeGuard extends AbstractNpcAI
  35. {
  36. // Skill
  37. private static SkillHolder ULTIMATE_DEFENSE = new SkillHolder(5044, 3); // NPC Ultimate Defense
  38. // Misc
  39. private static final int MIN_DISTANCE = 150;
  40. // Not allowed skills
  41. //@formatter:off
  42. private static final int[] NOT_ALLOWED_SKILLS =
  43. {
  44. 15, 28, // Charm / Aggression
  45. 51, 65, // Lure / Horror
  46. 106, 115, // Veil / Power Break
  47. 122, 127, // Hex / Hamstring
  48. 254, 352, // Spoil / Shield Bash
  49. 353, 358, // Shield Slam / Bluff
  50. 402, 403, // Arrest / Shackle
  51. 412, 485, // Sand Bomb / Disarm
  52. 501, 511, // Violent Temper / Temptation
  53. 522, 531, // Real Target / Critical Wound
  54. 680, 695, // Divine Knight Hate / Divine Wizard Divine Cloud
  55. 696, 716, // Divine Wizard Surrender to Divine / Zaken Hold
  56. 775, 792, // Weapon Blockade / Betrayal Mark
  57. 1042, 1049, // Hold Undead / Requiem
  58. 1069, 1071, // Sleep / Surrender To Water
  59. 1072, 1074, // Sleeping Cloud / Surrender To Wind
  60. 1083, 1097, // Surrender To Fire / Dreaming Spirit
  61. 1092, 1064, // Fear / Silence
  62. 1160, 1164, // Slow / Curse Weakness
  63. 1169, 1170, // Curse Fear / Anchor
  64. 1201, 1206, // Dryad Root / Wind Shackle
  65. 1222, 1223, // Curse Chaos / Surrender To Earth
  66. 1224, 1263, // Surrender To Poison / Curse Gloom
  67. 1269, 1336, // Curse Disease / Curse of Doom
  68. 1337, 1338, // Curse of Abyss / Arcane Chaos
  69. 1358, 1359, // Block Shield / Block Wind Walk
  70. 1386, 1394, // Arcane Disruption / Trance
  71. 1396, 1445, // Magical BackFire / Surrender to Dark
  72. 1446, 1447, // Shadow Bind / Voice Bind
  73. 1481, 1482, // Oblivion / Weak Constitution
  74. 1483, 1484, // Thin Skin / Enervation
  75. 1485, 1486, // Spite / Mental Impoverish
  76. 1511, 1524, // Curse of Life Flow / Surrender to the Divine
  77. 1529, // Soul Web
  78. };
  79. //@formatter:on
  80. private RangeGuard()
  81. {
  82. super(RangeGuard.class.getSimpleName(), "ai/group_template");
  83. final List<L2NpcTemplate> monsters = NpcData.getInstance().getAllNpcOfClassType("L2Monster");
  84. for (L2NpcTemplate template : monsters)
  85. {
  86. if (template.getParameters().getInt("LongRangeGuardRate", -1) > 0)
  87. {
  88. addAttackId(template.getId());
  89. }
  90. }
  91. }
  92. @Override
  93. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, Skill skill)
  94. {
  95. final L2Playable playable = (isSummon) ? attacker.getSummon() : attacker;
  96. final int longRangeGuardRate = npc.getTemplate().getParameters().getInt("LongRangeGuardRate");
  97. final double distance = Util.calculateDistance(npc, playable, true, false);
  98. if (npc.isAffectedBySkill(ULTIMATE_DEFENSE.getSkillId()) && (distance <= MIN_DISTANCE))
  99. {
  100. npc.stopSkillEffects(true, ULTIMATE_DEFENSE.getSkillId());
  101. }
  102. else if ((distance > MIN_DISTANCE) && !npc.isSkillDisabled(ULTIMATE_DEFENSE.getSkillId()) && !((skill != null) && Util.contains(NOT_ALLOWED_SKILLS, skill.getId())) && (getRandom(100) < longRangeGuardRate))
  103. {
  104. npc.setTarget(npc);
  105. npc.doCast(ULTIMATE_DEFENSE.getSkill());
  106. }
  107. return super.onAttack(npc, attacker, damage, isSummon, skill);
  108. }
  109. public static void main(String[] args)
  110. {
  111. new RangeGuard();
  112. }
  113. }