RequestExRemoveItemAttribute.java 4.5 KB

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