コード例 #1
0
 /**
  * Gets the count of all the inventory items matching with any of the provided ids.
  *
  * @param includeStacks <tt>true</tt> to count the stack sizes of each item; otherwise
  *     <tt>false</tt>
  * @param itemIds the item ids to include
  * @return the count
  */
 public static int getCount(boolean includeStacks, int... itemIds) {
   int count = 0;
   Item[] items = getItems(itemIds);
   for (Item item : items) {
     if (item == null) continue;
     int itemId = item.getId();
     if (itemId != -1) {
       count += includeStacks ? item.getStackSize() : 1;
     }
   }
   return count;
 }
コード例 #2
0
 /**
  * Uses an inventory item on either another inventory item or a game object.
  *
  * @param item the inventory item to use
  * @param target the inventory item or the game object to be used on by the inventory item
  * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game
  *     object/other inventory item; otherwise <tt>false</tt>
  */
 private static boolean useItem(Item item, Object target) {
   if (isItemSelected()) {
     Item selectedItem = getSelectedItem();
     int selectedItemId = selectedItem.getId();
     if (item.getId() != selectedItemId) {
       if (!selectedItem.interact("Cancel")) {
         return false;
       }
     } else if (target instanceof Item) {
       Item t = (Item) target;
       if (selectedItemId != t.getId() && selectedItemId != item.getId()) {
         if (!selectedItem.interact("Cancel")) {
           return false;
         }
       }
     }
   }
   for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) {
     if (isItemSelected()) {
       boolean success = false;
       for (int j = 0, k = Random.nextInt(5, 8); j < k; j++) {
         try {
           Item t = (Item) target;
           if (t.interact("Use")) {
             success = true;
             break;
           }
           Task.sleep(150, 300);
         } catch (final ClassCastException e) {
           return false;
         }
       }
       return success;
     }
     item.interact("Use");
     Task.sleep(150, 300);
   }
   return false;
 }
コード例 #3
0
 /**
  * Gets the count of all the inventory items excluding any of the provided ids.
  *
  * @param includeStacks <tt>true</tt> to count the stack sizes of each item; otherwise
  *     <tt>false</tt>
  * @param ids the ids to exclude
  * @return the count
  */
 public static int getCountExcept(boolean includeStacks, int... ids) {
   int count = 0;
   Item[] items = getItems();
   outer:
   for (Item item : items) {
     if (item == null) continue;
     int itemId = item.getId();
     for (int id : ids) {
       if (itemId == id) continue outer;
     }
     count += includeStacks ? item.getStackSize() : 1;
   }
   return count;
 }