PartyClan.java 4.1 KB

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