RequestHennaEquip.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.data.xml.impl.HennaData;
  22. import com.l2jserver.gameserver.model.PcCondOverride;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.items.L2Henna;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  27. import com.l2jserver.gameserver.util.Util;
  28. /**
  29. * @author Zoey76
  30. */
  31. public final class RequestHennaEquip extends L2GameClientPacket
  32. {
  33. private static final String _C__6F_REQUESTHENNAEQUIP = "[C] 6F RequestHennaEquip";
  34. private int _symbolId;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _symbolId = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. final L2PcInstance activeChar = getActiveChar();
  44. if (activeChar == null)
  45. {
  46. return;
  47. }
  48. if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("HennaEquip"))
  49. {
  50. return;
  51. }
  52. if (activeChar.getHennaEmptySlots() == 0)
  53. {
  54. activeChar.sendPacket(SystemMessageId.SYMBOLS_FULL);
  55. sendActionFailed();
  56. return;
  57. }
  58. final L2Henna henna = HennaData.getInstance().getHenna(_symbolId);
  59. if (henna == null)
  60. {
  61. _log.warning(getClass().getName() + ": Invalid Henna Id: " + _symbolId + " from player " + activeChar);
  62. sendActionFailed();
  63. return;
  64. }
  65. final long _count = activeChar.getInventory().getInventoryItemCount(henna.getDyeItemId(), -1);
  66. if (henna.isAllowedClass(activeChar.getClassId()) && (_count >= henna.getWearCount()) && (activeChar.getAdena() >= henna.getWearFee()) && activeChar.addHenna(henna))
  67. {
  68. activeChar.destroyItemByItemId("Henna", henna.getDyeItemId(), henna.getWearCount(), activeChar, true);
  69. activeChar.getInventory().reduceAdena("Henna", henna.getWearFee(), activeChar, activeChar.getLastFolkNPC());
  70. final InventoryUpdate iu = new InventoryUpdate();
  71. iu.addModifiedItem(activeChar.getInventory().getAdenaInstance());
  72. activeChar.sendPacket(iu);
  73. activeChar.sendPacket(SystemMessageId.SYMBOL_ADDED);
  74. }
  75. else
  76. {
  77. activeChar.sendPacket(SystemMessageId.CANT_DRAW_SYMBOL);
  78. if (!activeChar.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !henna.isAllowedClass(activeChar.getClassId()))
  79. {
  80. Util.handleIllegalPlayerAction(activeChar, "Exploit attempt: Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " tryed to add a forbidden henna.", Config.DEFAULT_PUNISH);
  81. }
  82. sendActionFailed();
  83. }
  84. }
  85. @Override
  86. public String getType()
  87. {
  88. return _C__6F_REQUESTHENNAEQUIP;
  89. }
  90. }