Пример #1
0
 public int countGeneralStackSize() {
   int count = 0;
   for (PersistentBuyCraftStack stack : this.items) {
     count += stack.getAmount();
   }
   return count;
 }
Пример #2
0
 @Override
 public String toString() {
   String txt = "BuyCraftInventory={ ";
   for (PersistentBuyCraftStack stack : this.items) {
     txt += "\r\n" + stack.toString() + " ; ";
   }
   txt += "}";
   return txt;
 }
Пример #3
0
 public int countItemStack(int TypeID, short SubID) {
   int count = 0;
   for (PersistentBuyCraftStack stack : this.items) {
     if (stack.equals(TypeID, SubID)) {
       count += stack.getAmount();
     }
   }
   return count;
 }
Пример #4
0
  public boolean removeItem(UserShop shop, int TypeID, short SubID, int Amount) {
    // make a copy of all current itemstacks
    ArrayList<BuyCraftStack> tempStacks = new ArrayList<BuyCraftStack>();
    for (PersistentBuyCraftStack stack : this.items) {
      tempStacks.add(new BuyCraftStack(stack.getTypeID(), stack.getSubID(), stack.getAmount()));
    }

    // clear inventory from DB and internally
    DatabaseManager.getInstance().removeInventory(shop);
    this.clearItems();

    // reduce the amount of the item
    int reduceAmount = Amount;
    for (BuyCraftStack stack : tempStacks) {
      // wrong type => continue
      if (!stack.equals(TypeID, SubID)) {
        continue;
      }

      // reduce it
      if (stack.getAmount() >= reduceAmount) {
        stack.setAmount(stack.getAmount() - reduceAmount);
        reduceAmount = 0;
      } else {
        // so we need to split it
        reduceAmount -= stack.getAmount();
        stack.setAmount(0);
      }

      // completely reduced?
      if (reduceAmount < 1) break;
    }

    // finally write the new items into the database
    for (BuyCraftStack stack : tempStacks) {
      // Amount < 1 => continue
      if (stack.getAmount() < 1) {
        continue;
      }

      // Add the item. If this fails, there is an internal error
      if (!this.addItem(shop, stack.getTypeID(), stack.getSubID(), stack.getAmount())) {
        return false;
      }
    }

    return true;
  }