RequestExRemoveItemAttribute.java 4.6 KB

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