示例#1
0
 public static int amountCanHold(ItemStack[] items, JItem check, boolean extraStack) {
   int amt = 0;
   if (items == null) {
     return 0;
   } else if (check == null) {
     return emptySlots(items);
   } else if (check.isEntity()) {
     return -1;
   } else if (check.isKit()) {
     Kit kit = check instanceof Kit ? (Kit) check : JItemDB.getKit(check);
     Kit.KitItem kititems[] = kit.getKitItems();
     ItemStack invCopy[] = copy(items);
     // loop through & "add" one at a time
     while (true) {
       int numtoadd = 0;
       for (int itn = 0; itn < kititems.length; ++itn) {
         numtoadd = kititems[itn].itemAmount;
         int maxStack =
             !extraStack || noStack.contains(kititems[itn].ID())
                 ? kititems[itn].MaxStackSize()
                 : 64;
         for (int i = 0; i < invCopy.length && numtoadd > 0; ++i) {
           if (invCopy[i] == null || invCopy[i].getAmount() == 0) {
             invCopy[i] = kititems[itn].toItemStack();
             invCopy[i].setAmount(numtoadd);
             numtoadd -= numtoadd;
           } else if (invCopy[i].getAmount() < maxStack && kititems[itn].iequals(invCopy[i])) {
             int d = maxStack < numtoadd ? maxStack : numtoadd;
             invCopy[i].setAmount(invCopy[i].getAmount() + d);
             numtoadd -= d;
           }
         }
         if (numtoadd > 0) {
           // has scanned through full stack & cannot add more
           return amt;
         }
       }
       // 1 was added to the copy
       ++amt;
     }
   } else {
     for (ItemStack item : items) {
       int mx =
           !extraStack || (item != null && noStack.contains(item.getTypeId()))
               ? check.MaxStackSize()
               : 64;
       if (item == null
           || item.getAmount() == 0
           || (check.equals(item) && item.getAmount() <= mx)) {
         amt += mx - (item == null ? 0 : item.getAmount());
       }
     }
   }
   return amt;
 }
示例#2
0
  public static ItemStack[] add(ItemStack[] items, JItem toAdd, int amt, boolean extraStack) {
    if (items == null) {
      return null;
    } else if (toAdd == null) {
      return items;
    } else if (toAdd.IsValidItem()) {
      int mx = !extraStack || noStack.contains(toAdd.ID()) ? toAdd.MaxStackSize() : 64;
      while (amt > 0) {
        add(items, toAdd.toItemStack(amt > mx ? mx : amt), extraStack);
        amt -= mx;
      }
      return items;
    } else if (toAdd.isKit()) {
      Kit kit = toAdd instanceof Kit ? (Kit) toAdd : JItemDB.getKit(toAdd);
      Kit.KitItem kititems[] = kit.getKitItems();

      // add one of each until fails
      for (int num = 0; num < amt; ++num) {
        int numtoadd = 0;
        for (int itn = 0; itn < kit.numItems(); ++itn) {
          numtoadd = kititems[itn].itemAmount;
          int maxStack =
              !extraStack || noStack.contains(kititems[itn].ID())
                  ? kititems[itn].MaxStackSize()
                  : 64;
          for (int i = 0; i < items.length && numtoadd > 0; ++i) {
            if (items[i] == null || items[i].getAmount() == 0) {
              items[i] = kititems[itn].toItemStack();
              items[i].setAmount(numtoadd);
              numtoadd -= numtoadd;
            } else if (items[i].getAmount() < maxStack && kititems[itn].iequals(items[i])) {
              int d = maxStack < numtoadd ? maxStack : numtoadd;
              items[i].setAmount(items[i].getAmount() + d);
              numtoadd -= d;
            }
          }
          if (numtoadd > 0) {
            break;
          }
        }
        if (numtoadd > 0) {
          // early exit while adding
          break;
        }
      }
    }
    return items;
  }
