示例#1
0
  public List<Pair<Item, String>> loadGifts() {
    List<Pair<Item, String>> gifts = new ArrayList<>();
    Connection con = DatabaseConnection.getConnection();
    try {
      PreparedStatement ps = con.prepareStatement("SELECT * FROM `gifts` WHERE `recipient` = ?");
      ps.setInt(1, characterId);
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        CashItemInfo cItem = CashItemFactory.getInstance().getItem(rs.getInt("sn"));
        if (cItem == null) {
          continue;
        }
        Item item = toItem(cItem, rs.getInt("uniqueid"), rs.getString("from"));
        gifts.add(new Pair<>(item, rs.getString("message")));
        uniqueids.add(item.getUniqueId());
        List<Integer> packages = CashItemFactory.getInstance().getPackageItems(cItem.getId());
        if (packages != null && packages.size() > 0) {
          for (int packageItem : packages) {
            CashItemInfo pack = CashItemFactory.getInstance().getSimpleItem(packageItem);
            if (pack != null) {
              addToInventory(toItem(pack, rs.getString("from")));
            }
          }
        } else {
          addToInventory(item);
        }
      }

      rs.close();
      ps.close();
      ps = con.prepareStatement("DELETE FROM `gifts` WHERE `recipient` = ?");
      ps.setInt(1, characterId);
      ps.executeUpdate();
      ps.close();
      save();
    } catch (SQLException sqle) {
    }
    return gifts;
  }
示例#2
0
 public Item toItem(CashItemInfo cItem, int uniqueid, String gift) {
   if (uniqueid <= 0) {
     uniqueid = MapleInventoryIdentifier.getInstance();
   }
   long period = cItem.getPeriod();
   if ((period <= 0 && GameConstants.getInventoryType(cItem.getId()) != MapleInventoryType.EQUIP)
       || GameConstants.isPet(cItem.getId())) {
     period = GameConstants.GMS ? 90 : 45;
   }
   if (cItem.getId() >= 5000100 && cItem.getId() < 5000200) { // permanent pet
     period = 20000; // permanent time millis
   }
   Item ret;
   if (GameConstants.getInventoryType(cItem.getId()) == MapleInventoryType.EQUIP) {
     Equip eq =
         (Equip) MapleItemInformationProvider.getInstance().getEquipById(cItem.getId(), uniqueid);
     if (period > 0) {
       eq.setExpiration(
           (long) (System.currentTimeMillis() + (long) (period * 24 * 60 * 60 * 1000)));
     }
     eq.setGMLog("Cash Shop: " + cItem.getSN() + " on " + FileoutputUtil.CurrentReadable_Date());
     eq.setGiftFrom(gift);
     if (GameConstants.isEffectRing(cItem.getId()) && uniqueid > 0) {
       MapleRing ring = MapleRing.loadFromDb(uniqueid);
       if (ring != null) {
         eq.setRing(ring);
       }
     }
     ret = eq.copy();
   } else {
     Item item = new Item(cItem.getId(), (byte) 0, (short) cItem.getCount(), (byte) 0, uniqueid);
     if (period > 0) {
       item.setExpiration(
           (long) (System.currentTimeMillis() + (long) (period * 24 * 60 * 60 * 1000)));
     }
     item.setGMLog("Cash Shop: " + cItem.getSN() + " on " + FileoutputUtil.CurrentReadable_Date());
     item.setGiftFrom(gift);
     if (GameConstants.isPet(cItem.getId())) {
       final MaplePet pet = MaplePet.createPet(cItem.getId(), uniqueid);
       if (pet != null) {
         item.setPet(pet);
       }
     }
     ret = item.copy();
   }
   return ret;
 }
示例#3
0
 public Item toItem(CashItemInfo cItem, String gift) {
   return toItem(cItem, MapleInventoryManipulator.getUniqueId(cItem.getId(), null), gift);
 }