Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. SellList.Java
  2.  
  3. /*
  4. * Copyright (C) 2004-2015 L2J Server
  5. *
  6. * This file is part of L2J Server.
  7. *
  8. * L2J Server is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * L2J Server is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package l2r.gameserver.network.serverpackets;
  22.  
  23. import java.util.ArrayList;
  24. import java.util.List;
  25.  
  26. import l2r.gameserver.model.actor.instance.L2MerchantInstance;
  27. import l2r.gameserver.model.actor.instance.L2PcInstance;
  28. import l2r.gameserver.model.items.instance.L2ItemInstance;
  29.  
  30. public class SellList extends L2GameServerPacket
  31. {
  32. private final L2PcInstance _activeChar;
  33. private final L2MerchantInstance _lease;
  34. private final long _money;
  35. private final List<L2ItemInstance> _selllist = new ArrayList<>();
  36.  
  37. public SellList(L2PcInstance player)
  38. {
  39. _activeChar = player;
  40. _lease = null;
  41. _money = _activeChar.getAdena();
  42. doLease();
  43. }
  44.  
  45. public SellList(L2PcInstance player, L2MerchantInstance lease)
  46. {
  47. _activeChar = player;
  48. _lease = lease;
  49. _money = _activeChar.getAdena();
  50. doLease();
  51. }
  52.  
  53. private void doLease()
  54. {
  55. if (_lease == null)
  56. {
  57. for (L2ItemInstance item : _activeChar.getInventory().getItems())
  58. {
  59. if (!item.isEquipped() && item.isSellable() && (!_activeChar.hasSummon() || (item.getObjectId() != _activeChar.getSummon().getControlObjectId()))) // Pet is summoned and not the item that summoned the pet
  60. {
  61. _selllist.add(item);
  62. }
  63. }
  64. }
  65. }
  66.  
  67. @Override
  68. protected final void writeImpl()
  69. {
  70. writeC(0x06);
  71. writeQ(_money);
  72. writeD(_lease == null ? 0x00 : 1000000 + _lease.getTemplate().getId());
  73. writeH(_selllist.size());
  74.  
  75. for (L2ItemInstance item : _selllist)
  76. {
  77. writeH(item.getItem().getType1());
  78. writeD(item.getObjectId());
  79. writeD(item.getDisplayId());
  80. writeQ(item.getCount());
  81. writeH(item.getItem().getType2());
  82. writeH(item.isEquipped() ? 0x01 : 0x00);
  83. writeD(item.getItem().getBodyPart());
  84. writeH(item.getEnchantLevel());
  85. writeH(0x00); // TODO: Verify me
  86. writeH(item.getCustomType2());
  87. writeQ(1);
  88. // T1
  89. writeH(item.getAttackElementType());
  90. writeH(item.getAttackElementPower());
  91. for (byte i = 0; i < 6; i++)
  92. {
  93. writeH(item.getElementDefAttr(i));
  94. }
  95. // Enchant Effects
  96. for (int op : item.getEnchantOptions())
  97. {
  98. writeH(op);
  99. }
  100. }
  101. }
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. RequestSellItem.java
  111.  
  112. /*
  113. * Copyright (C) 2004-2015 L2J Server
  114. *
  115. * This file is part of L2J Server.
  116. *
  117. * L2J Server is free software: you can redistribute it and/or modify
  118. * it under the terms of the GNU General Public License as published by
  119. * the Free Software Foundation, either version 3 of the License, or
  120. * (at your option) any later version.
  121. *
  122. * L2J Server is distributed in the hope that it will be useful,
  123. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  124. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  125. * General Public License for more details.
  126. *
  127. * You should have received a copy of the GNU General Public License
  128. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  129. */
  130. package l2r.gameserver.network.clientpackets;
  131.  
  132. import static l2r.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE;
  133. import static l2r.gameserver.model.itemcontainer.Inventory.MAX_ADENA;
  134.  
  135. import java.util.ArrayList;
  136. import java.util.List;
  137.  
  138. import l2r.Config;
  139. import l2r.gameserver.data.xml.impl.BuyListData;
  140. import l2r.gameserver.model.L2Object;
  141. import l2r.gameserver.model.actor.L2Character;
  142. import l2r.gameserver.model.actor.instance.L2MerchantInstance;
  143. import l2r.gameserver.model.actor.instance.L2PcInstance;
  144. import l2r.gameserver.model.buylist.L2BuyList;
  145. import l2r.gameserver.model.holders.UniqueItemHolder;
  146. import l2r.gameserver.model.items.instance.L2ItemInstance;
  147. import l2r.gameserver.network.serverpackets.ActionFailed;
  148. import l2r.gameserver.network.serverpackets.ExBuySellList;
  149. import l2r.gameserver.network.serverpackets.StatusUpdate;
  150. import l2r.gameserver.util.Util;
  151.  
  152. /**
  153. * RequestSellItem client packet class.
  154. */
  155. public final class RequestSellItem extends L2GameClientPacket
  156. {
  157. private static final String _C__37_REQUESTSELLITEM = "[C] 37 RequestSellItem";
  158.  
  159. private static final int BATCH_LENGTH = 16;
  160.  
  161. private int _listId;
  162. private List<UniqueItemHolder> _items = null;
  163.  
  164. @Override
  165. protected void readImpl()
  166. {
  167. _listId = readD();
  168. int size = readD();
  169. if ((size <= 0) || (size > Config.MAX_ITEM_IN_PACKET) || ((size * BATCH_LENGTH) != _buf.remaining()))
  170. {
  171. return;
  172. }
  173.  
  174. _items = new ArrayList<>(size);
  175. for (int i = 0; i < size; i++)
  176. {
  177. int objectId = readD();
  178. int itemId = readD();
  179. long count = readQ();
  180. if ((objectId < 1) || (itemId < 1) || (count < 1))
  181. {
  182. _items = null;
  183. return;
  184. }
  185. _items.add(new UniqueItemHolder(itemId, objectId, count));
  186. }
  187. }
  188.  
  189. @Override
  190. protected void runImpl()
  191. {
  192. processSell();
  193. }
  194.  
  195. protected void processSell()
  196. {
  197. L2PcInstance player = getClient().getActiveChar();
  198.  
  199. if (player == null)
  200. {
  201. return;
  202. }
  203.  
  204. if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy"))
  205. {
  206. player.sendMessage("You are buying too fast.");
  207. return;
  208. }
  209.  
  210. if (_items == null)
  211. {
  212. sendPacket(ActionFailed.STATIC_PACKET);
  213. return;
  214. }
  215.  
  216. // Alt game - Karma punishment
  217. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (player.getKarma() > 0))
  218. {
  219. sendPacket(ActionFailed.STATIC_PACKET);
  220. return;
  221. }
  222.  
  223. L2Object target = player.getTarget();
  224. L2Character merchant = null;
  225. if (!player.isGM() && !player.isAioMultisell())
  226. {
  227. if ((target == null) || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) // Distance is too far)
  228. || (player.getInstanceId() != target.getInstanceId()))
  229. {
  230. sendPacket(ActionFailed.STATIC_PACKET);
  231. return;
  232. }
  233. if (target instanceof L2MerchantInstance)
  234. {
  235. merchant = (L2Character) target;
  236. }
  237. else
  238. {
  239. sendPacket(ActionFailed.STATIC_PACKET);
  240. return;
  241. }
  242. }
  243.  
  244. double taxRate = 0;
  245.  
  246. if (_listId != -1)
  247. {
  248. final L2BuyList buyList = BuyListData.getInstance().getBuyList(_listId);
  249. if ((buyList == null))
  250. {
  251. Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
  252. return;
  253. }
  254.  
  255. if ((merchant != null))
  256. {
  257. if (merchant instanceof L2MerchantInstance)
  258. {
  259. if (!buyList.isNpcAllowed(((L2MerchantInstance) merchant).getId()))
  260. {
  261. sendPacket(ActionFailed.STATIC_PACKET);
  262. return;
  263. }
  264. }
  265. }
  266. }
  267.  
  268. long totalPrice = 0;
  269. // Proceed the sell
  270. for (UniqueItemHolder i : _items)
  271. {
  272. L2ItemInstance item = player.checkItemManipulation(i.getObjectId(), i.getCount(), "sell");
  273. if ((item == null) || (!item.isSellable()))
  274. {
  275. continue;
  276. }
  277.  
  278. long price = item.getReferencePrice() / 1;
  279. totalPrice += price * i.getCount();
  280. if (((MAX_ADENA / i.getCount()) < price) || (totalPrice > MAX_ADENA))
  281. {
  282. Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
  283. return;
  284. }
  285.  
  286. if (Config.ALLOW_REFUND)
  287. {
  288. item = player.getInventory().transferItem("Sell", i.getObjectId(), i.getCount(), player.getRefund(), player, merchant);
  289. }
  290. else
  291. {
  292. item = player.getInventory().destroyItem("Sell", i.getObjectId(), i.getCount(), player, merchant);
  293. }
  294. }
  295. player.addAdena("Sell", 1, merchant, false);
  296.  
  297. // Update current load as well
  298. StatusUpdate su = player.makeStatusUpdate(StatusUpdate.CUR_LOAD);
  299. player.sendPacket(su);
  300. player.sendPacket(new ExBuySellList(player, taxRate, true));
  301. }
  302.  
  303. @Override
  304. public String getType()
  305. {
  306. return _C__37_REQUESTSELLITEM;
  307. }
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement