2
0

ExShowCropSetting.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 com.l2jserver.gameserver.instancemanager.CastleManager;
  17. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  18. import com.l2jserver.gameserver.instancemanager.CastleManorManager.CropProcure;
  19. import com.l2jserver.gameserver.model.L2Manor;
  20. import com.l2jserver.gameserver.model.entity.Castle;
  21. import javolution.util.FastList;
  22. /**
  23. * format(packet 0xFE) ch dd [ddcdcdddddddcddc] c - id h - sub id
  24. *
  25. * d - manor id d - size
  26. * [ d - crop id d - seed level c d - reward 1 id c d - reward 2 id d - next
  27. * sale limit d d - min crop price d - max crop price d - today buy d - today
  28. * price c - today reward d - next buy d - next price c - next reward ]
  29. *
  30. * @author l3x
  31. */
  32. public class ExShowCropSetting extends L2GameServerPacket
  33. {
  34. private static final String _S__FE_20_EXSHOWCROPSETTING = "[S] FE:20 ExShowCropSetting";
  35. private int _manorId;
  36. private int _count;
  37. private long[] _cropData; // data to send, size:_count*14
  38. @Override
  39. public void runImpl()
  40. {
  41. }
  42. public ExShowCropSetting(int manorId)
  43. {
  44. _manorId = manorId;
  45. Castle c = CastleManager.getInstance().getCastleById(_manorId);
  46. FastList<Integer> crops = L2Manor.getInstance().getCropsForCastle(
  47. _manorId);
  48. _count = crops.size();
  49. _cropData = new long[_count * 14];
  50. int i = 0;
  51. for (int cr : crops)
  52. {
  53. _cropData[i * 14 + 0] = cr;
  54. _cropData[i * 14 + 1] = L2Manor.getInstance()
  55. .getSeedLevelByCrop(cr);
  56. _cropData[i * 14 + 2] = L2Manor.getInstance().getRewardItem(cr, 1);
  57. _cropData[i * 14 + 3] = L2Manor.getInstance().getRewardItem(cr, 2);
  58. _cropData[i * 14 + 4] = L2Manor.getInstance().getCropPuchaseLimit(
  59. cr);
  60. _cropData[i * 14 + 5] = 0; // Looks like not used
  61. _cropData[i * 14 + 6] = L2Manor.getInstance().getCropBasicPrice(cr) * 60 / 100;
  62. _cropData[i * 14 + 7] = L2Manor.getInstance().getCropBasicPrice(cr) * 10;
  63. CropProcure cropPr = c.getCrop(cr,
  64. CastleManorManager.PERIOD_CURRENT);
  65. if (cropPr != null)
  66. {
  67. _cropData[i * 14 + 8] = cropPr.getStartAmount();
  68. _cropData[i * 14 + 9] = cropPr.getPrice();
  69. _cropData[i * 14 + 10] = cropPr.getReward();
  70. }
  71. else
  72. {
  73. _cropData[i * 14 + 8] = 0;
  74. _cropData[i * 14 + 9] = 0;
  75. _cropData[i * 14 + 10] = 0;
  76. }
  77. cropPr = c.getCrop(cr, CastleManorManager.PERIOD_NEXT);
  78. if (cropPr != null)
  79. {
  80. _cropData[i * 14 + 11] = cropPr.getStartAmount();
  81. _cropData[i * 14 + 12] = cropPr.getPrice();
  82. _cropData[i * 14 + 13] = cropPr.getReward();
  83. }
  84. else
  85. {
  86. _cropData[i * 14 + 11] = 0;
  87. _cropData[i * 14 + 12] = 0;
  88. _cropData[i * 14 + 13] = 0;
  89. }
  90. i++;
  91. }
  92. }
  93. @Override
  94. public void writeImpl()
  95. {
  96. writeC(0xFE); // Id
  97. writeH(0x2b); // SubId
  98. writeD(_manorId); // manor id
  99. writeD(_count); // size
  100. for (int i = 0; i < _count; i++)
  101. {
  102. writeD((int) _cropData[i * 14 + 0]); // crop id
  103. writeD((int) _cropData[i * 14 + 1]); // seed level
  104. writeC(1);
  105. writeD((int) _cropData[i * 14 + 2]); // reward 1 id
  106. writeC(1);
  107. writeD((int) _cropData[i * 14 + 3]); // reward 2 id
  108. writeD((int) _cropData[i * 14 + 4]); // next sale limit
  109. writeD((int) _cropData[i * 14 + 5]); // ???
  110. writeD((int)_cropData[i * 14 + 6]); // min crop price
  111. writeD((int)_cropData[i * 14 + 7]); // max crop price
  112. writeQ(_cropData[i * 14 + 8]); // today buy
  113. writeQ(_cropData[i * 14 + 9]); // today price
  114. writeC((int) _cropData[i * 14 + 10]); // today reward
  115. writeQ(_cropData[i * 14 + 11]); // next buy
  116. writeQ(_cropData[i * 14 + 12]); // next price
  117. writeC((int) _cropData[i * 14 + 13]); // next reward
  118. }
  119. }
  120. @Override
  121. public String getType()
  122. {
  123. return _S__FE_20_EXSHOWCROPSETTING;
  124. }
  125. }