TargetClanMember.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. *
  3. */
  4. package handlers.targethandlers;
  5. import java.util.Collection;
  6. import java.util.List;
  7. import javolution.util.FastList;
  8. import com.l2jserver.gameserver.handler.ISkillTargetTypeHandler;
  9. import com.l2jserver.gameserver.model.L2Object;
  10. import com.l2jserver.gameserver.model.L2Skill;
  11. import com.l2jserver.gameserver.model.L2Skill.SkillTargetType;
  12. import com.l2jserver.gameserver.model.actor.L2Character;
  13. import com.l2jserver.gameserver.model.actor.L2Npc;
  14. import com.l2jserver.gameserver.util.Util;
  15. /**
  16. * @author UnAfraid
  17. *
  18. */
  19. public class TargetClanMember implements ISkillTargetTypeHandler
  20. {
  21. @Override
  22. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  23. {
  24. List<L2Character> targetList = new FastList<L2Character>();
  25. if (activeChar instanceof L2Npc)
  26. {
  27. // for buff purposes, returns friendly mobs nearby and mob itself
  28. final L2Npc npc = (L2Npc) activeChar;
  29. if (npc.getFactionId() == null || npc.getFactionId().isEmpty())
  30. {
  31. return new L2Character[] { activeChar };
  32. }
  33. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  34. for (L2Object newTarget : objs)
  35. {
  36. if (newTarget instanceof L2Npc && npc.getFactionId().equals(((L2Npc) newTarget).getFactionId()))
  37. {
  38. if (!Util.checkIfInRange(skill.getCastRange(), activeChar, newTarget, true))
  39. continue;
  40. if (((L2Npc) newTarget).getFirstEffect(skill) != null)
  41. continue;
  42. targetList.add((L2Npc) newTarget);
  43. break;
  44. }
  45. }
  46. if (targetList.isEmpty())
  47. targetList.add(npc);
  48. }
  49. else
  50. return _emptyTargetList;
  51. return targetList.toArray(new L2Character[targetList.size()]);
  52. }
  53. @Override
  54. public Enum<SkillTargetType> getTargetType()
  55. {
  56. return SkillTargetType.TARGET_CLAN_MEMBER;
  57. }
  58. }