RequestExTryToPutEnchantTargetItem.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.network.clientpackets;
  16. import com.l2jserver.gameserver.model.L2ItemInstance;
  17. import com.l2jserver.gameserver.model.L2World;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. import com.l2jserver.gameserver.network.serverpackets.ExPutEnchantTargetItemResult;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. /**
  23. *
  24. * @author KenM
  25. */
  26. public class RequestExTryToPutEnchantTargetItem extends AbstractEnchantPacket
  27. {
  28. private int _objectId = 0;
  29. /**
  30. * @see com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket#getType()
  31. */
  32. @Override
  33. public String getType()
  34. {
  35. return "[C] D0:4F RequestExTryToPutEnchantTargetItem";
  36. }
  37. /**
  38. * @see com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket#readImpl()
  39. */
  40. @Override
  41. protected void readImpl()
  42. {
  43. _objectId = readD();
  44. }
  45. /**
  46. * @see com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket#runImpl()
  47. */
  48. @Override
  49. protected void runImpl()
  50. {
  51. L2PcInstance activeChar = getClient().getActiveChar();
  52. if (_objectId == 0)
  53. return;
  54. if (activeChar != null)
  55. {
  56. if (activeChar.isEnchanting())
  57. return;
  58. L2ItemInstance item = (L2ItemInstance) L2World.getInstance().findObject(_objectId);
  59. L2ItemInstance scroll = activeChar.getActiveEnchantItem();
  60. if (item == null || scroll == null)
  61. return;
  62. // template for scroll
  63. EnchantScroll scrollTemplate = getEnchantScroll(scroll);
  64. if (!scrollTemplate.isValid(item) || !isEnchantable(item))
  65. {
  66. activeChar.sendPacket(new SystemMessage(SystemMessageId.DOES_NOT_FIT_SCROLL_CONDITIONS));
  67. activeChar.setActiveEnchantItem(null);
  68. activeChar.sendPacket(new ExPutEnchantTargetItemResult(0));
  69. return;
  70. }
  71. activeChar.setIsEnchanting(true);
  72. activeChar.setActiveEnchantTimestamp(System.currentTimeMillis());
  73. activeChar.sendPacket(new ExPutEnchantTargetItemResult(_objectId));
  74. }
  75. }
  76. }