2
0

ExShowCropInfo.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.serverpackets;
  20. import java.util.List;
  21. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  22. import com.l2jserver.gameserver.model.CropProcure;
  23. import com.l2jserver.gameserver.model.L2Seed;
  24. /**
  25. * @author l3x
  26. */
  27. public class ExShowCropInfo extends L2GameServerPacket
  28. {
  29. private final List<CropProcure> _crops;
  30. private final int _manorId;
  31. private final boolean _hideButtons;
  32. public ExShowCropInfo(int manorId, boolean nextPeriod, boolean hideButtons)
  33. {
  34. _manorId = manorId;
  35. _hideButtons = hideButtons;
  36. final CastleManorManager manor = CastleManorManager.getInstance();
  37. _crops = (nextPeriod && !manor.isManorApproved()) ? null : manor.getCropProcure(manorId, nextPeriod);
  38. }
  39. @Override
  40. protected void writeImpl()
  41. {
  42. writeC(0xFE); // Id
  43. writeH(0x24); // SubId
  44. writeC(_hideButtons ? 0x01 : 0x00); // Hide "Crop Sales" button
  45. writeD(_manorId); // Manor ID
  46. writeD(0x00);
  47. if (_crops == null)
  48. {
  49. writeD(0);
  50. return;
  51. }
  52. writeD(_crops.size());
  53. for (CropProcure crop : _crops)
  54. {
  55. writeD(crop.getId()); // Crop id
  56. writeQ(crop.getAmount()); // Buy residual
  57. writeQ(crop.getStartAmount()); // Buy
  58. writeQ(crop.getPrice()); // Buy price
  59. writeC(crop.getReward()); // Reward
  60. final L2Seed seed = CastleManorManager.getInstance().getSeedByCrop(crop.getId());
  61. if (seed == null)
  62. {
  63. writeD(0); // Seed level
  64. writeC(0x01); // Reward 1
  65. writeD(0); // Reward 1 - item id
  66. writeC(0x01); // Reward 2
  67. writeD(0); // Reward 2 - item id
  68. }
  69. else
  70. {
  71. writeD(seed.getLevel()); // Seed level
  72. writeC(0x01); // Reward 1
  73. writeD(seed.getReward(1)); // Reward 1 - item id
  74. writeC(0x01); // Reward 2
  75. writeD(seed.getReward(2)); // Reward 2 - item id
  76. }
  77. }
  78. }
  79. }