RequestExTryToPutEnchantTargetItem.java 2.7 KB

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