TargetAreaSummon.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.actor.instance.L2ServitorInstance;
  25. import com.l2jserver.gameserver.model.skills.L2Skill;
  26. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  27. import com.l2jserver.gameserver.util.Util;
  28. /**
  29. * @author UnAfraid
  30. */
  31. public class TargetAreaSummon implements ITargetTypeHandler
  32. {
  33. @Override
  34. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  35. {
  36. List<L2Character> targetList = new FastList<L2Character>();
  37. target = activeChar.getPet();
  38. if (target == null || !(target instanceof L2ServitorInstance) || target.isDead())
  39. return _emptyTargetList;
  40. if (onlyFirst)
  41. return new L2Character[] { target };
  42. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  43. final Collection<L2Character> objs = target.getKnownList().getKnownCharacters();
  44. final int radius = skill.getSkillRadius();
  45. for (L2Character obj : objs)
  46. {
  47. if (obj == null || obj == target || obj == activeChar)
  48. continue;
  49. if (!Util.checkIfInRange(radius, target, obj, true))
  50. continue;
  51. if (!(obj instanceof L2Attackable || obj instanceof L2Playable))
  52. continue;
  53. if (!L2Skill.checkForAreaOffensiveSkills(activeChar, obj, skill, srcInArena))
  54. continue;
  55. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  56. break;
  57. targetList.add(obj);
  58. }
  59. if (targetList.isEmpty())
  60. return _emptyTargetList;
  61. return targetList.toArray(new L2Character[targetList.size()]);
  62. }
  63. @Override
  64. public Enum<L2TargetType> getTargetType()
  65. {
  66. return L2TargetType.TARGET_AREA_SUMMON;
  67. }
  68. }