TargetAlly.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 TargetAlly 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 (activeChar.isPlayable())
  36. {
  37. final L2PcInstance player = activeChar.getActingPlayer();
  38. if (player == null)
  39. {
  40. return _emptyTargetList;
  41. }
  42. if (player.isInOlympiadMode())
  43. {
  44. return new L2Character[]
  45. {
  46. player
  47. };
  48. }
  49. if (onlyFirst)
  50. {
  51. return new L2Character[]
  52. {
  53. player
  54. };
  55. }
  56. targetList.add(player);
  57. final int radius = skill.getSkillRadius();
  58. if (L2Skill.addSummon(activeChar, player, radius, false))
  59. {
  60. targetList.add(player.getSummon());
  61. }
  62. if (player.getClan() != null)
  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. if (((obj.getAllyId() == 0) || (obj.getAllyId() != player.getAllyId())) && ((obj.getClan() == null) || (obj.getClanId() != player.getClanId())))
  73. {
  74. continue;
  75. }
  76. if (player.isInDuel())
  77. {
  78. if (player.getDuelId() != obj.getDuelId())
  79. {
  80. continue;
  81. }
  82. if (player.isInParty() && obj.isInParty() && (player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId()))
  83. {
  84. continue;
  85. }
  86. }
  87. // Don't add this target if this is a Pc->Pc pvp
  88. // 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. return targetList.toArray(new L2Character[targetList.size()]);
  121. }
  122. @Override
  123. public Enum<L2TargetType> getTargetType()
  124. {
  125. return L2TargetType.TARGET_ALLY;
  126. }
  127. }