示例#1
0
  public void saveItems(boolean shutdown) throws SQLException {
    List<ItemInventoryEntry> itemsWithType = new ArrayList<ItemInventoryEntry>();

    for (MaplePlayerShopItem pItems : items) {
      IItem newItem = pItems.getItem();
      if (shutdown) {
        newItem.setQuantity((short) (pItems.getItem().getQuantity() * pItems.getBundles()));
      } else {
        newItem.setQuantity(pItems.getItem().getQuantity());
      }
      if (pItems.getBundles() > 0) {
        itemsWithType.add(
            new ItemInventoryEntry(newItem, MapleInventoryType.getByType(newItem.getType())));
      }
    }
    ItemFactory.MERCHANT.saveItems(itemsWithType, this.ownerId);
  }
 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 static boolean addFromDrop(
     final MapleClient c, final IItem item, final boolean show, final boolean showAnyMessage) {
   final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   if (ii.isPickupRestricted(item.getId())
       && c.getPlayer().getItemQuantity(item.getId(), true) > 0
       && showAnyMessage) {
     c.announce(InventoryFactory.getInventoryFull());
     c.announce(InventoryFactory.showItemUnavailable());
     return false;
   }
   final MapleInventoryType type = ii.getInventoryType(item.getId());
   short quantity = item.getQuantity();
   if (!type.equals(MapleInventoryType.EQUIP)) {
     final short slotMax = ii.getSlotMax(c, item.getId());
     final List<IItem> existing = c.getPlayer().getInventory(type).listById(item.getId());
     if (!InventoryConstants.isRechargable(item.getId())) {
       if (existing.size() > 0) { // first update all existing slots to slotMax
         Iterator<IItem> i = existing.iterator();
         while (quantity > 0) {
           if (i.hasNext()) {
             final Item eItem = (Item) i.next();
             final short oldQ = eItem.getQuantity();
             if (oldQ < slotMax && item.getOwner().equals(eItem.getOwner())) {
               short newQ = (short) Math.min(oldQ + quantity, slotMax);
               quantity -= (newQ - oldQ);
               eItem.setQuantity(newQ);
               short newQi = (short) Math.min(quantity, slotMax);
               quantity -= newQi;
               Item nItem = new Item(item.getId(), (short) 0, newQi);
               nItem.setOwner(item.getOwner());
               if (c.getPlayer().getInventory(type).fakeAddItem(nItem) == -1) {
                 eItem.setQuantity(oldQ);
                 return false;
               }
               quantity += newQi;
               c.announce(InventoryFactory.updateInventorySlot(type, eItem, showAnyMessage));
             }
           } else {
             break;
           }
         }
       }
       while (quantity > 0 || InventoryConstants.isRechargable(item.getId())) {
         final short newQ = (short) Math.min(quantity, slotMax);
         quantity -= newQ;
         final Item nItem = new Item(item.getId(), (short) 0, newQ);
         nItem.setOwner(item.getOwner());
         final short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
         if (newSlot == -1) {
           if (showAnyMessage) {
             c.announce(InventoryFactory.getInventoryFull());
             c.announce(InventoryFactory.getShowInventoryFull());
           }
           item.setQuantity((short) (quantity + newQ));
           return false;
         }
         c.announce(InventoryFactory.addInventorySlot(type, nItem, true));
         if ((InventoryConstants.isRechargable(item.getId())) && quantity == 0) {
           break;
         }
       }
     } else {
       final Item nItem = new Item(item.getId(), (short) 0, quantity);
       final short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
       if (newSlot == -1) {
         if (showAnyMessage) {
           c.announce(InventoryFactory.getInventoryFull());
           c.announce(InventoryFactory.getShowInventoryFull());
         }
         return false;
       }
       c.announce(InventoryFactory.addInventorySlot(type, nItem));
       c.announce(IntraPersonalFactory.enableActions());
     }
   } else if (quantity == 1) {
     final short newSlot = c.getPlayer().getInventory(type).addItem(item);
     if (newSlot == -1) {
       if (showAnyMessage) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
       }
       return false;
     }
     c.announce(InventoryFactory.addInventorySlot(type, item, true));
   } else {
     return false;
   }
   if (show) {
     c.announce(EffectFactory.getShowItemGain(item.getId(), item.getQuantity()));
   }
   return true;
 }
示例#4
0
 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) {
     }
   }
 }