TargetAreaUndead.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.Config;
  20. import com.l2jserver.gameserver.GeoData;
  21. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.L2Skill;
  24. import com.l2jserver.gameserver.templates.skills.L2TargetType;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * @author UnAfraid
  31. */
  32. public class TargetAreaUndead implements ITargetTypeHandler
  33. {
  34. @Override
  35. public L2Object[] getTargetList(L2Skill skill, L2Character activeChar, boolean onlyFirst, L2Character target)
  36. {
  37. List<L2Character> targetList = new FastList<L2Character>();
  38. final L2Character cha;
  39. final int radius = skill.getSkillRadius();
  40. if (skill.getCastRange() >= 0 && (target instanceof L2Npc || target instanceof L2SummonInstance) && target.isUndead() && !target.isAlikeDead())
  41. {
  42. cha = target;
  43. if (!onlyFirst)
  44. targetList.add(cha);
  45. else
  46. return new L2Character[] { cha };
  47. }
  48. else
  49. cha = activeChar;
  50. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  51. for (L2Character obj : objs)
  52. {
  53. if (!Util.checkIfInRange(radius, cha, obj, true))
  54. continue;
  55. else if (obj instanceof L2Npc)
  56. target = obj;
  57. else if (obj instanceof L2SummonInstance)
  58. target = obj;
  59. else
  60. continue;
  61. if (!target.isAlikeDead())
  62. {
  63. if (!target.isUndead())
  64. continue;
  65. else if (Config.GEODATA > 0 && !GeoData.getInstance().canSeeTarget(activeChar, target))
  66. continue;
  67. else if (skill.getMaxTargets() > -1 && targetList.size() >= skill.getMaxTargets())
  68. break;
  69. else if (!onlyFirst)
  70. targetList.add(obj);
  71. else
  72. return new L2Character[] { obj };
  73. }
  74. }
  75. if (targetList.isEmpty())
  76. return _emptyTargetList;
  77. return targetList.toArray(new L2Character[targetList.size()]);
  78. }
  79. @Override
  80. public Enum<L2TargetType> getTargetType()
  81. {
  82. return L2TargetType.TARGET_AREA_UNDEAD;
  83. }
  84. }