L2ItemInstanceAction.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.actionhandlers;
  16. import com.l2jserver.gameserver.ai.CtrlIntention;
  17. import com.l2jserver.gameserver.handler.IActionHandler;
  18. import com.l2jserver.gameserver.instancemanager.MercTicketManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  23. public class L2ItemInstanceAction implements IActionHandler
  24. {
  25. @Override
  26. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  27. {
  28. // this causes the validate position handler to do the pickup if the location is reached.
  29. // mercenary tickets can only be picked up by the castle owner.
  30. final int castleId = MercTicketManager.getInstance().getTicketCastleId(((L2ItemInstance)target).getItemId());
  31. if (castleId > 0 && (!activeChar.isCastleLord(castleId) || activeChar.isInParty()))
  32. {
  33. if (activeChar.isInParty()) //do not allow owner who is in party to pick tickets up
  34. activeChar.sendMessage("You cannot pickup mercenaries while in a party.");
  35. else
  36. activeChar.sendMessage("Only the castle lord can pickup mercenaries.");
  37. activeChar.setTarget(target);
  38. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  39. }
  40. else if (!activeChar.isFlying()) // cannot pickup
  41. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_PICK_UP, target);
  42. return true;
  43. }
  44. @Override
  45. public InstanceType getInstanceType()
  46. {
  47. return InstanceType.L2ItemInstance;
  48. }
  49. }