RequestConfirmGemStone.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.ExPutCommissionResultForVariationMake;
  21. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  22. import net.sf.l2j.gameserver.templates.L2Item;
  23. /**
  24. * Format:(ch) dddd
  25. * @author -Wooden-
  26. */
  27. public final class RequestConfirmGemStone extends L2GameClientPacket
  28. {
  29. private static final String _C__D0_2B_REQUESTCONFIRMGEMSTONE = "[C] D0:2B RequestConfirmGemStone";
  30. private int _targetItemObjId;
  31. private int _refinerItemObjId;
  32. private int _gemstoneItemObjId;
  33. private int _gemstoneCount;
  34. /**
  35. * @param buf
  36. * @param client
  37. */
  38. @Override
  39. protected void readImpl()
  40. {
  41. _targetItemObjId = readD();
  42. _refinerItemObjId = readD();
  43. _gemstoneItemObjId = readD();
  44. _gemstoneCount= readD();
  45. }
  46. /**
  47. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#runImpl()
  48. */
  49. @Override
  50. protected
  51. void runImpl()
  52. {
  53. L2PcInstance activeChar = getClient().getActiveChar();
  54. L2ItemInstance targetItem = (L2ItemInstance)L2World.getInstance().findObject(_targetItemObjId);
  55. L2ItemInstance refinerItem = (L2ItemInstance)L2World.getInstance().findObject(_refinerItemObjId);
  56. L2ItemInstance gemstoneItem = (L2ItemInstance)L2World.getInstance().findObject(_gemstoneItemObjId);
  57. if (targetItem == null || refinerItem == null || gemstoneItem == null) return;
  58. // Make sure the item is a gemstone
  59. int gemstoneItemId = gemstoneItem.getItem().getItemId();
  60. if (gemstoneItemId != 2130 && gemstoneItemId != 2131)
  61. {
  62. activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_IS_NOT_A_SUITABLE_ITEM));
  63. return;
  64. }
  65. // Check if the gemstoneCount is sufficant
  66. int itemGrade = targetItem.getItem().getItemGrade();
  67. switch (itemGrade)
  68. {
  69. case L2Item.CRYSTAL_C:
  70. if (_gemstoneCount != 20 || gemstoneItemId != 2130)
  71. {
  72. activeChar.sendPacket(new SystemMessage(SystemMessageId.GEMSTONE_QUANTITY_IS_INCORRECT));
  73. return;
  74. }
  75. break;
  76. case L2Item.CRYSTAL_B:
  77. if (_gemstoneCount != 30 || gemstoneItemId != 2130)
  78. {
  79. activeChar.sendPacket(new SystemMessage(SystemMessageId.GEMSTONE_QUANTITY_IS_INCORRECT));
  80. return;
  81. }
  82. break;
  83. case L2Item.CRYSTAL_A:
  84. if (_gemstoneCount != 20 || gemstoneItemId != 2131)
  85. {
  86. activeChar.sendPacket(new SystemMessage(SystemMessageId.GEMSTONE_QUANTITY_IS_INCORRECT));
  87. return;
  88. }
  89. break;
  90. case L2Item.CRYSTAL_S:
  91. case L2Item.CRYSTAL_S80:
  92. if (_gemstoneCount != 25 || gemstoneItemId != 2131)
  93. {
  94. activeChar.sendPacket(new SystemMessage(SystemMessageId.GEMSTONE_QUANTITY_IS_INCORRECT));
  95. return;
  96. }
  97. break;
  98. }
  99. activeChar.sendPacket(new ExPutCommissionResultForVariationMake(_gemstoneItemObjId, _gemstoneCount));
  100. activeChar.sendPacket(new SystemMessage(SystemMessageId.PRESS_THE_AUGMENT_BUTTON_TO_BEGIN));
  101. }
  102. /**
  103. * @see net.sf.l2j.gameserver.BasePacket#getType()
  104. */
  105. @Override
  106. public String getType()
  107. {
  108. return _C__D0_2B_REQUESTCONFIRMGEMSTONE;
  109. }
  110. }