private void complete2() { items.clear(); meso = 0; for (IItem item : exchangeItems) { if ((item.getFlag() & InventoryConstants.KARMA) == InventoryConstants.KARMA) { item.setFlag( (byte) (item.getFlag() ^ InventoryConstants .KARMA)); // items with scissors of karma used on them are reset once traded } MapleInventoryManipulator.addFromDrop(chr.getClient(), item, true); } if (exchangeMeso > 0) { int overflow = chr.updateMesosGetOverflow(exchangeMeso - getFee(exchangeMeso)); partner.chr.gainMeso(overflow, true); } exchangeMeso = 0; if (exchangeItems != null) { exchangeItems.clear(); } chr.getClient().getSession().write(MaplePacketCreator.getTradeCompletion(number)); }
public void buy(MapleClient c, int item, short quantity) { MaplePlayerShopItem pItem = items.get(item); synchronized (items) { IItem newItem = pItem.getItem().copy(); newItem.setQuantity((short) ((pItem.getItem().getQuantity() * quantity))); if ((newItem.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA) { newItem.setFlag((byte) (newItem.getFlag() ^ ItemConstants.KARMA)); } if (newItem.getType() == IItem.ITEM && (newItem.getFlag() & ItemConstants.SPIKES) == ItemConstants.SPIKES) { newItem.setFlag((byte) (newItem.getFlag() ^ ItemConstants.SPIKES)); } if (quantity < 1 || pItem.getBundles() < 1 || !pItem.isExist() || pItem.getBundles() < quantity) { c.announce(MaplePacketCreator.enableActions()); return; } else if (newItem.getType() == 1 && newItem.getQuantity() > 1) { c.announce(MaplePacketCreator.enableActions()); return; } else if (!pItem.isExist()) { c.announce(MaplePacketCreator.enableActions()); return; } int price = pItem.getPrice() * quantity; if (c.getPlayer().getMeso() >= price) { if (MapleInventoryManipulator.addFromDrop(c, newItem, true)) { c.getPlayer().gainMeso(-price, false); sold.add( new SoldItem(c.getPlayer().getName(), pItem.getItem().getItemId(), quantity, price)); pItem.setBundles((short) (pItem.getBundles() - quantity)); if (pItem.getBundles() < 1) { pItem.setDoesExist(false); } MapleCharacter owner = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterByName(ownerName); if (owner != null) { owner.addMerchantMesos(price); } else { try { PreparedStatement ps = DatabaseConnection.getConnection() .prepareStatement( "UPDATE characters SET MerchantMesos = MerchantMesos + " + price + " WHERE id = ?", Statement.RETURN_GENERATED_KEYS); ps.setInt(1, ownerId); ps.executeUpdate(); ps.close(); } catch (Exception e) { } } } else { c.getPlayer() .dropMessage( 1, "Your inventory is full. Please clean a slot before buying this item."); } } else { c.getPlayer().dropMessage(1, "You do not have enough mesos."); } try { this.saveItems(false); } catch (Exception e) { } } }