2
0

RequestRefineCancel.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.L2World;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.ExVariationCancelResult;
  22. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. import com.l2jserver.gameserver.templates.item.L2Item;
  25. import com.l2jserver.gameserver.util.Util;
  26. /**
  27. * Format(ch) d
  28. * @author -Wooden-
  29. */
  30. public final class RequestRefineCancel extends L2GameClientPacket
  31. {
  32. private static final String _C__D0_2E_REQUESTREFINECANCEL = "[C] D0:2E RequestRefineCancel";
  33. private int _targetItemObjId;
  34. @Override
  35. protected void readImpl()
  36. {
  37. _targetItemObjId = readD();
  38. }
  39. /**
  40. * @see com.l2jserver.util.network.BaseRecievePacket.ClientBasePacket#runImpl()
  41. */
  42. @Override
  43. protected void runImpl()
  44. {
  45. L2PcInstance activeChar = getClient().getActiveChar();
  46. if (activeChar == null)
  47. return;
  48. L2ItemInstance targetItem = (L2ItemInstance)L2World.getInstance().findObject(_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(new SystemMessage(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 L2Item.CRYSTAL_C:
  71. if (targetItem.getCrystalCount() < 1720)
  72. price = 95000;
  73. else if (targetItem.getCrystalCount() < 2452)
  74. price = 150000;
  75. else
  76. price = 210000;
  77. break;
  78. case L2Item.CRYSTAL_B:
  79. if (targetItem.getCrystalCount() < 1746)
  80. price = 240000;
  81. else
  82. price = 270000;
  83. break;
  84. case L2Item.CRYSTAL_A:
  85. if (targetItem.getCrystalCount() < 2160)
  86. price = 330000;
  87. else if (targetItem.getCrystalCount() < 2824)
  88. price = 390000;
  89. else
  90. price = 420000;
  91. break;
  92. case L2Item.CRYSTAL_S:
  93. price = 480000;
  94. break;
  95. case L2Item.CRYSTAL_S80:
  96. case L2Item.CRYSTAL_S84:
  97. price = 920000;
  98. break;
  99. // any other item type is not augmentable
  100. default:
  101. activeChar.sendPacket(new ExVariationCancelResult(0));
  102. return;
  103. }
  104. // try to reduce the players adena
  105. if (!activeChar.reduceAdena("RequestRefineCancel", price, null, true)) return;
  106. // unequip item
  107. if (targetItem.isEquipped())
  108. activeChar.disarmWeapons();
  109. // remove the augmentation
  110. targetItem.removeAugmentation();
  111. // send ExVariationCancelResult
  112. activeChar.sendPacket(new ExVariationCancelResult(1));
  113. // send inventory update
  114. InventoryUpdate iu = new InventoryUpdate();
  115. iu.addModifiedItem(targetItem);
  116. activeChar.sendPacket(iu);
  117. }
  118. /**
  119. * @see com.l2jserver.gameserver.BasePacket#getType()
  120. */
  121. @Override
  122. public String getType()
  123. {
  124. return _C__D0_2E_REQUESTREFINECANCEL;
  125. }
  126. }