ConditionPlayerCanSweep.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.conditions;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.skills.L2Skill;
  25. import com.l2jserver.gameserver.model.stats.Env;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. /**
  28. * Checks Sweeper conditions:
  29. * <ul>
  30. * <li>Minimum checks, player not null, skill not null.</li>
  31. * <li>Checks if the target isn't null, is dead and spoiled.</li>
  32. * <li>Checks if the sweeper player is the target spoiler, or is in the spoiler party.</li>
  33. * <li>Checks if the corpse is too old.</li>
  34. * <li>Checks inventory limit and weight max load won't be exceed after sweep.</li>
  35. * </ul>
  36. * If two or more conditions aren't meet at the same time, one message per condition will be shown.
  37. * @author Zoey76
  38. */
  39. public class ConditionPlayerCanSweep extends Condition
  40. {
  41. private final boolean _val;
  42. public ConditionPlayerCanSweep(boolean val)
  43. {
  44. _val = val;
  45. }
  46. @Override
  47. public boolean testImpl(Env env)
  48. {
  49. boolean canSweep = false;
  50. if (env.getPlayer() != null)
  51. {
  52. final L2PcInstance sweeper = env.getPlayer();
  53. final L2Skill sweep = env.getSkill();
  54. if (sweep != null)
  55. {
  56. final L2Object[] targets = sweep.getTargetList(sweeper);
  57. if (targets != null)
  58. {
  59. L2Attackable target;
  60. for (L2Object objTarget : targets)
  61. {
  62. if (objTarget instanceof L2Attackable)
  63. {
  64. target = (L2Attackable) objTarget;
  65. if (target.isDead())
  66. {
  67. if (target.isSpoil())
  68. {
  69. canSweep = target.checkSpoilOwner(sweeper, true);
  70. canSweep &= !target.isOldCorpse(sweeper, Config.CORPSE_CONSUME_SKILL_ALLOWED_TIME_BEFORE_DECAY, true);
  71. canSweep &= sweeper.getInventory().checkInventorySlotsAndWeight(target.getSpoilLootItems(), true, true);
  72. }
  73. else
  74. {
  75. sweeper.sendPacket(SystemMessageId.SWEEPER_FAILED_TARGET_NOT_SPOILED);
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. return (_val == canSweep);
  84. }
  85. }