RequestSetCrop.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 javolution.util.FastList;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  19. import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
  20. import net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure;
  21. /**
  22. * Format: (ch) dd [dddc]
  23. * d - manor id
  24. * d - size
  25. * [
  26. * d - crop id
  27. * d - sales
  28. * d - price
  29. * c - reward type
  30. * ]
  31. * @author l3x
  32. *
  33. */
  34. public class RequestSetCrop extends L2GameClientPacket {
  35. private static final String _C__D0_0B_REQUESTSETCROP = "[C] D0:0B RequestSetCrop";
  36. private int _size;
  37. private int _manorId;
  38. private int[] _items; // _size*4
  39. @Override
  40. protected void readImpl()
  41. {
  42. _manorId = readD();
  43. _size = readD();
  44. if (_size * 13 > _buf.remaining() || _size > 500)
  45. {
  46. _size = 0;
  47. return;
  48. }
  49. _items = new int[_size * 4];
  50. for (int i = 0; i < _size; i++)
  51. {
  52. int itemId = readD();
  53. _items[i * 4 + 0] = itemId;
  54. int sales = readD();
  55. _items[i * 4 + 1] = sales;
  56. int price = readD();
  57. _items[i * 4 + 2] = price;
  58. int type = readC();
  59. _items[i * 4 + 3] = type;
  60. }
  61. }
  62. @Override
  63. protected void runImpl()
  64. {
  65. if (_size < 1)
  66. return;
  67. FastList<CropProcure> crops = new FastList<CropProcure>();
  68. for (int i = 0; i < _size; i++)
  69. {
  70. int id = _items[i * 4 + 0];
  71. int sales = _items[i * 4 + 1];
  72. int price = _items[i * 4 + 2];
  73. int type = _items[i * 4 + 3];
  74. if (id > 0)
  75. {
  76. CropProcure s = CastleManorManager.getInstance().getNewCropProcure(id, sales, type, price, sales);
  77. crops.add(s);
  78. }
  79. }
  80. CastleManager.getInstance().getCastleById(_manorId).setCropProcure(crops,
  81. CastleManorManager.PERIOD_NEXT);
  82. if (Config.ALT_MANOR_SAVE_ALL_ACTIONS)
  83. CastleManager.getInstance().getCastleById(_manorId).saveCropData(CastleManorManager.PERIOD_NEXT);
  84. }
  85. @Override
  86. public String getType()
  87. {
  88. return _C__D0_0B_REQUESTSETCROP;
  89. }
  90. }