Ally.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 Ally 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 (activeChar.isPlayable())
  40. {
  41. final L2PcInstance player = activeChar.getActingPlayer();
  42. if (player == null)
  43. {
  44. return _emptyTargetList;
  45. }
  46. if (player.isInOlympiadMode())
  47. {
  48. return new L2Character[]
  49. {
  50. player
  51. };
  52. }
  53. if (onlyFirst)
  54. {
  55. return new L2Character[]
  56. {
  57. player
  58. };
  59. }
  60. targetList.add(player);
  61. final int radius = skill.getAffectRange();
  62. if (L2Skill.addSummon(activeChar, player, radius, false))
  63. {
  64. targetList.add(player.getSummon());
  65. }
  66. if (player.getClan() != null)
  67. {
  68. // Get all visible objects in a spherical area near the L2Character
  69. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  70. for (L2PcInstance obj : objs)
  71. {
  72. if (obj == null)
  73. {
  74. continue;
  75. }
  76. if (((obj.getAllyId() == 0) || (obj.getAllyId() != player.getAllyId())) && ((obj.getClan() == null) || (obj.getClanId() != player.getClanId())))
  77. {
  78. continue;
  79. }
  80. if (player.isInDuel())
  81. {
  82. if (player.getDuelId() != obj.getDuelId())
  83. {
  84. continue;
  85. }
  86. if (player.isInParty() && obj.isInParty() && (player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId()))
  87. {
  88. continue;
  89. }
  90. }
  91. // Don't add this target if this is a Pc->Pc pvp
  92. // 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 && L2Skill.addSummon(activeChar, obj, radius, false))
  102. {
  103. targetList.add(obj.getSummon());
  104. }
  105. if (!L2Skill.addCharacter(activeChar, obj, radius, false))
  106. {
  107. continue;
  108. }
  109. if (onlyFirst)
  110. {
  111. return new L2Character[]
  112. {
  113. obj
  114. };
  115. }
  116. if ((skill.getMaxTargets() > -1) && (targetList.size() >= skill.getMaxTargets()))
  117. {
  118. break;
  119. }
  120. targetList.add(obj);
  121. }
  122. }
  123. }
  124. return targetList.toArray(new L2Character[targetList.size()]);
  125. }
  126. @Override
  127. public Enum<L2TargetType> getTargetType()
  128. {
  129. return L2TargetType.ALLY;
  130. }
  131. }