TargetPartyClan.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.L2Object;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.entity.TvTEvent;
  24. import com.l2jserver.gameserver.model.skills.L2Skill;
  25. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class TargetPartyClan implements ITargetTypeHandler
  30. {
  31. @Override
  32. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  33. {
  34. List<L2Character> targetList = new FastList<>();
  35. if (onlyFirst)
  36. {
  37. return new L2Character[]
  38. {
  39. activeChar
  40. };
  41. }
  42. final L2PcInstance player = activeChar.getActingPlayer();
  43. if (player == null)
  44. {
  45. return _emptyTargetList;
  46. }
  47. targetList.add(player);
  48. final int radius = skill.getSkillRadius();
  49. final boolean hasClan = player.getClan() != null;
  50. final boolean hasParty = player.isInParty();
  51. if (L2Skill.addSummon(activeChar, player, radius, false))
  52. {
  53. targetList.add(player.getSummon());
  54. }
  55. // if player in clan and not in party
  56. if (!(hasClan || hasParty))
  57. {
  58. return targetList.toArray(new L2Character[targetList.size()]);
  59. }
  60. // Get all visible objects in a spherical area near the L2Character
  61. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  62. for (L2PcInstance obj : objs)
  63. {
  64. if (obj == null)
  65. {
  66. continue;
  67. }
  68. // olympiad mode - adding only own side
  69. if (player.isInOlympiadMode())
  70. {
  71. if (!obj.isInOlympiadMode())
  72. {
  73. continue;
  74. }
  75. if (player.getOlympiadGameId() != obj.getOlympiadGameId())
  76. {
  77. continue;
  78. }
  79. if (player.getOlympiadSide() != obj.getOlympiadSide())
  80. {
  81. continue;
  82. }
  83. }
  84. if (player.isInDuel())
  85. {
  86. if (player.getDuelId() != obj.getDuelId())
  87. {
  88. continue;
  89. }
  90. if (hasParty && obj.isInParty() && (player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId()))
  91. {
  92. continue;
  93. }
  94. }
  95. if (!((hasClan && (obj.getClanId() == player.getClanId())) || (hasParty && obj.isInParty() && (player.getParty().getLeaderObjectId() == obj.getParty().getLeaderObjectId()))))
  96. {
  97. continue;
  98. }
  99. // Don't add this target if this is a Pc->Pc pvp
  100. // casting and pvp condition not met
  101. if (!player.checkPvpSkill(obj, skill))
  102. {
  103. continue;
  104. }
  105. if (!TvTEvent.checkForTvTSkill(player, obj, skill))
  106. {
  107. continue;
  108. }
  109. if (!onlyFirst && L2Skill.addSummon(activeChar, obj, radius, false))
  110. {
  111. targetList.add(obj.getSummon());
  112. }
  113. if (!L2Skill.addCharacter(activeChar, obj, radius, false))
  114. {
  115. continue;
  116. }
  117. if (onlyFirst)
  118. {
  119. return new L2Character[]
  120. {
  121. obj
  122. };
  123. }
  124. if ((skill.getMaxTargets() > -1) && (targetList.size() >= skill.getMaxTargets()))
  125. {
  126. break;
  127. }
  128. targetList.add(obj);
  129. }
  130. return targetList.toArray(new L2Character[targetList.size()]);
  131. }
  132. @Override
  133. public Enum<L2TargetType> getTargetType()
  134. {
  135. return L2TargetType.TARGET_PARTY_CLAN;
  136. }
  137. }