ConditionPlayerCanSweep.java 2.8 KB

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