Advertisement
Fabbian

Code

Dec 8th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  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.dream.game.network.clientpackets;
  16.  
  17. import java.util.ArrayList;
  18. import java.util.HashSet;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.Set;
  22.  
  23. import com.dream.Config;
  24. import com.dream.game.model.ItemRequest;
  25. import com.dream.game.model.TradeList;
  26. import com.dream.game.model.actor.instance.L2PcInstance;
  27. import com.dream.game.model.world.L2World;
  28. import com.dream.game.taskmanager.OfflineManager;
  29. import com.dream.game.util.Util;
  30.  
  31. public final class RequestPrivateStoreBuy extends L2GameClientPacket
  32. {
  33. private static final String _C__79_REQUESTPRIVATESTOREBUY = "[C] 79 RequestPrivateStoreBuy";
  34. private static final int BATCH_LENGTH = 12; // length of one item
  35.  
  36. private int _storePlayerId;
  37. private Set<ItemRequest> _items = null;
  38. private List<int[]> _buffs = null;
  39.  
  40. @Override
  41. protected void readImpl()
  42. {
  43. _storePlayerId = readD();
  44. int count = readD();
  45. if ((count <= 0) || (count > Config.MAX_ITEM_IN_PACKET) || ((count * BATCH_LENGTH) != _buf.remaining()))
  46. {
  47. return;
  48. }
  49.  
  50. _items = new HashSet<>();
  51. _buffs = new ArrayList<>();
  52.  
  53. for (int i = 0; i < count; i++)
  54. {
  55. int objectId = readD();
  56. long cnt = readD();
  57. int price = readD();
  58.  
  59. if ((objectId < 1) || (cnt < 1) || (price < 0))
  60. {
  61. _items = null;
  62. return;
  63. }
  64.  
  65. _items.add(new ItemRequest(objectId, (int) cnt, price));
  66. _buffs.add(new int[]
  67. {
  68. objectId,
  69. price
  70. });
  71. }
  72. }
  73.  
  74. @Override
  75. protected void runImpl()
  76. {
  77. L2PcInstance player = getClient().getActiveChar();
  78. if (player == null)
  79. {
  80. return;
  81. }
  82.  
  83. if (_items == null)
  84. {
  85. return;
  86. }
  87.  
  88. L2PcInstance storePlayer = L2World.getInstance().getPlayer(_storePlayerId);
  89. if (storePlayer == null)
  90. {
  91. return;
  92. }
  93.  
  94. if (player.isCursedWeaponEquipped())
  95. {
  96. return;
  97. }
  98.  
  99. if (!player.isInsideRadius(storePlayer, 150, true, false))
  100. {
  101. return;
  102. }
  103.  
  104. if (storePlayer.isBizy())
  105. {
  106. BuffShopManager.getInstance().broadcastBizy(storePlayer, player);
  107. return;
  108. }
  109.  
  110. if (!((storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_SELL) || (storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL)))
  111. {
  112. return;
  113. }
  114.  
  115. TradeList storeList = storePlayer.getSellList();
  116. if (storeList == null)
  117. {
  118. return;
  119. }
  120.  
  121. Map<Integer, int[]> sellList = storePlayer.getBuffShopSellList();
  122. if ((storePlayer.isBuffShop()) && (sellList == null))
  123. {
  124. return;
  125. }
  126.  
  127. if (storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL)
  128. {
  129. if (storeList.getItemCount() > _items.size())
  130. {
  131. Util.handleIllegalPlayerAction(getClient().getActiveChar(), "[RequestPrivateStoreBuy] " + player.getName() + " tried to buy less items than sold in package.", Config.DEFAULT_PUNISH);
  132. return;
  133. }
  134. }
  135.  
  136. if (storePlayer.isBuffShop())
  137. {
  138. BuffShopManager.getInstance().processBuffs(storePlayer, player, _buffs);
  139. return;
  140. }
  141.  
  142. if (storeList.getItemCount() == 0)
  143. {
  144. storePlayer.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
  145. storePlayer.broadcastUserInfo();
  146.  
  147. if (storePlayer.isOfflineTrade())
  148. {
  149. OfflineManager.getInstance().removeTrader(storePlayer);
  150. }
  151. }
  152. }
  153.  
  154. @Override
  155. public String getType()
  156. {
  157. return _C__79_REQUESTPRIVATESTOREBUY;
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement