ExShowSeedSetting.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.L2Seed;
  25. import com.l2jserver.gameserver.model.SeedProduction;
  26. /**
  27. * @author l3x
  28. */
  29. public class ExShowSeedSetting extends L2GameServerPacket
  30. {
  31. private final int _manorId;
  32. private final Set<L2Seed> _seeds;
  33. private final Map<Integer, SeedProduction> _current = new HashMap<>();
  34. private final Map<Integer, SeedProduction> _next = new HashMap<>();
  35. public ExShowSeedSetting(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. SeedProduction sp = manor.getSeedProduct(manorId, s.getSeedId(), false);
  44. if (sp != null)
  45. {
  46. _current.put(s.getSeedId(), sp);
  47. }
  48. // Next period
  49. sp = manor.getSeedProduct(manorId, s.getSeedId(), true);
  50. if (sp != null)
  51. {
  52. _next.put(s.getSeedId(), sp);
  53. }
  54. }
  55. }
  56. @Override
  57. public void writeImpl()
  58. {
  59. writeC(0xFE); // Id
  60. writeH(0x26); // SubId
  61. writeD(_manorId); // manor id
  62. writeD(_seeds.size()); // size
  63. SeedProduction sp;
  64. for (L2Seed s : _seeds)
  65. {
  66. writeD(s.getSeedId()); // seed id
  67. writeD(s.getLevel()); // 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.getSeedLimit()); // next sale limit
  73. writeD(s.getSeedReferencePrice()); // price for castle to produce 1
  74. writeD(s.getSeedMinPrice()); // min seed price
  75. writeD(s.getSeedMaxPrice()); // max seed price
  76. // Current period
  77. if (_current.containsKey(s.getSeedId()))
  78. {
  79. sp = _current.get(s.getSeedId());
  80. writeQ(sp.getStartAmount()); // sales
  81. writeQ(sp.getPrice()); // price
  82. }
  83. else
  84. {
  85. writeQ(0);
  86. writeQ(0);
  87. }
  88. // Next period
  89. if (_next.containsKey(s.getSeedId()))
  90. {
  91. sp = _next.get(s.getSeedId());
  92. writeQ(sp.getStartAmount()); // sales
  93. writeQ(sp.getPrice()); // price
  94. }
  95. else
  96. {
  97. writeQ(0);
  98. writeQ(0);
  99. }
  100. }
  101. _current.clear();
  102. _next.clear();
  103. }
  104. }