RequestRefineCancel.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 net.sf.l2j.gameserver.clientpackets;
  16. import net.sf.l2j.gameserver.model.L2ItemInstance;
  17. import net.sf.l2j.gameserver.model.L2World;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.network.SystemMessageId;
  20. import net.sf.l2j.gameserver.serverpackets.ExVariationCancelResult;
  21. import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
  22. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  23. import net.sf.l2j.gameserver.templates.L2Item;
  24. /**
  25. * Format(ch) d
  26. * @author -Wooden-
  27. */
  28. public final class RequestRefineCancel extends L2GameClientPacket
  29. {
  30. private static final String _C__D0_2E_REQUESTREFINECANCEL = "[C] D0:2E RequestRefineCancel";
  31. private int _targetItemObjId;
  32. @Override
  33. protected void readImpl()
  34. {
  35. _targetItemObjId = readD();
  36. }
  37. /**
  38. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#runImpl()
  39. */
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2PcInstance activeChar = getClient().getActiveChar();
  44. L2ItemInstance targetItem = (L2ItemInstance)L2World.getInstance().findObject(_targetItemObjId);
  45. if (activeChar == null) return;
  46. if (targetItem == null)
  47. {
  48. activeChar.sendPacket(new ExVariationCancelResult(0));
  49. return;
  50. }
  51. // cannot remove augmentation from a not augmented item
  52. if (!targetItem.isAugmented())
  53. {
  54. activeChar.sendPacket(new SystemMessage(SystemMessageId.AUGMENTATION_REMOVAL_CAN_ONLY_BE_DONE_ON_AN_AUGMENTED_ITEM));
  55. activeChar.sendPacket(new ExVariationCancelResult(0));
  56. return;
  57. }
  58. // get the price
  59. int price=0;
  60. switch (targetItem.getItem().getItemGrade())
  61. {
  62. case L2Item.CRYSTAL_C:
  63. if (targetItem.getCrystalCount() < 1720)
  64. price = 95000;
  65. else if (targetItem.getCrystalCount() < 2452)
  66. price = 150000;
  67. else
  68. price = 210000;
  69. break;
  70. case L2Item.CRYSTAL_B:
  71. if (targetItem.getCrystalCount() < 1746)
  72. price = 240000;
  73. else
  74. price = 270000;
  75. break;
  76. case L2Item.CRYSTAL_A:
  77. if (targetItem.getCrystalCount() < 2160)
  78. price = 330000;
  79. else if (targetItem.getCrystalCount() < 2824)
  80. price = 390000;
  81. else
  82. price = 420000;
  83. break;
  84. case L2Item.CRYSTAL_S:
  85. case L2Item.CRYSTAL_S80:
  86. price = 480000;
  87. break;
  88. // any other item type is not augmentable
  89. default:
  90. activeChar.sendPacket(new ExVariationCancelResult(0));
  91. return;
  92. }
  93. // try to reduce the players adena
  94. if (!activeChar.reduceAdena("RequestRefineCancel", price, null, true)) return;
  95. // unequip item
  96. if (targetItem.isEquipped()) activeChar.disarmWeapons();
  97. // remove the augmentation
  98. targetItem.removeAugmentation();
  99. // send ExVariationCancelResult
  100. activeChar.sendPacket(new ExVariationCancelResult(1));
  101. // send inventory update
  102. InventoryUpdate iu = new InventoryUpdate();
  103. iu.addModifiedItem(targetItem);
  104. activeChar.sendPacket(iu);
  105. // send system message
  106. SystemMessage sm = new SystemMessage(SystemMessageId.AUGMENTATION_HAS_BEEN_SUCCESSFULLY_REMOVED_FROM_YOUR_S1);
  107. sm.addString(targetItem.getItemName());
  108. activeChar.sendPacket(sm);
  109. }
  110. /**
  111. * @see net.sf.l2j.gameserver.BasePacket#getType()
  112. */
  113. @Override
  114. public String getType()
  115. {
  116. return _C__D0_2E_REQUESTREFINECANCEL;
  117. }
  118. }