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 static void drop(MapleClient c, MapleInventoryType type, short src, short quantity) { if (src < 0) { type = MapleInventoryType.EQUIPPED; } IItem source = c.getPlayer().getInventory(type).getItem(src); int Id = source.getId(); if (c.getPlayer().getItemEffect() == Id && source.getQuantity() == 1) { c.getPlayer().setItemEffect(0); c.getPlayer().getMap().broadcastMessage(EffectFactory.itemEffect(c.getPlayer().getId(), 0)); } else if (Id == 5370000 || Id == 5370001) { // not actually possible if (c.getPlayer().getItemQuantity(Id, false) == 1) { c.getPlayer().setChalkboard(null); } } else if ((Id >= 5000000 && Id <= 5000100) || Id == 4031284) { c.getPlayer().dropMessage("This item may not be dropped."); return; } if (c.getPlayer().getItemQuantity(Id, true) < quantity || quantity < 0 || source == null || source.getFlag() == InventoryConstants.LOCK || (quantity == 0 && !InventoryConstants.isRechargable(Id))) { return; } Point dropPos = new Point(c.getPlayer().getPosition()); if (quantity < source.getQuantity() && !InventoryConstants.isRechargable(Id)) { IItem target = source.copy(); target.setQuantity(quantity); source.setQuantity((short) (source.getQuantity() - quantity)); c.announce(InventoryFactory.dropInventoryItemUpdate(type, source)); dropItem(c, target, dropPos); } else { c.getPlayer().getInventory(type).removeSlot(src); c.announce( InventoryFactory.dropInventoryItem((src < 0 ? MapleInventoryType.EQUIP : type), src)); if (src < 0) { c.getPlayer().equipChanged(); } dropItem(c, source, dropPos); } }
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) { } } }