RequestSetSeed.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 net.sf.l2j.gameserver.clientpackets;
  16. import javolution.util.FastList;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  19. import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
  20. import net.sf.l2j.gameserver.instancemanager.CastleManorManager.SeedProduction;
  21. /**
  22. * Format: (ch) dd [ddd]
  23. * d - manor id
  24. * d - size
  25. * [
  26. * d - seed id
  27. * d - sales
  28. * d - price
  29. * ]
  30. * @author l3x
  31. *
  32. */
  33. public class RequestSetSeed extends L2GameClientPacket {
  34. private static final String _C__D0_0A_REQUESTSETSEED = "[C] D0:0A RequestSetSeed";
  35. private int _size;
  36. private int _manorId;
  37. private int[] _items; // _size*3
  38. /**
  39. * @param buf
  40. * @param client
  41. */
  42. @Override
  43. protected void readImpl()
  44. {
  45. _manorId = readD();
  46. _size = readD();
  47. if (_size * 12 > _buf.remaining() || _size > 500)
  48. {
  49. _size = 0;
  50. return;
  51. }
  52. _items = new int[_size * 3];
  53. for (int i = 0; i < _size; i++)
  54. {
  55. int itemId = readD();
  56. _items[i * 3 + 0] = itemId;
  57. int sales = readD();
  58. _items[i * 3 + 1] = sales;
  59. int price = readD();
  60. _items[i * 3 + 2] = price;
  61. }
  62. }
  63. @Override
  64. protected void runImpl()
  65. {
  66. if (_size < 1)
  67. return;
  68. FastList<SeedProduction> seeds = new FastList<SeedProduction>();
  69. for (int i = 0; i < _size; i++)
  70. {
  71. int id = _items[i * 3 + 0];
  72. int sales = _items[i * 3 + 1];
  73. int price = _items[i * 3 + 2];
  74. if (id > 0)
  75. {
  76. SeedProduction s = CastleManorManager.getInstance()
  77. .getNewSeedProduction(id, sales, price, sales);
  78. seeds.add(s);
  79. }
  80. }
  81. CastleManager.getInstance().getCastleById(_manorId).setSeedProduction(seeds, CastleManorManager.PERIOD_NEXT);
  82. if (Config.ALT_MANOR_SAVE_ALL_ACTIONS)
  83. CastleManager.getInstance().getCastleById(_manorId).saveSeedData(CastleManorManager.PERIOD_NEXT);
  84. }
  85. @Override
  86. public String getType()
  87. {
  88. return _C__D0_0A_REQUESTSETSEED;
  89. }
  90. }