ExShowProcureCropDetail.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.instancemanager.CastleManager;
  23. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  24. import com.l2jserver.gameserver.model.CropProcure;
  25. import com.l2jserver.gameserver.model.entity.Castle;
  26. /**
  27. * @author l3x
  28. */
  29. public class ExShowProcureCropDetail extends L2GameServerPacket
  30. {
  31. private final int _cropId;
  32. private final Map<Integer, CropProcure> _castleCrops = new HashMap<>();
  33. public ExShowProcureCropDetail(int cropId)
  34. {
  35. _cropId = cropId;
  36. for (Castle c : CastleManager.getInstance().getCastles())
  37. {
  38. final CropProcure cropItem = CastleManorManager.getInstance().getCropProcure(c.getResidenceId(), cropId, false);
  39. if ((cropItem != null) && (cropItem.getAmount() > 0))
  40. {
  41. _castleCrops.put(c.getResidenceId(), cropItem);
  42. }
  43. }
  44. }
  45. @Override
  46. public void writeImpl()
  47. {
  48. writeC(0xFE);
  49. writeH(0x78);
  50. writeD(_cropId); // crop id
  51. writeD(_castleCrops.size()); // size
  52. for (Map.Entry<Integer, CropProcure> entry : _castleCrops.entrySet())
  53. {
  54. final CropProcure crop = entry.getValue();
  55. writeD(entry.getKey()); // manor name
  56. writeQ(crop.getAmount()); // buy residual
  57. writeQ(crop.getPrice()); // buy price
  58. writeC(crop.getReward()); // reward type
  59. }
  60. }
  61. }