ConditionPlayerCanSweep.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 com.l2jserver.gameserver.skills.conditions;
  16. import com.l2jserver.gameserver.model.L2Object;
  17. import com.l2jserver.gameserver.model.L2Skill;
  18. import com.l2jserver.gameserver.model.actor.L2Attackable;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. import com.l2jserver.gameserver.skills.Env;
  23. /**
  24. * Checks Sweeper conditions:
  25. * <ul>
  26. * <li>Minimum checks, player not null, skill not null.</li>
  27. * <li>Checks if the target isn't null, is dead and spoiled.</li>
  28. * <li>Checks if the sweeper player is the target spoiler, or is in the spoiler party.</li>
  29. * <li>Checks if the corpse is too old.</li>
  30. * <li>Checks inventory limit and weight max load won't be exceed after sweep.</li>
  31. * </ul>
  32. * If two or more conditions aren't meet at the same time, one message per condition will be shown.
  33. * @author Zoey76
  34. */
  35. public class ConditionPlayerCanSweep extends Condition
  36. {
  37. private final boolean _val;
  38. private static final int maxSweepTime = 15000;
  39. public ConditionPlayerCanSweep(boolean val)
  40. {
  41. _val = val;
  42. }
  43. @Override
  44. public boolean testImpl(Env env)
  45. {
  46. boolean canSweep = (env.player != null) && (env.player instanceof L2PcInstance);
  47. if (canSweep)
  48. {
  49. final L2PcInstance sweeper = env.player.getActingPlayer();
  50. final L2Skill sweep = env.skill;
  51. canSweep &= (sweep != null);
  52. if (canSweep)
  53. {
  54. final L2Object[] targets = sweep.getTargetList(sweeper);
  55. canSweep &= (targets != null);
  56. if (canSweep)
  57. {
  58. L2Attackable target;
  59. for (L2Object objTarget : targets)
  60. {
  61. canSweep &= (objTarget != null) && (objTarget instanceof L2Attackable);
  62. if (canSweep)
  63. {
  64. target = (L2Attackable) objTarget;
  65. canSweep &= target.isDead();
  66. if (canSweep)
  67. {
  68. canSweep &= target.isSpoil();
  69. if (canSweep)
  70. {
  71. canSweep &= target.checkSpoilOwner(sweeper, true);
  72. canSweep &= target.checkCorpseTime(sweeper, maxSweepTime, true);
  73. canSweep &= sweeper.getInventory().checkInventorySlotsAndWeight(target.getSpoilLootItems(), true, true);
  74. }
  75. else
  76. {
  77. sweeper.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SWEEPER_FAILED_TARGET_NOT_SPOILED));
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. return (_val == canSweep);
  86. }
  87. }