ClanMember.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2004-2014 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.Collection;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.skills.Skill;
  28. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  29. import com.l2jserver.gameserver.util.Util;
  30. /**
  31. * @author UnAfraid
  32. */
  33. public class ClanMember implements ITargetTypeHandler
  34. {
  35. @Override
  36. public L2Object[] getTargetList(Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  37. {
  38. List<L2Character> targetList = new ArrayList<>();
  39. if (activeChar.isNpc())
  40. {
  41. // for buff purposes, returns friendly mobs nearby and mob itself
  42. final L2Npc npc = (L2Npc) activeChar;
  43. if ((npc.getTemplate().getClans() == null) || npc.getTemplate().getClans().isEmpty())
  44. {
  45. return new L2Character[]
  46. {
  47. activeChar
  48. };
  49. }
  50. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  51. for (L2Object newTarget : objs)
  52. {
  53. if (newTarget.isNpc() && npc.isInMyClan((L2Npc) newTarget))
  54. {
  55. if (!Util.checkIfInRange(skill.getCastRange(), activeChar, newTarget, true))
  56. {
  57. continue;
  58. }
  59. if (((L2Npc) newTarget).isAffectedBySkill(skill.getId()))
  60. {
  61. continue;
  62. }
  63. targetList.add((L2Npc) newTarget);
  64. break;
  65. }
  66. }
  67. if (targetList.isEmpty())
  68. {
  69. targetList.add(npc);
  70. }
  71. }
  72. else
  73. {
  74. return EMPTY_TARGET_LIST;
  75. }
  76. return targetList.toArray(new L2Character[targetList.size()]);
  77. }
  78. @Override
  79. public Enum<L2TargetType> getTargetType()
  80. {
  81. return L2TargetType.CLAN_MEMBER;
  82. }
  83. }