TargetFrontArea.java 3.3 KB

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