Ground.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.targethandlers;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.skills.Skill;
  28. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  29. import com.l2jserver.gameserver.model.zone.ZoneId;
  30. /**
  31. * @author St3eT
  32. */
  33. public class Ground implements ITargetTypeHandler
  34. {
  35. @Override
  36. public L2Object[] getTargetList(Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  37. {
  38. final List<L2Character> targetList = new ArrayList<>();
  39. final L2PcInstance player = (L2PcInstance) activeChar;
  40. final int maxTargets = skill.getAffectLimit();
  41. final boolean srcInArena = (activeChar.isInsideZone(ZoneId.PVP) && !activeChar.isInsideZone(ZoneId.SIEGE));
  42. for (L2Character character : activeChar.getKnownList().getKnownCharacters())
  43. {
  44. if ((character != null) && character.isInsideRadius(player.getCurrentSkillWorldPosition(), skill.getAffectRange(), false, false))
  45. {
  46. if (!Skill.checkForAreaOffensiveSkills(activeChar, character, skill, srcInArena))
  47. {
  48. continue;
  49. }
  50. if (character.isDoor())
  51. {
  52. continue;
  53. }
  54. if ((maxTargets > 0) && (targetList.size() >= maxTargets))
  55. {
  56. break;
  57. }
  58. targetList.add(character);
  59. }
  60. }
  61. if (targetList.isEmpty())
  62. {
  63. if (skill.hasEffectType(L2EffectType.SUMMON_NPC))
  64. {
  65. targetList.add(activeChar);
  66. }
  67. }
  68. return targetList.isEmpty() ? EMPTY_TARGET_LIST : targetList.toArray(new L2Character[targetList.size()]);
  69. }
  70. @Override
  71. public Enum<L2TargetType> getTargetType()
  72. {
  73. return L2TargetType.GROUND;
  74. }
  75. }