TargetAlly.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.L2Playable;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.TvTEvent;
  25. import com.l2jserver.gameserver.model.skills.L2Skill;
  26. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  27. /**
  28. * @author UnAfraid
  29. */
  30. public class TargetAlly implements ITargetTypeHandler
  31. {
  32. @Override
  33. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  34. {
  35. List<L2Character> targetList = new FastList<>();
  36. if (activeChar instanceof L2Playable)
  37. {
  38. final L2PcInstance player = activeChar.getActingPlayer();
  39. if (player == null)
  40. return _emptyTargetList;
  41. if (player.isInOlympiadMode())
  42. return new L2Character[] { player };
  43. if (onlyFirst)
  44. return new L2Character[] { player };
  45. targetList.add(player);
  46. final int radius = skill.getSkillRadius();
  47. if (L2Skill.addSummon(activeChar, player, radius, false))
  48. targetList.add(player.getPet());
  49. if (player.getClan() != null)
  50. {
  51. // Get all visible objects in a spherical area near the L2Character
  52. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  53. for (L2PcInstance obj : objs)
  54. {
  55. if (obj == null)
  56. continue;
  57. if ((obj.getAllyId() == 0 || obj.getAllyId() != player.getAllyId()) && (obj.getClan() == null || obj.getClanId() != player.getClanId()))
  58. continue;
  59. if (player.isInDuel())
  60. {
  61. if (player.getDuelId() != obj.getDuelId())
  62. continue;
  63. if (player.isInParty() && obj.isInParty() && player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId())
  64. continue;
  65. }
  66. // Don't add this target if this is a Pc->Pc pvp
  67. // casting and pvp condition not met
  68. if (!player.checkPvpSkill(obj, skill))
  69. continue;
  70. if (!TvTEvent.checkForTvTSkill(player, obj, skill))
  71. continue;
  72. if (!onlyFirst && L2Skill.addSummon(activeChar, obj, radius, false))
  73. targetList.add(obj.getPet());
  74. if (!L2Skill.addCharacter(activeChar, obj, radius, false))
  75. continue;
  76. if (onlyFirst)
  77. return new L2Character[] { obj };
  78. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  79. break;
  80. targetList.add(obj);
  81. }
  82. }
  83. }
  84. return targetList.toArray(new L2Character[targetList.size()]);
  85. }
  86. @Override
  87. public Enum<L2TargetType> getTargetType()
  88. {
  89. return L2TargetType.TARGET_ALLY;
  90. }
  91. }