public static boolean checkSpace(
     final MapleClient c, final int Id, int quantity, final String owner) {
   final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   final MapleInventoryType type = ii.getInventoryType(Id);
   if (!type.equals(MapleInventoryType.EQUIP)) {
     final short slotMax = ii.getSlotMax(c, Id);
     final List<IItem> existing = c.getPlayer().getInventory(type).listById(Id);
     if (!InventoryConstants.isRechargable(Id)) {
       if (existing.size() > 0) {
         for (IItem eItem : existing) {
           final short oldQ = eItem.getQuantity();
           if (oldQ < slotMax && owner.equals(eItem.getOwner())) {
             final short newQ = (short) Math.min(oldQ + quantity, slotMax);
             quantity -= (newQ - oldQ);
           }
           if (quantity <= 0) {
             break;
           }
         }
       }
     }
     final int numSlotsNeeded;
     if (slotMax > 0) {
       numSlotsNeeded = (int) (Math.ceil(((double) quantity) / slotMax));
     } else if (InventoryConstants.isRechargable(Id)) {
       numSlotsNeeded = 1;
     } else {
       numSlotsNeeded = 1;
       System.out.println("checkSpace error");
     }
     return !c.getPlayer().getInventory(type).isFull(numSlotsNeeded - 1);
   } else {
     return !c.getPlayer().getInventory(type).isFull();
   }
 }
 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;
 }
예제 #3
0
 private void addItemToDB(IItem item, int quantity, int mesos, String sName, int recipientID) {
   Connection con = DatabaseConnection.getConnection();
   try {
     PreparedStatement ps =
         con.prepareStatement(
             "INSERT INTO dueypackages (RecieverId, SenderName, Mesos, TimeStamp, Checked, Type) VALUES (?, ?, ?, ?, ?, ?)");
     ps.setInt(1, recipientID);
     ps.setString(2, sName);
     ps.setInt(3, mesos);
     ps.setString(4, getCurrentDate());
     ps.setInt(5, 1);
     if (item == null) {
       ps.setInt(6, 3);
       ps.executeUpdate();
     } else {
       ps.setInt(6, item.getType());
       ps.executeUpdate();
       ResultSet rs = ps.getGeneratedKeys();
       rs.next();
       PreparedStatement ps2;
       if (item.getType() == 1) { // equips
         ps2 =
             con.prepareStatement(
                 "INSERT INTO dueyitems (PackageId, itemid, quantity, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
         Equip eq = (Equip) item;
         ps2.setInt(2, eq.getItemId());
         ps2.setInt(3, 1);
         ps2.setInt(4, eq.getUpgradeSlots());
         ps2.setInt(5, eq.getLevel());
         ps2.setInt(6, eq.getStr());
         ps2.setInt(7, eq.getDex());
         ps2.setInt(8, eq.getInt());
         ps2.setInt(9, eq.getLuk());
         ps2.setInt(10, eq.getHp());
         ps2.setInt(11, eq.getMp());
         ps2.setInt(12, eq.getWatk());
         ps2.setInt(13, eq.getMatk());
         ps2.setInt(14, eq.getWdef());
         ps2.setInt(15, eq.getMdef());
         ps2.setInt(16, eq.getAcc());
         ps2.setInt(17, eq.getAvoid());
         ps2.setInt(18, eq.getHands());
         ps2.setInt(19, eq.getSpeed());
         ps2.setInt(20, eq.getJump());
         ps2.setString(21, eq.getOwner());
       } else {
         ps2 =
             con.prepareStatement(
                 "INSERT INTO dueyitems (PackageId, itemid, quantity, owner) VALUES (?, ?, ?, ?)");
         ps2.setInt(2, item.getItemId());
         ps2.setInt(3, quantity);
         ps2.setString(4, item.getOwner());
       }
       ps2.setInt(1, rs.getInt(1));
       ps2.executeUpdate();
       ps2.close();
       rs.close();
     }
     ps.close();
   } catch (SQLException e) {
   }
 }