TargetPartyClan.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 TargetPartyClan implements ITargetTypeHandler
  30. {
  31. @Override
  32. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  33. {
  34. List<L2Character> targetList = new FastList<L2Character>();
  35. if (onlyFirst)
  36. return new L2Character[] { activeChar };
  37. final L2PcInstance player = activeChar.getActingPlayer();
  38. if (player == null)
  39. return _emptyTargetList;
  40. targetList.add(player);
  41. final int radius = skill.getSkillRadius();
  42. final boolean hasClan = player.getClan() != null;
  43. final boolean hasParty = player.isInParty();
  44. if (L2Skill.addSummon(activeChar, player, radius, false))
  45. targetList.add(player.getPet());
  46. // if player in clan and not in party
  47. if (!(hasClan || hasParty))
  48. return targetList.toArray(new L2Character[targetList.size()]);
  49. // Get all visible objects in a spherical area near the L2Character
  50. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  51. for (L2PcInstance obj : objs)
  52. {
  53. if (obj == null)
  54. continue;
  55. // olympiad mode - adding only own side
  56. if (player.isInOlympiadMode())
  57. {
  58. if (!obj.isInOlympiadMode())
  59. continue;
  60. if (player.getOlympiadGameId() != obj.getOlympiadGameId())
  61. continue;
  62. if (player.getOlympiadSide() != obj.getOlympiadSide())
  63. continue;
  64. }
  65. if (player.isInDuel())
  66. {
  67. if (player.getDuelId() != obj.getDuelId())
  68. continue;
  69. if (hasParty && obj.isInParty() && player.getParty().getLeaderObjectId() != obj.getParty().getLeaderObjectId())
  70. continue;
  71. }
  72. if (!((hasClan && obj.getClanId() == player.getClanId()) || (hasParty && obj.isInParty() && player.getParty().getLeaderObjectId() == obj.getParty().getLeaderObjectId())))
  73. continue;
  74. // Don't add this target if this is a Pc->Pc pvp
  75. // casting and pvp condition not met
  76. if (!player.checkPvpSkill(obj, skill))
  77. continue;
  78. if (!TvTEvent.checkForTvTSkill(player, obj, skill))
  79. continue;
  80. if (!onlyFirst && L2Skill.addSummon(activeChar, obj, radius, false))
  81. targetList.add(obj.getPet());
  82. if (!L2Skill.addCharacter(activeChar, obj, radius, false))
  83. continue;
  84. if (onlyFirst)
  85. return new L2Character[] { obj };
  86. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  87. break;
  88. targetList.add(obj);
  89. }
  90. return targetList.toArray(new L2Character[targetList.size()]);
  91. }
  92. @Override
  93. public Enum<L2TargetType> getTargetType()
  94. {
  95. return L2TargetType.TARGET_PARTY_CLAN;
  96. }
  97. }