Clan.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) 2004-2015 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.L2Clan;
  25. import com.l2jserver.gameserver.model.L2ClanMember;
  26. import com.l2jserver.gameserver.model.L2Object;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.entity.TvTEvent;
  31. import com.l2jserver.gameserver.model.skills.Skill;
  32. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  33. import com.l2jserver.gameserver.util.Util;
  34. /**
  35. * @author UnAfraid
  36. */
  37. public class Clan implements ITargetTypeHandler
  38. {
  39. @Override
  40. public L2Object[] getTargetList(Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  41. {
  42. List<L2Character> targetList = new ArrayList<>();
  43. if (activeChar.isPlayable())
  44. {
  45. final L2PcInstance player = activeChar.getActingPlayer();
  46. if (player == null)
  47. {
  48. return EMPTY_TARGET_LIST;
  49. }
  50. if (player.isInOlympiadMode())
  51. {
  52. return new L2Character[]
  53. {
  54. player
  55. };
  56. }
  57. if (onlyFirst)
  58. {
  59. return new L2Character[]
  60. {
  61. player
  62. };
  63. }
  64. targetList.add(player);
  65. final int radius = skill.getAffectRange();
  66. final L2Clan clan = player.getClan();
  67. if (Skill.addSummon(activeChar, player, radius, false))
  68. {
  69. targetList.add(player.getSummon());
  70. }
  71. if (clan != null)
  72. {
  73. L2PcInstance obj;
  74. for (L2ClanMember member : clan.getMembers())
  75. {
  76. obj = member.getPlayerInstance();
  77. if ((obj == null) || (obj == player))
  78. {
  79. continue;
  80. }
  81. if (player.isInDuel())
  82. {
  83. if (player.getDuelId() != obj.getDuelId())
  84. {
  85. continue;
  86. }
  87. if (player.isInParty() && obj.isInParty() && (player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId()))
  88. {
  89. continue;
  90. }
  91. }
  92. // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met
  93. if (!player.checkPvpSkill(obj, skill))
  94. {
  95. continue;
  96. }
  97. if (!TvTEvent.checkForTvTSkill(player, obj, skill))
  98. {
  99. continue;
  100. }
  101. if (!onlyFirst && Skill.addSummon(activeChar, obj, radius, false))
  102. {
  103. targetList.add(obj.getSummon());
  104. }
  105. if (!Skill.addCharacter(activeChar, obj, radius, false))
  106. {
  107. continue;
  108. }
  109. if (onlyFirst)
  110. {
  111. return new L2Character[]
  112. {
  113. obj
  114. };
  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.getTemplate().getClans() == null) || npc.getTemplate().getClans().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. int maxTargets = skill.getAffectLimit();
  134. for (L2Object newTarget : objs)
  135. {
  136. if (newTarget.isNpc() && npc.isInMyClan((L2Npc) newTarget))
  137. {
  138. if (!Util.checkIfInRange(skill.getCastRange(), activeChar, newTarget, true))
  139. {
  140. continue;
  141. }
  142. if ((maxTargets > 0) && (targetList.size() >= maxTargets))
  143. {
  144. break;
  145. }
  146. targetList.add((L2Npc) newTarget);
  147. }
  148. }
  149. }
  150. return targetList.toArray(new L2Character[targetList.size()]);
  151. }
  152. @Override
  153. public Enum<L2TargetType> getTargetType()
  154. {
  155. return L2TargetType.CLAN;
  156. }
  157. }