ExShowCropSetting.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 java.util.Set;
  23. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  24. import com.l2jserver.gameserver.model.CropProcure;
  25. import com.l2jserver.gameserver.model.L2Seed;
  26. /**
  27. * @author l3x
  28. */
  29. public class ExShowCropSetting extends L2GameServerPacket
  30. {
  31. private final int _manorId;
  32. private final Set<L2Seed> _seeds;
  33. private final Map<Integer, CropProcure> _current = new HashMap<>();
  34. private final Map<Integer, CropProcure> _next = new HashMap<>();
  35. public ExShowCropSetting(int manorId)
  36. {
  37. final CastleManorManager manor = CastleManorManager.getInstance();
  38. _manorId = manorId;
  39. _seeds = manor.getSeedsForCastle(_manorId);
  40. for (L2Seed s : _seeds)
  41. {
  42. // Current period
  43. CropProcure cp = manor.getCropProcure(manorId, s.getCropId(), false);
  44. if (cp != null)
  45. {
  46. _current.put(s.getCropId(), cp);
  47. }
  48. // Next period
  49. cp = manor.getCropProcure(manorId, s.getCropId(), true);
  50. if (cp != null)
  51. {
  52. _next.put(s.getCropId(), cp);
  53. }
  54. }
  55. }
  56. @Override
  57. public void writeImpl()
  58. {
  59. writeC(0xFE); // Id
  60. writeH(0x2b); // SubId
  61. writeD(_manorId); // manor id
  62. writeD(_seeds.size()); // size
  63. CropProcure cp;
  64. for (L2Seed s : _seeds)
  65. {
  66. writeD(s.getCropId()); // crop id
  67. writeD(s.getLevel()); // seed level
  68. writeC(1);
  69. writeD(s.getReward(1)); // reward 1 id
  70. writeC(1);
  71. writeD(s.getReward(2)); // reward 2 id
  72. writeD(s.getCropLimit()); // next sale limit
  73. writeD(0); // ???
  74. writeD(s.getCropMinPrice()); // min crop price
  75. writeD(s.getCropMaxPrice()); // max crop price
  76. // Current period
  77. if (_current.containsKey(s.getCropId()))
  78. {
  79. cp = _current.get(s.getCropId());
  80. writeQ(cp.getStartAmount()); // buy
  81. writeQ(cp.getPrice()); // price
  82. writeC(cp.getReward()); // reward
  83. }
  84. else
  85. {
  86. writeQ(0);
  87. writeQ(0);
  88. writeC(0);
  89. }
  90. // Next period
  91. if (_next.containsKey(s.getCropId()))
  92. {
  93. cp = _next.get(s.getCropId());
  94. writeQ(cp.getStartAmount()); // buy
  95. writeQ(cp.getPrice()); // price
  96. writeC(cp.getReward()); // reward
  97. }
  98. else
  99. {
  100. writeQ(0);
  101. writeQ(0);
  102. writeC(0);
  103. }
  104. }
  105. _next.clear();
  106. _current.clear();
  107. }
  108. }