RequestRefineCancel.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.ExVariationCancelResult;
  25. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * Format(ch) d
  29. * @author -Wooden-
  30. */
  31. public final class RequestRefineCancel extends L2GameClientPacket
  32. {
  33. private static final String _C__D0_43_REQUESTREFINECANCEL = "[C] D0:43 RequestRefineCancel";
  34. private int _targetItemObjId;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _targetItemObjId = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2PcInstance activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. {
  46. return;
  47. }
  48. L2ItemInstance targetItem = activeChar.getInventory().getItemByObjectId(_targetItemObjId);
  49. if (targetItem == null)
  50. {
  51. activeChar.sendPacket(new ExVariationCancelResult(0));
  52. return;
  53. }
  54. if (targetItem.getOwnerId() != activeChar.getObjectId())
  55. {
  56. 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);
  57. return;
  58. }
  59. // cannot remove augmentation from a not augmented item
  60. if (!targetItem.isAugmented())
  61. {
  62. activeChar.sendPacket(SystemMessageId.AUGMENTATION_REMOVAL_CAN_ONLY_BE_DONE_ON_AN_AUGMENTED_ITEM);
  63. activeChar.sendPacket(new ExVariationCancelResult(0));
  64. return;
  65. }
  66. // get the price
  67. int price = 0;
  68. switch (targetItem.getItem().getCrystalType())
  69. {
  70. case C:
  71. if (targetItem.getCrystalCount() < 1720)
  72. {
  73. price = 95000;
  74. }
  75. else if (targetItem.getCrystalCount() < 2452)
  76. {
  77. price = 150000;
  78. }
  79. else
  80. {
  81. price = 210000;
  82. }
  83. break;
  84. case B:
  85. if (targetItem.getCrystalCount() < 1746)
  86. {
  87. price = 240000;
  88. }
  89. else
  90. {
  91. price = 270000;
  92. }
  93. break;
  94. case A:
  95. if (targetItem.getCrystalCount() < 2160)
  96. {
  97. price = 330000;
  98. }
  99. else if (targetItem.getCrystalCount() < 2824)
  100. {
  101. price = 390000;
  102. }
  103. else
  104. {
  105. price = 420000;
  106. }
  107. break;
  108. case S:
  109. price = 480000;
  110. break;
  111. case S80:
  112. case S84:
  113. price = 920000;
  114. break;
  115. // any other item type is not augmentable
  116. default:
  117. activeChar.sendPacket(new ExVariationCancelResult(0));
  118. return;
  119. }
  120. // try to reduce the players adena
  121. if (!activeChar.reduceAdena("RequestRefineCancel", price, null, true))
  122. {
  123. activeChar.sendPacket(new ExVariationCancelResult(0));
  124. activeChar.sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
  125. return;
  126. }
  127. // unequip item
  128. if (targetItem.isEquipped())
  129. {
  130. activeChar.disarmWeapons();
  131. }
  132. // remove the augmentation
  133. targetItem.removeAugmentation();
  134. // send ExVariationCancelResult
  135. activeChar.sendPacket(new ExVariationCancelResult(1));
  136. // send inventory update
  137. InventoryUpdate iu = new InventoryUpdate();
  138. iu.addModifiedItem(targetItem);
  139. activeChar.sendPacket(iu);
  140. }
  141. @Override
  142. public String getType()
  143. {
  144. return _C__D0_43_REQUESTREFINECANCEL;
  145. }
  146. }