Example #1
0
 /**
  * Gets all the equipped items.
  *
  * @return an array instance of <code>Item</code>
  */
 public static Item[] getItems() {
   final Widget widget = getWidget();
   if (widget != null) {
     final boolean isBank = widget.getIndex() != WIDGET;
     final WidgetChild[] equip =
         (isBank)
             ? widget.getChild(COMPONENT_EQUIP_INVENTORY).getChildren()
             : widget.getChildren();
     if (equip.length > 0) {
       if (!isBank) {
         final Item[] items = new Item[NUM_SLOTS];
         final Slot[] slots = Slot.values();
         for (int i = 0; i < NUM_SLOTS; i++) {
           items[i] = new Item(equip[slots[i].getComponentIndex()]);
         }
         return items;
       } else {
         final Item[] items = new Item[equip.length];
         for (int i = 0; i < items.length; i++) {
           items[i] = new Item(equip[i]);
         }
         return items;
       }
     }
   }
   return new Item[0];
 }
Example #2
0
 /**
  * Gets the equipped item at the given index.
  *
  * @param slot the <code>Slot</code> of the item
  * @return an <code>Item</code>; otherwise <code>null</code> if invalid
  */
 public static Item getItem(final Slot slot) {
   final Widget widget = getWidget();
   if (widget != null && widget.validate()) {
     try {
       final WidgetChild itemComp =
           (widget.getIndex() == WIDGET_BANK)
               ? widget.getChild(COMPONENT_EQUIP_INVENTORY).getChild(slot.getBankComponentIndex())
               : widget.getChild(slot.getComponentIndex());
       if (itemComp != null) {
         return new Item(itemComp);
       }
     } catch (IndexOutOfBoundsException ignored) {
     }
   }
   return null;
 }
Example #3
0
 /**
  * Gets the equipped item at the given index from the last known array of items.
  *
  * @param slot the <code>Slot</code> of the item
  * @return an <code>Item</code>; otherwise <code>null</code> if invalid
  */
 public static Item getCachedItem(final Slot slot) {
   final Widget cache = Widgets.get(WIDGET);
   if (cache != null && cache.validate()) {
     try {
       return new Item(cache.getChild(slot.getComponentIndex()));
     } catch (ArrayIndexOutOfBoundsException ignored) {
     }
   }
   return null;
 }