RequestRefineCancel.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.Config;
  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.ExVariationCancelResult;
  21. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. import com.l2jserver.gameserver.templates.item.L2Item;
  24. import com.l2jserver.gameserver.util.Util;
  25. /**
  26. * Format(ch) d
  27. * @author -Wooden-
  28. */
  29. public final class RequestRefineCancel extends L2GameClientPacket
  30. {
  31. private static final String _C__D0_2E_REQUESTREFINECANCEL = "[C] D0:2E RequestRefineCancel";
  32. private int _targetItemObjId;
  33. @Override
  34. protected void readImpl()
  35. {
  36. _targetItemObjId = readD();
  37. }
  38. /**
  39. * @see com.l2jserver.util.network.BaseRecievePacket.ClientBasePacket#runImpl()
  40. */
  41. @Override
  42. protected void runImpl()
  43. {
  44. L2PcInstance activeChar = getClient().getActiveChar();
  45. if (activeChar == null)
  46. return;
  47. L2ItemInstance targetItem = activeChar.getInventory().getItemByObjectId(_targetItemObjId);
  48. if (targetItem == null)
  49. {
  50. activeChar.sendPacket(new ExVariationCancelResult(0));
  51. return;
  52. }
  53. if (targetItem.getOwnerId() != activeChar.getObjectId())
  54. {
  55. Util.handleIllegalPlayerAction(getClient().getActiveChar(),"Warning!! Character "+getClient().getActiveChar().getName()+" of account "+getClient().getActiveChar().getAccountName()+" tryied to augment item that doesn't own.",Config.DEFAULT_PUNISH);
  56. return;
  57. }
  58. // cannot remove augmentation from a not augmented item
  59. if (!targetItem.isAugmented())
  60. {
  61. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.AUGMENTATION_REMOVAL_CAN_ONLY_BE_DONE_ON_AN_AUGMENTED_ITEM));
  62. activeChar.sendPacket(new ExVariationCancelResult(0));
  63. return;
  64. }
  65. // get the price
  66. int price = 0;
  67. switch (targetItem.getItem().getCrystalType())
  68. {
  69. case L2Item.CRYSTAL_C:
  70. if (targetItem.getCrystalCount() < 1720)
  71. price = 95000;
  72. else if (targetItem.getCrystalCount() < 2452)
  73. price = 150000;
  74. else
  75. price = 210000;
  76. break;
  77. case L2Item.CRYSTAL_B:
  78. if (targetItem.getCrystalCount() < 1746)
  79. price = 240000;
  80. else
  81. price = 270000;
  82. break;
  83. case L2Item.CRYSTAL_A:
  84. if (targetItem.getCrystalCount() < 2160)
  85. price = 330000;
  86. else if (targetItem.getCrystalCount() < 2824)
  87. price = 390000;
  88. else
  89. price = 420000;
  90. break;
  91. case L2Item.CRYSTAL_S:
  92. price = 480000;
  93. break;
  94. case L2Item.CRYSTAL_S80:
  95. case L2Item.CRYSTAL_S84:
  96. price = 920000;
  97. break;
  98. // any other item type is not augmentable
  99. default:
  100. activeChar.sendPacket(new ExVariationCancelResult(0));
  101. return;
  102. }
  103. // try to reduce the players adena
  104. if (!activeChar.reduceAdena("RequestRefineCancel", price, null, true))
  105. {
  106. activeChar.sendPacket(new ExVariationCancelResult(0));
  107. activeChar.sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
  108. return;
  109. }
  110. // unequip item
  111. if (targetItem.isEquipped())
  112. activeChar.disarmWeapons();
  113. // remove the augmentation
  114. targetItem.removeAugmentation();
  115. // send ExVariationCancelResult
  116. activeChar.sendPacket(new ExVariationCancelResult(1));
  117. // send inventory update
  118. InventoryUpdate iu = new InventoryUpdate();
  119. iu.addModifiedItem(targetItem);
  120. activeChar.sendPacket(iu);
  121. }
  122. /**
  123. * @see com.l2jserver.gameserver.BasePacket#getType()
  124. */
  125. @Override
  126. public String getType()
  127. {
  128. return _C__D0_2E_REQUESTREFINECANCEL;
  129. }
  130. }