ConditionPlayerHasPet.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 java.util.ArrayList;
  17. import com.l2jserver.gameserver.model.L2ItemInstance;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  20. import com.l2jserver.gameserver.skills.Env;
  21. public class ConditionPlayerHasPet extends Condition
  22. {
  23. private final ArrayList<Integer> _controlItemIds;
  24. public ConditionPlayerHasPet(ArrayList<Integer> itemIds)
  25. {
  26. if (itemIds.size() == 1 && itemIds.get(0) == 0)
  27. _controlItemIds = null;
  28. else
  29. _controlItemIds = itemIds;
  30. }
  31. @Override
  32. public boolean testImpl(Env env)
  33. {
  34. if (!(env.player instanceof L2PcInstance))
  35. return false;
  36. if (!(env.player.getPet() instanceof L2PetInstance))
  37. return false;
  38. if (_controlItemIds == null)
  39. return true;
  40. final L2ItemInstance controlItem = ((L2PetInstance)env.player.getPet()).getControlItem();
  41. if (controlItem == null)
  42. return false;
  43. return _controlItemIds.contains(controlItem.getItemId());
  44. }
  45. }