TargetFrontArea.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Playable;
  24. import com.l2jserver.gameserver.model.skills.L2Skill;
  25. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.util.Util;
  28. /**
  29. * @author UnAfraid
  30. */
  31. public class TargetFrontArea implements ITargetTypeHandler
  32. {
  33. @Override
  34. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  35. {
  36. List<L2Character> targetList = new FastList<>();
  37. if (((target == null || target == activeChar || target.isAlikeDead()) && skill.getCastRange() >= 0) || (!(target instanceof L2Attackable || target instanceof L2Playable)))
  38. {
  39. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  40. return _emptyTargetList;
  41. }
  42. final L2Character origin;
  43. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  44. final int radius = skill.getSkillRadius();
  45. if (skill.getCastRange() >= 0)
  46. {
  47. if (!L2Skill.checkForAreaOffensiveSkills(activeChar, target, skill, srcInArena))
  48. return _emptyTargetList;
  49. if (onlyFirst)
  50. return new L2Character[] { target };
  51. origin = target;
  52. targetList.add(origin); // Add target to target list
  53. }
  54. else
  55. origin = activeChar;
  56. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  57. for (L2Character obj : objs)
  58. {
  59. if (!(obj instanceof L2Attackable || obj instanceof L2Playable))
  60. continue;
  61. if (obj == origin)
  62. continue;
  63. if (Util.checkIfInRange(radius, origin, obj, true))
  64. {
  65. if (!obj.isInFrontOf(activeChar))
  66. continue;
  67. if (!L2Skill.checkForAreaOffensiveSkills(activeChar, obj, skill, srcInArena))
  68. continue;
  69. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  70. break;
  71. targetList.add(obj);
  72. }
  73. }
  74. if (targetList.isEmpty())
  75. return _emptyTargetList;
  76. return targetList.toArray(new L2Character[targetList.size()]);
  77. }
  78. @Override
  79. public Enum<L2TargetType> getTargetType()
  80. {
  81. return L2TargetType.TARGET_FRONT_AREA;
  82. }
  83. }