示例#3
0
 public boolean remove(String s) throws SQLException, Exception {
   return remove(JItemDB.findItem(s));
 }
示例#4
0
 public double getBuyPrice(String s) throws SQLException, Exception {
   return getBuyPrice(JItemDB.findItem(s));
 }
示例#5
0
 public boolean setPrice(String item, double b, double s)
     throws SQLException, IOException, Exception {
   return setPrice(JItemDB.findItem(item), b, s);
 }
示例#6
0
 public double getSellPrice(ItemStockEntry it) throws SQLException, Exception {
   return getSellPrice(JItemDB.GetItem(it.itemNum, (byte) it.itemSub));
 }
示例#7
0
 public double getSellPrice(ItemStack i) throws SQLException, Exception {
   return getSellPrice(JItemDB.findItem(i));
 }
示例#8
0
 public boolean itemExists(ItemStack check) throws SQLException, Exception {
   return itemExists(JItemDB.findItem(check));
 }
示例#9
0
 public boolean itemExists(ItemStockEntry i) throws SQLException, Exception {
   return itemExists(JItemDB.GetItem(i.itemNum, (byte) i.itemSub));
 }
示例#10
0
  public boolean loadFile(File toload) throws IOException, Exception {
    if (toload != null) {
      databaseType = DBType.FLATFILE;
      flatFile = toload;
      priceList.clear();
      if (toload.exists()) {
        isLoaded = false;
        FileReader fstream = null;
        try {
          fstream = new FileReader(toload.getAbsolutePath());
          BufferedReader in = new BufferedReader(fstream);
          try {
            int n = 0;
            for (String line = null; (line = in.readLine()) != null && line.length() > 0; ++n) {
              // if was edited in openoffice, will instead have semicolins..
              String fields[] = line.replace(";", ",").replace(",,", ", ,").split(",");

              if (fields.length > 4) {
                if (n == 0 && fields[0].equals("id")) {
                  continue;
                }
                JItem plItem =
                    JItemDB.findItem(fields[0] + ":" + (fields[1].equals(" ") ? "0" : fields[1]));
                if (plItem != null) {
                  // priceList.add(new PriceListItem(plItem, fields[2].length() == 0 ? -1 :
                  // CheckInput.GetDouble(fields[2], -1), fields[3].length() == 0 ? -1 :
                  // CheckInput.GetDouble(fields[3], -1)));
                  priceList.add(
                      new PriceListItem(
                          plItem,
                          fields[2].equals(" ") ? -1 : CheckInput.GetDouble(fields[2], -1),
                          fields[3].equals(" ") ? -1 : CheckInput.GetDouble(fields[3], -1)));
                } else if (n > 0) { // first line is expected invalid: is title
                  logger.log(
                      Level.WARNING,
                      String.format(
                          "Invalid item on line %d in %s (%s)",
                          (n + 1),
                          toload.getName(),
                          fields[0]
                              + ":"
                              + (fields[1].equals(" ") ? "0" : fields[1])
                              + (fields.length <= 4 ? "" : " [" + fields[4] + "]")));
                }
              } else {
                logger.log(
                    Level.WARNING,
                    String.format(
                        "unexpected pricelist line at %d in %s", (n + 1), toload.getName()));
              }
            }
          } finally {
            in.close();
          }
        } catch (IOException ex) {
          if (!log_nothrow) {
            throw new IOException("Error opening " + toload.getName() + " for reading", ex);
          }
          logger.log(Level.SEVERE, "Error opening " + toload.getName() + " for reading", ex);
        } finally {
          if (fstream != null) {
            try {
              fstream.close();
            } catch (IOException ex) {
              if (!log_nothrow) {
                throw new IOException("Error closing " + toload.getName(), ex);
              }
              logger.log(Level.SEVERE, "Error closing " + toload.getName(), ex);
            }
          }
        }
        return isLoaded = true && save();
      } else { // !toload.exists()
        // still set as loaded
        isLoaded = true;
        return save();
      }
    }
    return false;
  }