TargetPartyNotMe.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.List;
  17. import javolution.util.FastList;
  18. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  25. import com.l2jserver.gameserver.util.Util;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class TargetPartyNotMe 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 (onlyFirst)
  36. return new L2Character[] { activeChar };
  37. L2PcInstance player = null;
  38. if (activeChar instanceof L2Summon)
  39. {
  40. player = ((L2Summon) activeChar).getOwner();
  41. targetList.add(player);
  42. }
  43. else if (activeChar instanceof L2PcInstance)
  44. {
  45. player = (L2PcInstance) activeChar;
  46. if (activeChar.getPet() != null)
  47. targetList.add(activeChar.getPet());
  48. }
  49. if (activeChar.getParty() != null)
  50. {
  51. List<L2PcInstance> partyList = activeChar.getParty().getMembers();
  52. for (L2PcInstance partyMember : partyList)
  53. {
  54. if (partyMember == null)
  55. continue;
  56. else if (partyMember == player)
  57. continue;
  58. else if (!partyMember.isDead() && Util.checkIfInRange(skill.getSkillRadius(), activeChar, partyMember, true))
  59. {
  60. if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  61. break;
  62. targetList.add(partyMember);
  63. if (partyMember.getPet() != null && !partyMember.getPet().isDead())
  64. {
  65. targetList.add(partyMember.getPet());
  66. }
  67. }
  68. }
  69. }
  70. return targetList.toArray(new L2Character[targetList.size()]);
  71. }
  72. @Override
  73. public Enum<L2TargetType> getTargetType()
  74. {
  75. return L2TargetType.TARGET_PARTY_NOTME;
  76. }
  77. }