TargetAura.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 handlers.targethandlers;
  16. import java.util.Collection;
  17. import java.util.List;
  18. import javolution.util.FastList;
  19. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. import com.l2jserver.gameserver.model.skills.L2SkillType;
  25. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  26. import com.l2jserver.gameserver.model.zone.ZoneId;
  27. /**
  28. * @author UnAfraid
  29. */
  30. public class TargetAura implements ITargetTypeHandler
  31. {
  32. @Override
  33. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  34. {
  35. List<L2Character> targetList = new FastList<>();
  36. final boolean srcInArena = (activeChar.isInsideZone(ZoneId.PVP) && !activeChar.isInsideZone(ZoneId.SIEGE));
  37. final L2PcInstance sourcePlayer = activeChar.getActingPlayer();
  38. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharactersInRadius(skill.getSkillRadius());
  39. if (skill.getSkillType() == L2SkillType.DUMMY)
  40. {
  41. if (onlyFirst)
  42. {
  43. return new L2Character[]
  44. {
  45. activeChar
  46. };
  47. }
  48. targetList.add(activeChar);
  49. for (L2Character obj : objs)
  50. {
  51. if (!((obj == activeChar) || (obj == sourcePlayer) || obj.isNpc() || obj.isL2Attackable()))
  52. {
  53. continue;
  54. }
  55. if ((skill.getMaxTargets() > -1) && (targetList.size() >= skill.getMaxTargets()))
  56. {
  57. break;
  58. }
  59. targetList.add(obj);
  60. }
  61. }
  62. else
  63. {
  64. for (L2Character obj : objs)
  65. {
  66. if (obj.isL2Attackable() || obj.isPlayable())
  67. {
  68. if (!L2Skill.checkForAreaOffensiveSkills(activeChar, obj, skill, srcInArena))
  69. {
  70. continue;
  71. }
  72. if (onlyFirst)
  73. {
  74. return new L2Character[]
  75. {
  76. obj
  77. };
  78. }
  79. if ((skill.getMaxTargets() > -1) && (targetList.size() >= skill.getMaxTargets()))
  80. {
  81. break;
  82. }
  83. targetList.add(obj);
  84. }
  85. }
  86. }
  87. return targetList.toArray(new L2Character[targetList.size()]);
  88. }
  89. @Override
  90. public Enum<L2TargetType> getTargetType()
  91. {
  92. return L2TargetType.TARGET_AURA;
  93. }
  94. }