TargetClan.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.L2Clan;
  21. import com.l2jserver.gameserver.model.L2ClanMember;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.L2Playable;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.entity.TvTEvent;
  28. import com.l2jserver.gameserver.model.skills.L2Skill;
  29. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  30. import com.l2jserver.gameserver.util.Util;
  31. /**
  32. * @author UnAfraid
  33. */
  34. public class TargetClan implements ITargetTypeHandler
  35. {
  36. @Override
  37. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  38. {
  39. List<L2Character> targetList = new FastList<>();
  40. if (activeChar instanceof L2Playable)
  41. {
  42. final L2PcInstance player = activeChar.getActingPlayer();
  43. if (player == null)
  44. return _emptyTargetList;
  45. if (player.isInOlympiadMode())
  46. return new L2Character[] { player };
  47. if (onlyFirst)
  48. return new L2Character[] { player };
  49. targetList.add(player);
  50. final int radius = skill.getSkillRadius();
  51. final L2Clan clan = player.getClan();
  52. if (L2Skill.addSummon(activeChar, player, radius, false))
  53. targetList.add(player.getPet());
  54. if (clan != null)
  55. {
  56. L2PcInstance obj;
  57. for (L2ClanMember member : clan.getMembers())
  58. {
  59. obj = member.getPlayerInstance();
  60. if (obj == null || obj == player)
  61. continue;
  62. if (player.isInDuel())
  63. {
  64. if (player.getDuelId() != obj.getDuelId())
  65. continue;
  66. if (player.isInParty() && obj.isInParty() && player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId())
  67. continue;
  68. }
  69. // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met
  70. if (!player.checkPvpSkill(obj, skill))
  71. continue;
  72. if (!TvTEvent.checkForTvTSkill(player, obj, skill))
  73. continue;
  74. if (!onlyFirst && L2Skill.addSummon(activeChar, obj, radius, false))
  75. targetList.add(obj.getPet());
  76. if (!L2Skill.addCharacter(activeChar, obj, radius, false))
  77. continue;
  78. if (onlyFirst)
  79. return new L2Character[] { obj };
  80. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  81. break;
  82. targetList.add(obj);
  83. }
  84. }
  85. }
  86. else if (activeChar instanceof L2Npc)
  87. {
  88. // for buff purposes, returns friendly mobs nearby and mob itself
  89. final L2Npc npc = (L2Npc) activeChar;
  90. if (npc.getFactionId() == null || npc.getFactionId().isEmpty())
  91. {
  92. return new L2Character[] { activeChar };
  93. }
  94. targetList.add(activeChar);
  95. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  96. for (L2Object newTarget : objs)
  97. {
  98. if (newTarget instanceof L2Npc && npc.getFactionId().equals(((L2Npc) newTarget).getFactionId()))
  99. {
  100. if (!Util.checkIfInRange(skill.getCastRange(), activeChar, newTarget, true))
  101. continue;
  102. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  103. break;
  104. targetList.add((L2Npc) newTarget);
  105. }
  106. }
  107. }
  108. return targetList.toArray(new L2Character[targetList.size()]);
  109. }
  110. @Override
  111. public Enum<L2TargetType> getTargetType()
  112. {
  113. return L2TargetType.TARGET_CLAN;
  114. }
  115. }