RangeGuard.java 4.3 KB

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