TargetFrontArea.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.skills.L2Skill;
  23. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  24. import com.l2jserver.gameserver.model.zone.ZoneId;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * @author UnAfraid
  29. */
  30. public class TargetFrontArea 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. if ((target == null) || (((target == activeChar) || target.isAlikeDead()) && (skill.getCastRange() >= 0)) || (!(target.isL2Attackable() || target.isPlayable())))
  37. {
  38. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  39. return _emptyTargetList;
  40. }
  41. final L2Character origin;
  42. final boolean srcInArena = (activeChar.isInsideZone(ZoneId.PVP) && !activeChar.isInsideZone(ZoneId.SIEGE));
  43. final int radius = skill.getSkillRadius();
  44. if (skill.getCastRange() >= 0)
  45. {
  46. if (!L2Skill.checkForAreaOffensiveSkills(activeChar, target, skill, srcInArena))
  47. {
  48. return _emptyTargetList;
  49. }
  50. if (onlyFirst)
  51. {
  52. return new L2Character[]
  53. {
  54. target
  55. };
  56. }
  57. origin = target;
  58. targetList.add(origin); // Add target to target list
  59. }
  60. else
  61. {
  62. origin = activeChar;
  63. }
  64. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  65. for (L2Character obj : objs)
  66. {
  67. if (!(obj.isL2Attackable() || obj.isPlayable()))
  68. {
  69. continue;
  70. }
  71. if (obj == origin)
  72. {
  73. continue;
  74. }
  75. if (Util.checkIfInRange(radius, origin, obj, true))
  76. {
  77. if (!obj.isInFrontOf(activeChar))
  78. {
  79. continue;
  80. }
  81. if (!L2Skill.checkForAreaOffensiveSkills(activeChar, obj, skill, srcInArena))
  82. {
  83. continue;
  84. }
  85. if ((skill.getMaxTargets() > -1) && (targetList.size() >= skill.getMaxTargets()))
  86. {
  87. break;
  88. }
  89. targetList.add(obj);
  90. }
  91. }
  92. if (targetList.isEmpty())
  93. {
  94. return _emptyTargetList;
  95. }
  96. return targetList.toArray(new L2Character[targetList.size()]);
  97. }
  98. @Override
  99. public Enum<L2TargetType> getTargetType()
  100. {
  101. return L2TargetType.TARGET_FRONT_AREA;
  102. }
  103. }