ExShowProcureCropDetail.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.serverpackets;
  16. import javolution.util.FastMap;
  17. import com.l2jserver.gameserver.instancemanager.CastleManager;
  18. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  19. import com.l2jserver.gameserver.instancemanager.CastleManorManager.CropProcure;
  20. import com.l2jserver.gameserver.model.entity.Castle;
  21. /**
  22. * format(packet 0xFE) ch dd [dddc] c - id h - sub id
  23. *
  24. * d - crop id d - size
  25. * [ d - manor name d - buy residual d - buy price c - reward type ]
  26. *
  27. * @author l3x
  28. */
  29. public class ExShowProcureCropDetail extends L2GameServerPacket
  30. {
  31. private static final String _S__FE_22_EXSHOWPROCURECROPDETAIL = "[S] FE:78 ExShowProcureCropDetail";
  32. private int _cropId;
  33. private FastMap<Integer, CropProcure> _castleCrops;
  34. public ExShowProcureCropDetail(int cropId)
  35. {
  36. _cropId = cropId;
  37. _castleCrops = new FastMap<Integer, CropProcure>();
  38. for (Castle c : CastleManager.getInstance().getCastles())
  39. {
  40. CropProcure cropItem = c.getCrop(_cropId,
  41. CastleManorManager.PERIOD_CURRENT);
  42. if (cropItem != null && cropItem.getAmount() > 0)
  43. {
  44. _castleCrops.put(c.getCastleId(), cropItem);
  45. }
  46. }
  47. }
  48. @Override
  49. public void runImpl()
  50. {
  51. }
  52. @Override
  53. public void writeImpl()
  54. {
  55. writeC(0xFE);
  56. writeH(0x78);
  57. writeD(_cropId); // crop id
  58. writeD(_castleCrops.size()); // size
  59. for (int manorId : _castleCrops.keySet())
  60. {
  61. CropProcure crop = _castleCrops.get(manorId);
  62. writeD(manorId); // manor name
  63. writeQ(crop.getAmount()); // buy residual
  64. writeQ(crop.getPrice()); // buy price
  65. writeC(crop.getReward()); // reward type
  66. }
  67. }
  68. @Override
  69. public String getType()
  70. {
  71. return _S__FE_22_EXSHOWPROCURECROPDETAIL;
  72. }
  73. }