RequestSetSeed.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.clientpackets;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  24. import com.l2jserver.gameserver.model.ClanPrivilege;
  25. import com.l2jserver.gameserver.model.L2Seed;
  26. import com.l2jserver.gameserver.model.SeedProduction;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. /**
  29. * @author l3x
  30. */
  31. public class RequestSetSeed extends L2GameClientPacket
  32. {
  33. private static final int BATCH_LENGTH = 20; // length of the one item
  34. private int _manorId;
  35. private List<SeedProduction> _items;
  36. @Override
  37. protected void readImpl()
  38. {
  39. _manorId = readD();
  40. final int count = readD();
  41. if ((count <= 0) || (count > Config.MAX_ITEM_IN_PACKET) || ((count * BATCH_LENGTH) != _buf.remaining()))
  42. {
  43. return;
  44. }
  45. _items = new ArrayList<>(count);
  46. for (int i = 0; i < count; i++)
  47. {
  48. final int itemId = readD();
  49. final long sales = readQ();
  50. final long price = readQ();
  51. if ((itemId < 1) || (sales < 0) || (price < 0))
  52. {
  53. _items.clear();
  54. return;
  55. }
  56. if (sales > 0)
  57. {
  58. _items.add(new SeedProduction(itemId, sales, price, sales));
  59. }
  60. }
  61. }
  62. @Override
  63. protected void runImpl()
  64. {
  65. if (_items.isEmpty())
  66. {
  67. return;
  68. }
  69. final CastleManorManager manor = CastleManorManager.getInstance();
  70. if (!manor.isModifiablePeriod())
  71. {
  72. sendActionFailed();
  73. return;
  74. }
  75. // Check player privileges
  76. final L2PcInstance player = getActiveChar();
  77. if ((player == null) || (player.getClan() == null) || (player.getClan().getCastleId() != _manorId) || !player.hasClanPrivilege(ClanPrivilege.CS_MANOR_ADMIN) || !player.getLastFolkNPC().canInteract(player))
  78. {
  79. sendActionFailed();
  80. return;
  81. }
  82. // Filter seeds with start amount lower than 0 and incorrect price
  83. final List<SeedProduction> list = new ArrayList<>(_items.size());
  84. for (SeedProduction sp : _items)
  85. {
  86. final L2Seed s = manor.getSeed(sp.getId());
  87. if ((s != null) && (sp.getStartAmount() <= s.getSeedLimit()) && (sp.getPrice() >= s.getSeedMinPrice()) && (sp.getPrice() <= s.getSeedMaxPrice()))
  88. {
  89. list.add(sp);
  90. }
  91. }
  92. // Save new list
  93. manor.setNextSeedProduction(list, _manorId);
  94. }
  95. @Override
  96. public String getType()
  97. {
  98. return "[C] D0:03 RequestSetSeed";
  99. }
  100. }