SummonItems.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.itemhandlers;
  20. import com.l2jserver.gameserver.datatables.PetDataTable;
  21. import com.l2jserver.gameserver.model.L2PetData;
  22. import com.l2jserver.gameserver.model.actor.L2Playable;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.TvTEvent;
  25. import com.l2jserver.gameserver.model.holders.PetItemHolder;
  26. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. /**
  29. * @author HorridoJoho, UnAfraid
  30. */
  31. public class SummonItems extends ItemSkillsTemplate
  32. {
  33. @Override
  34. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  35. {
  36. if (!playable.isPlayer())
  37. {
  38. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  39. return false;
  40. }
  41. if (!TvTEvent.onItemSummon(playable.getObjectId()))
  42. {
  43. return false;
  44. }
  45. final L2PcInstance activeChar = playable.getActingPlayer();
  46. if (!activeChar.getFloodProtectors().getItemPetSummon().tryPerformAction("summon items") || (activeChar.getBlockCheckerArena() != -1) || activeChar.inObserverMode() || activeChar.isAllSkillsDisabled() || activeChar.isCastingNow())
  47. {
  48. return false;
  49. }
  50. if (activeChar.isSitting())
  51. {
  52. activeChar.sendPacket(SystemMessageId.CANT_MOVE_SITTING);
  53. return false;
  54. }
  55. if (activeChar.hasSummon() || activeChar.isMounted())
  56. {
  57. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_HAVE_A_PET);
  58. return false;
  59. }
  60. if (activeChar.isAttackingNow())
  61. {
  62. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_SUMMON_IN_COMBAT);
  63. return false;
  64. }
  65. final L2PetData petData = PetDataTable.getInstance().getPetDataByItemId(item.getId());
  66. if ((petData == null) || (petData.getNpcId() == -1))
  67. {
  68. return false;
  69. }
  70. activeChar.addScript(new PetItemHolder(item));
  71. return super.useItem(playable, item, forceUse);
  72. }
  73. }