RequestExRemoveItemAttribute.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.ExShowBaseAttributeCancelWindow;
  20. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. import com.l2jserver.gameserver.network.serverpackets.UserInfo;
  23. import com.l2jserver.gameserver.templates.item.L2Item;
  24. import com.l2jserver.gameserver.templates.item.L2Weapon;
  25. public class RequestExRemoveItemAttribute extends L2GameClientPacket
  26. {
  27. private static String _C__D0_23_REQUESTEXREMOVEITEMATTRIBUTE = "[C] D0:23 RequestExRemoveItemAttribute";
  28. private int _objectId;
  29. private long _price;
  30. public RequestExRemoveItemAttribute()
  31. {
  32. }
  33. @Override
  34. public void readImpl()
  35. {
  36. _objectId = readD();
  37. }
  38. @Override
  39. public void runImpl()
  40. {
  41. L2PcInstance activeChar = getClient().getActiveChar();
  42. if (activeChar == null)
  43. return;
  44. L2ItemInstance targetItem = activeChar.getInventory().getItemByObjectId(_objectId);
  45. if (targetItem == null)
  46. return;
  47. if (targetItem.getElementals() == null)
  48. return;
  49. if (activeChar.reduceAdena("RemoveElement", getPrice(targetItem), activeChar, true))
  50. {
  51. if (targetItem.isEquipped())
  52. targetItem.getElementals().removeBonus(activeChar);
  53. targetItem.clearElementAttr();
  54. activeChar.sendPacket(new UserInfo(activeChar));
  55. InventoryUpdate iu = new InventoryUpdate();
  56. iu.addModifiedItem(targetItem);
  57. activeChar.sendPacket(iu);
  58. if (targetItem.getEnchantLevel() > 0)
  59. {
  60. SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2_ELEMENTAL_POWER_REMOVED);
  61. sm.addNumber(targetItem.getEnchantLevel());
  62. sm.addItemName(targetItem);
  63. activeChar.sendPacket(sm);
  64. }
  65. else
  66. {
  67. SystemMessage sm = new SystemMessage(SystemMessageId.S1_ELEMENTAL_POWER_REMOVED);
  68. sm.addItemName(targetItem);
  69. activeChar.sendPacket(sm);
  70. }
  71. activeChar.sendPacket(new ExShowBaseAttributeCancelWindow(activeChar));
  72. return;
  73. }
  74. else
  75. {
  76. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
  77. return;
  78. }
  79. }
  80. private long getPrice(L2ItemInstance item)
  81. {
  82. switch(item.getItem().getCrystalType())
  83. {
  84. case L2Item.CRYSTAL_S:
  85. if (item.getItem() instanceof L2Weapon)
  86. _price = 50000;
  87. else
  88. _price = 40000;
  89. break;
  90. case L2Item.CRYSTAL_S80:
  91. if (item.getItem() instanceof L2Weapon)
  92. _price = 100000;
  93. else
  94. _price = 80000;
  95. break;
  96. case L2Item.CRYSTAL_S84:
  97. if (item.getItem() instanceof L2Weapon)
  98. _price = 200000;
  99. else
  100. _price = 160000;
  101. break;
  102. }
  103. return _price;
  104. }
  105. @Override
  106. public String getType()
  107. {
  108. return _C__D0_23_REQUESTEXREMOVEITEMATTRIBUTE;
  109. }
  110. }