TargetClanMember.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  25. import com.l2jserver.gameserver.util.Util;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class TargetClanMember implements ITargetTypeHandler
  30. {
  31. @Override
  32. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  33. {
  34. List<L2Character> targetList = new FastList<L2Character>();
  35. if (activeChar instanceof L2Npc)
  36. {
  37. // for buff purposes, returns friendly mobs nearby and mob itself
  38. final L2Npc npc = (L2Npc) activeChar;
  39. if (npc.getFactionId() == null || npc.getFactionId().isEmpty())
  40. {
  41. return new L2Character[] { activeChar };
  42. }
  43. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  44. for (L2Object newTarget : objs)
  45. {
  46. if (newTarget instanceof L2Npc && npc.getFactionId().equals(((L2Npc) newTarget).getFactionId()))
  47. {
  48. if (!Util.checkIfInRange(skill.getCastRange(), activeChar, newTarget, true))
  49. continue;
  50. if (((L2Npc) newTarget).getFirstEffect(skill) != null)
  51. continue;
  52. targetList.add((L2Npc) newTarget);
  53. break;
  54. }
  55. }
  56. if (targetList.isEmpty())
  57. targetList.add(npc);
  58. }
  59. else
  60. return _emptyTargetList;
  61. return targetList.toArray(new L2Character[targetList.size()]);
  62. }
  63. @Override
  64. public Enum<L2TargetType> getTargetType()
  65. {
  66. return L2TargetType.TARGET_CLAN_MEMBER;
  67. }
  68. }