TargetClan.java 4.6 KB

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