PartyClan.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C) 2004-2013 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.Collection;
  21. import java.util.List;
  22. import javolution.util.FastList;
  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.L2Skill;
  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(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  37. {
  38. List<L2Character> targetList = new FastList<>();
  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 _emptyTargetList;
  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 (L2Skill.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. for (L2PcInstance obj : objs)
  67. {
  68. if (obj == null)
  69. {
  70. continue;
  71. }
  72. // olympiad mode - adding only own side
  73. if (player.isInOlympiadMode())
  74. {
  75. if (!obj.isInOlympiadMode())
  76. {
  77. continue;
  78. }
  79. if (player.getOlympiadGameId() != obj.getOlympiadGameId())
  80. {
  81. continue;
  82. }
  83. if (player.getOlympiadSide() != obj.getOlympiadSide())
  84. {
  85. continue;
  86. }
  87. }
  88. if (player.isInDuel())
  89. {
  90. if (player.getDuelId() != obj.getDuelId())
  91. {
  92. continue;
  93. }
  94. if (hasParty && obj.isInParty() && (player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId()))
  95. {
  96. continue;
  97. }
  98. }
  99. if (!((hasClan && (obj.getClanId() == player.getClanId())) || (hasParty && obj.isInParty() && (player.getParty().getLeaderObjectId() == obj.getParty().getLeaderObjectId()))))
  100. {
  101. continue;
  102. }
  103. // Don't add this target if this is a Pc->Pc pvp
  104. // casting and pvp condition not met
  105. if (!player.checkPvpSkill(obj, skill))
  106. {
  107. continue;
  108. }
  109. if (!TvTEvent.checkForTvTSkill(player, obj, skill))
  110. {
  111. continue;
  112. }
  113. if (!onlyFirst && L2Skill.addSummon(activeChar, obj, radius, false))
  114. {
  115. targetList.add(obj.getSummon());
  116. }
  117. if (!L2Skill.addCharacter(activeChar, obj, radius, false))
  118. {
  119. continue;
  120. }
  121. if (onlyFirst)
  122. {
  123. return new L2Character[]
  124. {
  125. obj
  126. };
  127. }
  128. if ((skill.getMaxTargets() > -1) && (targetList.size() >= skill.getMaxTargets()))
  129. {
  130. break;
  131. }
  132. targetList.add(obj);
  133. }
  134. return targetList.toArray(new L2Character[targetList.size()]);
  135. }
  136. @Override
  137. public Enum<L2TargetType> getTargetType()
  138. {
  139. return L2TargetType.PARTY_CLAN;
  140. }
  141. }